mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-30 10:26:58 +01:00
add static boolean that controls whether logging is on (for java).
Add an Application subclass that fetches the value from a preference, a checkbox setting in advanced prefs, and modify the static when that's changed at runtime.
This commit is contained in:
parent
54ef8f73c9
commit
a344f26d1b
7 changed files with 76 additions and 8 deletions
|
@ -35,6 +35,7 @@
|
|||
|
||||
<application android:icon="@drawable/icon48x48"
|
||||
android:label="@string/app_name"
|
||||
android:name=".XWApp"
|
||||
>
|
||||
|
||||
<activity android:name="GamesList"
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
<string name="key_proxy_port">key_proxy_port</string>
|
||||
<string name="key_sms_port">key_sms_port</string>
|
||||
<string name="key_dict_host">key_dict_host2</string>
|
||||
<string name="key_logging_on">key_logging_on</string>
|
||||
<string name="key_init_hintsallowed">key_init_hintsallowed</string>
|
||||
<string name="key_board_size">key_board_size</string>
|
||||
<string name="key_initial_player_minutes">key_initial_player_minutes</string>
|
||||
|
@ -96,7 +97,7 @@
|
|||
|
||||
<string-array name="connect_frequencies_values">
|
||||
<item>-1</item>
|
||||
<!-- <item>30</item> -->
|
||||
<!-- <item>60</item> -->
|
||||
<item>300</item>
|
||||
<item>900</item>
|
||||
<item>1800</item>
|
||||
|
|
|
@ -292,6 +292,7 @@
|
|||
<string name="advanced_summary">You may never need these...</string>
|
||||
<string name="relay_host">Relay address</string>
|
||||
<string name="dict_host">Dictionary download URL</string>
|
||||
<string name="logging_on">Enable logging</string>
|
||||
<string name="relay_port">Relay game port</string>
|
||||
<string name="proxy_port">Relay device port</string>
|
||||
<string name="sms_port">SMS port</string>
|
||||
|
@ -388,7 +389,7 @@
|
|||
<string name="changes_button">Recent changes</string>
|
||||
|
||||
<string name="connect_frequency">Move check frequency</string>
|
||||
<string name="connect_thirty_seconds">30 seconds</string>
|
||||
<string name="connect_thirty_seconds">60 seconds</string>
|
||||
<string name="connect_five_mins">5 minutes</string>
|
||||
<string name="connect_fifteen_mins">15 minutes</string>
|
||||
<string name="connect_thirty_mins">30 minutes</string>
|
||||
|
|
|
@ -208,6 +208,10 @@
|
|||
android:defaultValue="@string/dict_url"
|
||||
/>
|
||||
|
||||
<CheckBoxPreference android:key="@string/key_logging_on"
|
||||
android:title="@string/logging_on"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<EditTextPreference android:title="@string/git_rev_title"
|
||||
android:summary="@string/git_rev_gen"
|
||||
android:enabled="false"
|
||||
|
|
|
@ -41,6 +41,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
|
||||
private HashSet<String> m_keys;
|
||||
private String m_keyEmpty;
|
||||
private String m_keyLogging;
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
|
@ -132,6 +133,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
m_keys.add( key );
|
||||
}
|
||||
m_keyEmpty = getString( R.string.key_empty );
|
||||
m_keyLogging = getString( R.string.key_logging_on );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,6 +157,9 @@ public class PrefsActivity extends PreferenceActivity
|
|||
if ( m_keys.contains( key ) ) {
|
||||
setSummary( sp, key );
|
||||
}
|
||||
if ( key.equals( m_keyLogging ) ) {
|
||||
Utils.logEnable( sp.getBoolean( key, false ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -25,6 +25,8 @@ import java.lang.Thread;
|
|||
import android.widget.Toast;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.widget.CheckBox;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
@ -43,22 +45,42 @@ public class Utils {
|
|||
|
||||
static final String DB_PATH = "XW_GAMES";
|
||||
|
||||
static boolean s_doLog = true;
|
||||
|
||||
private static Time s_time = new Time();
|
||||
|
||||
private Utils() {}
|
||||
|
||||
public static void logEnable( boolean enable )
|
||||
{
|
||||
s_doLog = enable;
|
||||
}
|
||||
|
||||
public static void logEnable( Context context )
|
||||
{
|
||||
SharedPreferences sp
|
||||
= PreferenceManager.getDefaultSharedPreferences( context );
|
||||
String key = context.getString( R.string.key_logging_on );
|
||||
boolean on = sp.getBoolean( key, false );
|
||||
logEnable( on );
|
||||
}
|
||||
|
||||
public static void logf( String msg )
|
||||
{
|
||||
s_time.setToNow();
|
||||
String time = s_time.format("[%H:%M:%S]");
|
||||
long id = Thread.currentThread().getId();
|
||||
Log.d( TAG, time + "-" + id + "-" + msg );
|
||||
if ( s_doLog ) {
|
||||
s_time.setToNow();
|
||||
String time = s_time.format("[%H:%M:%S]");
|
||||
long id = Thread.currentThread().getId();
|
||||
Log.d( TAG, time + "-" + id + "-" + msg );
|
||||
}
|
||||
} // logf
|
||||
|
||||
public static void logf( String format, Object... args )
|
||||
{
|
||||
Formatter formatter = new Formatter();
|
||||
logf( formatter.format( format, args ).toString() );
|
||||
if ( s_doLog ) {
|
||||
Formatter formatter = new Formatter();
|
||||
logf( formatter.format( format, args ).toString() );
|
||||
}
|
||||
} // logf
|
||||
|
||||
public static void notImpl( Context context )
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
|
||||
/*
|
||||
* Copyright 2010 - 2011 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.app.Application;
|
||||
|
||||
public class XWApp extends Application {
|
||||
|
||||
@Override
|
||||
public void onCreate()
|
||||
{
|
||||
Utils.logEnable( this );
|
||||
Utils.logf( "XWApp.onCreate()" );
|
||||
super.onCreate();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue