From 81fb934e4a185a387c1daa34877a18cef8d1b359 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 5 Oct 2010 18:36:56 -0700 Subject: [PATCH] new custom class for resetting polling timer on prefs change --- .../android/xw4/PollListPreference.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 xwords4/android/XWords4/src/org/eehouse/android/xw4/PollListPreference.java diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/PollListPreference.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PollListPreference.java new file mode 100644 index 000000000..68e8a23d9 --- /dev/null +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/PollListPreference.java @@ -0,0 +1,59 @@ +/* -*- compile-command: "cd ../../../../../; ant install"; -*- */ +/* + * 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.preference.Preference; +import android.preference.ListPreference; +import android.content.Context; +import android.util.AttributeSet; +import junit.framework.Assert; + + +public class PollListPreference extends ListPreference + implements Preference.OnPreferenceChangeListener { + + private Context m_context; + + public PollListPreference( Context context, AttributeSet attrs ) + { + super( context, attrs ); + m_context = context; + setOnPreferenceChangeListener( this ); + + } + + @Override + protected void onAttachedToActivity() + { + // String key = getString( R.string.key_connect_frequency ); + String val = getPersistedString( "0" ); + setSummary( String.format( "%s minutes", val ) ); + } + + // Preference.OnPreferenceChangeListener interface + public boolean onPreferenceChange( Preference preference, Object newValue ) + { + int val = Integer.parseInt((String)newValue); + RelayActivity.RestartTimer( m_context, val * 1000 ); + setSummary( String.format( "%d seconds", val ) ); + return true; + } +} \ No newline at end of file