List of usage examples for android.widget PopupMenu PopupMenu
public PopupMenu(Context context, View anchor)
From source file:org.lytsing.android.weibo.ui.ComposeActivity.java
@Override public void onClick(View view) { int viewId = view.getId(); if (viewId == android.R.id.home) { NavUtils.navigateUpFromSameTask(this); return;//from w w w . ja va 2s. c o m } if (viewId == R.id.ll_text_limit_unit) { mContent = mEdit.getText().toString(); if (TextUtils.isEmpty(mContent)) return; DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { mEdit.setText(""); } }; AlertUtil.showAlert(this, R.string.attention, R.string.delete_all, getString(R.string.ok), listener, getString(R.string.cancel), null); } else if (viewId == R.id.ib_insert_pic) { PopupMenu popup = new PopupMenu(this, view); popup.getMenuInflater().inflate(R.menu.pic, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(android.view.MenuItem item) { Intent galleryIntent = new Intent(); galleryIntent.setType("image/*"); galleryIntent.setAction(Intent.ACTION_GET_CONTENT); galleryIntent.putExtra(Intent.EXTRA_LOCAL_ONLY, true); startActivityForResult(galleryIntent, 2); return true; } }); popup.show(); } else if (viewId == R.id.ib_face_keyboard) { showOrHideIMM(); } else if (viewId == R.id.ib_insert_location) { if (mIsLocation) { aq.id(R.id.tv_location).gone(); aq.id(R.id.ib_insert_location).image(R.drawable.btn_insert_location_nor); mIsLocation = false; mLatitude = ""; mLongitude = ""; } else { aq.id(R.id.ly_loadlocation).visible(); location_ajax(); } } }
From source file:com.dgsd.android.ShiftTracker.Fragment.WeekFragment.java
@Override public void onItemClick(AdapterView<?> list, final View view, int pos, long id) { final WeekAdapter.ViewHolder holder = (WeekAdapter.ViewHolder) view.getTag(); final Intent intent = getIntentFor(holder); if (!mHasTemplates || (holder != null && holder.shift != null)) { startActivity(intent);/* w ww . j a va 2 s. c o m*/ return; } final int jd = holder == null ? -1 : holder.julianDay; if (Api.isMin(Api.HONEYCOMB)) { PopupMenu popup = new PopupMenu(getActivity(), view.findViewById(R.id.text)); popup.getMenuInflater().inflate(R.menu.week_list_item_popup, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.template_shift) { showTemplateChooser(jd); } else if (item.getItemId() == R.id.new_shift) { startActivity(intent); } return false; } }); popup.show(); } else { mList.showContextMenuForChild(view); } }
From source file:com.android.mail.browse.MessageAttachmentBar.java
private boolean onClick(final int res, final View v) { if (res == R.id.preview_attachment) { previewAttachment();//from w ww . j a va 2s .co m } else if (res == R.id.save_attachment) { if (mAttachment.canSave()) { mActionHandler.startDownloadingAttachment(AttachmentDestination.EXTERNAL); mSaveClicked = true; Analytics.getInstance().sendEvent("save_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } } else if (res == R.id.download_again) { if (mAttachment.isPresentLocally()) { mActionHandler.showDownloadingDialog(); mActionHandler.startRedownloadingAttachment(mAttachment); Analytics.getInstance().sendEvent("redownload_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } } else if (res == R.id.cancel_attachment) { mActionHandler.cancelAttachment(); mSaveClicked = false; Analytics.getInstance().sendEvent("cancel_attachment", Utils.normalizeMimeType(mAttachment.getContentType()), "attachment_bar", mAttachment.size); } else if (res == R.id.attachment_extra_option1) { mActionHandler.handleOption1(); } else if (res == R.id.overflow) { // If no overflow items are visible, just bail out. // We shouldn't be able to get here anyhow since the overflow // button should be hidden. if (shouldShowOverflow()) { if (mPopup == null) { mPopup = new PopupMenu(getContext(), v); mPopup.getMenuInflater().inflate(R.menu.message_footer_overflow_menu, mPopup.getMenu()); mPopup.setOnMenuItemClickListener(this); } final Menu menu = mPopup.getMenu(); menu.findItem(R.id.preview_attachment).setVisible(shouldShowPreview()); menu.findItem(R.id.save_attachment).setVisible(shouldShowSave()); menu.findItem(R.id.download_again).setVisible(shouldShowDownloadAgain()); menu.findItem(R.id.attachment_extra_option1).setVisible(shouldShowExtraOption1()); mPopup.show(); } } else { // Handles clicking the attachment // in any area that is not the overflow // button or cancel button or one of the // overflow items. final String mime = Utils.normalizeMimeType(mAttachment.getContentType()); final String action; if ((mAttachment.flags & Attachment.FLAG_DUMMY_ATTACHMENT) != 0) { // This is a dummy. We need to download it, but not attempt to open or preview. mActionHandler.showDownloadingDialog(); mActionHandler.setViewOnFinish(false); mActionHandler.startDownloadingAttachment(AttachmentDestination.CACHE); action = null; } // If we can install, install. else if (MimeType.isInstallable(mAttachment.getContentType())) { // Save to external because the package manager only handles // file:// uris not content:// uris. We do the same // workaround in // UiProvider#getUiAttachmentsCursorForUIAttachments() mActionHandler.showAttachment(AttachmentDestination.EXTERNAL); action = "attachment_bar_install"; } // If we can view or play with an on-device app, // view or play. else if (MimeType.isViewable(getContext(), mAttachment.contentUri, mAttachment.getContentType())) { mActionHandler.showAttachment(AttachmentDestination.CACHE); action = "attachment_bar"; } // If we can only preview the attachment, preview. else if (mAttachment.canPreview()) { previewAttachment(); action = null; } // Otherwise, if we cannot do anything, show the info dialog. else { AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); int dialogMessage = R.string.no_application_found; builder.setTitle(R.string.more_info_attachment).setMessage(dialogMessage).show(); action = "attachment_bar_no_viewer"; } if (action != null) { Analytics.getInstance().sendEvent("view_attachment", mime, action, mAttachment.size); } } return true; }
From source file:com.custom.music.MusicBrowserActivity.java
private void showPupopMenu(View v) { Log.i(TAG, "showPupopMenu:BEGIN=" + v, Log.APP); if (v == null) { return;// w w w . j a v a 2 s.com } Context context = v.getContext(); popup = new PopupMenu(context, v); popup.inflate(R.menu.music_popup_menu); popup.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getItemId() == R.id.artistAblum) { mViewPager.setCurrentItem(ARTIST_INDEX); mCurrentTab = ARTIST_INDEX; } else if (item.getItemId() == R.id.ablum_list) { mViewPager.setCurrentItem(ALBUM_INDEX); mCurrentTab = ALBUM_INDEX; } else if (item.getItemId() == R.id.song_list) { mViewPager.setCurrentItem(SONG_INDEX); mCurrentTab = SONG_INDEX; } else if (item.getItemId() == R.id.playing_list) { mViewPager.setCurrentItem(PLAYLIST_INDEX); mCurrentTab = PLAYLIST_INDEX; } return false; } }); popup.show(); }
From source file:com.battlelancer.seriesguide.ui.ActivityFragment.java
@Override public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) { PopupMenu popupMenu = new PopupMenu(view.getContext(), view); Menu menu = popupMenu.getMenu(); Cursor episode = (Cursor) mAdapter.getItem(position); if (episode == null) { return false; }// www . j a v a 2 s . c o m // only display the action appropriate for the items current state menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin); if (EpisodeTools.isWatched(episode.getInt(ActivityQuery.WATCHED))) { menu.add(0, CONTEXT_FLAG_UNWATCHED_ID, 1, R.string.action_unwatched); } else { menu.add(0, CONTEXT_FLAG_WATCHED_ID, 1, R.string.action_watched); } if (EpisodeTools.isCollected(episode.getInt(ActivityQuery.COLLECTED))) { menu.add(0, CONTEXT_COLLECTION_REMOVE_ID, 2, R.string.action_collection_remove); } else { menu.add(0, CONTEXT_COLLECTION_ADD_ID, 2, R.string.action_collection_add); } final int showTvdbId = episode.getInt(ActivityQuery.SHOW_ID); final int episodeTvdbId = episode.getInt(ActivityQuery._ID); final int seasonNumber = episode.getInt(ActivityQuery.SEASON); final int episodeNumber = episode.getInt(ActivityQuery.NUMBER); popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case CONTEXT_CHECKIN_ID: { checkInEpisode((int) id); return true; } case CONTEXT_FLAG_WATCHED_ID: { updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true); return true; } case CONTEXT_FLAG_UNWATCHED_ID: { updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false); return true; } case CONTEXT_COLLECTION_ADD_ID: { updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true); return true; } case CONTEXT_COLLECTION_REMOVE_ID: { updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false); return true; } } return false; } }); popupMenu.show(); return true; }
From source file:org.messic.android.smartphone.activities.main.fragments.explore.ExploreFragment.java
@Override public void moreTouch(final MDMAlbum album, View anchor, int index) { // Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(ExploreFragment.this.getActivity(), anchor); // Inflating the Popup using xml file popup.getMenuInflater().inflate(R.menu.activity_explore_menu_album, popup.getMenu()); // registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.menu_album_item_play: presenter.playAction(album); break; case R.id.menu_album_item_playnow: presenter.longPlayAction(album); break; case R.id.menu_album_item_download: presenter.downloadAlbum(album); break; }// w w w. j a v a 2 s. c o m return true; } }); popup.show();// showing popup menu }
From source file:net.lp.actionbarpoirot.actions.UiAction.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) void addActionItemToLeftNavBar(C context) { if (UiUtilities.isGoogleTV(context.getApplicationContext())) { try {//from w ww . j a v a 2s . c o m final LeftNavBar leftNavBar = ((LeftNavBar) ((ActivityHelperHoneycomb) context.getActivityHelper()) .getActionBar()); final PopupMenu tempMenu = new PopupMenu(context, leftNavBar.getCustomView());// TODO: Should not use // MenuItem and // onCreateOptionsMenu, but // build an own stack of // methods for the // LeftNavBar. leftNavBar.addActionItem(onCreateOptionsMenu(tempMenu.getMenu(), context), this); } catch (ClassCastException ce) { if (PoirotWindow.DEBUG) Log.d(TAG, "ClassCastException with LeftNavBar", ce); } } }
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);// www . j a v 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.audiokernel.euphonyrmt.fragments.SongsFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.songs, container, false); mList = (AbsListView) view.findViewById(R.id.list); registerForContextMenu(mList);//from ww w . j a va 2 s. co m mList.setOnItemClickListener(this); mLoadingView = view.findViewById(R.id.loadingLayout); mLoadingTextView = (TextView) view.findViewById(R.id.loadingText); mNoResultView = view.findViewById(R.id.noResultLayout); mLoadingTextView.setText(getLoadingText()); final View headerView = inflater.inflate(R.layout.song_header, null, false); mCoverArt = (ImageView) view.findViewById(R.id.albumCover); if (mCoverArt != null) { mHeaderArtist = (TextView) view.findViewById(R.id.tracks_artist); mHeaderInfo = (TextView) view.findViewById(R.id.tracks_info); mCoverArtProgress = (ProgressBar) view.findViewById(R.id.albumCoverProgress); mAlbumMenu = (ImageButton) view.findViewById(R.id.album_menu); } else { mHeaderArtist = (TextView) headerView.findViewById(R.id.tracks_artist); mHeaderInfo = (TextView) headerView.findViewById(R.id.tracks_info); mCoverArt = (ImageView) headerView.findViewById(R.id.albumCover); mCoverArtProgress = (ProgressBar) headerView.findViewById(R.id.albumCoverProgress); mAlbumMenu = (ImageButton) headerView.findViewById(R.id.album_menu); } mCoverArtListener = new AlbumCoverDownloadListener(mCoverArt, mCoverArtProgress, false); mCoverHelper = new CoverAsyncHelper(); mCoverHelper.setCoverMaxSizeFromScreen(getActivity()); final ViewTreeObserver vto = mCoverArt.getViewTreeObserver(); vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { if (mCoverHelper != null) { mCoverHelper.setCachedCoverMaxSize(mCoverArt.getMeasuredHeight()); } return true; } }); mCoverHelper.addCoverDownloadListener(mCoverArtListener); ((TextView) headerView.findViewById(R.id.separator_title)).setText(R.string.songs); ((ListView) mList).addHeaderView(headerView, null, false); mPopupMenu = new PopupMenu(getActivity(), mAlbumMenu); mPopupMenu.getMenu().add(Menu.NONE, ADD, Menu.NONE, R.string.addAlbum); mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE, Menu.NONE, R.string.addAndReplace); mPopupMenu.getMenu().add(Menu.NONE, ADD_REPLACE_PLAY, Menu.NONE, R.string.addAndReplacePlay); mPopupMenu.getMenu().add(Menu.NONE, ADD_PLAY, Menu.NONE, R.string.addAndPlay); mPopupMenu.getMenu().add(Menu.NONE, GOTO_ARTIST, Menu.NONE, R.string.goToArtist); mPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { final int itemId = item.getItemId(); if (itemId == GOTO_ARTIST) { final Intent intent = new Intent(getActivity(), SimpleLibraryActivity.class); intent.putExtra("artist", mAlbum.getArtist()); startActivityForResult(intent, -1); } else { mApp.oMPDAsyncHelper.execAsync(new Runnable() { @Override public void run() { boolean replace = false; boolean play = false; switch (itemId) { case ADD_REPLACE_PLAY: replace = true; play = true; break; case ADD_REPLACE: replace = true; break; case ADD_PLAY: play = true; break; default: break; } try { mApp.oMPDAsyncHelper.oMPD.add(mAlbum, replace, play); Tools.notifyUser(R.string.albumAdded, mAlbum); } catch (final IOException | MPDException e) { Log.e(TAG, "Failed to add, replace, play.", e); } } }); } return true; } }); mAlbumMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(mPopupMenu)); mAlbumMenu.setOnClickListener(new OnClickListener() { @Override public void onClick(final View v) { mPopupMenu.show(); } }); mCoverPopupMenu = new PopupMenu(getActivity(), mCoverArt); mCoverPopupMenu.getMenu().add(POPUP_COVER_BLACKLIST, POPUP_COVER_BLACKLIST, 0, R.string.otherCover); mCoverPopupMenu.getMenu().add(POPUP_COVER_SELECTIVE_CLEAN, POPUP_COVER_SELECTIVE_CLEAN, 0, R.string.resetCover); mCoverPopupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(final MenuItem item) { final int groupId = item.getGroupId(); boolean result = true; if (groupId == POPUP_COVER_BLACKLIST) { final AlbumInfo albumInfo = new AlbumInfo(mAlbum); CoverManager.getInstance().markWrongCover(albumInfo); updateCover(albumInfo); updateNowPlayingSmallFragment(albumInfo); } else if (groupId == POPUP_COVER_SELECTIVE_CLEAN) { final AlbumInfo albumInfo = new AlbumInfo(mAlbum); CoverManager.getInstance().clear(albumInfo); updateCover(albumInfo); updateNowPlayingSmallFragment(albumInfo); } else { result = false; } return result; } }); mCoverArt.setOnLongClickListener(new View.OnLongClickListener() { @Override public boolean onLongClick(final View v) { mCoverPopupMenu.show(); return false; } }); updateFromItems(); return view; }
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 .c o m 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; }