mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-28 07:58:08 +01:00
add debug-prefs checkbox to turn on Toasts when SMS sent or received;
send on emulator too -- which works to test between two instances.
This commit is contained in:
parent
1e22a33d55
commit
18a781d516
4 changed files with 42 additions and 21 deletions
|
@ -38,6 +38,7 @@
|
|||
<string name="key_sms_port">key_sms_port</string>
|
||||
<string name="key_dict_host">key_dict_host3</string>
|
||||
<string name="key_logging_on">key_logging_on</string>
|
||||
<string name="key_show_sms">key_show_sms</string>
|
||||
<string name="key_init_hintsallowed">key_init_hintsallowed</string>
|
||||
<string name="key_init_autojuggle">key_init_autojuggle</string>
|
||||
<string name="key_board_size">key_board_size</string>
|
||||
|
|
|
@ -302,6 +302,10 @@
|
|||
android:title="@string/logging_on"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<CheckBoxPreference android:key="@string/key_show_sms"
|
||||
android:title="Show SMS sends, receives"
|
||||
android:defaultValue="false"
|
||||
/>
|
||||
<EditTextPreference android:title="@string/git_rev_title"
|
||||
android:summary="@string/git_rev"
|
||||
android:enabled="false"
|
||||
|
|
|
@ -37,6 +37,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
private static final int REVERT_ALL = 2;
|
||||
|
||||
private String m_keyLogging;
|
||||
private String m_smsToasting;
|
||||
|
||||
@Override
|
||||
protected Dialog onCreateDialog( int id )
|
||||
|
@ -112,6 +113,7 @@ public class PrefsActivity extends PreferenceActivity
|
|||
setContentView( R.layout.prefs_w_buttons );
|
||||
|
||||
m_keyLogging = getString( R.string.key_logging_on );
|
||||
m_smsToasting = getString( R.string.key_show_sms );
|
||||
|
||||
Button button = (Button)findViewById( R.id.revert_colors );
|
||||
button.setOnClickListener( new View.OnClickListener() {
|
||||
|
@ -147,6 +149,8 @@ public class PrefsActivity extends PreferenceActivity
|
|||
{
|
||||
if ( key.equals( m_keyLogging ) ) {
|
||||
DbgUtils.logEnable( sp.getBoolean( key, false ) );
|
||||
} else if ( key.equals( m_smsToasting ) ) {
|
||||
SMSService.smsToastEnable( sp.getBoolean( key, false ) );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@ import android.app.PendingIntent;
|
|||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.IBinder;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.telephony.SmsManager;
|
||||
import android.telephony.SmsMessage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -33,9 +35,9 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.lang.System;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.lang.System;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||
|
@ -60,6 +62,8 @@ public class SMSService extends Service {
|
|||
private static final String NPLAYERST = "NPLAYERST";
|
||||
private static final String NPLAYERSH = "NPLAYERSH";
|
||||
|
||||
private static Boolean s_showToasts = null;
|
||||
|
||||
// All messages are base64-encoded byte arrays. The first byte is
|
||||
// always one of these. What follows depends.
|
||||
private enum SMS_CMD { NONE, INVITE, DATA, };
|
||||
|
@ -69,6 +73,11 @@ public class SMSService extends Service {
|
|||
private static HashMap<String, HashMap <Integer, MsgStore>> s_partialMsgs
|
||||
= new HashMap<String, HashMap <Integer, MsgStore>>();
|
||||
|
||||
public static void smsToastEnable( boolean newVal )
|
||||
{
|
||||
s_showToasts = newVal;
|
||||
}
|
||||
|
||||
public static void handleFrom( Context context, String buffer, String phone )
|
||||
{
|
||||
Intent intent = getIntentTo( context, HANDLE );
|
||||
|
@ -121,6 +130,13 @@ public class SMSService extends Service {
|
|||
|
||||
private static Intent getIntentTo( Context context, int cmd )
|
||||
{
|
||||
if ( null == s_showToasts ) {
|
||||
SharedPreferences sp
|
||||
= PreferenceManager.getDefaultSharedPreferences( context );
|
||||
String key = context.getString( R.string.key_show_sms );
|
||||
s_showToasts = sp.getBoolean( key, false );
|
||||
}
|
||||
|
||||
Intent intent = new Intent( context, SMSService.class );
|
||||
intent.putExtra( CMD_STR, cmd );
|
||||
return intent;
|
||||
|
@ -388,27 +404,23 @@ public class SMSService extends Service {
|
|||
{
|
||||
DbgUtils.logf( "SMSService.sendBuffers()" );
|
||||
boolean success = false;
|
||||
if ( XWApp.onEmulator() ) {
|
||||
DbgUtils.logf( "sendBuffer(phone=%s): FAKING IT", phone );
|
||||
} else {
|
||||
try {
|
||||
SmsManager mgr = SmsManager.getDefault();
|
||||
for ( String fragment : fragments ) {
|
||||
DbgUtils.logf( "sending len %d packet: %s",
|
||||
fragment.length(), fragment );
|
||||
String asPublic = toPublicFmt( fragment );
|
||||
mgr.sendTextMessage( phone, null, asPublic, null, null );
|
||||
DbgUtils.logf( "Message \"%s\" of %d bytes sent to %s.",
|
||||
asPublic, asPublic.length(), phone );
|
||||
}
|
||||
DbgUtils.showf( this, "sent %dth msg", ++s_nSent );
|
||||
success = true;
|
||||
} catch ( IllegalArgumentException iae ) {
|
||||
DbgUtils.logf( "%s", iae.toString() );
|
||||
} catch ( Exception ee ) {
|
||||
DbgUtils.logf( "sendDataMessage message failed: %s",
|
||||
ee.toString() );
|
||||
try {
|
||||
SmsManager mgr = SmsManager.getDefault();
|
||||
for ( String fragment : fragments ) {
|
||||
DbgUtils.logf( "sending len %d packet: %s",
|
||||
fragment.length(), fragment );
|
||||
String asPublic = toPublicFmt( fragment );
|
||||
mgr.sendTextMessage( phone, null, asPublic, null, null );
|
||||
DbgUtils.logf( "Message \"%s\" of %d bytes sent to %s.",
|
||||
asPublic, asPublic.length(), phone );
|
||||
}
|
||||
DbgUtils.showf( this, "sent %dth msg", ++s_nSent );
|
||||
success = true;
|
||||
} catch ( IllegalArgumentException iae ) {
|
||||
DbgUtils.logf( "%s", iae.toString() );
|
||||
} catch ( Exception ee ) {
|
||||
DbgUtils.logf( "sendDataMessage message failed: %s",
|
||||
ee.toString() );
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue