diff --git a/xwords4/android/XWords4/AndroidManifest.xml b/xwords4/android/XWords4/AndroidManifest.xml index 8903c13e2..c1d6ae598 100644 --- a/xwords4/android/XWords4/AndroidManifest.xml +++ b/xwords4/android/XWords4/AndroidManifest.xml @@ -35,6 +35,7 @@ key_proxy_port key_sms_port key_dict_host2 + key_logging_on key_init_hintsallowed key_board_size key_initial_player_minutes @@ -96,7 +97,7 @@ -1 - + 300 900 1800 diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 8e4106731..7e4530eb2 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -292,6 +292,7 @@ You may never need these... Relay address Dictionary download URL + Enable logging Relay game port Relay device port SMS port @@ -388,7 +389,7 @@ Recent changes Move check frequency - 30 seconds + 60 seconds 5 minutes 15 minutes 30 minutes diff --git a/xwords4/android/XWords4/res/xml/xwprefs.xml b/xwords4/android/XWords4/res/xml/xwprefs.xml index b95a55616..3e7424d1a 100644 --- a/xwords4/android/XWords4/res/xml/xwprefs.xml +++ b/xwords4/android/XWords4/res/xml/xwprefs.xml @@ -208,6 +208,10 @@ android:defaultValue="@string/dict_url" /> + 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 diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java index 3a127dd8f..4c5c8d944 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/Utils.java @@ -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 ) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java new file mode 100644 index 000000000..dcdee3204 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/XWApp.java @@ -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(); + } +}