GamesList starts a repeating alarm that invokes a new activity that

launches the service.  Service can now do a single check with the
relay, notify if needed, and exit (but doesn't yet.)
This commit is contained in:
Andy2 2010-08-19 08:45:18 -07:00
parent 25e7889c28
commit 48ac79be51
4 changed files with 72 additions and 19 deletions

View file

@ -81,6 +81,10 @@
>
</activity>
<activity android:name="RelayActivity"
>
</activity>
<!-- downloading dicts -->
<activity android:name=".DictImportActivity"
android:label="@string/app_name"

View file

@ -23,6 +23,9 @@ package org.eehouse.android.xw4;
import android.app.ListActivity;
import android.app.Dialog;
import android.app.AlertDialog;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.DialogInterface;
import android.net.Uri;
@ -45,6 +48,7 @@ import org.eehouse.android.xw4.jni.*;
public class GamesList extends ListActivity {
private static final int WARN_NODICT = Utils.DIALOG_LAST + 1;
private static final int CONFIRM_DELETE_ALL = Utils.DIALOG_LAST + 2;
private static final long CHECK_INTERVAL_SECONDS = 5;
private GameListAdapter m_adapter;
private String m_invalPath = null;
@ -105,7 +109,8 @@ public class GamesList extends ListActivity {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
PreferenceManager.setDefaultValues( this, R.xml.xwprefs, false );
@ -130,8 +135,16 @@ public class GamesList extends ListActivity {
FirstRunDialog.show( this, false );
Intent service = new Intent(this, RelayService.class );
startService( service );
// Intent service = new Intent(this, RelayService.class );
// startService( service );
AlarmManager am = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
PendingIntent intent =
PendingIntent.getActivity( this, 0,
new Intent(this, RelayActivity.class), 0);
am.setInexactRepeating( AlarmManager.ELAPSED_REALTIME_WAKEUP,
0, // first firing
CHECK_INTERVAL_SECONDS*1000, intent );
}
@Override

View file

@ -0,0 +1,38 @@
/* -*- compile-command: "cd ../../../../../; ant install"; -*- */
/*
* Copyright 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.app.Activity;
import android.os.Bundle;
import android.content.Intent;
public class RelayActivity extends Activity {
@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
Intent service = new Intent(this, RelayService.class );
startService( service );
finish();
}
}

View file

@ -21,6 +21,7 @@
package org.eehouse.android.xw4;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.app.Notification;
@ -28,6 +29,7 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
public class RelayService extends Service {
private NotificationManager m_nm;
@Override
@ -36,9 +38,8 @@ public class RelayService extends Service {
super.onCreate();
Utils.logf( "RelayService::onCreate() called" );
// setupNotification();
Thread thread = new Thread(null, m_task, getClass().getName() );
Thread thread = new Thread( null, m_task, getClass().getName() );
thread.start();
}
@ -66,32 +67,29 @@ public class RelayService extends Service {
// return 0;
// }
private void setupNotification()
{
m_nm = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );
// private void setupNotification()
// {
// m_nm = (NotificationManager)getSystemService( NOTIFICATION_SERVICE );
Notification notification =
new Notification( R.drawable.icon48x48, "foo",
System.currentTimeMillis());
// Notification notification =
// new Notification( R.drawable.icon48x48, "foo",
// System.currentTimeMillis());
PendingIntent intent = PendingIntent
.getActivity( this, 0, new Intent(this, BoardActivity.class), 0);
// PendingIntent intent = PendingIntent
// .getActivity( this, 0, new Intent(this, BoardActivity.class), 0);
notification.setLatestEventInfo( this, "bazz", "bar", intent );
// notification.setLatestEventInfo( this, "bazz", "bar", intent );
m_nm.notify( R.string.running_notification, notification );
}
// m_nm.notify( R.string.running_notification, notification );
// }
// Thread that does the actual work of pinging the relay
private Runnable m_task = new Runnable() {
public void run() {
// Set an alarm to try again in n minutes, then quit.
RelayService.this.stopSelf();
}
};
}