1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.deskclock.actionbarmenu; 18 19 import android.app.Activity; 20 import android.content.Intent; 21 import android.view.Menu; 22 import android.view.MenuItem; 23 24 import com.android.deskclock.R; 25 import com.android.deskclock.settings.SettingsActivity; 26 27 import static android.view.Menu.NONE; 28 29 /** 30 * {@link MenuItemController} for settings menu. 31 */ 32 public final class SettingsMenuItemController implements MenuItemController { 33 34 public static final int REQUEST_CHANGE_SETTINGS = 1; 35 36 private static final int SETTING_MENU_RES_ID = R.id.menu_item_settings; 37 38 private final Activity mActivity; 39 SettingsMenuItemController(Activity activity)40 public SettingsMenuItemController(Activity activity) { 41 mActivity = activity; 42 } 43 44 @Override getId()45 public int getId() { 46 return SETTING_MENU_RES_ID; 47 } 48 49 @Override onCreateOptionsItem(Menu menu)50 public void onCreateOptionsItem(Menu menu) { 51 menu.add(NONE, SETTING_MENU_RES_ID, NONE, R.string.menu_item_settings) 52 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); 53 } 54 55 @Override onPrepareOptionsItem(MenuItem item)56 public void onPrepareOptionsItem(MenuItem item) { 57 } 58 59 @Override onOptionsItemSelected(MenuItem item)60 public boolean onOptionsItemSelected(MenuItem item) { 61 final Intent settingIntent = new Intent(mActivity, SettingsActivity.class); 62 mActivity.startActivityForResult(settingIntent, REQUEST_CHANGE_SETTINGS); 63 return true; 64 } 65 } 66