move remaining non-jni prefs stuff from CommonPrefs to XWPrefs. No

other changes.
This commit is contained in:
Eric House 2012-08-16 06:31:23 -07:00
parent 81d7903aa3
commit 6226efe8d6
18 changed files with 184 additions and 208 deletions

View file

@ -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, String>();
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()

View file

@ -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 );
}

View file

@ -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() );

View file

@ -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>();
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 );
}

View file

@ -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";

View file

@ -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,

View file

@ -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;

View file

@ -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;

View file

@ -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 ) );

View file

@ -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 );

View file

@ -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 )

View file

@ -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 {

View file

@ -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<PhoneRec>(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 );
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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<String> getPrefsStringArrayList( Context context,
int keyID )
{
ArrayList<String> list = new ArrayList<String>();
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 ) );
}
}

View file

@ -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<String> getPrefsStringArrayList( Context context,
int keyID )
{
ArrayList<String> list = new ArrayList<String>();
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 ) );
}
}