@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.read_aloud: mCompassService.readHeadingAloud(); return true; case R.id.stop: stopService(new Intent(this, CompassService.class)); return true; case R.id.set_landmark: mCompassService.markCurrentHeading(); return true; case R.id.reset_landmark: mCompassService.resetLandmarks(); return true; default: return super.onOptionsItemSelected(item); } }
/* * Performs the requested actions if connected. Since the connection may establish * either before or after actions are requested, we simply record requested actions, * and try to perform them both when the action establishes and when menu panel * closes (either due to dismissing or selecting an item). */ private void performActionsIfConnected() { if (mCompassService != null) { if (mDoReadAloud) { mDoReadAloud = false; mCompassService.readHeadingAloud(); } if (mDoStop) { mDoStop = false; stopService(new Intent(CompassMenuActivity.this, CompassService.class)); } if (mDoFinish) { mCompassService = null; unbindService(mConnection); finish(); } } }