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"); 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  * {@link 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 public final class NavUpMenuItemController implements MenuItemController {
     28 
     29     private final Activity mActivity;
     30 
     31     public NavUpMenuItemController(Activity activity) {
     32         mActivity = activity;
     33     }
     34 
     35     @Override
     36     public int getId() {
     37         return android.R.id.home;
     38     }
     39 
     40     @Override
     41     public void onCreateOptionsItem(Menu menu) {
     42         // "Home" option is automatically created by the Toolbar.
     43     }
     44 
     45     @Override
     46     public void onPrepareOptionsItem(MenuItem item) {
     47     }
     48 
     49     @Override
     50     public boolean onOptionsItemSelected(MenuItem item) {
     51         mActivity.finish();
     52         return true;
     53     }
     54 }
     55