List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
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 a 2s. 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:android_network.hetnet.vpn_service.AdapterRule.java
@Override public void onBindViewHolder(final ViewHolder holder, final int position) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); // Get rule//from w w w .j a va2 s .c o m final Rule rule = listFiltered.get(position); // Handle expanding/collapsing holder.llApplication.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { rule.expanded = !rule.expanded; notifyItemChanged(position); } }); // Show if non default rules holder.itemView.setBackgroundColor(rule.changed ? colorChanged : Color.TRANSPARENT); // Show expand/collapse indicator holder.ivExpander.setImageLevel(rule.expanded ? 1 : 0); // Show application icon if (rule.info.applicationInfo == null || rule.info.applicationInfo.icon == 0) Picasso.with(context).load(android.R.drawable.sym_def_app_icon).into(holder.ivIcon); else { Uri uri = Uri .parse("android.resource://" + rule.info.packageName + "/" + rule.info.applicationInfo.icon); Picasso.with(context).load(uri).resize(iconSize, iconSize).into(holder.ivIcon); } // Show application label holder.tvName.setText(rule.name); // Show application state int color = rule.system ? colorOff : colorText; if (!rule.internet || !rule.enabled) color = Color.argb(128, Color.red(color), Color.green(color), Color.blue(color)); holder.tvName.setTextColor(color); // Show rule count new AsyncTask<Object, Object, Long>() { @Override protected void onPreExecute() { holder.tvHosts.setVisibility(View.GONE); } @Override protected Long doInBackground(Object... objects) { return DatabaseHelper.getInstance(context).getRuleCount(rule.info.applicationInfo.uid); } @Override protected void onPostExecute(Long rules) { if (rules > 0) { holder.tvHosts.setVisibility(View.VISIBLE); holder.tvHosts.setText(Long.toString(rules)); } } }.execute(); boolean screen_on = prefs.getBoolean("screen_on", true); // Wi-Fi settings holder.cbWifi.setEnabled(rule.apply); holder.cbWifi.setAlpha(wifiActive ? 1 : 0.5f); holder.cbWifi.setOnCheckedChangeListener(null); holder.cbWifi.setChecked(rule.wifi_blocked); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbWifi)); DrawableCompat.setTint(wrap, rule.apply ? (rule.wifi_blocked ? colorOff : colorOn) : colorGrayed); } holder.cbWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { rule.wifi_blocked = isChecked; updateRule(rule, true, listAll); } }); holder.ivScreenWifi.setEnabled(rule.apply); holder.ivScreenWifi.setAlpha(wifiActive ? 1 : 0.5f); holder.ivScreenWifi.setVisibility(rule.screen_wifi && rule.wifi_blocked ? View.VISIBLE : View.INVISIBLE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(holder.ivScreenWifi.getDrawable()); DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed); } // Mobile settings holder.cbOther.setEnabled(rule.apply); holder.cbOther.setAlpha(otherActive ? 1 : 0.5f); holder.cbOther.setOnCheckedChangeListener(null); holder.cbOther.setChecked(rule.other_blocked); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(CompoundButtonCompat.getButtonDrawable(holder.cbOther)); DrawableCompat.setTint(wrap, rule.apply ? (rule.other_blocked ? colorOff : colorOn) : colorGrayed); } holder.cbOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { rule.other_blocked = isChecked; updateRule(rule, true, listAll); } }); holder.ivScreenOther.setEnabled(rule.apply); holder.ivScreenOther.setAlpha(otherActive ? 1 : 0.5f); holder.ivScreenOther.setVisibility(rule.screen_other && rule.other_blocked ? View.VISIBLE : View.INVISIBLE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(holder.ivScreenOther.getDrawable()); DrawableCompat.setTint(wrap, rule.apply ? colorOn : colorGrayed); } holder.tvRoaming.setTextColor(rule.apply ? colorOff : colorGrayed); holder.tvRoaming.setAlpha(otherActive ? 1 : 0.5f); holder.tvRoaming.setVisibility( rule.roaming && (!rule.other_blocked || rule.screen_other) ? View.VISIBLE : View.INVISIBLE); // Expanded configuration section holder.llConfiguration.setVisibility(rule.expanded ? View.VISIBLE : View.GONE); // Show application details holder.tvUid .setText(rule.info.applicationInfo == null ? "?" : Integer.toString(rule.info.applicationInfo.uid)); holder.tvPackage.setText(rule.info.packageName); holder.tvVersion.setText(rule.info.versionName + '/' + rule.info.versionCode); holder.tvDescription.setVisibility(rule.description == null ? View.GONE : View.VISIBLE); holder.tvDescription.setText(rule.description); // Show application state holder.tvInternet.setVisibility(rule.internet ? View.GONE : View.VISIBLE); holder.tvDisabled.setVisibility(rule.enabled ? View.GONE : View.VISIBLE); // Show traffic statistics holder.tvStatistics .setVisibility(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N ? View.GONE : View.VISIBLE); holder.tvStatistics.setText(context.getString(R.string.msg_mbday, rule.upspeed, rule.downspeed)); // Show related holder.btnRelated.setVisibility(rule.relateduids ? View.VISIBLE : View.GONE); holder.btnRelated.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent main = new Intent(context, MainActivity.class); main.putExtra(MainActivity.EXTRA_SEARCH, Integer.toString(rule.info.applicationInfo.uid)); context.startActivity(main); } }); // Launch application settings holder.ibSettings.setVisibility(rule.settings == null ? View.GONE : View.VISIBLE); holder.ibSettings.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(rule.settings); } }); // Data saver holder.ibDatasaver.setVisibility(rule.datasaver == null ? View.GONE : View.VISIBLE); holder.ibDatasaver.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(rule.datasaver); } }); // Launch application holder.ibLaunch.setVisibility(rule.launch == null ? View.GONE : View.VISIBLE); holder.ibLaunch.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(rule.launch); } }); // Apply holder.cbApply.setEnabled(rule.pkg); holder.cbApply.setOnCheckedChangeListener(null); holder.cbApply.setChecked(rule.apply); holder.cbApply.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { rule.apply = isChecked; updateRule(rule, true, listAll); } }); // Show Wi-Fi screen on condition holder.llScreenWifi.setVisibility(screen_on ? View.VISIBLE : View.GONE); holder.cbScreenWifi.setEnabled(rule.wifi_blocked && rule.apply); holder.cbScreenWifi.setOnCheckedChangeListener(null); holder.cbScreenWifi.setChecked(rule.screen_wifi); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(holder.ivWifiLegend.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } holder.cbScreenWifi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { rule.screen_wifi = isChecked; updateRule(rule, true, listAll); } }); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { Drawable wrap = DrawableCompat.wrap(holder.ivOtherLegend.getDrawable()); DrawableCompat.setTint(wrap, colorOn); } // Show mobile screen on condition holder.llScreenOther.setVisibility(screen_on ? View.VISIBLE : View.GONE); holder.cbScreenOther.setEnabled(rule.other_blocked && rule.apply); holder.cbScreenOther.setOnCheckedChangeListener(null); holder.cbScreenOther.setChecked(rule.screen_other); holder.cbScreenOther.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { rule.screen_other = isChecked; updateRule(rule, true, listAll); } }); // Show roaming condition holder.cbRoaming.setEnabled((!rule.other_blocked || rule.screen_other) && rule.apply); holder.cbRoaming.setOnCheckedChangeListener(null); holder.cbRoaming.setChecked(rule.roaming); holder.cbRoaming.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override @TargetApi(Build.VERSION_CODES.M) public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { rule.roaming = isChecked; updateRule(rule, true, listAll); // Request permissions if (isChecked && !Util.hasPhoneStatePermission(context)) context.requestPermissions(new String[] { Manifest.permission.READ_PHONE_STATE }, MainActivity.REQUEST_ROAMING); } }); // Reset rule holder.btnClear.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.areYouSure(view.getContext(), R.string.msg_clear_rules, new Util.DoubtListener() { @Override public void onSure() { holder.cbApply.setChecked(true); holder.cbWifi.setChecked(rule.wifi_default); holder.cbOther.setChecked(rule.other_default); holder.cbScreenWifi.setChecked(rule.screen_wifi_default); holder.cbScreenOther.setChecked(rule.screen_other_default); holder.cbRoaming.setChecked(rule.roaming_default); } }); } }); // Live holder.ivLive.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { live = !live; TypedValue tv = new TypedValue(); view.getContext().getTheme().resolveAttribute(live ? R.attr.iconPause : R.attr.iconPlay, tv, true); holder.ivLive.setImageResource(tv.resourceId); if (live) AdapterRule.this.notifyDataSetChanged(); } }); // Show logging is disabled boolean log_app = prefs.getBoolean("log_app", false); holder.tvNoLog.setVisibility(log_app ? View.GONE : View.VISIBLE); holder.tvNoLog.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(new Intent(context, ActivitySettings.class)); } }); // Show filtering is disabled boolean filter = prefs.getBoolean("filter", false); holder.tvNoFilter.setVisibility(filter ? View.GONE : View.VISIBLE); holder.tvNoFilter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { context.startActivity(new Intent(context, ActivitySettings.class)); } }); // Show access rules if (rule.expanded) { // Access the database when expanded only final AdapterAccess badapter = new AdapterAccess(context, DatabaseHelper.getInstance(context).getAccess(rule.info.applicationInfo.uid)); holder.lvAccess.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, final int bposition, long bid) { PackageManager pm = context.getPackageManager(); Cursor cursor = (Cursor) badapter.getItem(bposition); final long id = cursor.getLong(cursor.getColumnIndex("ID")); final int version = cursor.getInt(cursor.getColumnIndex("version")); final int protocol = cursor.getInt(cursor.getColumnIndex("protocol")); final String daddr = cursor.getString(cursor.getColumnIndex("daddr")); final int dport = cursor.getInt(cursor.getColumnIndex("dport")); long time = cursor.getLong(cursor.getColumnIndex("time")); int block = cursor.getInt(cursor.getColumnIndex("block")); PopupMenu popup = new PopupMenu(context, context.findViewById(R.id.vwPopupAnchor)); popup.inflate(R.menu.access); popup.getMenu().findItem(R.id.menu_host).setTitle(Util.getProtocolName(protocol, version, false) + " " + daddr + (dport > 0 ? "/" + dport : "")); // markPro(popup.getMenu().findItem(R.id.menu_allow), ActivityPro.SKU_FILTER); // markPro(popup.getMenu().findItem(R.id.menu_block), ActivityPro.SKU_FILTER); // Whois final Intent lookupIP = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.tcpiputils.com/whois-lookup/" + daddr)); if (pm.resolveActivity(lookupIP, 0) == null) popup.getMenu().removeItem(R.id.menu_whois); else popup.getMenu().findItem(R.id.menu_whois) .setTitle(context.getString(R.string.title_log_whois, daddr)); // Lookup port final Intent lookupPort = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.speedguide.net/port.php?port=" + dport)); if (dport <= 0 || pm.resolveActivity(lookupPort, 0) == null) popup.getMenu().removeItem(R.id.menu_port); else popup.getMenu().findItem(R.id.menu_port) .setTitle(context.getString(R.string.title_log_port, dport)); popup.getMenu().findItem(R.id.menu_time) .setTitle(SimpleDateFormat.getDateTimeInstance().format(time)); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_whois: context.startActivity(lookupIP); return true; case R.id.menu_port: context.startActivity(lookupPort); return true; case R.id.menu_allow: if (true) { DatabaseHelper.getInstance(context).setAccess(id, 0); ServiceSinkhole.reload("allow host", context); } // context.startActivity(new Intent(context, ActivityPro.class)); return true; case R.id.menu_block: if (true) { DatabaseHelper.getInstance(context).setAccess(id, 1); ServiceSinkhole.reload("block host", context); } // context.startActivity(new Intent(context, ActivityPro.class)); return true; case R.id.menu_reset: DatabaseHelper.getInstance(context).setAccess(id, -1); ServiceSinkhole.reload("reset host", context); return true; } return false; } }); if (block == 0) popup.getMenu().removeItem(R.id.menu_allow); else if (block == 1) popup.getMenu().removeItem(R.id.menu_block); popup.show(); } }); holder.lvAccess.setAdapter(badapter); } else { holder.lvAccess.setAdapter(null); holder.lvAccess.setOnItemClickListener(null); } // Clear access log holder.btnClearAccess.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Util.areYouSure(view.getContext(), R.string.msg_reset_access, new Util.DoubtListener() { @Override public void onSure() { DatabaseHelper.getInstance(context).clearAccess(rule.info.applicationInfo.uid, true); if (!live) notifyDataSetChanged(); if (rv != null) rv.scrollToPosition(position); } }); } }); // Notify on access holder.cbNotify.setEnabled(prefs.getBoolean("notify_access", false) && rule.apply); holder.cbNotify.setOnCheckedChangeListener(null); holder.cbNotify.setChecked(rule.notify); holder.cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { rule.notify = isChecked; updateRule(rule, true, listAll); } }); }
From source file:com.filemanager.free.adapters.Recycleradapter.java
void showPopup(View v, final Layoutelements rowItem) { v.setOnClickListener(new View.OnClickListener() { @Override// w ww . j a v a 2 s . co m public void onClick(View view) { PopupMenu popupMenu = new PopupMenu(main.getActivity(), view); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.about: main.utils.showProps((rowItem).generateBaseFile(), rowItem.getPermissions(), main, main.ROOT_MODE); return true; case R.id.share: ArrayList<File> arrayList = new ArrayList<File>(); arrayList.add(new File(rowItem.getDesc())); main.utils.shareFiles(arrayList, main.MAIN_ACTIVITY, main.theme1, Color.parseColor(main.fabSkin)); return true; case R.id.rename: main.rename(rowItem.generateBaseFile()); return true; case R.id.cpy: MainActivity MAIN_ACTIVITY = main.MAIN_ACTIVITY; main.MAIN_ACTIVITY.MOVE_PATH = null; ArrayList<BaseFile> copies = new ArrayList<>(); copies.add(rowItem.generateBaseFile()); MAIN_ACTIVITY.COPY_PATH = copies; MAIN_ACTIVITY.supportInvalidateOptionsMenu(); return true; case R.id.cut: MainActivity MAIN_ACTIVITY1 = main.MAIN_ACTIVITY; MAIN_ACTIVITY1.COPY_PATH = null; ArrayList<BaseFile> copie = new ArrayList<>(); copie.add(rowItem.generateBaseFile()); MAIN_ACTIVITY1.MOVE_PATH = copie; MAIN_ACTIVITY1.supportInvalidateOptionsMenu(); return true; case R.id.ex: main.MAIN_ACTIVITY.mainActivityHelper.extractFile(new File(rowItem.getDesc())); return true; case R.id.book: DataUtils.addBook(new String[] { rowItem.getTitle(), rowItem.getDesc() }, true); main.MAIN_ACTIVITY.updateDrawer(); Toast.makeText(main.getActivity(), main.utils.getString(main.getActivity(), R.string.bookmarksadded), Toast.LENGTH_LONG).show(); return true; } return false; } }); popupMenu.inflate(R.menu.item_extras); String x = rowItem.getDesc().toLowerCase(); if (rowItem.isDirectory()) popupMenu.getMenu().findItem(R.id.share).setVisible(false); if (x.endsWith(".zip") || x.endsWith(".jar") || x.endsWith(".apk") || x.endsWith(".rar") || x.endsWith(".tar") || x.endsWith(".tar.gz")) popupMenu.getMenu().findItem(R.id.ex).setVisible(true); popupMenu.show(); } }); }
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 w w. jav a2s.c o m*/ 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.google.android.apps.muzei.MuzeiActivity.java
@TargetApi(Build.VERSION_CODES.KITKAT) private void setupOverflowButton() { final View overflowButton = findViewById(R.id.overflow_button); mOverflowMenu = new PopupMenu(this, overflowButton); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { overflowButton.setOnTouchListener(mOverflowMenu.getDragToOpenListener()); }/*from w w w .j ava2 s . c om*/ overflowButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { mOverflowMenuVisible = true; mOverflowMenu.show(); } }); mOverflowMenu.setOnDismissListener(new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu popupMenu) { mOverflowMenuVisible = false; } }); mOverflowMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { int id = mOverflowSourceActionMap.get(menuItem.getItemId()); if (id > 0) { mSourceManager.sendAction(id); return true; } switch (menuItem.getItemId()) { case R.id.action_settings: startActivity(new Intent(MuzeiActivity.this, SettingsActivity.class)); return true; } return false; } }); }
From source file:org.brandroid.openmanager.fragments.ContentFragment.java
public boolean createContextMenu(final OpenPath file, final AdapterView<?> list, final View view, final int pos, final int xOffset, final int yOffset) { Logger.LogInfo(getClassName() + ".onItemLongClick: " + file); final OpenContextMenuInfo info = new OpenContextMenuInfo(file); if (!OpenExplorer.USE_PRETTY_CONTEXT_MENUS) { if (Build.VERSION.SDK_INT > 10) { final PopupMenu pop = new PopupMenu(view.getContext(), view); pop.setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (onOptionsItemSelected(item)) { pop.dismiss();/*from ww w . j a v a 2s .c om*/ return true; } else if (getExplorer() != null) return getExplorer().onIconContextItemSelected(pop, item, item.getMenuInfo(), view); return false; } }); pop.getMenuInflater().inflate(R.menu.context_file, pop.getMenu()); onPrepareOptionsMenu(pop.getMenu()); if (DEBUG) Logger.LogDebug("PopupMenu.show()"); pop.show(); return true; } else return list.showContextMenu(); } else if (OpenExplorer.BEFORE_HONEYCOMB || !OpenExplorer.USE_ACTIONMODE) { try { //View anchor = view; //view.findViewById(R.id.content_context_helper); //if(anchor == null) anchor = view; //view.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); //Rect r = new Rect(view.getLeft(),view.getTop(),view.getMeasuredWidth(),view.getMeasuredHeight()); MenuBuilder cmm = IconContextMenu.newMenu(list.getContext(), R.menu.context_file); if (!file.canRead()) { MenuUtils.setMenuEnabled(cmm, false); MenuUtils.setMenuEnabled(cmm, true, R.id.menu_context_info); } MenuUtils.setMenuEnabled(cmm, file.canWrite(), R.id.menu_context_paste, R.id.menu_context_cut, R.id.menu_context_delete, R.id.menu_context_rename); onPrepareOptionsMenu(cmm); //if(!file.isArchive()) hideItem(cmm, R.id.menu_context_unzip); if (getClipboard().size() > 0) MenuUtils.setMenuVisible(cmm, false, R.id.menu_multi); else MenuUtils.setMenuVisible(cmm, false, R.id.menu_context_paste); MenuUtils.setMenuEnabled(cmm, !file.isDirectory(), R.id.menu_context_edit, R.id.menu_context_view); final IconContextMenu cm = new IconContextMenu(list.getContext(), cmm, view); //cm.setAnchor(anchor); cm.setNumColumns(2); cm.setOnIconContextItemSelectedListener(getExplorer()); cm.setInfo(info); cm.setTextLayout(R.layout.context_item); cm.setTitle(file.getName()); if (!cm.show()) //r.left, r.top); return list.showContextMenu(); else return true; } catch (Exception e) { Logger.LogWarning("Couldn't show Iconified menu.", e); return list.showContextMenu(); } } if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) { if (!file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) { try { Method mStarter = getActivity().getClass().getMethod("startActionMode"); mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() { //@Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { return false; } //@Override public void onDestroyActionMode(android.view.ActionMode mode) { mActionMode = null; mActionModeSelected = false; } //@Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.context_file, menu); mActionModeSelected = true; return true; } //@Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { //ArrayList<OpenPath> files = new ArrayList<OpenPath>(); //OpenPath file = mLastPath.getChild(mode.getTitle().toString()); //files.add(file); if (item.getItemId() != R.id.menu_context_cut && item.getItemId() != R.id.menu_multi && item.getItemId() != R.id.menu_context_copy) { mode.finish(); mActionModeSelected = false; } return executeMenu(item.getItemId(), mode, file); } }); Class cAM = Class.forName("android.view.ActionMode"); Method mST = cAM.getMethod("setTitle", CharSequence.class); mST.invoke(mActionMode, file.getName()); } catch (Exception e) { Logger.LogError("Error using ActionMode", e); } } return true; } if (file.isDirectory() && mActionMode == null && !getClipboard().isMultiselect()) { if (!OpenExplorer.BEFORE_HONEYCOMB && OpenExplorer.USE_ACTIONMODE) { try { Method mStarter = getActivity().getClass().getMethod("startActionMode"); mActionMode = mStarter.invoke(getActivity(), new ActionModeHelper.Callback() { //@Override public boolean onPrepareActionMode(android.view.ActionMode mode, Menu menu) { return false; } //@Override public void onDestroyActionMode(android.view.ActionMode mode) { mActionMode = null; mActionModeSelected = false; } //@Override public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) { mode.getMenuInflater().inflate(R.menu.context_file, menu); menu.findItem(R.id.menu_context_paste).setEnabled(getClipboard().size() > 0); //menu.findItem(R.id.menu_context_unzip).setEnabled(mHoldingZip); mActionModeSelected = true; return true; } //@Override public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) { return executeMenu(item.getItemId(), mode, file); } }); Class cAM = Class.forName("android.view.ActionMode"); Method mST = cAM.getMethod("setTitle", CharSequence.class); mST.invoke(mActionMode, file.getName()); } catch (Exception e) { Logger.LogError("Error using ActionMode", e); } } return true; } return false; }
From source file:com.fastbootmobile.encore.app.adapters.SearchAdapter.java
private void showPlaylistOverflow(final Context context, View parent, final Playlist playlist) { PopupMenu popupMenu = new PopupMenu(context, parent); popupMenu.inflate(R.menu.search_res_playlist); popupMenu.show();//from w w w . j a v a2s. co m popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.menu_play_now: PlaybackProxy.playPlaylist(playlist); break; case R.id.menu_add_to_queue: PlaybackProxy.queuePlaylist(playlist, false); break; case R.id.menu_add_to_playlist: PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(playlist); fragment.show(((FragmentActivity) context).getSupportFragmentManager(), playlist.getRef()); break; default: return false; } return true; } }); }
From source file:org.spinsuite.view.V_Process.java
/** * Show Print Formats//from w w w . j a v a 2 s . c o m * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 31/03/2014, 11:57:26 * @return void */ private void showPrintFormat() { View menuItemView = findViewById(R.id.action_print_format); pPrintFormat = new PopupMenu(this, menuItemView); for (KeyNamePair pFormat : m_PrintFormats) { pPrintFormat.getMenu().add(Menu.NONE, pFormat.getKey(), Menu.NONE, pFormat.getName()); } // Listener pPrintFormat.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { int m_AD_PrintFormatItem_ID = item.getItemId(); if (isLoaded) { showReport(m_AD_PrintFormatItem_ID); } return false; } }); // Show pPrintFormat.show(); }
From source file:com.msopentech.applicationgateway.EnterpriseBrowserActivity.java
public void showSettingsPopup(View v) { try {/* www. ja v a2s . c om*/ PopupMenu popup = new PopupMenu(this, v); MenuInflater inflater = popup.getMenuInflater(); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_connection: { showAgentsList(); return true; } case R.id.menu_sign_in_or_out: { if (mIsSigninRequired) { // Menu item in sign in mode. //TODO: showSignIn(null, true); return true; } // Clean up the session. mTraits.sessionID = null; mTraits.token = null; mTraits.agent = null; // Indicate the condition. mIsSigninRequired = true; //Remove all tabs except one. mCustomTabHost.resetTabs(); mUrlEditTextView.setText(""); mProgressBarView.setProgress(0); // Disable the reload button and set the right image for it. mReloadButtonView.setEnabled(false); mReloadButtonView.setImageResource(R.drawable.reload_button); mStatusButtonView.setImageResource(R.drawable.connection_red); // Since it's the user's intention to sign out, his // history must be dropped. PersistenceManager.dropContent(PersistenceManager.ContentType.HISTORY); return true; } // Removed from RELEASE version. Should be active for development ONLY. // case R.id.menu_advanced_router_settings: { // showAdvancedRouterSettings(null); // } default: { return false; } } } }); inflater.inflate(R.menu.settings_menu, popup.getMenu()); if (mIsSigninRequired) { MenuItem signItem = popup.getMenu().findItem(R.id.menu_sign_in_or_out); signItem.setTitle(getResources().getString(R.string.browser_menu_item_sign_in)); } // Assumes that agent always has a display name. If display name is not present agent is considered to be not connected. MenuItem agentItem = popup.getMenu().findItem(R.id.menu_connection); String status = getResources().getString(R.string.browser_menu_item_choose_connection_not_connected); if (mTraits != null && mTraits.agent != null && !TextUtils.isEmpty(mTraits.agent.getDisplayName())) { status = mTraits.agent.getDisplayName(); } Spannable span = new SpannableString( getResources().getString(R.string.browser_menu_item_choose_connection, status)); span.setSpan(new RelativeSizeSpan(0.8f), 18, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.GRAY), 18, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); agentItem.setTitle(span); popup.show(); } catch (final Exception e) { Utility.showAlertDialog(EnterpriseBrowserActivity.class.getSimpleName() + ".showSettingsPopup(): Failed. " + e.toString(), EnterpriseBrowserActivity.this); } }
From source file:com.google.android.apps.santatracker.presentquest.MapsActivity.java
private void initializeDebugUI() { if (!isDebug()) { return;/*from w w w . j a v a 2 s . c om*/ } FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab_debug); fab.setVisibility(View.VISIBLE); final PopupMenu popup = new PopupMenu(this, fab); MenuInflater inflater = popup.getMenuInflater(); inflater.inflate(R.menu.menu_debug_popup, popup.getMenu()); // Show the menu when clicked fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popup.show(); } }); // Handle debug menu clicks popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { final int id = item.getItemId(); if (id == R.id.item_drop_present) { // This should be about 20m away, so within the action radius LatLng fuzzyCurrent = FuzzyLocationUtil.fuzz(mCurrentLatLng); addPresent(fuzzyCurrent, true); } if (id == R.id.item_delete_present) { if (!mPresents.isEmpty()) { deletePresent(mPresents.get(0)); drawMarkers(); drawMarkerLabels(); } } if (id == R.id.item_play_jetpack) { showPlayJetpackDialog(null); } if (id == R.id.item_play_present_toss) { showPlayWorkshopDialog(); } if (id == R.id.item_collect_20) { onPresentsCollected(20); } if (id == R.id.item_return) { onPresentsReturned(3); } if (id == R.id.item_downlevel) { mUser.downlevel(); setUserProgress(); } if (id == R.id.reset_prefs) { // Reset prefs mPreferences.resetAll(); // Reset user mUser.presentsCollected = 0; mUser.presentsReturned = 0; mUser.save(); // Delete all workshops Workshop.deleteAll(Workshop.class); // Delete all places and presents Present.deleteAll(Present.class); Place.deleteAll(Place.class); // Restart the activity recreate(); } return true; } }); }