Back to project page kitty-compass.
The source code is released under:
Apache License
If you think the Android project kitty-compass listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2013 The Android Open Source Project */*w w w.jav a2 s. c om*/ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.google.android.glass.sample.kittycompass; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.view.Menu; import android.view.MenuItem; /** * This activity manages the options menu that appears when the user taps on the compass's live * card. */ public class CompassMenuActivity extends Activity { private CompassService.CompassBinder mCompassService; private boolean mResumed; private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { if (service instanceof CompassService.CompassBinder) { mCompassService = (CompassService.CompassBinder) service; openOptionsMenu(); } } @Override public void onServiceDisconnected(ComponentName name) { // Do nothing. } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); bindService(new Intent(this, CompassService.class), mConnection, 0); } @Override protected void onResume() { super.onResume(); mResumed = true; openOptionsMenu(); } @Override protected void onPause() { super.onPause(); mResumed = false; } @Override public void openOptionsMenu() { if (mResumed && mCompassService != null) { super.openOptionsMenu(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.compass, menu); return true; } @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; default: return super.onOptionsItemSelected(item); } } @Override public void onOptionsMenuClosed(Menu menu) { super.onOptionsMenuClosed(menu); unbindService(mConnection); // We must call finish() from this method to ensure that the activity ends either when an // item is selected from the menu or when the menu is dismissed by swiping down. finish(); } }