diff --git a/xwords4/android/app/build.gradle b/xwords4/android/app/build.gradle
index d4db90809..2b1b7af14 100644
--- a/xwords4/android/app/build.gradle
+++ b/xwords4/android/app/build.gradle
@@ -340,6 +340,7 @@ android {
dependencies {
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.core:core:1.0.0'
+ implementation 'androidx.preference:preference:1.1.+'
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
annotationProcessor 'androidx.lifecycle:lifecycle-compiler:2.0.0'
diff --git a/xwords4/android/app/src/main/AndroidManifest.xml b/xwords4/android/app/src/main/AndroidManifest.xml
index 172fef2d7..52affacb3 100644
--- a/xwords4/android/app/src/main/AndroidManifest.xml
+++ b/xwords4/android/app/src/main/AndroidManifest.xml
@@ -97,10 +97,6 @@
android:theme="@android:style/Theme.Translucent.NoTitleBar"
/>
-
-
@@ -115,27 +111,13 @@
android:label="@string/mqtt_invite_title"
/>
-
-
-
-
-
-
-
-
-
@@ -154,7 +136,7 @@
-
+
> shift) & 0xFF;
+ int byt = (mCurColor >> shift) & 0xFF;
SeekBar seekbar = (SeekBar)parent.findViewById( m_seekbarIds[indx] );
EditText edittext = (EditText)parent.findViewById( m_editIds[indx] );
@@ -197,7 +236,8 @@ public class EditColorPreference extends DialogPreference {
}
}
- private int getOneByte( DialogInterface parent, int id ) {
+ private static int getOneByte( DialogInterface parent, int id )
+ {
int val = 0;
Dialog dialog = (Dialog)parent;
SeekBar seekbar = (SeekBar)dialog.findViewById( id );
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigActivity.java
deleted file mode 100644
index 27039a130..000000000
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigActivity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
-/*
- * Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
- * rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.eehouse.android.xw4;
-
-import android.os.Bundle;
-
-public class GameConfigActivity extends XWActivity {
-
- @Override
- public void onCreate( Bundle savedInstanceState )
- {
- super.onCreate( savedInstanceState,
- new GameConfigDelegate( this, savedInstanceState ) );
- } // onCreate
-}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java
index c695afce4..7f7ff9e57 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameConfigDelegate.java
@@ -1390,17 +1390,9 @@ public class GameConfigDelegate extends DelegateBase
bundle.putLong( GameUtils.INTENT_KEY_ROWID, rowID );
bundle.putBoolean( INTENT_FORRESULT_NEWGAME, newGame );
- if ( delegator.inDPMode() ) {
- delegator
- .addFragmentForResult( GameConfigFrag.newInstance( delegator ),
- bundle, requestCode );
- } else {
- Activity activity = delegator.getActivity();
- Intent intent = new Intent( activity, GameConfigActivity.class );
- intent.setAction( Intent.ACTION_EDIT );
- intent.putExtras( bundle );
- activity.startActivityForResult( intent, requestCode.ordinal() );
- }
+ delegator
+ .addFragmentForResult( GameConfigFrag.newInstance( delegator ),
+ bundle, requestCode );
}
private void setConnLabel()
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java
index e563abb4e..e55198eac 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/GameUtils.java
@@ -962,14 +962,7 @@ public class GameUtils {
extras.putAll( moreExtras );
}
- if ( delegator.inDPMode() ) {
- delegator.addFragment( BoardFrag.newInstance( delegator ), extras );
- } else {
- Activity activity = delegator.getActivity();
- Intent intent = new Intent( activity, BoardActivity.class );
- intent.putExtras( extras );
- activity.startActivity( intent );
- }
+ delegator.addFragment( BoardFrag.newInstance( delegator ), extras );
}
private static class FeedUtilsImpl extends UtilCtxtImpl {
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersActivity.java
deleted file mode 100644
index 1ac512731..000000000
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersActivity.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
-/*
- * Copyright 2020 by Eric House (xwords@eehouse.org). All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.eehouse.android.xw4;
-
-import android.os.Bundle;
-
-public class KnownPlayersActivity extends XWActivity {
-
- @Override
- protected void onCreate( Bundle savedInstanceState )
- {
- KnownPlayersDelegate dlgt =
- new KnownPlayersDelegate( this, savedInstanceState );
- super.onCreate( savedInstanceState, dlgt );
- }
-}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java
index 22f237925..44e5e5afa 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/KnownPlayersDelegate.java
@@ -312,13 +312,8 @@ public class KnownPlayersDelegate extends DelegateBase {
Activity activity = delegator.getActivity();
if ( XwJNI.hasKnownPlayers() ) {
- if ( delegator.inDPMode() ) {
- delegator.addFragment( KnownPlayersFrag.newInstance( delegator ),
- null );
- } else {
- Intent intent = new Intent( activity, KnownPlayersActivity.class );
- activity.startActivity( intent );
- }
+ delegator.addFragment( KnownPlayersFrag.newInstance( delegator ),
+ null );
} else {
Assert.failDbg();
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LangListPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LangListPreference.java
index 48a1cb2b4..49c7ed2d7 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LangListPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/LangListPreference.java
@@ -21,23 +21,101 @@
package org.eehouse.android.xw4;
import android.content.Context;
+import android.os.Handler;
import android.util.AttributeSet;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
import org.eehouse.android.xw4.loc.LocUtils;
-public class LangListPreference extends XWListPreference {
- private Context m_context;
+public class LangListPreference extends XWListPreference
+ implements Preference.OnPreferenceChangeListener {
+ private static final String TAG = LangListPreference.class.getSimpleName();
+ private Context mContext;
+ private String mKey;
public LangListPreference( Context context, AttributeSet attrs )
{
super( context, attrs );
- m_context = context;
+ mContext = context;
+ mKey = context.getString( R.string.key_default_language );
}
@Override
public void setSummary( CharSequence summary )
{
- super.setSummary( LocUtils.xlateLang( m_context, summary.toString(), true ) );
+ super.setSummary( LocUtils.xlateLang( mContext, summary.toString(), true ) );
}
+ @Override
+ public void onAttached()
+ {
+ super.onAttached();
+ setOnPreferenceChangeListener( this );
+ setupLangPref();
+ }
+
+ @Override
+ public boolean onPreferenceChange( Preference preference, Object newValue )
+ {
+ final String newLang = (String)newValue;
+ new Handler().post( new Runnable() {
+ @Override
+ public void run() {
+ forceDictsMatch( newLang );
+ }
+ } );
+ return true;
+ }
+
+ private void setupLangPref()
+ {
+ String keyLangs = mContext.getString( R.string.key_default_language );
+ String value = getValue();
+ String curLang = null == value ? null : value.toString();
+ boolean haveDictForLang = false;
+
+ String[] langs = DictLangCache.listLangs( m_context );
+ String[] langsLoc = new String[langs.length];
+ for ( int ii = 0; ii < langs.length; ++ii ) {
+ String lang = langs[ii];
+ haveDictForLang = haveDictForLang || lang.equals( curLang );
+ langsLoc[ii] = LocUtils.xlateLang( mContext, lang, true );
+ }
+
+ if ( !haveDictForLang ) {
+ curLang = DictLangCache.getLangName( mContext, 1 ); // English, unlocalized
+ setValue( curLang );
+ }
+ forceDictsMatch( curLang );
+
+ setEntries( langsLoc );
+ setDefaultValue( LocUtils.xlateLang( mContext, curLang, true ) );
+ setEntryValues( langs );
+ }
+
+ private void forceDictsMatch( String newLang )
+ {
+ if ( null != newLang ) {
+ int code = DictLangCache.getLangLangCode( mContext, newLang );
+ int[] keyIds = { R.string.key_default_dict,
+ R.string.key_default_robodict };
+ for ( int id : keyIds ) {
+ String key = mContext.getString( id );
+
+ PreferenceManager mgr = getPreferenceManager();
+ Assert.assertNotNull( mgr );
+
+ DictListPreference pref = (DictListPreference)mgr.findPreference( key );
+ Assert.assertNotNull( pref );
+
+ String curDict = pref.getValue().toString();
+ if ( ! DictUtils.dictExists( mContext, curDict )
+ || code != DictLangCache.getDictLangCode( mContext,
+ curDict ) ) {
+ pref.invalidate();
+ }
+ }
+ }
+ }
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java
index 194d576f0..83fef8a5a 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MainActivity.java
@@ -47,9 +47,6 @@ public class MainActivity extends XWActivity
private static final boolean LOG_IDS = true;
private DelegateBase m_dlgt;
- private boolean m_dpEnabled;
-
- // Used only if m_dpEnabled is true
private LinearLayout m_root;
private boolean m_safeToCommit;
private ArrayList m_runWhenSafe = new ArrayList<>();
@@ -66,23 +63,18 @@ public class MainActivity extends XWActivity
Log.e( TAG, "isTaskRoot() => false!!! What to do?" );
}
- m_dpEnabled = XWPrefs.getIsTablet( this );
-
- m_dlgt = m_dpEnabled ? new DualpaneDelegate( this, savedInstanceState )
- : new GamesListDelegate( this, savedInstanceState );
+ m_dlgt = new DualpaneDelegate( this, savedInstanceState );
super.onCreate( savedInstanceState, m_dlgt );
- if ( m_dpEnabled ) {
- m_root = (LinearLayout)findViewById( R.id.main_container );
- getSupportFragmentManager().addOnBackStackChangedListener( this );
+ m_root = (LinearLayout)findViewById( R.id.main_container );
+ getSupportFragmentManager().addOnBackStackChangedListener( this );
- // Nothing to do if we're restarting
- if ( savedInstanceState == null ) {
- // In case this activity was started with special instructions from an Intent,
- // pass the Intent's extras to the fragment as arguments
- addFragmentImpl( GamesListFrag.newInstance(),
- getIntent().getExtras(), null );
- }
+ // Nothing to do if we're restarting
+ if ( savedInstanceState == null ) {
+ // In case this activity was started with special instructions from an Intent,
+ // pass the Intent's extras to the fragment as arguments
+ addFragmentImpl( GamesListFrag.newInstance(),
+ getIntent().getExtras(), null );
}
setSafeToRun();
@@ -100,9 +92,7 @@ public class MainActivity extends XWActivity
{
setSafeToRun();
super.onPostResume();
- if ( m_dpEnabled ) {
- setVisiblePanes();
- }
+ setVisiblePanes();
logPaneFragments();
}
@@ -250,11 +240,6 @@ public class MainActivity extends XWActivity
//////////////////////////////////////////////////////////////////////
// Delegator interface
//////////////////////////////////////////////////////////////////////
- @Override
- public boolean inDPMode() {
- return m_dpEnabled;
- }
-
@Override
public void addFragment( XWFragment fragment, Bundle extras )
{
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java
index 79208b3db..0c2dad25a 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/MultiService.java
@@ -129,7 +129,7 @@ public class MultiService {
public static Intent makeMissingDictIntent( Context context, NetLaunchInfo nli,
DictFetchOwner owner )
{
- Intent intent = new Intent( context, DictsActivity.class );
+ Intent intent = new Intent( context, MainActivity.class ); // PENDING TEST THIS!!!
intent.setAction( ACTION_FETCH_DICT );
intent.putExtra( LANG, nli.lang );
intent.putExtra( DICT, nli.dict );
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java
index fd4c2b45b..1b3a62c12 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsActivity.java
@@ -1,6 +1,6 @@
/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
/*
- * Copyright 2009-2010 by Eric House (xwords@eehouse.org). All
+ * Copyright 2009 - 2021 by Eric House (xwords@eehouse.org). All
* rights reserved.
*
* This program is free software; you can redistribute it and/or
@@ -22,133 +22,242 @@ package org.eehouse.android.xw4;
import android.app.Activity;
import android.app.Dialog;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
-import android.preference.PreferenceActivity;
+import android.view.View;
+import androidx.fragment.app.Fragment;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat.OnPreferenceDisplayDialogCallback;
+import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartFragmentCallback;
+import androidx.preference.PreferenceFragmentCompat.OnPreferenceStartScreenCallback;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.PreferenceViewHolder;
+import java.util.HashSet;
+import java.util.Set;
+
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.DlgDelegate.Builder;
-import org.eehouse.android.xw4.loc.LocUtils;
+import org.eehouse.android.xw4.jni.CommonPrefs;
-public class PrefsActivity extends PreferenceActivity
- implements Delegator, DlgDelegate.HasDlgDelegate {
+public class PrefsActivity extends XWActivity
+ implements Delegator, DlgDelegate.HasDlgDelegate,
+ // OnPreferenceStartScreenCallback,
+ OnPreferenceStartFragmentCallback,
+ OnPreferenceDisplayDialogCallback {
+ private final static String TAG = PrefsActivity.class.getSimpleName();
private PrefsDelegate m_dlgt;
+ interface DialogProc {
+ XWDialogFragment makeDialogFrag();
+ }
+
@Override
protected void onCreate( Bundle savedInstanceState )
{
- super.onCreate( savedInstanceState );
m_dlgt = new PrefsDelegate( this, this, savedInstanceState );
+ super.onCreate( savedInstanceState, m_dlgt );
int layoutID = m_dlgt.getLayoutID();
- if ( 0 < layoutID ) {
- m_dlgt.setContentView( layoutID );
- }
+ Assert.assertTrue( 0 < layoutID );
+ m_dlgt.setContentView( layoutID );
- m_dlgt.init( savedInstanceState );
+ PreferenceFragmentCompat rootFrag = new FragPrefs();
+ m_dlgt.setRootFragment( rootFrag );
+
+ getSupportFragmentManager()
+ .beginTransaction()
+ .replace( R.id.main_container, rootFrag )
+ .commit();
}
@Override
- protected void onStart()
- {
- LocUtils.xlatePreferences( this );
- super.onStart();
- m_dlgt.onStart();
- }
-
- @Override
- protected void onResume()
- {
- super.onResume();
- m_dlgt.onResume();
- }
-
- @Override
- protected void onPause()
- {
- super.onPause();
- m_dlgt.onPause();
- }
-
- @Override
- protected void onStop()
- {
- m_dlgt.onStop();
- super.onStop();
- }
-
- @Override
- protected void onDestroy()
- {
- m_dlgt.onDestroy();
- super.onDestroy();
- }
-
- @Override
- protected Dialog onCreateDialog( int id )
- {
- return m_dlgt.onCreateDialog( id );
- }
-
- @Override
- protected void onActivityResult( int requestCode, int resultCode,
- Intent data )
- {
- RequestCode rc = RequestCode.values()[requestCode];
- m_dlgt.onActivityResult( rc, resultCode, data );
- }
-
- public Builder makeOkOnlyBuilder( int msgID )
- {
- return m_dlgt.makeOkOnlyBuilder( msgID );
- }
-
public Builder makeOkOnlyBuilder( String msg )
{
return m_dlgt.makeOkOnlyBuilder( msg );
}
+ @Override
public Builder makeNotAgainBuilder(int msgID, int key, Action action)
{
return m_dlgt.makeNotAgainBuilder( msgID, key, action );
}
- public Builder makeNotAgainBuilder( int msgID, int key )
+ @Override
+ public boolean onPreferenceDisplayDialog( PreferenceFragmentCompat caller,
+ Preference pref )
{
- return m_dlgt.makeNotAgainBuilder( msgID, key );
+ boolean success = false;
+ if ( pref instanceof DialogProc ) {
+ show( ((DialogProc)pref).makeDialogFrag() );
+ success = true;
+ } else {
+ Log.e( TAG, "unexpected class: %s", pref.getClass().getSimpleName() );
+ }
+ return success;
}
- public Builder makeConfirmThenBuilder( String msg, Action action )
+ @Override
+ public boolean onPreferenceStartFragment( PreferenceFragmentCompat caller,
+ Preference pref )
+ {
+ final Bundle args = pref.getExtras();
+ final Fragment fragment = getSupportFragmentManager().getFragmentFactory()
+ .instantiate( getClassLoader(), pref.getFragment());
+ fragment.setArguments(args);
+ fragment.setTargetFragment( caller, 0 );
+
+ getSupportFragmentManager().beginTransaction()
+ .replace( R.id.main_container, fragment)
+ .addToBackStack(null)
+ .commit();
+ setTitle( pref.getTitle() );
+
+ return true;
+ }
+
+ Builder makeConfirmThenBuilder( String msg, Action action )
{
return m_dlgt.makeConfirmThenBuilder( msg, action );
}
- public Builder makeConfirmThenBuilder( int msgID, Action action )
- {
- return m_dlgt.makeConfirmThenBuilder( msgID, action );
- }
-
protected void showSMSEnableDialog( Action action )
{
m_dlgt.showSMSEnableDialog( action );
}
- //////////////////////////////////////////////////////////////////////
- // Delegator interface
- //////////////////////////////////////////////////////////////////////
- public Activity getActivity()
+ private static Set sHideSet = null;
+ private synchronized static Set getHideSet( Context context )
{
- return this;
+ if ( null == sHideSet ) {
+ Set tmp = new HashSet<>();
+ if ( !Utils.isGSMPhone( context ) || Perms23.haveNativePerms() ) {
+ tmp.add( R.string.key_enable_nbs );
+ }
+ if ( ABUtils.haveActionBar() ) {
+ tmp.add( R.string.key_hide_title );
+ }
+
+ if ( ! BuildConfig.WIDIR_ENABLED ) {
+ tmp.add( R.string.key_enable_p2p );
+ }
+
+ if ( null == FBMService.getFCMDevID( context ) ) {
+ tmp.add( R.string.key_show_fcm );
+ }
+
+ if ( BuildConfig.DEBUG ) {
+ tmp.add( R.string.key_logging_on );
+ tmp.add( R.string.key_enable_debug );
+ } else {
+ tmp.add( R.string.key_unhide_dupmode );
+ }
+
+ if ( CommonPrefs.getDupModeHidden( context ) ) {
+ tmp.add( R.string.key_init_dupmodeon );
+ }
+
+ if ( null == BuildConfig.KEY_FCMID ) {
+ tmp.add( R.string.key_relay_poll );
+ }
+
+ sHideSet = new HashSet<>();
+ for ( int key : tmp ) {
+ sHideSet.add( context.getString( key ) );
+ }
+ }
+ return sHideSet;
}
- public Bundle getArguments()
- {
- return getIntent().getExtras();
+ // Every subscreen in the prefs.xml heierarchy has to have a class
+ // associated with it just to provide its xml-file ID. Stupid design; not
+ // mine!
+
+ private abstract static class BasePrefsFrag extends PreferenceFragmentCompat {
+ @Override
+ public void onCreatePreferences( Bundle savedInstanceState, String rootKey )
+ {
+ setPreferencesFromResource( getResID(), rootKey );
+ }
+
+ @Override
+ public void onViewCreated( View view, Bundle savedInstanceState )
+ {
+ Context context = view.getContext();
+ Set hideSet = getHideSet( context );
+
+ for ( String key : hideSet ) {
+ Preference pref = findPreference( key );
+ if ( null != pref ) {
+ Log.d( TAG, "in %s, found pref %s", getClass().getSimpleName(),
+ pref.getTitle() );
+ pref.setVisible( false );
+ }
+ }
+
+ super.onViewCreated( view, savedInstanceState );
+ }
+
+ abstract int getResID();
}
- public boolean inDPMode() { Assert.failDbg(); return false; }
- public void addFragment( XWFragment fragment, Bundle extras ) { Assert.failDbg(); }
- public void addFragmentForResult( XWFragment fragment, Bundle extras,
- RequestCode code ) { Assert.failDbg(); }
+ public static class FragPrefs extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs; }
+ }
+ public static class FragPrefsDflts extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dflts; }
+ }
+ public static class FragPrefsDfltsNames extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dflts_names; }
+ }
+ public static class FragPrefsDfltsDicts extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dflts_dicts; }
+ }
+ public static class FragPrefsAppear extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_appear; }
+ }
+ public static class FragPrefsAppearColors extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_appear_colors; }
+ }
+ public static class FragPrefsBehave extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_behave; }
+ }
+ public static class FragPrefsBehaveNag extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_behave_nag; }
+ }
+ public static class FragPrefsNet extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_net; }
+ }
+ public static class FragPrefsNetAdv extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_net_adv; }
+ }
+ public static class FragPrefsDbg extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dbg; }
+ }
+ public static class FragPrefsDbgNet extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dbg_net; }
+ }
+ public static class FragPrefsDbgSms extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dbg_sms; }
+ }
+ public static class FragPrefsDbgL10n extends BasePrefsFrag {
+ @Override
+ int getResID() { return R.xml.prefs_dbg_l10n; }
+ }
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java
index 869accf9c..1f56e7539 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/PrefsDelegate.java
@@ -28,11 +28,12 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.preference.ListPreference;
-import android.preference.Preference;
-import android.preference.PreferenceActivity;
-import android.preference.PreferenceManager;
-import android.preference.PreferenceScreen;
+import androidx.preference.ListPreference;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceFragmentCompat;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.PreferenceCategory;
import android.view.View;
import android.widget.Button;
@@ -45,10 +46,12 @@ import java.util.HashMap;
import java.util.Map;
public class PrefsDelegate extends DelegateBase
- implements SharedPreferences.OnSharedPreferenceChangeListener {
+ implements SharedPreferences.OnSharedPreferenceChangeListener,
+ View.OnClickListener {
private static final String TAG = PrefsDelegate.class.getSimpleName();
- private PreferenceActivity m_activity;
+ private XWActivity mActivity;
+ private PreferenceFragmentCompat mFragment;
private static int[] s_keys = {
R.string.key_logging_on,
R.string.key_show_sms,
@@ -69,22 +72,25 @@ public class PrefsDelegate extends DelegateBase
};
private static Map s_keysHash = null;
- public PrefsDelegate( PreferenceActivity activity, Delegator delegator,
+ public PrefsDelegate( XWActivity activity, Delegator delegator,
Bundle savedInstanceState )
{
super( delegator, savedInstanceState, R.layout.prefs_w_buttons );
- m_activity = activity;
+ mActivity = activity;
}
- protected Dialog onCreateDialog( int id )
+ @Override
+ protected Dialog makeDialog( DBAlert alert, Object[] params )
{
+ final DlgID dlgID = alert.getDlgID();
DialogInterface.OnClickListener lstnr = null;
int confirmID = 0;
- switch( DlgID.values()[id] ) {
+ switch( dlgID ) {
case REVERT_COLORS:
confirmID = R.string.confirm_revert_colors;
lstnr = new DialogInterface.OnClickListener() {
+ @Override
public void onClick( DialogInterface dlg, int item ) {
PrefsDelegate self = (PrefsDelegate)curThis();
SharedPreferences sp = self.getSharedPreferences();
@@ -116,6 +122,7 @@ public class PrefsDelegate extends DelegateBase
case REVERT_ALL:
confirmID = R.string.confirm_revert_all;
lstnr = new DialogInterface.OnClickListener() {
+ @Override
public void onClick( DialogInterface dlg, int item ) {
PrefsDelegate self = (PrefsDelegate)curThis();
SharedPreferences sp = self.getSharedPreferences();
@@ -143,6 +150,7 @@ public class PrefsDelegate extends DelegateBase
@Override
protected void init( Bundle savedInstanceState )
{
+ // Assert.assertNotNull( m_fragment );
if ( null == s_keysHash ) {
s_keysHash = new HashMap<>();
for ( int key : s_keys ) {
@@ -150,26 +158,12 @@ public class PrefsDelegate extends DelegateBase
s_keysHash.put( str, key );
}
}
+ }
- // Load the preferences from an XML resource
- m_activity.addPreferencesFromResource( R.xml.xwprefs );
-
- Button button = (Button)findViewById( R.id.revert_colors );
- button.setOnClickListener( new View.OnClickListener() {
- public void onClick( View v ) {
- showDialog( DlgID.REVERT_COLORS );
- }
- } );
- button = (Button)findViewById( R.id.revert_all );
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick( View v ) {
- showDialog( DlgID.REVERT_ALL );
- }
- } );
-
- setupLangPref();
-
- hideStuff();
+ void setRootFragment( PreferenceFragmentCompat fragment )
+ {
+ Assert.assertNotNull( fragment );
+ mFragment = fragment;
}
@Override
@@ -177,14 +171,42 @@ public class PrefsDelegate extends DelegateBase
{
super.onResume();
getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+
+ // It's too early somehow to do this in init() above
+ findViewById( R.id.revert_colors ).setOnClickListener(this);
+ findViewById( R.id.revert_all ).setOnClickListener(this);
}
+ @Override
protected void onPause()
{
getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
+ // interface View.OnClickListener
+ @Override
+ public void onClick( View view )
+ {
+ DlgID dlgID = null;
+ int id = view.getId();
+ switch ( id ) {
+ case R.id.revert_all:
+ dlgID = DlgID.REVERT_ALL;
+ break;
+ case R.id.revert_colors:
+ dlgID = DlgID.REVERT_COLORS;
+ break;
+ default:
+ Assert.failDbg();
+ }
+
+ if ( null != dlgID ) {
+ showDialogFragment( dlgID );
+ }
+ }
+
+ // interface SharedPreferences.OnSharedPreferenceChangeListener
@Override
public void onSharedPreferenceChanged( SharedPreferences sp, String key )
{
@@ -220,26 +242,26 @@ public class PrefsDelegate extends DelegateBase
DictUtils.invalDictList();
break;
case R.string.key_thumbsize:
- DBUtils.clearThumbnails( m_activity );
+ DBUtils.clearThumbnails( mActivity );
break;
case R.string.key_xlations_locale:
- LocUtils.localeChanged( m_activity, sp.getString( key, null ) );
+ LocUtils.localeChanged( mActivity, sp.getString( key, null ) );
break;
case R.string.key_default_language:
- forceDictsMatch( sp.getString( key, null ) );
+ // forceDictsMatch( sp.getString( key, null ) );
break;
case R.string.key_force_radio:
SMSPhoneInfo.reset();
break;
case R.string.key_disable_nag:
case R.string.key_disable_nag_solo:
- NagTurnReceiver.resetNagsDisabled( m_activity );
+ NagTurnReceiver.resetNagsDisabled( mActivity );
break;
case R.string.key_disable_relay:
- RelayService.enabledChanged( m_activity );
+ RelayService.enabledChanged( mActivity );
break;
case R.string.key_disable_bt:
- BTUtils.disabledChanged( m_activity );
+ BTUtils.disabledChanged( mActivity );
break;
case R.string.key_force_tablet:
makeOkOnlyBuilder( R.string.after_restart ).show();
@@ -247,7 +269,7 @@ public class PrefsDelegate extends DelegateBase
case R.string.key_mqtt_host:
case R.string.key_mqtt_port:
case R.string.key_mqtt_qos:
- MQTTUtils.onConfigChanged( m_activity );
+ MQTTUtils.onConfigChanged( mActivity );
break;
default:
Assert.failDbg();
@@ -262,15 +284,15 @@ public class PrefsDelegate extends DelegateBase
boolean handled = true;
switch ( action ) {
case ENABLE_NBS_DO:
- XWPrefs.setNBSEnabled( m_activity, true );
+ XWPrefs.setNBSEnabled( mActivity, true );
SMSCheckBoxPreference.setChecked();
break;
case DISABLE_RELAY_DO:
- RelayService.setEnabled( m_activity, false );
+ RelayService.setEnabled( mActivity, false );
RelayCheckBoxPreference.setChecked();
break;
case DISABLE_BT_DO:
- BTUtils.setEnabled( m_activity, false );
+ BTUtils.setEnabled( mActivity, false );
BTCheckBoxPreference.setChecked();
break;
default:
@@ -288,7 +310,7 @@ public class PrefsDelegate extends DelegateBase
case DIALOG_OKONLY:
case DIALOG_ENABLESMS:
case DIALOG_NOTAGAIN:
- HostDelegate.showForResult( m_activity, state );
+ HostDelegate.showForResult( mActivity, state );
break;
default:
@@ -307,118 +329,18 @@ public class PrefsDelegate extends DelegateBase
private void relaunch()
{
- PreferenceManager.setDefaultValues( m_activity, R.xml.xwprefs,
+ PreferenceManager.setDefaultValues( mActivity, R.xml.prefs,
false );
// Now replace this activity with a new copy
// so the new values get loaded.
- PrefsDelegate.launch( m_activity );
+ PrefsDelegate.launch( mActivity );
finish();
}
private SharedPreferences getSharedPreferences()
{
- return m_activity.getPreferenceScreen().getSharedPreferences();
- }
-
- private void setupLangPref()
- {
- String keyLangs = getString( R.string.key_default_language );
- ListPreference lp = (ListPreference)
- m_activity.findPreference( keyLangs );
- String curLang = lp.getValue().toString();
- boolean haveDictForLang = false;
-
- String[] langs = DictLangCache.listLangs( m_activity );
- String[] langsLoc = new String[langs.length];
- for ( int ii = 0; ii < langs.length; ++ii ) {
- String lang = langs[ii];
- haveDictForLang = haveDictForLang
- || lang.equals( curLang );
- langsLoc[ii] = xlateLang( lang, true );
- }
-
- if ( !haveDictForLang ) {
- curLang = DictLangCache.getLangName( m_activity, 1 ); // English, unlocalized
- lp.setValue( curLang );
- }
- forceDictsMatch( curLang );
-
- lp.setEntries( langsLoc );
- lp.setDefaultValue( xlateLang( curLang, true ) );
- lp.setEntryValues( langs );
- }
-
- private void forceDictsMatch( String newLang )
- {
- int code = DictLangCache.getLangLangCode( m_activity, newLang );
- int[] keyIds = { R.string.key_default_dict,
- R.string.key_default_robodict };
- for ( int id : keyIds ) {
- String key = getString( id );
- DictListPreference pref = (DictListPreference)m_activity.findPreference( key );
- String curDict = pref.getValue().toString();
- if ( ! DictUtils.dictExists( m_activity, curDict )
- || code != DictLangCache.getDictLangCode( m_activity,
- curDict ) ) {
- pref.invalidate();
- }
- }
- }
-
- private void hideOne( int prefID, int screenID )
- {
- try {
- Preference pref = m_activity.findPreference( getString( prefID ) );
- String key = getString( screenID );
- ((PreferenceScreen)m_activity.findPreference( key ))
- .removePreference( pref );
- } catch ( NullPointerException ex ) {
- // This is happening hiding key_enable_sms, but the hide still
- // works!
- // Log.ex( TAG, ex );
- }
- }
-
- private void showDialog( DlgID dlgID )
- {
- if ( !m_activity.isFinishing() ) {
- m_activity.showDialog( dlgID.ordinal() );
- }
- }
-
- private void hideStuff()
- {
- if ( !Utils.isGSMPhone( m_activity ) || Perms23.haveNativePerms() ) {
- hideOne( R.string.key_enable_nbs, R.string.key_network_behavior );
- }
-
- if ( ABUtils.haveActionBar() ) {
- hideOne( R.string.key_hide_title, R.string.prefs_appearance );
- }
-
- if ( ! BuildConfig.WIDIR_ENABLED ) {
- hideOne( R.string.key_enable_p2p, R.string.key_network_behavior );
- }
-
- if ( null == FBMService.getFCMDevID( m_activity ) ) {
- hideOne( R.string.key_show_fcm, R.string.pref_group_relay_title );
- }
-
- if ( BuildConfig.DEBUG ) {
- hideOne( R.string.key_logging_on, R.string.advanced_summary );
- hideOne( R.string.key_enable_debug, R.string.advanced_summary );
- } else {
- hideOne( R.string.key_unhide_dupmode, R.string.advanced_summary );
- }
-
- if ( CommonPrefs.getDupModeHidden( m_activity ) ) {
- hideOne( R.string.key_init_dupmodeon, R.string.key_prefs_defaults );
- }
-
- if ( null == BuildConfig.KEY_FCMID ) {
- hideOne( R.string.key_relay_poll, R.string.pref_group_relay_title );
- }
+ return mFragment.getPreferenceScreen().getSharedPreferences();
}
public static void launch( Context context )
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSCheckBoxPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSCheckBoxPreference.java
index 55605ef30..df4b18218 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSCheckBoxPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/SMSCheckBoxPreference.java
@@ -36,9 +36,9 @@ public class SMSCheckBoxPreference extends ConfirmingCheckBoxPreference {
}
@Override
- protected void onAttachedToActivity()
+ public void onAttached()
{
- super.onAttachedToActivity();
+ super.onAttached();
if ( !Utils.deviceSupportsNBS( getContext() ) ) {
setEnabled( false );
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListActivity.java
deleted file mode 100644
index 5fda39de9..000000000
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListActivity.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/* -*- compile-command: "find-and-gradle.sh inXw4dDeb"; -*- */
-/*
- * Copyright 2014 by Eric House (xwords@eehouse.org). All rights reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- */
-
-package org.eehouse.android.xw4;
-
-import android.os.Bundle;
-
-public class StudyListActivity extends XWActivity {
-
- @Override
- protected void onCreate( Bundle savedInstanceState )
- {
- StudyListDelegate dlgt =
- new StudyListDelegate( this, savedInstanceState );
- super.onCreate( savedInstanceState, dlgt );
- }
-
-}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java
index 54918472b..12edcbba7 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/StudyListDelegate.java
@@ -401,14 +401,8 @@ public class StudyListDelegate extends ListDelegateBase
bundle.putInt( START_LANG, lang );
}
- if ( delegator.inDPMode() ) {
- delegator.addFragment( StudyListFrag.newInstance( delegator ),
- bundle );
- } else {
- Intent intent = new Intent( activity, StudyListActivity.class );
- intent.putExtras( bundle );
- activity.startActivity( intent );
- }
+ delegator.addFragment( StudyListFrag.newInstance( delegator ),
+ bundle );
}
if ( null != msg ) {
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java
index 286e439ac..7e8ec3562 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/UpdateCheckReceiver.java
@@ -401,8 +401,7 @@ public class UpdateCheckReceiver extends BroadcastReceiver {
String name, DictUtils.DictLoc loc,
boolean isUpdate )
{
- Intent intent =
- new Intent( context, DictsActivity.class );
+ Intent intent = new Intent( context, MainActivity.class ); // PENDING TEST THIS!!!
intent.putExtra( NEW_DICT_URL, url );
intent.putExtra( NEW_DICT_NAME, name );
intent.putExtra( NEW_DICT_LOC, loc.ordinal() );
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java
index 12f5e3a85..f71f6fd3d 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWActivity.java
@@ -23,12 +23,8 @@ package org.eehouse.android.xw4;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import android.os.Bundle;
-import androidx.fragment.app.DialogFragment;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentActivity;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.ContextMenu;
import android.view.Menu;
@@ -36,6 +32,11 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.ListAdapter;
import android.widget.ListView;
+import androidx.fragment.app.DialogFragment;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+import androidx.fragment.app.FragmentTransaction;
import org.eehouse.android.xw4.DlgDelegate.Action;
@@ -52,12 +53,24 @@ public class XWActivity extends FragmentActivity
this, savedInstanceState );
}
super.onCreate( savedInstanceState );
+ Assert.assertNotNull( dlgt );
m_dlgt = dlgt;
-
Assert.assertTrue( getApplicationContext() == XWApp.getContext() );
+ int orientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+ if ( XWPrefs.getIsTablet( this ) ) {
+ orientation = ActivityInfo.SCREEN_ORIENTATION_USER;
+ } else {
+ Assert.assertTrueNR( 9 <= Integer.valueOf( android.os.Build.VERSION.SDK ) );
+ orientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT;
+ }
+ if ( ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED != orientation ) {
+ setRequestedOrientation( orientation );
+ }
+
int layoutID = m_dlgt.getLayoutID();
if ( 0 < layoutID ) {
+ Log.d( TAG, "onCreate() calling setContentView()" );
m_dlgt.setContentView( layoutID );
}
@@ -116,7 +129,8 @@ public class XWActivity extends FragmentActivity
Log.i( TAG, "%s.onStart(this=%H)", getClass().getSimpleName(), this );
}
super.onStart();
- m_dlgt.onStart();
+ Assert.assertNotNull( m_dlgt );
+ m_dlgt.onStart(); // m_dlgt null?
}
@Override
@@ -252,10 +266,6 @@ public class XWActivity extends FragmentActivity
return getListView().getAdapter();
}
- public boolean inDPMode() {
- return false;
- }
-
@Override
public void addFragment( XWFragment fragment, Bundle extras )
{
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java
index b7bd713b7..c74c82d06 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWApp.java
@@ -29,7 +29,7 @@ import androidx.lifecycle.ProcessLifecycleOwner;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
-import android.preference.PreferenceManager;
+import androidx.preference.PreferenceManager;
import org.eehouse.android.nbsplib.NBSProxy;
@@ -80,7 +80,7 @@ public class XWApp extends Application
OnBootReceiver.startTimers( this );
boolean mustCheck = Utils.firstBootThisVersion( this );
- PreferenceManager.setDefaultValues( this, R.xml.xwprefs, mustCheck );
+ PreferenceManager.setDefaultValues( this, R.xml.prefs, mustCheck );
if ( mustCheck ) {
XWPrefs.setHaveCheckedUpgrades( this, false );
} else {
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java
index 0214fa557..4229571fc 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWConnAddrPreference.java
@@ -20,44 +20,55 @@
package org.eehouse.android.xw4;
-import android.app.AlertDialog;
+import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
-import android.preference.DialogPreference;
+import android.os.Bundle;
import android.util.AttributeSet;
import android.view.View;
-
-
+import androidx.preference.DialogPreference;
+import androidx.preference.Preference;
import org.eehouse.android.xw4.DlgDelegate.Action;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnTypeSet;
import org.eehouse.android.xw4.loc.LocUtils;
-public class XWConnAddrPreference extends DialogPreference {
-
+public class XWConnAddrPreference extends DialogPreference
+ implements PrefsActivity.DialogProc {
+ private static final String TAG = XWConnAddrPreference.class.getSimpleName();
private Context m_context;
private ConnViaViewLayout m_view;
public XWConnAddrPreference( Context context, AttributeSet attrs )
{
super( context, attrs );
- m_context = context;
-
- setDialogLayoutResource( R.layout.conn_types_display );
-
- setNegativeButtonText( LocUtils.getString( context, android.R.string.cancel ) );
CommsConnTypeSet curSet = XWPrefs.getAddrTypes( context );
setSummary( curSet.toString( context, true ) );
}
@Override
- protected void onBindDialogView( View view )
+ public XWDialogFragment makeDialogFrag()
{
- LocUtils.xlateView( m_context, view );
- m_view = (ConnViaViewLayout)view.findViewById( R.id.conn_types );
- final PrefsActivity activity = (PrefsActivity)m_context;
- m_view.configure( XWPrefs.getAddrTypes( m_context ),
+ return new XWConnAddrDialogFrag( this );
+ }
+
+ public static class XWConnAddrDialogFrag extends XWDialogFragment {
+ private XWConnAddrPreference mSelf;
+
+ public XWConnAddrDialogFrag( XWConnAddrPreference self )
+ {
+ mSelf = self;
+ }
+
+ @Override
+ public Dialog onCreateDialog( Bundle sis )
+ {
+ final PrefsActivity activity = (PrefsActivity)getContext();
+ View view = LocUtils.inflate( activity, R.layout.conn_types_display );
+
+ final ConnViaViewLayout cvl = (ConnViaViewLayout)view.findViewById( R.id.conn_types );
+ cvl.configure( XWPrefs.getAddrTypes( activity ),
new ConnViaViewLayout.CheckEnabledWarner() {
@Override
public void warnDisabled( CommsConnType typ ) {
@@ -78,10 +89,10 @@ public class XWConnAddrPreference extends DialogPreference {
break;
case COMMS_CONN_RELAY:
msg = LocUtils
- .getString( m_context, R.string
+ .getString( activity, R.string
.warn_relay_disabled );
msg += "\n\n" + LocUtils
- .getString( m_context,
+ .getString( activity,
R.string.warn_relay_later );
action = Action.ENABLE_RELAY_DO;
buttonID = R.string.button_enable_relay;
@@ -106,22 +117,34 @@ public class XWConnAddrPreference extends DialogPreference {
new ConnViaViewLayout.SetEmptyWarner() {
@Override
public void typeSetEmpty() {
- PrefsActivity activity = (PrefsActivity)m_context;
activity
.makeOkOnlyBuilder( R.string.warn_no_comms )
.show();
}
}, activity );
- }
- @Override
- public void onClick( DialogInterface dialog, int which )
- {
- if ( AlertDialog.BUTTON_POSITIVE == which && null != m_view ) {
- CommsConnTypeSet curSet = m_view.getTypes();
- XWPrefs.setAddrTypes( m_context, curSet );
- setSummary( curSet.toString( m_context, true ) );
+ DialogInterface.OnClickListener onOk =
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick( DialogInterface di,
+ int which )
+ {
+ Log.d( TAG, "onClick()" );
+ CommsConnTypeSet curSet = cvl.getTypes();
+ XWPrefs.setAddrTypes( activity, curSet );
+ mSelf.setSummary( curSet.toString( activity, true ) );
+ }
+ };
+
+ return LocUtils.makeAlertBuilder( activity )
+ .setTitle( R.string.title_addrs_pref )
+ .setView( view )
+ .setPositiveButton( android.R.string.ok, onOk )
+ .setNegativeButton( android.R.string.cancel, null )
+ .create();
}
- super.onClick( dialog, which );
+
+ @Override
+ protected String getFragTag() { return getClass().getSimpleName(); }
}
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWEditTextPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWEditTextPreference.java
index c266cd2d5..3e4ff43dd 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWEditTextPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWEditTextPreference.java
@@ -21,7 +21,7 @@
package org.eehouse.android.xw4;
import android.content.Context;
-import android.preference.EditTextPreference;
+import androidx.preference.EditTextPreference;
import android.util.AttributeSet;
public class XWEditTextPreference extends EditTextPreference {
@@ -31,9 +31,10 @@ public class XWEditTextPreference extends EditTextPreference {
super( context, attrs );
}
- protected void onAttachedToActivity()
+ @Override
+ public void onAttached()
{
- super.onAttachedToActivity();
+ super.onAttached();
setSummary( getPersistedString( "" ) );
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java
index ba80081a0..3c9817f1d 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWFragment.java
@@ -213,13 +213,6 @@ abstract class XWFragment extends Fragment implements Delegator {
public void setTitle() { m_dlgt.setTitle(); }
- @Override
- public boolean inDPMode() {
- MainActivity main = (MainActivity)getActivity();
- Assert.assertTrue( !isAdded() || main.inDPMode() ); // otherwise should be somewhere else
- return true;
- }
-
@Override
public void addFragment( XWFragment fragment, Bundle extras )
{
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWListPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWListPreference.java
index c1b939c90..f1b86bf95 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWListPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWListPreference.java
@@ -21,7 +21,7 @@
package org.eehouse.android.xw4;
import android.content.Context;
-import android.preference.ListPreference;
+import androidx.preference.ListPreference;
import android.util.AttributeSet;
import org.eehouse.android.xw4.loc.LocUtils;
@@ -36,9 +36,9 @@ public class XWListPreference extends ListPreference {
}
@Override
- protected void onAttachedToActivity()
+ public void onAttached()
{
- super.onAttachedToActivity();
+ super.onAttached();
setSummary( getPersistedString( "" ) );
}
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java
index 9c366926b..1ba960ddf 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWPrefs.java
@@ -23,7 +23,7 @@ package org.eehouse.android.xw4;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
-import android.preference.PreferenceManager;
+import androidx.preference.PreferenceManager;
import android.text.TextUtils;
import org.json.JSONException;
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWSumListPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWSumListPreference.java
index e725616d3..84467c534 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWSumListPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWSumListPreference.java
@@ -42,9 +42,9 @@ public class XWSumListPreference extends XWListPreference {
// Why I exist: insert the rowid and gameid lines if debug is on
@Override
- protected void onAttachedToActivity()
+ public void onAttached()
{
- super.onAttachedToActivity();
+ super.onAttached();
CharSequence[] entries = getEntries();
CharSequence[] newEntries = LocUtils.xlateStrings( m_context, entries );
diff --git a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWThumbListPreference.java b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWThumbListPreference.java
index af7dcc78a..58a432881 100644
--- a/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWThumbListPreference.java
+++ b/xwords4/android/app/src/main/java/org/eehouse/android/xw4/XWThumbListPreference.java
@@ -35,9 +35,10 @@ public class XWThumbListPreference extends XWListPreference {
}
// Why I exist: insert the rowid and gameid lines if debug is on
- protected void onAttachedToActivity()
+ @Override
+ public void onAttached()
{
- super.onAttachedToActivity();
+ super.onAttached();
CharSequence[] newEntries = new CharSequence[7];
newEntries[0] = LocUtils.getString( m_context, R.string.thumb_off );
diff --git a/xwords4/android/app/src/main/res/layout/prefs_w_buttons.xml b/xwords4/android/app/src/main/res/layout/prefs_w_buttons.xml
index b165db508..686d927c5 100644
--- a/xwords4/android/app/src/main/res/layout/prefs_w_buttons.xml
+++ b/xwords4/android/app/src/main/res/layout/prefs_w_buttons.xml
@@ -7,12 +7,12 @@
android:layout_weight="1"
>
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_appear.xml b/xwords4/android/app/src/main/res/xml/prefs_appear.xml
new file mode 100644
index 000000000..7ab352c9b
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_appear.xml
@@ -0,0 +1,63 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_appear_colors.xml b/xwords4/android/app/src/main/res/xml/prefs_appear_colors.xml
new file mode 100644
index 000000000..8d4339817
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_appear_colors.xml
@@ -0,0 +1,83 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_behave.xml b/xwords4/android/app/src/main/res/xml/prefs_behave.xml
new file mode 100644
index 000000000..e3a43d06e
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_behave.xml
@@ -0,0 +1,56 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_behave_nag.xml b/xwords4/android/app/src/main/res/xml/prefs_behave_nag.xml
new file mode 100644
index 000000000..8bb50404e
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_behave_nag.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dbg.xml b/xwords4/android/app/src/main/res/xml/prefs_dbg.xml
new file mode 100644
index 000000000..a0e6f8289
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dbg.xml
@@ -0,0 +1,74 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dbg_l10n.xml b/xwords4/android/app/src/main/res/xml/prefs_dbg_l10n.xml
new file mode 100644
index 000000000..75bfa6dd6
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dbg_l10n.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dbg_net.xml b/xwords4/android/app/src/main/res/xml/prefs_dbg_net.xml
new file mode 100644
index 000000000..48ead1cf1
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dbg_net.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dbg_sms.xml b/xwords4/android/app/src/main/res/xml/prefs_dbg_sms.xml
new file mode 100644
index 000000000..bf0499691
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dbg_sms.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dflts.xml b/xwords4/android/app/src/main/res/xml/prefs_dflts.xml
new file mode 100644
index 000000000..737a00cac
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dflts.xml
@@ -0,0 +1,77 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dflts_dicts.xml b/xwords4/android/app/src/main/res/xml/prefs_dflts_dicts.xml
new file mode 100644
index 000000000..539b56c26
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dflts_dicts.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_dflts_names.xml b/xwords4/android/app/src/main/res/xml/prefs_dflts_names.xml
new file mode 100644
index 000000000..c45ccff08
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_dflts_names.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_net.xml b/xwords4/android/app/src/main/res/xml/prefs_net.xml
new file mode 100644
index 000000000..b92ca12e0
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_net.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/prefs_net_adv.xml b/xwords4/android/app/src/main/res/xml/prefs_net_adv.xml
new file mode 100644
index 000000000..a326f6e2d
--- /dev/null
+++ b/xwords4/android/app/src/main/res/xml/prefs_net_adv.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
diff --git a/xwords4/android/app/src/main/res/xml/xwprefs.xml b/xwords4/android/app/src/main/res/xml/xwprefs.xml
deleted file mode 100644
index 4b26fc6dc..000000000
--- a/xwords4/android/app/src/main/res/xml/xwprefs.xml
+++ /dev/null
@@ -1,554 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-