Back to project page gdk-line-sample.
The source code is released under:
Apache License
If you think the Android project gdk-line-sample 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 *//from w ww . j ava 2s .c o m * 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.kitware.android.glass.sample.line; import com.kitware.android.glass.sample.line.util.MathUtils; import android.app.Activity; import android.content.ComponentName; import android.content.Intent; import android.content.ServiceConnection; import android.content.res.Resources; 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 line's live * card. */ public class LineMenuActivity extends Activity { private LineService.LineBinder mLineService; private boolean mResumed; private ServiceConnection mConnection = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { if (service instanceof LineService.LineBinder) { mLineService = (LineService.LineBinder) service; openOptionsMenu(); } } @Override public void onServiceDisconnected(ComponentName name) { // Do nothing. } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); bindService(new Intent(this, LineService.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 && mLineService != null) { super.openOptionsMenu(); } } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.line, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.read_aloud: mLineService.readHeadingAloud(); return true; case R.id.stop: stopService(new Intent(this, LineService.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(); } }