• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.dialer.main.impl.toolbar;
18 
19 import android.content.Context;
20 import android.support.v7.app.AppCompatActivity;
21 import android.view.Gravity;
22 import android.view.MenuItem;
23 import android.view.View;
24 import android.widget.PopupMenu;
25 import com.android.dialer.simulator.Simulator;
26 import com.android.dialer.simulator.SimulatorComponent;
27 
28 /** Popup menu accessible from the search bar */
29 public final class MainToolbarMenu extends PopupMenu {
30 
MainToolbarMenu(Context context, View anchor)31   public MainToolbarMenu(Context context, View anchor) {
32     super(context, anchor, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0);
33   }
34 
showClearFrequents(boolean show)35   public void showClearFrequents(boolean show) {
36     getMenu().findItem(R.id.clear_frequents).setVisible(show);
37   }
38 
maybeShowSimulator(AppCompatActivity activity)39   public void maybeShowSimulator(AppCompatActivity activity) {
40     MenuItem simulatorMenuItem = getMenu().findItem(R.id.menu_simulator_submenu);
41     Simulator simulator = SimulatorComponent.get(activity).getSimulator();
42     if (simulator.shouldShow()) {
43       simulatorMenuItem.setVisible(true);
44       simulatorMenuItem.setActionProvider(simulator.getActionProvider(activity));
45     } else {
46       simulatorMenuItem.setVisible(false);
47     }
48   }
49 }
50