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.content.Context;
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.ScreensaverActivity;
25 
26 /**
27  * {@link MenuItemController} for controlling night mode display.
28  */
29 public final class NightModeMenuItemController extends AbstractMenuItemController {
30 
31     private static final int NIGHT_MODE_MENU_RES_ID = R.id.menu_item_night_mode;
32 
33     private final Context mContext;
34 
NightModeMenuItemController(Context context)35     public NightModeMenuItemController(Context context) {
36         mContext = context;
37     }
38 
39     @Override
getId()40     public int getId() {
41         return NIGHT_MODE_MENU_RES_ID;
42     }
43 
44     @Override
showMenuItem(Menu menu)45     public void showMenuItem(Menu menu) {
46         menu.findItem(NIGHT_MODE_MENU_RES_ID).setVisible(true);
47     }
48 
49     @Override
handleMenuItemClick(MenuItem item)50     public boolean handleMenuItemClick(MenuItem item) {
51         mContext.startActivity(new Intent(mContext, ScreensaverActivity.class));
52         return true;
53     }
54 }
55