mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
get maintenance mode message into an alert -- and create a new common
superclass for Service subclasses to reuse some code.
This commit is contained in:
parent
fd2f4309f4
commit
3df0484e6a
9 changed files with 92 additions and 69 deletions
|
@ -29,7 +29,6 @@ import android.bluetooth.BluetoothSocket;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
@ -49,7 +48,7 @@ import junit.framework.Assert;
|
||||||
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||||
|
|
||||||
public class BTService extends Service {
|
public class BTService extends XWService {
|
||||||
|
|
||||||
private static final long RESEND_TIMEOUT = 5; // seconds
|
private static final long RESEND_TIMEOUT = 5; // seconds
|
||||||
private static final int MAX_SEND_FAIL = 3;
|
private static final int MAX_SEND_FAIL = 3;
|
||||||
|
@ -77,8 +76,6 @@ public class BTService extends Service {
|
||||||
private static final String NTO_STR = "TOT";
|
private static final String NTO_STR = "TOT";
|
||||||
private static final String NHE_STR = "HER";
|
private static final String NHE_STR = "HER";
|
||||||
|
|
||||||
private static MultiService s_srcMgr = null;
|
|
||||||
|
|
||||||
private enum BTCmd {
|
private enum BTCmd {
|
||||||
PING,
|
PING,
|
||||||
PONG,
|
PONG,
|
||||||
|
@ -147,16 +144,6 @@ public class BTService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setListener( MultiService.MultiEventListener li )
|
|
||||||
{
|
|
||||||
if ( XWApp.BTSUPPORTED ) {
|
|
||||||
if ( null == s_srcMgr ) {
|
|
||||||
s_srcMgr = new MultiService();
|
|
||||||
}
|
|
||||||
s_srcMgr.setListener( li );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void radioChanged( Context context, boolean cameOn )
|
public static void radioChanged( Context context, boolean cameOn )
|
||||||
{
|
{
|
||||||
Intent intent = getIntentTo( context, RADIO );
|
Intent intent = getIntentTo( context, RADIO );
|
||||||
|
@ -316,12 +303,6 @@ public class BTService extends Service {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind( Intent intent )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class BTListenerThread extends Thread {
|
private class BTListenerThread extends Thread {
|
||||||
private BluetoothServerSocket m_serverSocket;
|
private BluetoothServerSocket m_serverSocket;
|
||||||
|
|
||||||
|
@ -852,11 +833,6 @@ public class BTService extends Service {
|
||||||
sendResult( MultiEvent.SCAN_DONE, (Object)(names()) );
|
sendResult( MultiEvent.SCAN_DONE, (Object)(names()) );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendResult( MultiEvent event, Object ... args )
|
|
||||||
{
|
|
||||||
s_srcMgr.sendResult( event, args );
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listLocalBTGames( boolean force )
|
private void listLocalBTGames( boolean force )
|
||||||
{
|
{
|
||||||
if ( null == s_devGames ) {
|
if ( null == s_devGames ) {
|
||||||
|
|
|
@ -272,6 +272,11 @@ public class DlgDelegate {
|
||||||
(String)args[0] );
|
(String)args[0] );
|
||||||
asToast = false;
|
asToast = false;
|
||||||
break;
|
break;
|
||||||
|
case RELAY_ALERT:
|
||||||
|
msg = (String)args[0];
|
||||||
|
asToast = false;
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
DbgUtils.logf( "eventOccurred: unhandled event %s", event.toString() );
|
DbgUtils.logf( "eventOccurred: unhandled event %s", event.toString() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,6 +62,8 @@ public class MultiService {
|
||||||
, SMS_SEND_OK
|
, SMS_SEND_OK
|
||||||
, SMS_SEND_FAILED
|
, SMS_SEND_FAILED
|
||||||
, SMS_SEND_FAILED_NORADIO
|
, SMS_SEND_FAILED_NORADIO
|
||||||
|
|
||||||
|
, RELAY_ALERT
|
||||||
};
|
};
|
||||||
|
|
||||||
public interface MultiEventListener {
|
public interface MultiEventListener {
|
||||||
|
|
|
@ -23,7 +23,6 @@ package org.eehouse.android.xw4;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.IBinder;
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
|
@ -41,8 +40,9 @@ import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eehouse.android.xw4.jni.GameSummary;
|
import org.eehouse.android.xw4.jni.GameSummary;
|
||||||
import org.eehouse.android.xw4.jni.UtilCtxt;
|
import org.eehouse.android.xw4.jni.UtilCtxt;
|
||||||
|
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||||
|
|
||||||
public class RelayService extends Service {
|
public class RelayService extends XWService {
|
||||||
private static final int MAX_SEND = 1024;
|
private static final int MAX_SEND = 1024;
|
||||||
private static final int MAX_BUF = MAX_SEND - 2;
|
private static final int MAX_BUF = MAX_SEND - 2;
|
||||||
|
|
||||||
|
@ -86,12 +86,6 @@ public class RelayService extends Service {
|
||||||
startFetchThreadIf();
|
startFetchThreadIf();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind( Intent intent )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand( Intent intent, int flags, int startId )
|
public int onStartCommand( Intent intent, int flags, int startId )
|
||||||
{
|
{
|
||||||
|
@ -276,8 +270,7 @@ public class RelayService extends Service {
|
||||||
short len = dis.readShort();
|
short len = dis.readShort();
|
||||||
byte[] tmp = new byte[len];
|
byte[] tmp = new byte[len];
|
||||||
dis.read( tmp );
|
dis.read( tmp );
|
||||||
String msg = new String( tmp );
|
sendResult( MultiEvent.RELAY_ALERT, new String( tmp ) );
|
||||||
DbgUtils.logf( "got message: %s", msg );
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DbgUtils.logf( "RelayService: Unhandled cmd: %d", cmd );
|
DbgUtils.logf( "RelayService: Unhandled cmd: %d", cmd );
|
||||||
|
|
|
@ -32,7 +32,6 @@ import android.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.telephony.SmsManager;
|
import android.telephony.SmsManager;
|
||||||
import android.telephony.SmsMessage;
|
import android.telephony.SmsMessage;
|
||||||
|
@ -52,7 +51,7 @@ import org.eehouse.android.xw4.jni.CommsAddrRec;
|
||||||
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
import org.eehouse.android.xw4.jni.CommsAddrRec.CommsConnType;
|
||||||
import org.eehouse.android.xw4.jni.XwJNI;
|
import org.eehouse.android.xw4.jni.XwJNI;
|
||||||
|
|
||||||
public class SMSService extends Service {
|
public class SMSService extends XWService {
|
||||||
|
|
||||||
private static final String INSTALL_URL = "http://eehouse.org/_/a.py/a ";
|
private static final String INSTALL_URL = "http://eehouse.org/_/a.py/a ";
|
||||||
private static final int MAX_SMS_LEN = 140; // ??? differs by network
|
private static final int MAX_SMS_LEN = 140; // ??? differs by network
|
||||||
|
@ -76,7 +75,6 @@ public class SMSService extends Service {
|
||||||
private static final String PHONE = "PHONE";
|
private static final String PHONE = "PHONE";
|
||||||
|
|
||||||
private static Boolean s_showToasts = null;
|
private static Boolean s_showToasts = null;
|
||||||
private static MultiService s_srcMgr = null;
|
|
||||||
|
|
||||||
// All messages are base64-encoded byte arrays. The first byte is
|
// All messages are base64-encoded byte arrays. The first byte is
|
||||||
// always one of these. What follows depends.
|
// always one of these. What follows depends.
|
||||||
|
@ -189,16 +187,6 @@ public class SMSService extends Service {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setListener( MultiService.MultiEventListener li )
|
|
||||||
{
|
|
||||||
if ( XWApp.SMSSUPPORTED ) {
|
|
||||||
if ( null == s_srcMgr ) {
|
|
||||||
s_srcMgr = new MultiService();
|
|
||||||
}
|
|
||||||
s_srcMgr.setListener( li );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Intent getIntentTo( Context context, int cmd )
|
private static Intent getIntentTo( Context context, int cmd )
|
||||||
{
|
{
|
||||||
if ( null == s_showToasts ) {
|
if ( null == s_showToasts ) {
|
||||||
|
@ -289,12 +277,6 @@ public class SMSService extends Service {
|
||||||
return result;
|
return result;
|
||||||
} // onStartCommand
|
} // onStartCommand
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind( Intent intent )
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void inviteRemote( String phone, int gameID, String gameName,
|
private void inviteRemote( String phone, int gameID, String gameName,
|
||||||
int lang, String dict,
|
int lang, String dict,
|
||||||
int nPlayersT, int nPlayersH )
|
int nPlayersT, int nPlayersH )
|
||||||
|
@ -647,13 +629,6 @@ public class SMSService extends Service {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendResult( MultiEvent event, Object ... args )
|
|
||||||
{
|
|
||||||
if ( null != s_srcMgr ) {
|
|
||||||
s_srcMgr.sendResult( event, args );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerReceivers()
|
private void registerReceivers()
|
||||||
{
|
{
|
||||||
registerReceiver( new BroadcastReceiver() {
|
registerReceiver( new BroadcastReceiver() {
|
||||||
|
|
|
@ -54,8 +54,7 @@ public class XWActivity extends Activity
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
||||||
BTService.setListener( this );
|
XWService.setListener( this );
|
||||||
SMSService.setListener( this );
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +62,7 @@ public class XWActivity extends Activity
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
||||||
BTService.setListener( null );
|
XWService.setListener( null );
|
||||||
SMSService.setListener( null );
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,22 @@ public class XWExpandableListActivity extends ExpandableListActivity
|
||||||
m_delegate = new DlgDelegate( this, this, savedInstanceState );
|
m_delegate = new DlgDelegate( this, this, savedInstanceState );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume()
|
||||||
|
{
|
||||||
|
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
||||||
|
XWService.setListener( this );
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause()
|
||||||
|
{
|
||||||
|
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
||||||
|
XWService.setListener( null );
|
||||||
|
super.onPause();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState( Bundle outState )
|
protected void onSaveInstanceState( Bundle outState )
|
||||||
{
|
{
|
||||||
|
|
|
@ -51,8 +51,7 @@ public class XWListActivity extends ListActivity
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
DbgUtils.logf( "%s.onResume(this=%H)", getClass().getName(), this );
|
||||||
BTService.setListener( this );
|
XWService.setListener( this );
|
||||||
SMSService.setListener( this );
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,8 +59,7 @@ public class XWListActivity extends ListActivity
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
DbgUtils.logf( "%s.onPause(this=%H)", getClass().getName(), this );
|
||||||
BTService.setListener( null );
|
XWService.setListener( null );
|
||||||
SMSService.setListener( null );
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
/* -*- compile-command: "cd ../../../../../; ant debug install"; -*- */
|
||||||
|
/*
|
||||||
|
* Copyright 2010 - 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.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.IBinder;
|
||||||
|
|
||||||
|
import org.eehouse.android.xw4.MultiService.MultiEvent;
|
||||||
|
|
||||||
|
|
||||||
|
public class XWService extends Service {
|
||||||
|
|
||||||
|
protected static MultiService s_srcMgr = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind( Intent intent )
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static void setListener( MultiService.MultiEventListener li )
|
||||||
|
{
|
||||||
|
if ( null == s_srcMgr ) {
|
||||||
|
DbgUtils.logf( "setListener: registering %s", li.getClass().getName() );
|
||||||
|
s_srcMgr = new MultiService();
|
||||||
|
}
|
||||||
|
s_srcMgr.setListener( li );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void sendResult( MultiEvent event, Object ... args )
|
||||||
|
{
|
||||||
|
if ( null != s_srcMgr ) {
|
||||||
|
s_srcMgr.sendResult( event, args );
|
||||||
|
} else {
|
||||||
|
DbgUtils.logf( "sendResult: dropping event" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue