mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-01 06:19:57 +01:00
Add a debug preference allowing to provide, or override, the download
dir. This will let users work around bugs on devices like my Blaze 4G where the OS gives the wrong path, and also allows testing. Inval DictUtil's dict cache eash time this is changed, so in effect adding a wrong path pref hides all dicts in the Downloads dir.
This commit is contained in:
parent
69108fd8a1
commit
3942a49cac
7 changed files with 54 additions and 15 deletions
|
@ -92,6 +92,7 @@
|
|||
<string name="key_na_browse">key_na_browse</string>
|
||||
<string name="key_na_values">key_na_values</string>
|
||||
<string name="key_enable_debug">key_enable_debug</string>
|
||||
<string name="key_download_path">key_download_path</string>
|
||||
|
||||
<!-- Nor is my email address -->
|
||||
<string name="email_author_email">xwords@eehouse.org</string>
|
||||
|
|
|
@ -2140,4 +2140,6 @@
|
|||
|
||||
<string name="default_loc">Store wordlists internally</string>
|
||||
<string name="default_loc_summary">(Not in external/sdcard memory)</string>
|
||||
|
||||
<string name="download_path_title">Downloads Directory</string>
|
||||
</resources>
|
||||
|
|
|
@ -299,6 +299,10 @@
|
|||
android:summary="Menuitems etc."
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<org.eehouse.android.xw4.XWEditTextPreference
|
||||
android:key="@string/key_download_path"
|
||||
android:title="@string/download_path_title"
|
||||
/>
|
||||
<CheckBoxPreference android:key="@string/key_show_sms"
|
||||
android:title="Show SMS sends, receives"
|
||||
android:defaultValue="false"
|
||||
|
|
|
@ -149,7 +149,8 @@ public class DictUtils {
|
|||
}
|
||||
|
||||
tryDir( context, getSDDir( context ), false, DictLoc.EXTERNAL, al );
|
||||
tryDir( context, getDownloadDir(), true, DictLoc.DOWNLOAD, al );
|
||||
tryDir( context, getDownloadDir( context ), true,
|
||||
DictLoc.DOWNLOAD, al );
|
||||
|
||||
s_dictListCache =
|
||||
al.toArray( new DictUtils.DictAndLoc[al.size()] );
|
||||
|
@ -248,7 +249,7 @@ public class DictUtils {
|
|||
File path = null;
|
||||
switch( loc ) {
|
||||
case DOWNLOAD:
|
||||
path = getDownloadsPathFor( name );
|
||||
path = getDownloadsPathFor( context, name );
|
||||
break;
|
||||
case EXTERNAL:
|
||||
path = getSDPathFor( context, name );
|
||||
|
@ -305,7 +306,7 @@ public class DictUtils {
|
|||
FileInputStream fis = null;
|
||||
if ( null == fis ) {
|
||||
if ( loc == DictLoc.UNKNOWN || loc == DictLoc.DOWNLOAD ) {
|
||||
File path = getDownloadsPathFor( name );
|
||||
File path = getDownloadsPathFor( context, name );
|
||||
if ( null != path && path.exists() ) {
|
||||
DbgUtils.logf( "loading %s from Download", name );
|
||||
fis = new FileInputStream( path );
|
||||
|
@ -365,7 +366,7 @@ public class DictUtils {
|
|||
File path;
|
||||
switch ( to ) {
|
||||
case DOWNLOAD:
|
||||
path = getDownloadsPathFor( name );
|
||||
path = getDownloadsPathFor( context, name );
|
||||
break;
|
||||
case EXTERNAL:
|
||||
path = getSDPathFor( context, name );
|
||||
|
@ -560,30 +561,36 @@ public class DictUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
public static boolean haveDownloadDir()
|
||||
public static boolean haveDownloadDir( Context context )
|
||||
{
|
||||
return null != getDownloadDir();
|
||||
return null != getDownloadDir( context );
|
||||
}
|
||||
|
||||
private static File getDownloadDir()
|
||||
private static File getDownloadDir( Context context )
|
||||
{
|
||||
File result = null;
|
||||
if ( haveWriteableSD() ) {
|
||||
File storage = Environment.getExternalStorageDirectory();
|
||||
if ( null != storage ) {
|
||||
result = new File( storage.getPath(), "download/" );
|
||||
if ( !result.exists() ) {
|
||||
result = null;
|
||||
File file = null;
|
||||
String myPath = XWPrefs.getMyDownloadDir( context );
|
||||
if ( null != myPath && 0 < myPath.length() ) {
|
||||
file = new File( myPath );
|
||||
} else {
|
||||
file = Environment.getExternalStorageDirectory();
|
||||
if ( null != file ) {
|
||||
file = new File( file, "download/" );
|
||||
}
|
||||
}
|
||||
if ( null != file && file.exists() && file.isDirectory() ) {
|
||||
result = file;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static File getDownloadsPathFor( String name )
|
||||
private static File getDownloadsPathFor( Context context, String name )
|
||||
{
|
||||
File result = null;
|
||||
File dir = getDownloadDir();
|
||||
File dir = getDownloadDir( context );
|
||||
if ( dir != null ) {
|
||||
result = new File( dir, name );
|
||||
}
|
||||
|
|
|
@ -711,7 +711,7 @@ public class DictsActivity extends ExpandableListActivity
|
|||
|
||||
private String[] makeDictDirItems()
|
||||
{
|
||||
boolean showDownload = DictUtils.haveDownloadDir();
|
||||
boolean showDownload = DictUtils.haveDownloadDir( this );
|
||||
int nItems = showDownload ? 3 : 2;
|
||||
int nextI = 0;
|
||||
String[] items = new String[nItems];
|
||||
|
|
|
@ -29,6 +29,7 @@ import android.os.Bundle;
|
|||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import java.io.File;
|
||||
|
||||
public class PrefsActivity extends PreferenceActivity
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
@ -40,6 +41,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
private String m_keyLogging;
|
||||
private String m_smsToasting;
|
||||
private String m_smsEnable;
|
||||
private String m_downloadPath;
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
|
@ -120,6 +122,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
m_keyLogging = getString( R.string.key_logging_on );
|
||||
m_smsToasting = getString( R.string.key_show_sms );
|
||||
m_smsEnable = getString( R.string.key_enable_sms );
|
||||
m_downloadPath = getString( R.string.key_download_path );
|
||||
|
||||
Button button = (Button)findViewById( R.id.revert_colors );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
|
@ -164,6 +167,23 @@ public class PrefsActivity extends PreferenceActivity
|
|||
} else {
|
||||
XWPrefs.setHaveCheckedSMS( this, false );
|
||||
}
|
||||
} else if ( key.equals( m_downloadPath ) ) {
|
||||
String value = sp.getString( key, null );
|
||||
if ( null != value ) {
|
||||
File dir = new File( value );
|
||||
String msg = null;
|
||||
if ( !dir.exists() ) {
|
||||
msg = String.format( "%s does not exist", value );
|
||||
} else if ( !dir.isDirectory() ) {
|
||||
msg = String.format( "%s is not a directory", value );
|
||||
} else if ( !dir.canWrite() ) {
|
||||
msg = String.format( "Cannot write to %s", value );
|
||||
}
|
||||
if ( null != msg ) {
|
||||
Utils.showToast( this, msg );
|
||||
}
|
||||
}
|
||||
DictUtils.invalDictList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -206,6 +206,11 @@ public class XWPrefs {
|
|||
: DictUtils.DictLoc.EXTERNAL;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getMyDownloadDir( Context context )
|
||||
{
|
||||
return getPrefsString( context, R.string.key_download_path );
|
||||
}
|
||||
|
||||
protected static String getPrefsString( Context context, int keyID )
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue