Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 package edu.nimbus.glass;
00033
00034
00035 import android.app.Activity;
00036 import android.content.ComponentName;
00037 import android.content.Intent;
00038 import android.content.ServiceConnection;
00039 import android.os.Bundle;
00040 import android.os.IBinder;
00041 import android.view.Menu;
00042 import android.view.MenuItem;
00043
00048 public class MenuActivity extends Activity {
00049
00051 private ROSMonitorService.ROSMonitorBinder mService;
00052 private boolean mResumed;
00053
00054
00055
00056 private ServiceConnection mConnection = new ServiceConnection() {
00057 @Override
00058 public void onServiceConnected(ComponentName name, IBinder service) {
00059 if (service instanceof ROSMonitorService.ROSMonitorBinder) {
00060 mService = (ROSMonitorService.ROSMonitorBinder) service;
00061 openOptionsMenu();
00062 }
00063 }
00064
00065 @Override
00066 public void onServiceDisconnected(ComponentName name) {
00067
00068 }
00069 };
00070
00071 @Override
00072 protected void onCreate(Bundle savedInstanceState) {
00073 super.onCreate(savedInstanceState);
00074
00075 bindService(new Intent(this, ROSMonitorService.class), mConnection, 0);
00076 }
00077
00078 @Override
00079 protected void onResume() {
00080
00081 super.onResume();
00082 mResumed = true;
00083 openOptionsMenu();
00084 }
00085
00086 @Override
00087 protected void onPause() {
00088
00089 super.onPause();
00090 mResumed = false;
00091 }
00092
00093 @Override
00094 public void openOptionsMenu() {
00095 if (mResumed && mService != null) {
00096
00097 super.openOptionsMenu();
00098 }
00099 }
00100
00101 @Override
00102 public boolean onCreateOptionsMenu(Menu menu) {
00103 getMenuInflater().inflate(R.menu.main, menu);
00104 return true;
00105 }
00106
00110 @Override
00111 public boolean onOptionsItemSelected(MenuItem item) {
00112 switch (item.getItemId()) {
00113 case R.id.stop:
00114 stopService(new Intent(this, ROSMonitorService.class));
00115 return true;
00116 case R.id.remove_card:
00117 mService.remove_card();
00118 return true;
00119 default:
00120 return super.onOptionsItemSelected(item);
00121 }
00122
00123 }
00124
00125
00126
00127
00128
00129 @Override
00130 public void onOptionsMenuClosed(Menu menu) {
00131 super.onOptionsMenuClosed(menu);
00132
00133 unbindService(mConnection);
00134
00135
00136
00137 finish();
00138 }
00139 }