mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-09 22:00:39 +01:00
make default settable by sdk version
This is a better way to do it: use separate values that user doesn't see and so that they can be defined as defaults without worrying about translation.
This commit is contained in:
parent
cf553a0aed
commit
4ed46f6681
6 changed files with 44 additions and 24 deletions
|
@ -159,18 +159,10 @@ public class PrefsDelegate extends DelegateBase
|
|||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
SharedPreferences sp = getSharedPreferences();
|
||||
sp.registerOnSharedPreferenceChangeListener( this );
|
||||
getSharedPreferences().registerOnSharedPreferenceChangeListener( this );
|
||||
|
||||
// It's too early somehow to do this in init() above
|
||||
findViewById( R.id.prefs_menu ).setOnClickListener(this);
|
||||
|
||||
String key = LocUtils.getString( mActivity, R.string.key_theme_which );
|
||||
if ( null == sp.getString( key, null ) ) {
|
||||
Resources res = mActivity.getResources();
|
||||
String[] vals = res.getStringArray( R.array.color_themes );
|
||||
sp.edit().putString( key, vals[0] ).commit();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -52,6 +52,13 @@ public class XWListPreference extends ListPreference {
|
|||
@Override
|
||||
public void setSummary( CharSequence summary )
|
||||
{
|
||||
CharSequence[] entries = getEntries();
|
||||
if ( null != entries ) {
|
||||
int indx = findIndexOfValue( summary.toString() );
|
||||
if ( 0 <= indx && indx < entries.length ) {
|
||||
summary = entries[indx];
|
||||
}
|
||||
}
|
||||
String xlated = LocUtils.xlateString( getContext(), summary.toString() );
|
||||
if ( null != xlated ) {
|
||||
summary = xlated;
|
||||
|
|
|
@ -109,19 +109,28 @@ public class CommonPrefs extends XWPrefs {
|
|||
int strsID = R.array.color_ids_light;
|
||||
String which = LocUtils.getString( context, R.string.key_theme_which );
|
||||
which = sp.getString( which, null );
|
||||
if ( null == which ) {
|
||||
// do nothing
|
||||
} else if ( which.equals( LocUtils.getString( context,
|
||||
R.string.color_use_theme_light ) ) ) {
|
||||
// do nothing
|
||||
} else if ( which.equals( LocUtils.getString( context,
|
||||
R.string.color_use_theme_dark ) ) ) {
|
||||
strsID = R.array.color_ids_dark;
|
||||
} else {
|
||||
int uiMode = res.getConfiguration().uiMode;
|
||||
if ( Configuration.UI_MODE_NIGHT_YES
|
||||
== (uiMode & Configuration.UI_MODE_NIGHT_MASK) ) {
|
||||
strsID = R.array.color_ids_dark;
|
||||
if ( null != which ) {
|
||||
try {
|
||||
switch ( Integer.parseInt( which ) ) {
|
||||
case 0:
|
||||
// do nothing
|
||||
break;
|
||||
case 1:
|
||||
strsID = R.array.color_ids_dark;
|
||||
break;
|
||||
case 2:
|
||||
int uiMode = res.getConfiguration().uiMode;
|
||||
if ( Configuration.UI_MODE_NIGHT_YES
|
||||
== (uiMode & Configuration.UI_MODE_NIGHT_MASK) ) {
|
||||
strsID = R.array.color_ids_dark;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Assert.failDbg();
|
||||
}
|
||||
} catch ( Exception ex ) {
|
||||
// Will happen with old not-an-int saved value
|
||||
Log.ex( TAG, ex );
|
||||
}
|
||||
}
|
||||
String[] colorStrIds = res.getStringArray( strsID );
|
||||
|
|
|
@ -3,9 +3,15 @@
|
|||
tools:ignore="MissingTranslation"
|
||||
>
|
||||
<string-array name="color_themes">
|
||||
<item>@string/color_use_theme_os</item>
|
||||
<item>@string/color_use_theme_light</item>
|
||||
<item>@string/color_use_theme_dark</item>
|
||||
<item>@string/color_use_theme_os</item>
|
||||
</string-array>
|
||||
<string-array name="color_themes_vals">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
<string name="theme_which_default">2</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -387,6 +387,11 @@
|
|||
<item>@string/color_use_theme_light</item>
|
||||
<item>@string/color_use_theme_dark</item>
|
||||
</string-array>
|
||||
<string-array name="color_themes_vals">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</string-array>
|
||||
<string name="theme_which_default">0</string>
|
||||
|
||||
<!-- Keep in sync with the color_ids_{light,dark} below -->
|
||||
<string-array name="color_url_keys">
|
||||
|
|
|
@ -11,7 +11,8 @@
|
|||
android:key="@string/key_theme_which"
|
||||
android:title="@string/theme_which"
|
||||
android:entries="@array/color_themes"
|
||||
android:entryValues="@array/color_themes"
|
||||
android:entryValues="@array/color_themes_vals"
|
||||
android:defaultValue="@string/theme_which_default"
|
||||
/>
|
||||
|
||||
<Preference app:title="@string/color_theme_edit_light"
|
||||
|
|
Loading…
Add table
Reference in a new issue