Home | History | Annotate | Download | only in actionbarmenu
      1 /*
      2  * Copyright (C) 2015 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 extends AbstractMenuItemController {
     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 showMenuItem(Menu menu) {
     42         // Intentionally left empty, because back button in actionbar is not shown by inflating
     43         // menu layouts. It's directly controlled by actionbar.
     44     }
     45 
     46     @Override
     47     public boolean handleMenuItemClick(MenuItem item) {
     48         mActivity.finish();
     49         return true;
     50     }
     51 }
     52