if the download dir doesn't exist (and on my "Blaze 4G" the function

getDownloadCacheDirectory() returns a path that doesn't) then don't
offer to move things there.
This commit is contained in:
Eric House 2012-11-03 17:26:43 -07:00
parent 27935752a8
commit 4dd094b2b3
2 changed files with 27 additions and 10 deletions

View file

@ -560,6 +560,11 @@ public class DictUtils {
return result; return result;
} }
public static boolean haveDownloadDir()
{
return null != getDownloadDir();
}
private static File getDownloadDir() private static File getDownloadDir()
{ {
File result = null; File result = null;

View file

@ -263,15 +263,6 @@ public class DictsActivity extends ExpandableListActivity
message = Utils.format( this, R.string.move_dictf, message = Utils.format( this, R.string.move_dictf,
m_adapter.getSelChildView().getText() ); m_adapter.getSelChildView().getText() );
String[] items = new String[3];
for ( int ii = 0; ii < 3; ++ii ) {
DictLoc loc = itemToRealLoc(ii);
if ( loc.equals( m_moveFromLoc ) ) {
m_moveFromItem = ii;
}
items[ii] = m_locNames[loc.ordinal()];
}
OnClickListener newSelLstnr = OnClickListener newSelLstnr =
new OnClickListener() { new OnClickListener() {
public void onClick( DialogInterface dlgi, int item ) { public void onClick( DialogInterface dlgi, int item ) {
@ -307,7 +298,8 @@ public class DictsActivity extends ExpandableListActivity
dialog = new AlertDialog.Builder( this ) dialog = new AlertDialog.Builder( this )
.setTitle( message ) .setTitle( message )
.setSingleChoiceItems( items, m_moveFromItem, newSelLstnr ) .setSingleChoiceItems( makeDictDirItems(), m_moveFromItem,
newSelLstnr )
.setPositiveButton( R.string.button_move, lstnr ) .setPositiveButton( R.string.button_move, lstnr )
.setNegativeButton( R.string.button_cancel, null ) .setNegativeButton( R.string.button_cancel, null )
.create(); .create();
@ -716,6 +708,26 @@ public class DictsActivity extends ExpandableListActivity
XWPrefs.setClosedLangs( this, asArray ); XWPrefs.setClosedLangs( this, asArray );
} }
private String[] makeDictDirItems()
{
boolean showDownload = DictUtils.haveDownloadDir();
int nItems = showDownload ? 3 : 2;
int nextI = 0;
String[] items = new String[nItems];
for ( int ii = 0; ii < 3; ++ii ) {
DictLoc loc = itemToRealLoc(ii);
if ( !showDownload && DictLoc.DOWNLOAD == loc ) {
continue;
}
if ( loc.equals( m_moveFromLoc ) ) {
m_moveFromItem = nextI;
}
items[nextI++] = m_locNames[loc.ordinal()];
}
return items;
}
private static Intent mkDownloadIntent( Context context, String dict_url ) private static Intent mkDownloadIntent( Context context, String dict_url )
{ {
Uri uri = Uri.parse( dict_url ); Uri uri = Uri.parse( dict_url );