From 6226efe8d63218a25a49b09df69a5b4a3672e5ea Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 16 Aug 2012 06:31:23 -0700 Subject: [PATCH] move remaining non-jni prefs stuff from CommonPrefs to XWPrefs. No other changes. --- .../org/eehouse/android/xw4/BTService.java | 9 +- .../eehouse/android/xw4/BoardActivity.java | 4 +- .../android/xw4/ConnStatusHandler.java | 11 +- .../eehouse/android/xw4/DictsActivity.java | 7 +- .../eehouse/android/xw4/DispatchNotify.java | 2 - .../org/eehouse/android/xw4/DlgDelegate.java | 7 +- .../org/eehouse/android/xw4/GameConfig.java | 4 +- .../org/eehouse/android/xw4/GameUtils.java | 8 +- .../eehouse/android/xw4/NetLaunchInfo.java | 6 +- .../src/org/eehouse/android/xw4/NetUtils.java | 7 +- .../eehouse/android/xw4/RelayReceiver.java | 4 +- .../org/eehouse/android/xw4/RelayService.java | 1 - .../android/xw4/SMSInviteActivity.java | 6 +- .../org/eehouse/android/xw4/SMSService.java | 1 - .../org/eehouse/android/xw4/XWActivity.java | 2 - .../eehouse/android/xw4/XWListActivity.java | 2 - .../src/org/eehouse/android/xw4/XWPrefs.java | 156 ++++++++++++++++++ .../eehouse/android/xw4/jni/CommonPrefs.java | 155 ----------------- 18 files changed, 184 insertions(+), 208 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java index 223b1244f..71b506ce1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BTService.java @@ -47,7 +47,6 @@ import java.util.concurrent.TimeUnit; import junit.framework.Assert; import org.eehouse.android.xw4.MultiService.MultiEvent; -import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommsAddrRec; public class BTService extends Service { @@ -877,9 +876,9 @@ public class BTService extends Service { { m_names = new HashMap(); - String[] names = CommonPrefs.getBTNames( this ); + String[] names = XWPrefs.getBTNames( this ); if ( null != names ) { - String[] addrs = CommonPrefs.getBTAddresses( this ); + String[] addrs = XWPrefs.getBTAddresses( this ); if ( null != addrs && names.length == addrs.length ) { for ( int ii = 0; ii < names.length; ++ii ) { m_names.put( names[ii], addrs[ii] ); @@ -905,8 +904,8 @@ public class BTService extends Service { addrs[ii] = entry.getValue(); } - CommonPrefs.setBTNames( this, names ); - CommonPrefs.setBTAddresses( this, addrs ); + XWPrefs.setBTNames( this, names ); + XWPrefs.setBTAddresses( this, addrs ); } private void startListener() diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index 019da85fc..0182c2ce7 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -463,7 +463,7 @@ public class BoardActivity extends XWActivity if ( null != m_exchCancelButton ) { m_exchCancelButton.setOnClickListener( this ); } - m_volKeysZoom = CommonPrefs.getVolKeysZoom( this ); + m_volKeysZoom = XWPrefs.getVolKeysZoom( this ); Intent intent = getIntent(); m_rowid = intent.getLongExtra( GameUtils.INTENT_KEY_ROWID, -1 ); @@ -560,7 +560,7 @@ public class BoardActivity extends XWActivity if ( hasFocus ) { if ( m_firingPrefs ) { m_firingPrefs = false; - m_volKeysZoom = CommonPrefs.getVolKeysZoom( this ); + m_volKeysZoom = XWPrefs.getVolKeysZoom( this ); if ( null != m_jniThread ) { m_jniThread.handle( JNIThread.JNICmd.CMD_PREFS_CHANGE ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnStatusHandler.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnStatusHandler.java index c20565329..73b8e39ba 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnStatusHandler.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/ConnStatusHandler.java @@ -39,7 +39,6 @@ import java.io.ObjectOutputStream; import java.util.HashMap; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; import org.eehouse.android.xw4.jni.XwJNI; @@ -324,8 +323,8 @@ public class ConnStatusHandler { public static void loadState( Context context ) { synchronized( s_lockObj ) { - String as64 = CommonPrefs.getPrefsString( context, - R.string.key_connstat_data ); + String as64 = XWPrefs.getPrefsString( context, + R.string.key_connstat_data ); if ( null != as64 && 0 < as64.length() ) { byte[] bytes = XwJNI.base64Decode( as64 ); try { @@ -451,10 +450,8 @@ public class ConnStatusHandler { out.flush(); String as64 = XwJNI.base64Encode( bas.toByteArray() ); - CommonPrefs. - setPrefsString( context, - R.string.key_connstat_data, - as64 ); + XWPrefs.setPrefsString( context, R.string.key_connstat_data, + as64 ); } catch ( java.io.IOException ioe ) { DbgUtils.logf( "loadState: %s", ioe.toString() ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java index 62e64fc14..28b1edccd 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DictsActivity.java @@ -56,7 +56,6 @@ import junit.framework.Assert; import org.eehouse.android.xw4.DictUtils.DictAndLoc; import org.eehouse.android.xw4.jni.XwJNI; import org.eehouse.android.xw4.jni.JNIUtilsImpl; -import org.eehouse.android.xw4.jni.CommonPrefs; public class DictsActivity extends ExpandableListActivity implements View.OnClickListener, XWListItem.DeleteCallback, @@ -383,7 +382,7 @@ public class DictsActivity extends ExpandableListActivity getBundledData( savedInstanceState ); m_closedLangs = new HashSet(); - String[] closed = CommonPrefs.getClosedLangs( this ); + String[] closed = XWPrefs.getClosedLangs( this ); if ( null != closed ) { for ( String str : closed ) { m_closedLangs.add( str ); @@ -716,7 +715,7 @@ public class DictsActivity extends ExpandableListActivity private void saveClosed() { String[] asArray = m_closedLangs.toArray( new String[m_closedLangs.size()] ); - CommonPrefs.setClosedLangs( this, asArray ); + XWPrefs.setClosedLangs( this, asArray ); } private static Intent mkDownloadIntent( Context context, String dict_url ) @@ -730,7 +729,7 @@ public class DictsActivity extends ExpandableListActivity private static Intent mkDownloadIntent( Context context, int lang, String dict ) { - String dict_url = CommonPrefs.getDefaultDictURL( context ); + String dict_url = XWPrefs.getDefaultDictURL( context ); if ( 0 != lang ) { dict_url += "/" + DictLangCache.getLangName( context, lang ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java index 290b93b8f..ab9231174 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DispatchNotify.java @@ -29,8 +29,6 @@ import android.os.Bundle; import java.util.HashSet; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class DispatchNotify extends Activity { public static final String RELAYIDS_EXTRA = "relayids"; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index b7d868cf1..cc473580b 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -34,8 +34,6 @@ import android.widget.Toast; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class DlgDelegate { @@ -180,7 +178,7 @@ public class DlgDelegate { public void showNotAgainDlgThen( int msgID, int prefsKey, int callbackID ) { - boolean set = CommonPrefs.getPrefsBoolean( m_activity, prefsKey, false ); + boolean set = XWPrefs.getPrefsBoolean( m_activity, prefsKey, false ); if ( set || 0 != m_cbckID ) { // If it's set, do the action without bothering with the // dialog @@ -364,8 +362,7 @@ public class DlgDelegate { DialogInterface.OnClickListener lstnr_n = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int item ) { - CommonPrefs.setPrefsBoolean( m_activity, m_prefsKey, - true ); + XWPrefs.setPrefsBoolean( m_activity, m_prefsKey, true ); if ( SKIP_CALLBACK != m_cbckID ) { m_clickCallback. dlgButtonClicked( m_cbckID, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java index 9028f53c6..63f4680df 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameConfig.java @@ -489,8 +489,8 @@ public class GameConfig extends XWActivity XwJNI.comms_getAddr( gamePtr, m_carOrig ); m_remoteAddrs = XwJNI.comms_getAddrs( gamePtr ); } else if (DeviceRole.SERVER_STANDALONE != m_giOrig.serverRole){ - String relayName = CommonPrefs.getDefaultRelayHost( this ); - int relayPort = CommonPrefs.getDefaultRelayPort( this ); + String relayName = XWPrefs.getDefaultRelayHost( this ); + int relayPort = XWPrefs.getDefaultRelayPort( this ); XwJNI.comms_getInitialAddr( m_carOrig, relayName, relayPort ); } m_conType = m_carOrig.conType; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java index d0aad372e..35733df48 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/GameUtils.java @@ -214,8 +214,8 @@ public class GameUtils { addr = new CommsAddrRec(); XwJNI.comms_getAddr( gamePtr, addr ); if ( CommsAddrRec.CommsConnType.COMMS_CONN_NONE == addr.conType ) { - String relayName = CommonPrefs.getDefaultRelayHost( context ); - int relayPort = CommonPrefs.getDefaultRelayPort( context ); + String relayName = XWPrefs.getDefaultRelayHost( context ); + int relayPort = XWPrefs.getDefaultRelayPort( context ); XwJNI.comms_getInitialAddr( addr, relayName, relayPort ); } } @@ -453,8 +453,8 @@ public class GameUtils { int nPlayersT, int nPlayersH ) { long rowid = -1; - String relayName = CommonPrefs.getDefaultRelayHost( context ); - int relayPort = CommonPrefs.getDefaultRelayPort( context ); + String relayName = XWPrefs.getDefaultRelayHost( context ); + int relayPort = XWPrefs.getDefaultRelayPort( context ); CommsAddrRec addr = new CommsAddrRec( relayName, relayPort ); addr.ip_relay_invite = room; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java index 3d5f415df..01d987341 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetLaunchInfo.java @@ -26,8 +26,6 @@ import android.net.Uri.Builder; import android.os.Bundle; import java.net.URLEncoder; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class NetLaunchInfo { public String room; @@ -85,8 +83,8 @@ public class NetLaunchInfo { Builder ub = new Builder(); ub.scheme( "http" ); String format = context.getString( R.string.game_url_pathf ); - ub.path( String.format( format, - CommonPrefs.getDefaultRedirHost( context ) ) ); + ub.path( String.format( format, + XWPrefs.getDefaultRedirHost( context ) ) ); ub.appendQueryParameter( "lang", String.format("%d", lang ) ); ub.appendQueryParameter( "np", String.format( "%d", nPlayers ) ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java index 63db986ab..647a61509 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/NetUtils.java @@ -34,9 +34,6 @@ import java.util.HashMap; import java.util.Iterator; import javax.net.SocketFactory; - -import org.eehouse.android.xw4.jni.CommonPrefs; - public class NetUtils { private static final int MAX_SEND = 1024; @@ -55,8 +52,8 @@ public class NetUtils { { Socket socket = null; try { - int port = CommonPrefs.getDefaultProxyPort( context ); - String host = CommonPrefs.getDefaultRelayHost( context ); + int port = XWPrefs.getDefaultProxyPort( context ); + String host = XWPrefs.getDefaultRelayHost( context ); SocketFactory factory = SocketFactory.getDefault(); InetAddress addr = InetAddress.getByName( host ); diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java index 56047f6ed..cfd239cf9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayReceiver.java @@ -28,8 +28,6 @@ import android.content.Intent; import android.os.SystemClock; import android.widget.Toast; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class RelayReceiver extends BroadcastReceiver { @Override @@ -51,7 +49,7 @@ public class RelayReceiver extends BroadcastReceiver { public static void RestartTimer( Context context, boolean force ) { RestartTimer( context, - 1000 * CommonPrefs.getProxyInterval( context ), force ); + 1000 * XWPrefs.getProxyInterval( context ), force ); } public static void RestartTimer( Context context ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java index 8295e1093..76fc3c1f8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/RelayService.java @@ -34,7 +34,6 @@ import java.io.DataOutputStream; import java.util.ArrayList; import org.eehouse.android.xw4.jni.GameSummary; -import org.eehouse.android.xw4.jni.CommonPrefs; public class RelayService extends Service { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java index e1da00576..dc7922317 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSInviteActivity.java @@ -46,8 +46,6 @@ import java.util.Comparator; import java.util.Iterator; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class SMSInviteActivity extends InviteActivity { private static final int GET_CONTACT = 1; @@ -281,7 +279,7 @@ public class SMSInviteActivity extends InviteActivity { private void getSavedState() { - String[] phones = CommonPrefs.getSMSPhones( this ); + String[] phones = XWPrefs.getSMSPhones( this ); m_phoneRecs = new ArrayList(phones.length); for ( String phone : phones ) { @@ -298,7 +296,7 @@ public class SMSInviteActivity extends InviteActivity { PhoneRec rec = iter.next(); phones[ii] = rec.m_phone; } - CommonPrefs.setSMSPhones( this, phones ); + XWPrefs.setSMSPhones( this, phones ); rebuildList( false ); } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java index c283a2908..7890eba64 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/SMSService.java @@ -49,7 +49,6 @@ import junit.framework.Assert; import org.eehouse.android.xw4.MultiService.MultiEvent; import org.eehouse.android.xw4.jni.CommsAddrRec; import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType; -import org.eehouse.android.xw4.jni.CommonPrefs; import org.eehouse.android.xw4.jni.XwJNI; public class SMSService extends Service { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java index c22698ac1..13534f03c 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWActivity.java @@ -30,8 +30,6 @@ import android.view.View; import android.widget.TextView; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class XWActivity extends Activity implements DlgDelegate.DlgClickNotify, MultiService.BTEventListener { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java index a1b1113fc..397085e70 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWListActivity.java @@ -27,8 +27,6 @@ import android.os.Bundle; import junit.framework.Assert; -import org.eehouse.android.xw4.jni.CommonPrefs; - public class XWListActivity extends ListActivity implements DlgDelegate.DlgClickNotify, MultiService.BTEventListener { diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java index e5af01811..b163cd8b9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWPrefs.java @@ -23,6 +23,9 @@ package org.eehouse.android.xw4; import android.content.Context; import android.content.SharedPreferences; import android.preference.PreferenceManager; +import android.text.TextUtils; +import java.util.ArrayList; +import java.util.ArrayList; public class XWPrefs { @@ -36,6 +39,74 @@ public class XWPrefs { return getPrefsBoolean( context, R.string.key_enable_debug, false ); } + public static String getDefaultRelayHost( Context context ) + { + return getPrefsString( context, R.string.key_relay_host ); + } + + public static String getDefaultRedirHost( Context context ) + { + return getPrefsString( context, R.string.key_redir_host ); + } + + public static int getDefaultRelayPort( Context context ) + { + String val = getPrefsString( context, R.string.key_relay_port ); + int result = 0; + try { + result = Integer.parseInt( val ); + } catch ( Exception ex ) { + } + return result; + } + + public static int getDefaultProxyPort( Context context ) + { + String val = getPrefsString( context, R.string.key_proxy_port ); + int result = 0; + try { + result = Integer.parseInt( val ); + } catch ( Exception ex ) { + } + // DbgUtils.logf( "getDefaultProxyPort=>%d", result ); + return result; + } + + public static String getDefaultDictURL( Context context ) + { + return getPrefsString( context, R.string.key_dict_host ); + } + + public static boolean getVolKeysZoom( Context context ) + { + return getPrefsBoolean( context, R.string.key_ringer_zoom, false ); + } + + public static int getDefaultPlayerMinutes( Context context ) + { + String value = + getPrefsString( context, R.string.key_initial_player_minutes ); + int result; + try { + result = Integer.parseInt( value ); + } catch ( Exception ex ) { + result = 25; + } + return result; + } + + public static long getProxyInterval( Context context ) + { + String value = getPrefsString( context, R.string.key_connect_frequency ); + long result; + try { + result = Long.parseLong( value ); + } catch ( Exception ex ) { + result = -1; + } + return result; + } + public static boolean getPrefsBoolean( Context context, int keyID, boolean defaultValue ) { @@ -56,4 +127,89 @@ public class XWPrefs { editor.commit(); } + public static void setClosedLangs( Context context, String[] langs ) + { + setPrefsString( context, R.string.key_closed_langs, + TextUtils.join( "\n", langs ) ); + } + + public static String[] getClosedLangs( Context context ) + { + return getPrefsStringArray( context, R.string.key_closed_langs ); + } + + public static void setBTNames( Context context, String[] names ) + { + setPrefsStringArray( context, R.string.key_bt_names, names ); + } + + public static void setSMSPhones( Context context, String[] names ) + { + setPrefsStringArray( context, R.string.key_sms_phones, names ); + } + + public static String[] getBTNames( Context context ) + { + return getPrefsStringArray( context, R.string.key_bt_names ); + } + + public static String[] getSMSPhones( Context context ) + { + return getPrefsStringArray( context, R.string.key_sms_phones ); + } + + public static void setBTAddresses( Context context, String[] addrs ) + { + setPrefsStringArray( context, R.string.key_bt_addrs, addrs ); + } + + public static String[] getBTAddresses( Context context ) + { + return getPrefsStringArray( context, R.string.key_bt_addrs ); + } + + protected static String getPrefsString( Context context, int keyID ) + { + String key = context.getString( keyID ); + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences( context ); + return sp.getString( key, "" ); + } + + protected static void setPrefsString( Context context, int keyID, + String newValue ) + { + SharedPreferences sp = PreferenceManager + .getDefaultSharedPreferences( context ); + SharedPreferences.Editor editor = sp.edit(); + String key = context.getString( keyID ); + editor.putString( key, newValue ); + editor.commit(); + } + + protected static String[] getPrefsStringArray( Context context, int keyID ) + { + String asStr = getPrefsString( context, keyID ); + String[] result = null == asStr ? null : TextUtils.split( asStr, "\n" ); + return result; + } + + protected static ArrayList getPrefsStringArrayList( Context context, + int keyID ) + { + ArrayList list = new ArrayList(); + String[] strs = getPrefsStringArray( context, keyID ); + if ( null != strs ) { + for ( int ii = 0; ii < strs.length; ++ii ) { + list.add( strs[ii] ); + } + } + return list; + } + + protected static void setPrefsStringArray( Context context, int keyID, + String[] value ) + { + setPrefsString( context, keyID, TextUtils.join( "\n", value ) ); + } } \ No newline at end of file diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java index f0af5119e..0eb6626e8 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/CommonPrefs.java @@ -25,8 +25,6 @@ import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Paint; import android.preference.PreferenceManager; -import android.text.TextUtils; -import java.util.ArrayList; import junit.framework.Assert; import org.eehouse.android.xw4.XWPrefs; @@ -140,49 +138,6 @@ public class CommonPrefs extends XWPrefs { return s_cp.refresh( context ); } - public static String getDefaultRelayHost( Context context ) - { - return getPrefsString( context, R.string.key_relay_host ); - } - - public static String getDefaultRedirHost( Context context ) - { - return getPrefsString( context, R.string.key_redir_host ); - } - - public static int getDefaultRelayPort( Context context ) - { - String val = getPrefsString( context, R.string.key_relay_port ); - int result = 0; - try { - result = Integer.parseInt( val ); - } catch ( Exception ex ) { - } - return result; - } - - public static int getDefaultProxyPort( Context context ) - { - String val = getPrefsString( context, R.string.key_proxy_port ); - int result = 0; - try { - result = Integer.parseInt( val ); - } catch ( Exception ex ) { - } - // DbgUtils.logf( "getDefaultProxyPort=>%d", result ); - return result; - } - - public static String getDefaultDictURL( Context context ) - { - return getPrefsString( context, R.string.key_dict_host ); - } - - public static boolean getVolKeysZoom( Context context ) - { - return getPrefsBoolean( context, R.string.key_ringer_zoom, false ); - } - public static int getDefaultBoardSize( Context context ) { String value = getPrefsString( context, R.string.key_board_size ); @@ -195,31 +150,6 @@ public class CommonPrefs extends XWPrefs { return result; } - public static int getDefaultPlayerMinutes( Context context ) - { - String value = - getPrefsString( context, R.string.key_initial_player_minutes ); - int result; - try { - result = Integer.parseInt( value ); - } catch ( Exception ex ) { - result = 25; - } - return result; - } - - public static long getProxyInterval( Context context ) - { - String value = getPrefsString( context, R.string.key_connect_frequency ); - long result; - try { - result = Long.parseLong( value ); - } catch ( Exception ex ) { - result = -1; - } - return result; - } - public static String getDefaultHumanDict( Context context ) { String value = getPrefsString( context, R.string.key_default_dict ); @@ -337,89 +267,4 @@ public class CommonPrefs extends XWPrefs { return getPrefsString( context, R.string.key_summary_field ); } - public static void setClosedLangs( Context context, String[] langs ) - { - setPrefsString( context, R.string.key_closed_langs, - TextUtils.join( "\n", langs ) ); - } - - public static String[] getClosedLangs( Context context ) - { - return getPrefsStringArray( context, R.string.key_closed_langs ); - } - - public static void setBTNames( Context context, String[] names ) - { - setPrefsStringArray( context, R.string.key_bt_names, names ); - } - - public static void setSMSPhones( Context context, String[] names ) - { - setPrefsStringArray( context, R.string.key_sms_phones, names ); - } - - public static String[] getBTNames( Context context ) - { - return getPrefsStringArray( context, R.string.key_bt_names ); - } - - public static String[] getSMSPhones( Context context ) - { - return getPrefsStringArray( context, R.string.key_sms_phones ); - } - - public static void setBTAddresses( Context context, String[] addrs ) - { - setPrefsStringArray( context, R.string.key_bt_addrs, addrs ); - } - - public static String[] getBTAddresses( Context context ) - { - return getPrefsStringArray( context, R.string.key_bt_addrs ); - } - - public static String getPrefsString( Context context, int keyID ) - { - String key = context.getString( keyID ); - SharedPreferences sp = PreferenceManager - .getDefaultSharedPreferences( context ); - return sp.getString( key, "" ); - } - - public static void setPrefsString( Context context, int keyID, - String newValue ) - { - SharedPreferences sp = PreferenceManager - .getDefaultSharedPreferences( context ); - SharedPreferences.Editor editor = sp.edit(); - String key = context.getString( keyID ); - editor.putString( key, newValue ); - editor.commit(); - } - - private static String[] getPrefsStringArray( Context context, int keyID ) - { - String asStr = getPrefsString( context, keyID ); - String[] result = null == asStr ? null : TextUtils.split( asStr, "\n" ); - return result; - } - - private static ArrayList getPrefsStringArrayList( Context context, - int keyID ) - { - ArrayList list = new ArrayList(); - String[] strs = getPrefsStringArray( context, keyID ); - if ( null != strs ) { - for ( int ii = 0; ii < strs.length; ++ii ) { - list.add( strs[ii] ); - } - } - return list; - } - - private static void setPrefsStringArray( Context context, int keyID, - String[] value ) - { - setPrefsString( context, keyID, TextUtils.join( "\n", value ) ); - } }