mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-04 20:46:28 +01:00
add not-again hint when dark-theme used
This commit is contained in:
parent
a8abdaad8c
commit
2e6572f250
7 changed files with 123 additions and 35 deletions
|
@ -55,10 +55,13 @@ import java.util.Set;
|
|||
import org.eehouse.android.xw4.DBUtils.SentInvitesInfo;
|
||||
import org.eehouse.android.xw4.DlgDelegate.Action;
|
||||
import org.eehouse.android.xw4.DlgDelegate.ActionPair;
|
||||
import org.eehouse.android.xw4.NFCUtils.Wrapper;
|
||||
import org.eehouse.android.xw4.Perms23.Perm;
|
||||
import org.eehouse.android.xw4.TilePickAlert.TilePickState;
|
||||
import org.eehouse.android.xw4.Toolbar.Buttons;
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
import org.eehouse.android.xw4.gen.PrefsWrappers;
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs.TileValueType;
|
||||
import org.eehouse.android.xw4.jni.CommonPrefs;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
|
@ -77,8 +80,6 @@ import org.eehouse.android.xw4.jni.UtilCtxtImpl;
|
|||
import org.eehouse.android.xw4.jni.XwJNI.GamePtr;
|
||||
import org.eehouse.android.xw4.jni.XwJNI;
|
||||
import org.eehouse.android.xw4.loc.LocUtils;
|
||||
import org.eehouse.android.xw4.TilePickAlert.TilePickState;
|
||||
import org.eehouse.android.xw4.NFCUtils.Wrapper;
|
||||
|
||||
public class BoardDelegate extends DelegateBase
|
||||
implements TransportProcs.TPMsgHandler, View.OnClickListener,
|
||||
|
@ -538,6 +539,25 @@ public class BoardDelegate extends DelegateBase
|
|||
} else {
|
||||
m_startSkipped = true;
|
||||
}
|
||||
newThemeFeatureAlert();
|
||||
}
|
||||
|
||||
private static boolean s_themeNAShown = false;
|
||||
private void newThemeFeatureAlert()
|
||||
{
|
||||
if ( ! s_themeNAShown ) {
|
||||
s_themeNAShown = true;
|
||||
if ( CommonPrefs.darkThemeEnabled( m_activity ) ) {
|
||||
String prefsName = LocUtils.getString( m_activity, R.string.theme_which );
|
||||
String msg = LocUtils
|
||||
.getString( m_activity, R.string.not_again_boardThemes_fmt,
|
||||
prefsName );
|
||||
makeNotAgainBuilder( msg, R.string.key_na_boardThemes )
|
||||
.setTitle( R.string. new_feature_title )
|
||||
.setActionPair( Action.LAUNCH_THEME_CONFIG, R.string.button_settings )
|
||||
.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1134,6 +1154,10 @@ public class BoardDelegate extends DelegateBase
|
|||
}
|
||||
break;
|
||||
|
||||
case LAUNCH_THEME_CONFIG:
|
||||
PrefsDelegate.launch( m_activity, PrefsWrappers.prefs_appear_themes.class );
|
||||
break;
|
||||
|
||||
case ENABLE_NBS_DO:
|
||||
post( new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -55,6 +55,7 @@ public class DlgDelegate {
|
|||
QUARANTINE_CLEAR,
|
||||
QUARANTINE_DELETE,
|
||||
APPLY_CONFIG,
|
||||
LAUNCH_THEME_CONFIG,
|
||||
|
||||
// BoardDelegate
|
||||
UNDO_LAST_ACTION,
|
||||
|
|
|
@ -49,6 +49,7 @@ public class PrefsActivity extends XWActivity
|
|||
OnPreferenceStartFragmentCallback,
|
||||
OnPreferenceDisplayDialogCallback {
|
||||
private final static String TAG = PrefsActivity.class.getSimpleName();
|
||||
private static final String CLASS_NAME = "CLASS_NAME";
|
||||
|
||||
private PrefsDelegate m_dlgt;
|
||||
|
||||
|
@ -66,7 +67,17 @@ public class PrefsActivity extends XWActivity
|
|||
Assert.assertTrue( 0 < layoutID );
|
||||
m_dlgt.setContentView( layoutID );
|
||||
|
||||
PreferenceFragmentCompat rootFrag = new PrefsWrappers.prefs();
|
||||
PreferenceFragmentCompat rootFrag;
|
||||
try {
|
||||
String rootName = getIntent().getExtras().getString( CLASS_NAME );
|
||||
Assert.assertTrueNR( null != rootName );
|
||||
Class clazz = Class.forName( rootName );
|
||||
rootFrag = (PreferenceFragmentCompat)clazz.newInstance();
|
||||
} catch ( Exception ex ) {
|
||||
Log.ex( TAG, ex );
|
||||
rootFrag = new PrefsWrappers.prefs();
|
||||
Assert.failDbg();
|
||||
}
|
||||
m_dlgt.setRootFragment( rootFrag );
|
||||
|
||||
getSupportFragmentManager()
|
||||
|
@ -208,4 +219,12 @@ public class PrefsActivity extends XWActivity
|
|||
|
||||
public abstract int getResID();
|
||||
}
|
||||
|
||||
public static void bundleRoot( Class root, Intent intent )
|
||||
{
|
||||
Assert.assertTrueNR( null == intent.getExtras() );
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putCharSequence( CLASS_NAME, root.getName() );
|
||||
intent.putExtras( bundle );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -338,7 +338,7 @@ public class PrefsDelegate extends DelegateBase
|
|||
|
||||
// Now replace this activity with a new copy
|
||||
// so the new values get loaded.
|
||||
PrefsDelegate.launch( mActivity );
|
||||
launch( mActivity );
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -349,7 +349,16 @@ public class PrefsDelegate extends DelegateBase
|
|||
|
||||
public static void launch( Context context )
|
||||
{
|
||||
launch( context, PrefsWrappers.prefs.class );
|
||||
}
|
||||
|
||||
public static void launch( Context context, Class root )
|
||||
{
|
||||
Bundle bundle = null;
|
||||
Intent intent = new Intent( context, PrefsActivity.class );
|
||||
if ( null != root ) {
|
||||
PrefsActivity.bundleRoot( root, intent );
|
||||
}
|
||||
context.startActivity( intent );
|
||||
}
|
||||
|
||||
|
|
|
@ -105,36 +105,8 @@ public class CommonPrefs extends XWPrefs {
|
|||
int ord = getInt(context, sp, R.string.key_tile_valuetype, 0);
|
||||
tvType = TileValueType.values()[ord];
|
||||
|
||||
Resources res = context.getResources();
|
||||
ColorTheme theme = ColorTheme.LIGHT;
|
||||
String which = LocUtils.getString( context, R.string.key_theme_which );
|
||||
which = sp.getString( which, null );
|
||||
if ( null != which ) {
|
||||
try {
|
||||
switch ( Integer.parseInt( which ) ) {
|
||||
case 0:
|
||||
// do nothing
|
||||
break;
|
||||
case 1:
|
||||
theme = ColorTheme.DARK;
|
||||
break;
|
||||
case 2:
|
||||
int uiMode = res.getConfiguration().uiMode;
|
||||
if ( Configuration.UI_MODE_NIGHT_YES
|
||||
== (uiMode & Configuration.UI_MODE_NIGHT_MASK) ) {
|
||||
theme = ColorTheme.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( theme.getArrayID() );
|
||||
|
||||
ColorTheme theme = getTheme( context, null );
|
||||
String[] colorStrIds = context.getResources().getStringArray( theme.getArrayID() );
|
||||
int offset = copyColors( sp, colorStrIds, 0, playerColors, 0 );
|
||||
offset += copyColors( sp, colorStrIds, offset, bonusColors, 1 );
|
||||
offset += copyColors( sp, colorStrIds, offset, otherColors, 0 );
|
||||
|
@ -180,6 +152,54 @@ public class CommonPrefs extends XWPrefs {
|
|||
return s_cp.refresh( context );
|
||||
}
|
||||
|
||||
// Is the OS-level setting on?
|
||||
public static boolean darkThemeEnabled( Context context )
|
||||
{
|
||||
boolean[] fromOS = {false};
|
||||
ColorTheme theme = getTheme( context, fromOS );
|
||||
boolean result = theme == ColorTheme.DARK && fromOS[0];
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ColorTheme getTheme( Context context, boolean[] fromOSOut )
|
||||
{
|
||||
ColorTheme theme = ColorTheme.LIGHT;
|
||||
SharedPreferences sp = PreferenceManager
|
||||
.getDefaultSharedPreferences( context );
|
||||
String which = LocUtils.getString( context, R.string.key_theme_which );
|
||||
which = sp.getString( which, null );
|
||||
if ( null != which ) {
|
||||
try {
|
||||
switch ( Integer.parseInt( which ) ) {
|
||||
case 0:
|
||||
// do nothing
|
||||
break;
|
||||
case 1:
|
||||
theme = ColorTheme.DARK;
|
||||
break;
|
||||
case 2:
|
||||
Assert.assertTrueNR( Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q );
|
||||
Resources res = context.getResources();
|
||||
int uiMode = res.getConfiguration().uiMode;
|
||||
if ( Configuration.UI_MODE_NIGHT_YES
|
||||
== (uiMode & Configuration.UI_MODE_NIGHT_MASK) ) {
|
||||
theme = ColorTheme.DARK;
|
||||
if ( null != fromOSOut ) {
|
||||
fromOSOut[0] = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
Assert.failDbg();
|
||||
}
|
||||
} catch ( Exception ex ) {
|
||||
// Will happen with old not-an-int saved value
|
||||
Log.ex( TAG, ex );
|
||||
}
|
||||
}
|
||||
return theme;
|
||||
}
|
||||
|
||||
public static int getDefaultBoardSize( Context context )
|
||||
{
|
||||
String value = getPrefsString( context, R.string.key_board_size );
|
||||
|
|
|
@ -180,6 +180,7 @@
|
|||
<string name="key_na_dupstatus_host">key_na_dupstatus_host</string>
|
||||
<string name="key_na_dupstatus_guest">key_na_dupstatus_guest</string>
|
||||
<string name="key_na_quicknetgame">key_na_quicknetgame</string>
|
||||
<string name="key_na_boardThemes">key_na_boardThemes</string>
|
||||
|
||||
<string name="key_theme_which">key_theme_which</string>
|
||||
|
||||
|
|
|
@ -2771,4 +2771,18 @@
|
|||
\n\nThis action cannot be undone, but you can always restore the
|
||||
default colors for this theme.</string>
|
||||
<string name="button_apply_config">Import</string>
|
||||
|
||||
<!-- hint about new board themes (i.e. dark mode) feature. The
|
||||
name of the preference controlling the theme is substituted in -->
|
||||
<string name="not_again_boardThemes_fmt">The board is now being
|
||||
drawn dark because “Dark theme” is enabled on your device.
|
||||
|
||||
\n\nIf you prefer the old “Light” theme, or to choose a theme
|
||||
independent of Android’s “Dark theme” setting, you can change “%1$s”
|
||||
in App Settings at any time. The “Settings” button below will take
|
||||
you there now.
|
||||
</string>
|
||||
<!-- Button referenced in text above. Should match! -->
|
||||
<string name="button_settings">Settings…</string>
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Reference in a new issue