1 /* 2 * Copyright (C) 2020 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.content.Context 20 import android.content.Intent 21 import android.view.Menu 22 import android.view.Menu.NONE 23 import android.view.MenuItem 24 25 import com.android.deskclock.R 26 import com.android.deskclock.ScreensaverActivity 27 import com.android.deskclock.events.Events 28 29 /** 30 * [MenuItemController] for controlling night mode display. 31 */ 32 class NightModeMenuItemController(private val context: Context) : MenuItemController { 33 34 override val id: Int = R.id.menu_item_night_mode 35 onCreateOptionsItemnull36 override fun onCreateOptionsItem(menu: Menu) { 37 menu.add(NONE, id, NONE, R.string.menu_item_night_mode) 38 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) 39 } 40 onPrepareOptionsItemnull41 override fun onPrepareOptionsItem(item: MenuItem) { 42 } 43 onOptionsItemSelectednull44 override fun onOptionsItemSelected(item: MenuItem): Boolean { 45 context.startActivity(Intent(context, ScreensaverActivity::class.java) 46 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK) 47 .putExtra(Events.EXTRA_EVENT_LABEL, R.string.label_deskclock)) 48 return true 49 } 50 }