1 /* 2 * Copyright (C) 2015 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 package com.android.deskclock.actionbarmenu; 17 18 import android.app.Activity; 19 import android.content.Intent; 20 import android.view.Menu; 21 import android.view.MenuItem; 22 23 import com.android.deskclock.R; 24 import com.android.deskclock.settings.SettingsActivity; 25 26 /** 27 * {@link MenuItemController} for setting menu. 28 */ 29 public final class SettingMenuItemController extends AbstractMenuItemController { 30 31 public static final int REQUEST_CHANGE_SETTINGS = 1; 32 33 private static final int SETTING_MENU_RES_ID = R.id.menu_item_settings; 34 private final Activity mActivity; 35 SettingMenuItemController(Activity activity)36 public SettingMenuItemController(Activity activity) { 37 mActivity = activity; 38 } 39 40 @Override getId()41 public int getId() { 42 return SETTING_MENU_RES_ID; 43 } 44 45 @Override showMenuItem(Menu menu)46 public void showMenuItem(Menu menu) { 47 menu.findItem(SETTING_MENU_RES_ID).setVisible(true); 48 } 49 50 @Override handleMenuItemClick(MenuItem item)51 public boolean handleMenuItemClick(MenuItem item) { 52 Intent settingIntent = new Intent(mActivity, SettingsActivity.class); 53 mActivity.startActivityForResult(settingIntent, REQUEST_CHANGE_SETTINGS); 54 return true; 55 } 56 } 57