Service for starting and stopping Bote
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
package="i2p.bote.android"
|
||||
android:versionCode="1"
|
||||
android:versionName="0.1" >
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-sdk
|
||||
android:minSdkVersion="9"
|
||||
@@ -13,6 +14,7 @@
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme" >
|
||||
<service android:name="i2p.bote.android.service.BoteService" />
|
||||
<activity
|
||||
android:name="i2p.bote.android.EmailListActivity"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@@ -1,6 +1,18 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:i2pandroid="http://schemas.android.com/apk/res-auto" >
|
||||
|
||||
<item
|
||||
android:id="@+id/action_start_bote"
|
||||
android:orderInCategory="1"
|
||||
android:title="@string/action_start_bote"
|
||||
i2pandroid:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_stop_bote"
|
||||
android:orderInCategory="2"
|
||||
android:title="@string/action_stop_bote"
|
||||
i2pandroid:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
<string name="app_name">Bote</string>
|
||||
<string name="action_new_email">New email</string>
|
||||
<string name="action_send_email">Send email</string>
|
||||
<string name="action_start_bote">Start Bote</string>
|
||||
<string name="action_stop_bote">Stop Bote</string>
|
||||
<string name="action_settings">Settings</string>
|
||||
|
||||
<string name="items_selected">%s selected</string>
|
||||
|
||||
@@ -4,10 +4,13 @@ import net.i2p.client.I2PClient;
|
||||
import i2p.bote.I2PBote;
|
||||
import i2p.bote.android.addressbook.AddressBookActivity;
|
||||
import i2p.bote.android.config.SettingsActivity;
|
||||
import i2p.bote.android.service.BoteService;
|
||||
import i2p.bote.android.util.MoveToDialogFragment;
|
||||
import i2p.bote.folder.EmailFolder;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -200,9 +203,22 @@ public class EmailListActivity extends ActionBarActivity implements
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
if (isBoteServiceRunning())
|
||||
menu.findItem(R.id.action_start_bote).setVisible(false);
|
||||
else
|
||||
menu.findItem(R.id.action_stop_bote).setVisible(false);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
private boolean isBoteServiceRunning() {
|
||||
ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
||||
if (BoteService.class.getName().equals(service.service.getClassName()))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// The action bar home/up action should open or close the drawer.
|
||||
@@ -212,6 +228,16 @@ public class EmailListActivity extends ActionBarActivity implements
|
||||
}
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_start_bote:
|
||||
Intent start = new Intent(this, BoteService.class);
|
||||
startService(start);
|
||||
return true;
|
||||
|
||||
case R.id.action_stop_bote:
|
||||
Intent stop = new Intent(this, BoteService.class);
|
||||
stopService(stop);
|
||||
return true;
|
||||
|
||||
case R.id.action_settings:
|
||||
Intent si = new Intent(this, SettingsActivity.class);
|
||||
startActivity(si);
|
||||
|
||||
24
src/i2p/bote/android/service/BoteService.java
Normal file
24
src/i2p/bote/android/service/BoteService.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package i2p.bote.android.service;
|
||||
|
||||
import i2p.bote.I2PBote;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class BoteService extends Service {
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
I2PBote.getInstance().startUp();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
I2PBote.getInstance().shutDown();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user