Home | History | Annotate | Download | only in actionbarmenu
      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 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 import com.android.deskclock.events.Events;
     26 
     27 import static android.view.Menu.NONE;
     28 
     29 /**
     30  * {@link MenuItemController} for controlling night mode display.
     31  */
     32 public final class NightModeMenuItemController implements MenuItemController {
     33 
     34     private static final int NIGHT_MODE_MENU_RES_ID = R.id.menu_item_night_mode;
     35 
     36     private final Context mContext;
     37 
     38     public NightModeMenuItemController(Context context) {
     39         mContext = context;
     40     }
     41 
     42     @Override
     43     public int getId() {
     44         return NIGHT_MODE_MENU_RES_ID;
     45     }
     46 
     47     @Override
     48     public void onCreateOptionsItem(Menu menu) {
     49         menu.add(NONE, NIGHT_MODE_MENU_RES_ID, NONE, R.string.menu_item_night_mode)
     50                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
     51     }
     52 
     53     @Override
     54     public void onPrepareOptionsItem(MenuItem item) {
     55     }
     56 
     57     @Override
     58     public boolean onOptionsItemSelected(MenuItem item) {
     59         mContext.startActivity(new Intent(mContext, ScreensaverActivity.class)
     60                 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
     61                 .putExtra(Events.EXTRA_EVENT_LABEL, R.string.label_deskclock));
     62         return true;
     63     }
     64 }
     65