List of usage examples for android.widget PopupMenu getMenu
public Menu getMenu()
From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java
private void handleLongPress(final TaskDescription ad, View view) { final PopupMenu popup = new PopupMenu(mContext, view); mPopup = popup;/*w w w . j a va 2 s. co m*/ popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.recent_remove_item) { mRecentsManager.killTask(ad); } else if (item.getItemId() == R.id.recent_inspect_item) { startApplicationDetailsActivity(ad.getPackageName()); } else { return false; } return true; } }); popup.setOnDismissListener(new PopupMenu.OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopup = null; } }); popup.show(); }
From source file:com.battlelancer.seriesguide.ui.MoviesSearchFragment.java
@Override public void onPopupMenuClick(View v, final int movieTmdbId) { PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.inflate(R.menu.movies_popup_menu); // check if movie is already in watchlist or collection boolean isInWatchlist = false; boolean isInCollection = false; Cursor movie = getActivity().getContentResolver().query( SeriesGuideContract.Movies.buildMovieUri(movieTmdbId), new String[] { SeriesGuideContract.Movies.IN_WATCHLIST, SeriesGuideContract.Movies.IN_COLLECTION }, null, null, null);// w w w. j av a2 s . c om if (movie != null) { if (movie.moveToFirst()) { isInWatchlist = movie.getInt(0) == 1; isInCollection = movie.getInt(1) == 1; } movie.close(); } Menu menu = popupMenu.getMenu(); menu.findItem(R.id.menu_action_movies_watchlist_add).setVisible(!isInWatchlist); menu.findItem(R.id.menu_action_movies_watchlist_remove).setVisible(isInWatchlist); menu.findItem(R.id.menu_action_movies_collection_add).setVisible(!isInCollection); menu.findItem(R.id.menu_action_movies_collection_remove).setVisible(isInCollection); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_action_movies_watchlist_add: { MovieTools.addToWatchlist(getActivity(), movieTmdbId); fireTrackerEvent("Add to watchlist"); return true; } case R.id.menu_action_movies_watchlist_remove: { MovieTools.removeFromWatchlist(getActivity(), movieTmdbId); fireTrackerEvent("Remove from watchlist"); return true; } case R.id.menu_action_movies_collection_add: { MovieTools.addToCollection(getActivity(), movieTmdbId); fireTrackerEvent("Add to collection"); return true; } case R.id.menu_action_movies_collection_remove: { MovieTools.removeFromCollection(getActivity(), movieTmdbId); fireTrackerEvent("Remove from collection"); return true; } } return false; } }); popupMenu.show(); }
From source file:com.zhengde163.netguard.ActivityLog.java
@Override protected void onCreate(Bundle savedInstanceState) { // Util.setTheme(this); setTheme(R.style.AppThemeBlue);//from w w w. j a va 2s .com super.onCreate(savedInstanceState); setContentView(R.layout.logging); running = true; // Action bar View actionView = getLayoutInflater().inflate(R.layout.actionlog, null, false); // SwitchCompat swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled); ImageView ivEnabled = (ImageView) actionView.findViewById(R.id.ivEnabled); getSupportActionBar().setDisplayShowCustomEnabled(true); getSupportActionBar().setCustomView(actionView); getSupportActionBar().setTitle(R.string.menu_log); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Get settings final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); resolve = prefs.getBoolean("resolve", false); organization = prefs.getBoolean("organization", false); log = prefs.getBoolean("log", false); // Show disabled message // TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled); // tvDisabled.setVisibility(log ? View.GONE : View.VISIBLE); final LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable); ly.setVisibility(log ? View.GONE : View.VISIBLE); ImageView ivClose = (ImageView) findViewById(R.id.ivClose); ivClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ly.setVisibility(View.GONE); } }); // Set enabled switch // swEnabled.setChecked(log); if (ivEnabled != null) { if (log) { ivEnabled.setImageResource(R.drawable.on); } else { ivEnabled.setImageResource(R.drawable.off); } ivEnabled.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { log = !log; boolean isChecked = log; prefs.edit().putBoolean("log", isChecked).apply(); } }); } // swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // prefs.edit().putBoolean("log", isChecked).apply(); // } // }); // Listen for preference changes prefs.registerOnSharedPreferenceChangeListener(this); lvLog = (ListView) findViewById(R.id.lvLog); boolean udp = prefs.getBoolean("proto_udp", true); boolean tcp = prefs.getBoolean("proto_tcp", true); boolean other = prefs.getBoolean("proto_other", true); boolean allowed = prefs.getBoolean("traffic_allowed", true); boolean blocked = prefs.getBoolean("traffic_blocked", true); adapter = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(udp, tcp, other, allowed, blocked), resolve, organization); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return DatabaseHelper.getInstance(ActivityLog.this).searchLog(constraint.toString()); } }); lvLog.setAdapter(adapter); try { vpn4 = InetAddress.getByName(prefs.getString("vpn4", "10.1.10.1")); vpn6 = InetAddress.getByName(prefs.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1")); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { PackageManager pm = getPackageManager(); Cursor cursor = (Cursor) adapter.getItem(position); long time = cursor.getLong(cursor.getColumnIndex("time")); int version = cursor.getInt(cursor.getColumnIndex("version")); int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String saddr = cursor.getString(cursor.getColumnIndex("saddr")); final int sport = (cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"))); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = (cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"))); final String dname = cursor.getString(cursor.getColumnIndex("dname")); final int uid = (cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"))); int allowed = (cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"))); // Get external address InetAddress addr = null; try { addr = InetAddress.getByName(daddr); } catch (UnknownHostException ex) { Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex)); } String ip; int port; if (addr.equals(vpn4) || addr.equals(vpn6)) { ip = saddr; port = sport; } else { ip = daddr; port = dport; } // Build popup menu PopupMenu popup = new PopupMenu(ActivityLog.this, findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.log); // Application name if (uid >= 0) popup.getMenu().findItem(R.id.menu_application) .setTitle(TextUtils.join(", ", Util.getApplicationNames(uid, ActivityLog.this))); else popup.getMenu().removeItem(R.id.menu_application); // Destination IP popup.getMenu().findItem(R.id.menu_protocol) .setTitle(Util.getProtocolName(protocol, version, false)); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + ip)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois).setTitle(getString(R.string.title_log_whois, ip)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + port)); if (port <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port).setTitle(getString(R.string.title_log_port, port)); if (!prefs.getBoolean("filter", false)) { popup.getMenu().removeItem(R.id.menu_allow); popup.getMenu().removeItem(R.id.menu_block); } final Packet packet = new Packet(); packet.version = version; packet.protocol = protocol; packet.daddr = daddr; packet.dport = dport; packet.time = time; packet.uid = uid; packet.allowed = (allowed > 0); // Time popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); // Handle click popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_application: { Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; } case R.id.menu_whois: startActivity(lookupIP); return true; case R.id.menu_port: startActivity(lookupPort); return true; case R.id.menu_allow: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 0); ServiceSinkhole.reload("allow host", ActivityLog.this); Intent main = new Intent(ActivityLog.this, ActivityMain.class); main.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main); return true; case R.id.menu_block: DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, dname, 1); ServiceSinkhole.reload("block host", ActivityLog.this); Intent main1 = new Intent(ActivityLog.this, ActivityMain.class); main1.putExtra(ActivityMain.EXTRA_SEARCH, Integer.toString(uid)); startActivity(main1); return true; default: return false; } } }); // Show popup.show(); } }); live = true; }
From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java
private void showSongOverflow(final Context context, View parent, final Song song) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.search_res_song); popupMenu.show();//from w ww. j a v a2 s .c om if (song.getArtist() == null) { // No attached artist, don't show the menu entry popupMenu.getMenu().removeItem(R.id.menu_open_artist_page); } if (song.getAlbum() == null) { // No attached album, don't show the menu entry popupMenu.getMenu().removeItem(R.id.menu_open_album_page); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { Intent intent; switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playSong(song); break; case R.id.menu_add_to_queue: PlaybackProxy.queueSong(song, false); break; case R.id.menu_open_artist_page: if (song.getArtist() != null) { intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(), 0xFF333333); context.startActivity(intent); } break; case R.id.menu_open_album_page: if (song.getAlbum() != null) { intent = AlbumActivity.craftIntent(context, null, song.getAlbum(), song.getProvider(), 0xFF333333); context.startActivity(intent); } break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song); fragment.show(((FragmentActivity) context).getSupportFragmentManager(), song.getRef()); break; default: return false; } return true; } }); }
From source file:com.cecs492a_group4.sp.SingleEvent.java
public void showPopup(View v) { PopupMenu popup = new PopupMenu(this, v); popup.setOnMenuItemClickListener(this); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.menu, popup.getMenu()); popup.show();//from ww w . j a v a 2 s . c o m }
From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java
private PopupMenu initializeHeaderOverflowPopup(final View headerOverflowMenu) { final PopupMenu resultPopupMenu; if (headerOverflowMenu == null) { resultPopupMenu = null;/*from w ww . j av a 2 s .c o m*/ } else { final PopupMenu popupMenu = new PopupMenu(this, headerOverflowMenu); popupMenu.getMenuInflater().inflate(R.menu.mpd_mainmenu, popupMenu.getMenu()); popupMenu.getMenuInflater().inflate(R.menu.mpd_playlistmenu, popupMenu.getMenu()); popupMenu.getMenu().removeItem(R.id.PLM_EditPL); popupMenu.setOnMenuItemClickListener(this); headerOverflowMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popupMenu)); headerOverflowMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (mSlidingLayout != null && mSlidingLayout.isPanelExpanded()) { prepareNowPlayingMenu(popupMenu.getMenu()); popupMenu.show(); } } }); resultPopupMenu = popupMenu; } return resultPopupMenu; }
From source file:com.android.music.MusicBrowserActivity.java
/** * M: Create fake menu.// w w w . j a v a 2 s . com */ private void createFakeMenu() { if (mPermissionReqProcessed == true) { if (mHasMenukey) { MusicLogUtils.d(TAG, "createFakeMenu Quit when there has Menu Key"); return; } if (mOrientaiton == Configuration.ORIENTATION_LANDSCAPE) { mOverflowMenuButtonId = R.id.overflow_menu; mOverflowMenuButton = findViewById(R.id.overflow_menu); } else { mOverflowMenuButtonId = R.id.overflow_menu_nowplaying; mOverflowMenuButton = findViewById(R.id.overflow_menu_nowplaying); View parent = (View) mOverflowMenuButton.getParent(); if (parent != null) { parent.setVisibility(View.VISIBLE); } } mOverflowMenuButton.setVisibility(View.VISIBLE); mOverflowMenuButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { MusicLogUtils.d(TAG, "createFakeMenu:onClick()"); if (v.getId() == mOverflowMenuButtonId) { final PopupMenu popupMenu = new PopupMenu(MusicBrowserActivity.this, mOverflowMenuButton); mPopupMenu = popupMenu; final Menu menu = popupMenu.getMenu(); onCreateOptionsMenu(menu); popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { return onOptionsItemSelected(item); } }); popupMenu.setOnDismissListener(new OnDismissListener() { public void onDismiss(PopupMenu menu) { mPopupMenuShowing = false; MusicLogUtils.d(TAG, "createFakeMenu:onDismiss() called"); return; } }); onPrepareOptionsMenu(menu); mPopupMenuShowing = true; if (popupMenu != null) { MusicLogUtils.d(TAG, "createFakeMenu:popupMenu.show()"); popupMenu.show(); } } } }); } }
From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java
private void showAlbumOverflow(final Context context, View parent, final Album album) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.search_res_album); popupMenu.show();// w ww . ja v a2 s. c o m final String artist = Utils.getMainArtist(album); if (artist == null) { // No artist could be found for this album, don't show the entry popupMenu.getMenu().removeItem(R.id.menu_open_artist_page); } popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playAlbum(album); break; case R.id.menu_add_to_queue: PlaybackProxy.queueAlbum(album, false); break; case R.id.menu_open_artist_page: if (artist != null) { Intent intent = ArtistActivity.craftIntent(context, null, artist, album.getProvider(), 0xFF333333); context.startActivity(intent); } break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(album); fragment.show(((FragmentActivity) context).getSupportFragmentManager(), album.getRef()); break; default: return false; } return true; } }); }
From source file:org.rm3l.ddwrt.tiles.admin.nvram.AdminNVRAMTile.java
public AdminNVRAMTile(@NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) {/*from w w w . ja v a 2s. c o m*/ super(parentFragment, arguments, router, R.layout.tile_admin_nvram, R.id.tile_admin_nvram_togglebutton); sortIds.put(R.id.tile_admin_nvram_sort_default, 11); sortIds.put(R.id.tile_admin_nvram_sort_asc, 12); sortIds.put(R.id.tile_admin_nvram_sort_desc, 13); this.mNvramInfoDefaultSorting = new NVRAMInfo(); mRecyclerView = (RecyclerView) layout.findViewById(R.id.tile_admin_nvram_ListView); // use this setting to improve performance if you know that changes // in content do not change the layout size of the RecyclerView // allows for optimizations if all items are of the same size: mRecyclerView.setHasFixedSize(true); // use a linear layout manager mLayoutManager = new LinearLayoutManager(mParentFragmentActivity); mLayoutManager.scrollToPosition(0); mRecyclerView.setLayoutManager(mLayoutManager); // specify an adapter (see also next example) mAdapter = new NVRAMDataRecyclerViewAdapter(mParentFragmentActivity, router, mNvramInfoDefaultSorting); mRecyclerView.setAdapter(mAdapter); //Create Options Menu final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_admin_nvram_menu); if (!isThemeLight(mParentFragmentActivity, mRouter.getUuid())) { //Set menu background to white tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark); } tileMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v); popup.setOnMenuItemClickListener(AdminNVRAMTile.this); final MenuInflater inflater = popup.getMenuInflater(); final Menu menu = popup.getMenu(); inflater.inflate(R.menu.tile_admin_nvram_options, menu); //Disable menu item from preference Integer currentSort = null; if (mParentFragmentPreferences != null) { currentSort = sortIds.inverse().get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), sortIds.get(R.id.tile_admin_nvram_sort_default))); } if (currentSort == null) { currentSort = R.id.tile_admin_nvram_sort_default; } final MenuItem currentSortMenuItem = menu.findItem(currentSort); if (currentSortMenuItem != null) { currentSortMenuItem.setEnabled(false); } // Locate MenuItem with ShareActionProvider final MenuItem shareMenuItem = menu.findItem(R.id.tile_admin_nvram_share); // Fetch and store ShareActionProvider mShareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider(); popup.show(); } }); //Handle for Search EditText final EditText filterEditText = (EditText) this.layout.findViewById(R.id.tile_admin_nvram_filter); //Initialize with existing search data filterEditText.setText(mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING) : EMPTY_STRING); filterEditText.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (filterEditText.getRight() - filterEditText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { //'Clear' button - clear data, and reset everything out //Reset everything filterEditText.setText(EMPTY_STRING); final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplay = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplay = new HashMap<>(); break; } mNvramInfoToDisplay.putAll(mNvramInfoDefaultSortingData); } } else { mNvramInfoToDisplay = new HashMap<>(mNvramInfoDefaultSortingData); } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplay); mAdapter.notifyDataSetChanged(); if (mParentFragmentPreferences != null) { final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), EMPTY_STRING); editor.apply(); } return true; } } return false; } }); filterEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEARCH) { final String textToFind = filterEditText.getText().toString(); if (isNullOrEmpty(textToFind)) { //extra-check, even though we can be pretty sure the button is enabled only if textToFind is present return true; } final String existingSearch = mParentFragmentPreferences != null ? mParentFragmentPreferences.getString(getFormattedPrefKey(LAST_SEARCH), null) : null; if (mParentFragmentPreferences != null) { if (textToFind.equalsIgnoreCase(existingSearch)) { //No need to go further as this is already the string we are looking for return true; } final SharedPreferences.Editor editor = mParentFragmentPreferences.edit(); editor.putString(getFormattedPrefKey(LAST_SEARCH), textToFind); editor.apply(); } //Filter out (and sort by user-preference) final Properties mNvramInfoDefaultSortingData = mNvramInfoDefaultSorting.getData(); //Update adapter in the preferences final Map<Object, Object> mNvramInfoToDisplayCopy; if (mParentFragmentPreferences != null) { final Integer currentSort = sortIds.inverse() .get(mParentFragmentPreferences.getInt(getFormattedPrefKey(SORT), -1)); if (currentSort == null || currentSort <= 0) { mNvramInfoToDisplayCopy = new HashMap<>(mNvramInfoDefaultSortingData); } else { switch (currentSort) { case R.id.tile_admin_nvram_sort_asc: //asc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_desc: //desc mNvramInfoToDisplayCopy = new TreeMap<>(COMPARATOR_REVERSE_STRING_CASE_INSENSITIVE); break; case R.id.tile_admin_nvram_sort_default: default: mNvramInfoToDisplayCopy = new HashMap<>(); break; } //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } } else { mNvramInfoToDisplayCopy = new HashMap<>(); //noinspection ConstantConditions for (Map.Entry<Object, Object> entry : mNvramInfoDefaultSortingData.entrySet()) { final Object key = entry.getKey(); final Object value = entry.getValue(); if (key == null) { continue; } if (containsIgnoreCase(key.toString(), textToFind) || containsIgnoreCase(value.toString(), textToFind)) { mNvramInfoToDisplayCopy.put(key, value); } } } ((NVRAMDataRecyclerViewAdapter) mAdapter).setEntryList(mNvramInfoToDisplayCopy); mAdapter.notifyDataSetChanged(); return true; } return false; } }); }
From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java
private void showViewMenu() { View menuView = findViewById(R.id.action_view); PopupMenu popup = new PopupMenu(menuView.getContext(), menuView); final List<IExperimentSensor> experimentRuns = getActiveSensors(); for (int i = 0; i < experimentRuns.size(); i++) { IExperimentSensor experiment = experimentRuns.get(i); MenuItem item = popup.getMenu().add(1, i, i, experiment.getClass().getSimpleName()); item.setCheckable(true);/*from w w w . j a v a 2s .co m*/ } popup.getMenu().setGroupCheckable(1, true, true); IExperimentSensor currentExperimentSensor = experiment.getCurrentExperimentSensor(); if (currentExperimentSensor != null) popup.getMenu().getItem(experimentRuns.indexOf(currentExperimentSensor)).setChecked(true); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int itemPosition = menuItem.getItemId(); IExperimentSensor experimentRun = experimentRuns.get(itemPosition); setCurrentSensor(experimentRun); pager.requestLayout(); pager.setCurrentItem(itemPosition, true); return true; } }); popup.show(); }