Java Code Examples for android.support.v7.widget.PopupMenu#getMenu()

The following examples show how to use android.support.v7.widget.PopupMenu#getMenu() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WhiteListActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
public void showPopupMenu(View view) {
    //参数View 是设置当前菜单显示的相对于View组件位置,具体位置系统会处理
    PopupMenu popupMenu = new PopupMenu(this, view, Gravity.RIGHT, R.attr.popupMenuStyle, R.style.PopUpMenuStyle);
    //加载menu布局
    Menu menu = popupMenu.getMenu();
    String[] spinnerArray = getResources().getStringArray(SPINNER_ARRAY);
    int i = 0;
    for (i = 0; i < spinnerArray.length; i++) {
        menu.add(0, i, i, spinnerArray[i]);
    }
    menu.add(0, i, i, R.string.select_cancel);
    //设置menu中的item点击事件
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mAppAdapter == null) {
                return false;
            }
            int id = item.getItemId();
            if (id < spinnerArray.length) {
                for (AppListAdapter.ApplicationInfoWrap app : mSelectedApplicationInfos) {
                    app.selection = id;
                }
                mAppAdapter.notifyDataSetChanged();
                refreshMenu(true);
            } else {
                unSelectAll();
                refreshMenu(false);
            }
            UrlCountUtil.onEvent(UrlCountUtil.STATUS_WL_SELECTION, id + "");
            return true;
        }
    });
    popupMenu.show();
}
 
Example 2
Source File: XposedAppManagerActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
public void showPopupMenu(View view) {
    //参数View 是设置当前菜单显示的相对于View组件位置,具体位置系统会处理
    PopupMenu popupMenu = new PopupMenu(this, view, Gravity.RIGHT,R.attr.popupMenuStyle,R.style.PopUpMenuStyle);
    //加载menu布局
    Menu menu=popupMenu.getMenu();
    String[] spinnerArray = getResources().getStringArray(SPINNER_ARRAY);
    int i=0;
    for (i=0;i<spinnerArray.length;i++) {
        menu.add(0,i,i,spinnerArray[i]);
    }
    menu.add(0,i,i,R.string.select_cancel);
    //设置menu中的item点击事件
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            if (mAppAdapter==null){
                return false;
            }
            int id = item.getItemId();
            if (id<spinnerArray.length){
                for (AppListAdapter.ApplicationInfoWrap app:mSelectedApplicationInfos){
                    app.selection=id;
                }
                mAppAdapter.notifyDataSetChanged();
                refreshMenu(true);
            }else {
                unSelectAll();
                refreshMenu(false);
            }
            UrlCountUtil.onEvent(UrlCountUtil.STATUS_WL_SELECTION,id+"");
            return true;
        }
    });
    popupMenu.show();
}
 
Example 3
Source File: MenuParserHelper.java    From fluentAppBar with Apache License 2.0 5 votes vote down vote up
public static void parseMenu(Context context, @MenuRes int menuRes, List<MenuEntry> menuEntryList){
    PopupMenu p = new PopupMenu(context, null);
    Menu menu = p.getMenu();
    new MenuInflater(context).inflate(menuRes, menu);

    for (int i = 0; i < menu.size(); i++) {
        android.view.MenuItem item = menu.getItem(i);
        menuEntryList.add(new MenuEntry(item.getTitle().toString(), item.getIcon(), item.getItemId()));
    }
}
 
Example 4
Source File: ExVidPlayerImp.java    From ExVidPlayer with Apache License 2.0 5 votes vote down vote up
@Override public void setQuality(View v) {
  PopupMenu popup = new PopupMenu(activity, v);
  popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
    @Override public boolean onMenuItemClick(MenuItem item) {
      player.setSelectedTrack(0, (item.getItemId() - 1));
      return false;
    }
  });
  ArrayList<Integer> formats = new ArrayList<>();
  Menu menu = popup.getMenu();
  menu.add(Menu.NONE, 0, 0, "Bitrate");

  for (int i = 0; i < player.getTrackCount(0); i++) {
    MediaFormat format = player.getTrackFormat(0, i);
    if (MimeTypes.isVideo(format.mimeType)) {
      Log.e("dsa", format.bitrate + "");
      if (format.adaptive) {
        menu.add(1, (i + 1), (i + 1), "Auto");
      } else {

        if (!formats.contains(format.bitrate)) {
          menu.add(1, (i + 1), (i + 1), (format.bitrate) / 1000 + " kbps");
          formats.add(format.bitrate);
        }
      }
    }
  }
  menu.setGroupCheckable(1, true, true);
  menu.findItem((player.getSelectedTrack(0) + 1)).setChecked(true);
  popup.show();
}
 
Example 5
Source File: BottomSheetBuilder.java    From BottomSheetBuilder with Apache License 2.0 5 votes vote down vote up
public BottomSheetBuilder setMenu(@MenuRes int menu) {
    @SuppressWarnings("ConstantConditions")
    PopupMenu popupMenu = new PopupMenu(mContext, null);
    mMenu = popupMenu.getMenu();
    popupMenu.getMenuInflater().inflate(menu, mMenu);
    return setMenu(mMenu);
}
 
Example 6
Source File: WorldMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void updateSpeedMenu(Context context, PopupMenu menu)
{
    Menu m = menu.getMenu();
    boolean is1d = WorldMapWidgetSettings.loadWorldMapPref(context, 0, WorldMapWidgetSettings.PREF_KEY_WORLDMAP_SPEED1D, WorldMapWidgetSettings.MAPTAG_3x2);

    MenuItem speed_15m = m.findItem(R.id.mapSpeed_15m);
    if (speed_15m != null) {
        speed_15m.setChecked(!is1d);
    }

    MenuItem speed_1d = m.findItem(R.id.mapSpeed_1d);
    if (speed_1d != null) {
        speed_1d.setChecked(is1d);
    }
}
 
Example 7
Source File: WorldMapDialog.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
private void updateContextMenu(Context context, PopupMenu menu)
{
    Menu m = menu.getMenu();
    WorldMapTask.WorldMapOptions options = worldmap.getOptions();

    MenuItem option_latitudes = m.findItem(R.id.mapOption_majorLatitudes);
    if (option_latitudes != null) {
        option_latitudes.setChecked(WorldMapWidgetSettings.loadWorldMapPref(context, 0,  WorldMapWidgetSettings.PREF_KEY_WORLDMAP_MAJORLATITUDES, WorldMapWidgetSettings.MAPTAG_3x2));
    }

    MenuItem option_location = m.findItem(R.id.mapOption_location);
    if (option_location != null) {
        option_location.setChecked(WorldMapWidgetSettings.loadWorldMapPref(context, 0,  WorldMapWidgetSettings.PREF_KEY_WORLDMAP_LOCATION, WorldMapWidgetSettings.MAPTAG_3x2));
    }

    MenuItem option_sunlight = m.findItem(R.id.mapOption_sunlight);
    if (option_sunlight != null) {
        option_sunlight.setChecked(options.showSunShadow);
    }

    MenuItem option_moonlight = m.findItem(R.id.mapOption_moonlight);
    if (option_moonlight != null) {
        option_moonlight.setChecked(options.showMoonLight);
    }

    MenuItem action_date = m.findItem(R.id.setDate);
    if (action_date != null) {
        action_date.setEnabled( !WidgetSettings.DateInfo.isToday(getMapDate()) );
    }
}
 
Example 8
Source File: MainActivity.java    From Bluefruit_LE_Connect_Android with MIT License 5 votes vote down vote up
public void onClickFilterNameSettings(View view) {
    PopupMenu popup = new PopupMenu(this, view);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean processed = true;
            switch (item.getItemId()) {
                case R.id.scanfilter_name_contains:
                    mPeripheralList.setFilterNameExact(false);
                    break;
                case R.id.scanfilter_name_exact:
                    mPeripheralList.setFilterNameExact(true);
                    break;
                case R.id.scanfilter_name_sensitive:
                    mPeripheralList.setFilterNameCaseInsensitive(false);
                    break;
                case R.id.scanfilter_name_insensitive:
                    mPeripheralList.setFilterNameCaseInsensitive(true);
                    break;
                default:
                    processed = false;
                    break;
            }
            updateFilters();
            return processed;
        }
    });
    MenuInflater inflater = popup.getMenuInflater();
    Menu menu = popup.getMenu();
    inflater.inflate(R.menu.menu_scan_filters_name, menu);
    final boolean isFilterNameExact = mPeripheralList.isFilterNameExact();
    menu.findItem(isFilterNameExact ? R.id.scanfilter_name_exact : R.id.scanfilter_name_contains).setChecked(true);
    final boolean isFilterNameCaseInsensitive = mPeripheralList.isFilterNameCaseInsensitive();
    menu.findItem(isFilterNameCaseInsensitive ? R.id.scanfilter_name_insensitive : R.id.scanfilter_name_sensitive).setChecked(true);
    popup.show();
}