add pref enabling SMS games, and a scary confirmation dialog meant to

force user to realize the potential costs (by requiring interaction).
Until that's enabled, show in New Game activity an explanation and
button that goes to Preferences.
This commit is contained in:
Eric House 2012-07-24 07:15:27 -07:00
parent 4f437f0d55
commit cd1eb2e4da
12 changed files with 197 additions and 7 deletions

View file

@ -28,3 +28,4 @@ rename_game.xml
smsinviter_item.xml
smsinviter.xml
game_list_tmp.xml
confirm_sms.xml

View file

@ -270,6 +270,12 @@
android:summary="@string/notify_other_summary"
android:defaultValue="false"
/>
<org.eehouse.android.xw4sms.SMSCheckBoxPreference
android:key="@string/key_enable_sms"
android:title="@string/enable_sms"
android:summary="@string/enable_sms_summary"
android:defaultValue="false"
/>
</PreferenceScreen>
<PreferenceScreen android:title="@string/advanced"

View file

@ -56,3 +56,5 @@ XWListItem.java
XWListPreference.java
MultiService.java
ConnStatusHandler.java
SMSCheckBoxPreference.java
XWPrefs.java

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="8dp"
android:paddingRight="8dp"
>
<TextView android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/confirm_sms_expl"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<Spinner android:id="@+id/confirm_sms_reasons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:entries="@array/confirm_sms_reasons"
/>
</LinearLayout>

View file

@ -55,6 +55,7 @@
<string name="key_connect_frequency">key_connect_frequency</string>
<string name="key_notify_sound">key_notify_sound</string>
<string name="key_notify_vibrate">key_notify_vibrate</string>
<string name="key_enable_sms">key_enable_sms</string>
<string name="key_hide_intro">key_hide_intro</string>
<string name="key_keep_screenon">key_keep_screenon</string>
<string name="key_summary_field">key_summary_field</string>
@ -238,4 +239,10 @@
<item>@string/game_summary_field_state</item>
</string-array>
<string-array name="confirm_sms_reasons">
<item>@string/confirm_sms_noclue</item>
<item>@string/confirm_sms_unlimited</item>
<item>@string/confirm_sms_willpay</item>
</string-array>
</resources>

View file

@ -1902,8 +1902,11 @@
<string name="sms_networked_desc">Create a game that will be
played via invisible text messages. !!!DO NOT DO THIS UNLESS YOU HAVE
AN UNLIMITED TEXT MESSAGING PLAN!!!</string>
<string name="sms_disabled">sms_disabled</string>
<string name="newgame_enable_sms">newgame_enable_sms</string>
<string name="sms_disabled">Playing vis SMS is currently disabled.
You can enable it in Settings->Network game settings.</string>
<string name="newgame_enable_sms">Launch Settings</string>
<string name="err_no_phone">Phone number required</string>
<string name="dft_sms_namef">SMS Game %X</string>
<string name="sms_devs_missing">Missing connections? Invite SMS
@ -1970,4 +1973,17 @@
<string name="connstat_sms">sms/texting</string>
<string name="connstat_bt">bluetooth</string>
<string name="enable_sms">Allow games via SMS</string>
<string name="enable_sms_summary">Only if you have unlimited texting!</string>
<string name="confirm_sms_title">Confirm SMS plan</string>
<string name="confirm_sms_expl">Warning: A single game over SMS
may cause 50 text messages to be sent. Unless you have an
unlimited plan these may cost you up to 50 cents each. How will
you deal with this? (If it isn\'t clear, you SHOULD NOT ENABLE this
feature unless you have unlimited texting.)</string>
<string name="confirm_sms_noclue">Leave disabled</string>
<string name="confirm_sms_unlimited">I have an unlimited texting plan</string>
<string name="confirm_sms_willpay">I will happily pay all charges</string>
</resources>

View file

@ -270,6 +270,12 @@
android:summary="@string/notify_other_summary"
android:defaultValue="false"
/>
<org.eehouse.android.xw4.SMSCheckBoxPreference
android:key="@string/key_enable_sms"
android:title="@string/enable_sms"
android:summary="@string/enable_sms_summary"
android:defaultValue="false"
/>
</PreferenceScreen>
<PreferenceScreen android:title="@string/advanced"

View file

@ -61,6 +61,7 @@ public class NewGameActivity extends XWActivity {
private boolean m_showsOn;
private boolean m_nameForBT;
private boolean m_firingPrefs = false;
private int m_chosen;
private int m_lang = 0;
private long m_newRowID = -1;
@ -136,6 +137,16 @@ public class NewGameActivity extends XWActivity {
}
}
@Override
public void onWindowFocusChanged( boolean hasFocus )
{
super.onWindowFocusChanged( hasFocus );
if ( hasFocus && m_firingPrefs ) {
m_firingPrefs = false;
checkEnableSMS();
}
}
// DlgDelegate.DlgClickNotify interface
@Override
public void dlgButtonClicked( int id, int which )
@ -419,7 +430,7 @@ public class NewGameActivity extends XWActivity {
private void checkEnableSMS()
{
if ( XWApp.SMSSUPPORTED && Utils.deviceSupportsSMS(this) ) {
boolean enabled = true; // is the phone on
boolean enabled = XWPrefs.getSMSEnabled( this );
findViewById( R.id.sms_separator ).setVisibility( View.VISIBLE );
findViewById( R.id.sms_disabled ).
@ -447,8 +458,9 @@ public class NewGameActivity extends XWActivity {
button = (Button)findViewById( R.id.newgame_enable_sms );
button.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick( View v ) {
Utils.notImpl( NewGameActivity.this );
public void onClick( View v ) {
m_firingPrefs = true;
Utils.launchSettings( NewGameActivity.this );
}
} );
}

View file

@ -35,6 +35,7 @@ public class PrefsActivity extends PreferenceActivity
private static final int REVERT_COLORS = 1;
private static final int REVERT_ALL = 2;
public static final int CONFIRM_SMS = 3;
private String m_keyLogging;
private String m_smsToasting;
@ -42,6 +43,7 @@ public class PrefsActivity extends PreferenceActivity
@Override
protected Dialog onCreateDialog( int id )
{
Dialog dialog = null;
DialogInterface.OnClickListener lstnr = null;
int confirmID = 0;
@ -89,10 +91,12 @@ public class PrefsActivity extends PreferenceActivity
}
};
break;
case CONFIRM_SMS:
dialog = SMSCheckBoxPreference.onCreateDialog( this, id );
break;
}
Dialog dialog = null;
if ( null != lstnr ) {
if ( null == dialog && null != lstnr ) {
dialog = new AlertDialog.Builder( this )
.setTitle( R.string.query_title )
.setMessage( confirmID )
@ -145,6 +149,7 @@ public class PrefsActivity extends PreferenceActivity
unregisterOnSharedPreferenceChangeListener(this);
}
@Override
public void onSharedPreferenceChanged( SharedPreferences sp, String key )
{
if ( key.equals( m_keyLogging ) ) {

View file

@ -0,0 +1,101 @@
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
/*
* Copyright 2009 - 2012 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.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.preference.CheckBoxPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Spinner;
public class SMSCheckBoxPreference extends CheckBoxPreference {
private PrefsActivity m_activity;
private boolean m_attached = false;
protected static SMSCheckBoxPreference s_this = null;
public SMSCheckBoxPreference( Context context, AttributeSet attrs )
{
super( context, attrs );
s_this = this;
m_activity = (PrefsActivity)context;
}
@Override
protected void onAttachedToActivity()
{
super.onAttachedToActivity();
if ( !XWApp.SMSSUPPORTED || !Utils.deviceSupportsSMS( m_activity ) ) {
setEnabled( false );
}
m_attached = true;
}
@Override
public void setChecked( boolean checked )
{
if ( !checked || !m_attached ) {
super.setChecked( false );
} else {
m_activity.showDialog( PrefsActivity.CONFIRM_SMS );
}
}
// Because s_this.super.setChecked() isn't allowed...
private void super_setChecked( boolean checked )
{
super.setChecked( checked );
}
public static Dialog onCreateDialog( final Activity activity, final int id )
{
final View layout = Utils.inflate( activity, R.layout.confirm_sms );
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int item ) {
Spinner reasons = (Spinner)
layout.findViewById( R.id.confirm_sms_reasons );
if ( 0 < reasons.getSelectedItemPosition() ) {
s_this.super_setChecked( true );
}
}
};
AlertDialog.Builder ab = new AlertDialog.Builder( activity )
.setTitle( R.string.confirm_sms_title )
.setView( layout )
.setNegativeButton( R.string.button_ok, lstnr );
Dialog dialog = ab.create();
dialog.setOnDismissListener( new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
activity.removeDialog( id );
}
} );
return dialog;
}
}

View file

@ -114,6 +114,12 @@ public class Utils {
} );
}
public static void launchSettings( Context context )
{
Intent intent = new Intent( context, PrefsActivity.class );
context.startActivity( intent );
}
public static void emailAuthor( Context context )
{
Intent intent = new Intent( Intent.ACTION_SEND );

View file

@ -26,6 +26,11 @@ import android.preference.PreferenceManager;
public class XWPrefs {
public static boolean getSMSEnabled( Context context )
{
return getPrefsBoolean( context, R.string.key_enable_sms, false );
}
public static boolean getPrefsBoolean( Context context, int keyID,
boolean defaultValue )
{