mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
disable delete menuitem when dicts are builtin (since can't be deleted)
This commit is contained in:
parent
70f0a5fe90
commit
42a4a19911
2 changed files with 52 additions and 16 deletions
|
@ -89,8 +89,21 @@ public class DictsActivity extends ListActivity
|
|||
@Override
|
||||
public void onCreateContextMenu( ContextMenu menu, View view,
|
||||
ContextMenuInfo menuInfo ) {
|
||||
|
||||
super.onCreateContextMenu( menu, view, menuInfo );
|
||||
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate( R.menu.dicts_item_menu, menu );
|
||||
|
||||
AdapterView.AdapterContextMenuInfo info
|
||||
= (AdapterView.AdapterContextMenuInfo)menuInfo;
|
||||
|
||||
String dict = m_dicts[info.position];
|
||||
if ( GameUtils.dictIsBuiltin( this, dict ) ) {
|
||||
MenuItem item = menu.findItem( R.id.dicts_item_delete );
|
||||
item.setEnabled( false );
|
||||
// item.setVisible( false ) completely removes item
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -213,16 +213,10 @@ public class GameUtils {
|
|||
{
|
||||
ArrayList<String> al = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
AssetManager am = context.getAssets();
|
||||
String[] files = am.list("");
|
||||
for ( String file : files ) {
|
||||
if ( isDict( file ) ) {
|
||||
al.add( removeExtn( file ) );
|
||||
}
|
||||
for ( String file : getAssets( context ) ) {
|
||||
if ( isDict( file ) ) {
|
||||
al.add( removeExtn( file ) );
|
||||
}
|
||||
} catch( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
}
|
||||
|
||||
for ( String file : context.fileList() ) {
|
||||
|
@ -234,12 +228,24 @@ public class GameUtils {
|
|||
return al.toArray( new String[al.size()] );
|
||||
}
|
||||
|
||||
public static boolean dictIsBuiltin( Context context, String name )
|
||||
{
|
||||
boolean builtin = false;
|
||||
name = addDictExtn( name );
|
||||
|
||||
for ( String file : getAssets( context ) ) {
|
||||
if ( file.equals( name ) ) {
|
||||
builtin = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return builtin;
|
||||
}
|
||||
|
||||
public static void deleteDict( Context context, String name )
|
||||
{
|
||||
if ( ! name.endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
name += XWConstants.DICT_EXTN;
|
||||
}
|
||||
context.deleteFile( name );
|
||||
context.deleteFile( addDictExtn( name ) );
|
||||
}
|
||||
|
||||
public static byte[] openDict( Context context, String name )
|
||||
|
@ -247,9 +253,7 @@ public class GameUtils {
|
|||
byte[] bytes = null;
|
||||
InputStream dict = null;
|
||||
|
||||
if ( ! name.endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
name += XWConstants.DICT_EXTN;
|
||||
}
|
||||
name = addDictExtn( name );
|
||||
|
||||
AssetManager am = context.getAssets();
|
||||
try {
|
||||
|
@ -328,4 +332,23 @@ public class GameUtils {
|
|||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private static String addDictExtn( String str )
|
||||
{
|
||||
if ( ! str.endsWith( XWConstants.DICT_EXTN ) ) {
|
||||
str += XWConstants.DICT_EXTN;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
private static String[] getAssets( Context context )
|
||||
{
|
||||
try {
|
||||
AssetManager am = context.getAssets();
|
||||
return am.list("");
|
||||
} catch( java.io.IOException ioe ) {
|
||||
Utils.logf( ioe.toString() );
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue