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.app.Activity
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.settings.SettingsActivity
27 
28 /**
29  * [MenuItemController] for settings menu.
30  */
31 class SettingsMenuItemController(private val activity: Activity) : MenuItemController {
32 
33     override val id: Int = R.id.menu_item_settings
34 
onCreateOptionsItemnull35     override fun onCreateOptionsItem(menu: Menu) {
36         menu.add(NONE, id, NONE, R.string.menu_item_settings)
37                 .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER)
38     }
39 
onPrepareOptionsItemnull40     override fun onPrepareOptionsItem(item: MenuItem) {
41     }
42 
onOptionsItemSelectednull43     override fun onOptionsItemSelected(item: MenuItem): Boolean {
44         val settingIntent = Intent(activity, SettingsActivity::class.java)
45         activity.startActivityForResult(settingIntent, REQUEST_CHANGE_SETTINGS)
46         return true
47     }
48 
49     companion object {
50         const val REQUEST_CHANGE_SETTINGS = 1
51     }
52 }