1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * 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, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */
16 
17 package com.android.deskclock.actionbarmenu
18 
19 import android.app.Activity
20 import android.view.Menu
21 import android.view.MenuItem
22 
23 /**
24  * [MenuItemController] for handling navigation up button in actionbar. It is a special
25  * menu item because it's not inflated through menu.xml, and has its own predefined id.
26  */
27 class NavUpMenuItemController(private val activity: Activity) : MenuItemController {
28 
29     override val id: Int = android.R.id.home
30 
onCreateOptionsItemnull31     override fun onCreateOptionsItem(menu: Menu) {
32         // "Home" option is automatically created by the Toolbar.
33     }
34 
onPrepareOptionsItemnull35     override fun onPrepareOptionsItem(item: MenuItem) {
36     }
37 
onOptionsItemSelectednull38     override fun onOptionsItemSelected(item: MenuItem): Boolean {
39         activity.finish()
40         return true
41     }
42 }