protected void showPopup(final Experiment experiment, View v) { PopupMenu popup = new PopupMenu(MyExperimentsActivity.this, v); final Menu menu = popup.getMenu(); popup.getMenuInflater().inflate(R.menu.experiment_popup, menu); if (!userCanEditAtLeastOneSchedule(experiment)) { menu.removeItem(R.id.editSchedule); } popup.show(); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.editSchedule: launchScheduleDetailScreen(experiment); break; case R.id.emailResearcher: emailResearcher(experiment); break; case R.id.stopExperiment: deleteExperiment(experiment); break; default: break; } return true; } }); }
private void showFilterPopup(View v) { PopupMenu popup = new PopupMenu(getContext(), v); // Inflate the menu from xml popup.getMenuInflater().inflate(R.menu.popup_filter, popup.getMenu()); // Setup menu item selection popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.profile: Intent intent = new Intent(getContext(), MyProfile.class); startActivity(intent); return true; case R.id.logout: Toast.makeText(getContext(), "LogOut", Toast.LENGTH_SHORT).show(); return true; default: return false; } } }); // Handle dismissal with: popup.setOnDismissListener(...); // Show the menu popup.show(); }
@Override public void itemClicked(View v, final int position) { clickedPosition = position; if (v instanceof RelativeLayout) { String videoUrl = videoList.get(position).player; UrlHelper.playVideo(getActivity(), videoUrl); } else if (v instanceof ImageButton) { PopupMenu popupMenu = new PopupMenu(getActivity(), v); if (isMy) { popupMenu.inflate(R.menu.popup_menu_my_video); } else { popupMenu.inflate(R.menu.popup_menu_video); } popupMenu.setOnMenuItemClickListener( item -> { switch (item.getItemId()) { case R.id.add: AdditionRequests.addVideo(getActivity(), videoList.get(position)); return true; case R.id.add_to_album: AdditionRequests.addVideoToAlbum(getFragmentManager(), videoList.get(position)); return true; case R.id.delete: showDeleteDialog(); return true; default: return false; } }); popupMenu.show(); } }
private void showMorePopup( View v, final GithubComment comment, final boolean canEdit, final boolean canDelete) { PopupMenu menu = new PopupMenu(context, v); menu.inflate(R.menu.comment_popup); menu.getMenu().findItem(R.id.m_edit).setEnabled(canEdit); menu.getMenu().findItem(R.id.m_delete).setEnabled(canDelete); menu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.m_edit: if (editCommentListener != null) { editCommentListener.onEditComment(comment); } break; case R.id.m_delete: if (deleteCommentListener != null) { deleteCommentListener.onDeleteComment(comment); } break; } return false; } }); menu.show(); }
@Override public void onClick(View v) { if ((v.getId() == editProfileImageText.getId()) || (v.getId() == profileImage.getId())) { popupMenu = new PopupMenu(getActivity(), v); popupMenu .getMenuInflater() .inflate(R.menu.edit_profile_edit_picture_dropdown, popupMenu.getMenu()); popupMenu.setOnMenuItemClickListener( new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.getTitle().toString().equalsIgnoreCase("From Camera")) { /* TODO */ } else if (item.getTitle().toString().equalsIgnoreCase("From Gallery")) { /* TODO */ } popupMenu.dismiss(); return true; } }); popupMenu.show(); } else if (v.getId() == submitButton.getId()) { if (IsValid()) { PostToServer(); } } }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.instanceMore: final PopupMenu menu = new PopupMenu(context, v, Gravity.END); String[] options = context.getResources().getStringArray(R.array.queue_options_playlist); for (int i = 0; i < options.length; i++) { menu.getMenu().add(Menu.NONE, i, i, options[i]); } menu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case 0: // Queue this playlist next PlayerController.queueNext(Library.getPlaylistEntries(context, reference)); return true; case 1: // Queue this playlist last PlayerController.queueLast(Library.getPlaylistEntries(context, reference)); return true; case 2: // Delete this playlist Library.removePlaylist(itemView, reference); return true; } return false; } }); menu.show(); break; default: Navigate.to(context, PlaylistActivity.class, PlaylistActivity.PLAYLIST_EXTRA, reference); break; } }
public void setSubmenuOptions(String[] s) { popup = new PopupMenu(MainActivity.this, submenu_button); for (int i = 0; i < s.length; i++) { popup.getMenu().add(Menu.NONE, i, i, s[i]); } popup.getMenuInflater().inflate(R.menu.submenu, popup.getMenu()); }
public void showMenu(View v) { PopupMenu popup = new PopupMenu(getActivity(), v); // This activity implements OnMenuItemClickListener popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { return false; } }); popup.inflate(R.menu.share_menu); popup.show(); }
@Override public void onClick(final DialogInterface dialog, final int which) { final ParcelableStatus status = getStatus(); if (status == null) return; switch (which) { case DialogInterface.BUTTON_POSITIVE: { final AsyncTwitterWrapper twitter = mTwitterWrapper; if (twitter == null) return; retweetOrQuote(twitter, status); break; } case DialogInterface.BUTTON_NEUTRAL: { final Intent intent = new Intent(INTENT_ACTION_QUOTE); final Menu menu = mPopupMenu.getMenu(); final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status); intent.putExtra(EXTRA_STATUS, status); intent.putExtra(EXTRA_QUOTE_ORIGINAL_STATUS, quoteOriginalStatus.isChecked()); startActivity(intent); break; } default: break; } }
private void retweetOrQuote(AsyncTwitterWrapper twitter, ParcelableStatus status) { final Dialog dialog = getDialog(); if (dialog == null) return; final EditText editComment = ((EditText) dialog.findViewById(R.id.edit_comment)); if (editComment.length() > 0) { final Menu menu = mPopupMenu.getMenu(); final MenuItem quoteOriginalStatus = menu.findItem(R.id.quote_original_status); final MenuItem linkToQuotedStatus = menu.findItem(R.id.link_to_quoted_status); final Uri statusLink; final long inReplyToStatusId; if (!status.is_quote || !quoteOriginalStatus.isChecked()) { inReplyToStatusId = status.id; statusLink = LinkCreator.getTwitterStatusLink(status.user_screen_name, status.id); } else { inReplyToStatusId = status.quoted_id; statusLink = LinkCreator.getTwitterStatusLink(status.quoted_user_screen_name, status.quoted_id); } final String commentText = editComment.getText() + " " + statusLink; twitter.updateStatusAsync( new long[] {status.account_id}, commentText, null, null, linkToQuotedStatus.isChecked() ? inReplyToStatusId : -1, status.is_possibly_sensitive); } else if (isMyRetweet(status)) { twitter.cancelRetweetAsync(status.account_id, status.id, status.my_retweet_id); } else { twitter.retweetStatusAsync(status.account_id, status.id); } }
@Override public void call(final Subscriber<? super MenuItem> subscriber) { verifyMainThread(); PopupMenu.OnMenuItemClickListener listener = new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (!subscriber.isUnsubscribed()) { subscriber.onNext(item); } return true; } }; view.setOnMenuItemClickListener(listener); subscriber.add( new MainThreadSubscription() { @Override protected void onUnsubscribe() { view.setOnMenuItemClickListener(null); } }); }
private void FadingOutOtherItems(PopupMenu popupMenu) { // Dim out all the other list items if they exist LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) { if (i == mHolder.getLayoutPosition()) continue; RecyclerViewHolder viewHolder = (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i); View itemView = viewHolder.getItemView(); itemView.clearAnimation(); itemView.startAnimation(mFadeOut); } // Make sure to bring them back to normal after the menu is gone popupMenu.setOnDismissListener( new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu popupMenu) { LinearLayoutManager layoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager(); int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); for (int i = firstVisibleItemPosition; i <= lastVisibleItemPosition; i++) { if (i == mHolder.getLayoutPosition()) continue; RecyclerViewHolder viewHolder = (RecyclerViewHolder) mRecyclerView.findViewHolderForLayoutPosition(i); View itemView = viewHolder.getItemView(); viewHolder.getLayoutPosition(); itemView.clearAnimation(); itemView.startAnimation(mFadeIn); } } }); }
@Override public void onClick(View v) { switch (v.getId()) { case R.id.instanceMore: final PopupMenu menu = new PopupMenu(context, v, Gravity.END); String[] options = context.getResources().getStringArray(R.array.queue_options_genre); for (int i = 0; i < options.length; i++) { menu.getMenu().add(Menu.NONE, i, i, options[i]); } menu.setOnMenuItemClickListener(this); menu.show(); break; default: Navigate.to(context, GenreActivity.class, GenreActivity.GENRE_EXTRA, reference); break; } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.camera_list); mLayoutInflater = LayoutInflater.from(this); mCameraListView = (ListView) findViewById(R.id.cameraList); TextView titleView = (TextView) findViewById(R.id.title); titleView.setText(R.string.app_name); mMenuView = (ImageView) findViewById(R.id.menu); mMenuView.setVisibility(View.VISIBLE); mMenuView.setOnClickListener(this); mMenu = new PopupMenu(this, mMenuView); MenuInflater inflater = mMenu.getMenuInflater(); inflater.inflate(R.menu.popup_menu, mMenu.getMenu()); mMenu.setOnMenuItemClickListener(this); mViewer = Viewer.getViewer(); mMyViewerHelper = MyViewerHelper.getInstance(getApplicationContext()); mMyViewerHelper.addCameraStateListener(this); mCameraDefaulThumb = BitmapFactory.decodeResource(getResources(), R.drawable.avs_type_android); mCameraInfoManager = new CameraInfoManager(this); mCameraInfos = mMyViewerHelper.getAllCameraInfos(); for (CameraInfo info : mCameraInfos) { addStreamer(info.getCid(), info.getCameraUser(), info.getCameraPwd()); } mCameraListAdapter = new CameraListAdapter(this, mCameraInfos); mCameraListView.setAdapter(mCameraListAdapter); mCameraListView.setOnItemClickListener(this); mShowChinese = "zh".equals(Locale.getDefault().getLanguage().toLowerCase()); // update UmengUpdateAgent.setUpdateOnlyWifi(false); UmengUpdateAgent.update(this); // admob ad RelativeLayout adContainer = (RelativeLayout) findViewById(R.id.adLayout); AdView ad = new AdView(this, AdSize.BANNER, AD_UNIT_ID); // .addTestDevice("703C305FC29B7ED91BD7625874CFDEBC") ad.loadAd(new AdRequest()); adContainer.addView(ad); }
@Override public void onClick(View v) { int id = v.getId(); switch (id) { case R.id.menu: mMenu.show(); break; default: break; } }
private void setTopicBarListView() { if (mPopup == null) { mPopup = new PopupMenu(getActivity(), viewMenu); } Menu menu = mPopup.getMenu(); if (mTopicBarList == null) return; for (int i = 0; i < mTopicBarList.size(); ++i) { TopicBarList.TopicbarsEntity tBar = mTopicBarList.get(i); menu.add(0, i, Menu.NONE, tBar.getTopicbarname()); } onFilterTpByBarID(0); }
public void showPopUp(View v, Todo todo, int position) { PopupMenu popup = new PopupMenu(mContext, v); popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { case R.id.remove_todo: listener.onDeleteClick(todo, position); return true; case R.id.share_todo: listener.onShareClick(todo); return true; default: return false; } } }); popup.inflate(R.menu.menu_popup_todo); popup.show(); }
@Override public void onClick(View v) { if (v == playPauseButton) { PlayerController.togglePlay(); } else if (v == skipPrevButton) { PlayerController.previous(); } else if (v == skipNextButton) { PlayerController.skip(); } else if (v == moreInfoButton) { // Song info final Song nowPlaying = PlayerController.getNowPlaying(); if (nowPlaying != null) { final PopupMenu menu = new PopupMenu(getContext(), v, Gravity.END); String[] options = getResources().getStringArray(R.array.now_playing_options); for (int i = 0; i < options.length; i++) { menu.getMenu().add(Menu.NONE, i, i, options[i]); } menu.setOnMenuItemClickListener(this); menu.show(); } } }
@Override public void onClick(View v) { if (v.getId() == R.id.chat_send && keyboard.getText().toString().length() != 0) { Calendar cal = new GregorianCalendar(); Date date = cal.getTime(); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy"); String dateFormat = df.format(date); boolean isGroup = false; Message message = new Message(keyboard.getText().toString(), dateFormat, true, toID, toID, isGroup); messages.add(message); sendMessage(message.getText()); showMessage(message); } else { popupMenu.show(); } }
private static void showPopupMenu(final View v, final Object context) { if (ActivityFactory.getMainActivity().getCurrentUser() == null) return; id_menu = (int) context; PopupMenu popupMenu = new PopupMenu(v.getContext(), v); popupMenu.inflate(R.menu.menu_item); if (ActivityFactory.getMainActivity().getCurrentUser().getPost() == IUser.Posts.Адміністратар) popupMenu.getMenu().setGroupVisible(R.id.group_admin, true); else { // TODO:change admin menu } popupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { IItem iItem = ActivityFactory.getMainActivity().getItem(id_menu); IUser iUser = ActivityFactory.getMainActivity().getCurrentUser(); switch (item.getItemId()) { case R.id.menu_item_change: { if (iItem.getUserId() == iUser.getId()) { Bundle args = new Bundle(); args.putInt(IItem.ITEM_PARAM, (int) v.getTag()); ActivityFactory.getMainActivity() .openFragment(iMainActivity.Fragments.ItemAdd, true, args); } return true; } case R.id.menu_item_user_set: { Bundle args = new Bundle(); args.putInt(IItem.ITEM_PARAM, iItem.getId()); ActivityFactory.getMainActivity() .openFragment(iMainActivity.Fragments.Users, true, args); return true; } case R.id.menu_item_status_set: { ActivityFactory.getMainActivity().setTempItem(iItem); ActivityFactory.getMainActivity() .openFragment(iMainActivity.Fragments.Status, true); return true; } default: return false; } } }); popupMenu.setOnDismissListener( new PopupMenu.OnDismissListener() { @Override public void onDismiss(PopupMenu menu) {} }); popupMenu.show(); }
protected void contextMenu( View v, final IndexItem indexItem, final DownloadResourceGroup parentOptional) { final PopupMenu optionsMenu = new PopupMenu(context, v); MenuItem item; final File fl = indexItem.getTargetFile(context.getMyApplication()); if (fl.exists()) { item = optionsMenu .getMenu() .add(R.string.shared_string_remove) .setIcon( context .getMyApplication() .getIconsCache() .getThemedIcon(R.drawable.ic_action_remove_dark)); item.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { LocalIndexType tp = LocalIndexType.MAP_DATA; if (indexItem.getType() == DownloadActivityType.HILLSHADE_FILE) { tp = LocalIndexType.TILES_DATA; } else if (indexItem.getType() == DownloadActivityType.ROADS_FILE) { tp = LocalIndexType.MAP_DATA; } else if (indexItem.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) { tp = LocalIndexType.SRTM_DATA; } else if (indexItem.getType() == DownloadActivityType.WIKIPEDIA_FILE) { tp = LocalIndexType.MAP_DATA; } else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) { tp = indexItem.getBasename().contains("tts") ? LocalIndexType.TTS_VOICE_DATA : LocalIndexType.VOICE_DATA; } final LocalIndexInfo info = new LocalIndexInfo(tp, fl, false, context.getMyApplication()); AlertDialog.Builder confirm = new AlertDialog.Builder(context); confirm.setPositiveButton( R.string.shared_string_yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { new LocalIndexOperationTask( context, null, LocalIndexOperationTask.DELETE_OPERATION) .execute(info); } }); confirm.setNegativeButton(R.string.shared_string_no, null); String fn = FileNameTranslationHelper.getFileName( context, context.getMyApplication().getRegions(), indexItem.getVisibleName(context, context.getMyApplication().getRegions())); confirm.setMessage(context.getString(R.string.delete_confirmation_msg, fn)); confirm.show(); return true; } }); } item = optionsMenu .getMenu() .add(R.string.shared_string_download) .setIcon( context .getMyApplication() .getIconsCache() .getThemedIcon(R.drawable.ic_action_import)); item.setOnMenuItemClickListener( new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { download(indexItem, parentOptional); return true; } }); optionsMenu.show(); }
protected void initialize(Context context, AttributeSet attrs) { View view = View.inflate(context, R.layout.view_calculator_output, this); mViewHolder = new ViewHolder(view); mViewHolder.textViewTransactionDate.setVisibility(View.GONE); mViewHolder.textViewCalculatorPrice.setText(""); mViewHolder.textViewCalculatorProductName.setText(""); mViewHolder.textViewCurrencyCode.setText(PreferenceHelper.DEFAULT_CURRENCY_CODE); mViewHolder.textViewIncomingOrOutgoing.setText(""); mViewHolder.textViewCurrencyCode.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { FragmentActivity activity = (FragmentActivity) getContext(); final ChooseCurrencyFragment fragment = ChooseCurrencyFragment.newInstance(getCurrencyCode()); fragment.setOnFragmentDialogDismissListener( new OnFragmentDialogDismissListener<String>() { @Override public void onFragmentDialogDismiss(String result) { setCurrencyCode(result); ConfigurationManager.changeDefaultCurrencyCode(getContext(), result); } }); fragment.show(activity.getSupportFragmentManager(), ChooseCurrencyFragment.TAG); } }); mViewHolder.textViewTransactionDate.setOnClickListener( new OnClickListener() { @Override public void onClick(View view) { EventBus.getDefault().post(new ShowDatePickerEvent(mCalculatorOutputInfo.date)); } }); mPopupMenu = new PopupMenu(getContext(), mViewHolder.textViewCalculatorProductName); mPopupMenu.getMenuInflater().inflate(R.menu.menu_product_name, mPopupMenu.getMenu()); mPopupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (mCalculatorOutputInfo.product == null) { return true; } switch (item.getItemId()) { case R.id.menu_rename_product: AppCompatActivity activity = (AppCompatActivity) getContext(); ProductRenameDialog.showDialog( getContext(), activity.getSupportFragmentManager(), mCalculatorOutputInfo.product); return true; case R.id.menu_remove_product: DialogHelper.showConfirmDialog( getContext(), getContext().getString(R.string.confirm_remove_product), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { long productId = mCalculatorOutputInfo.product.getId(); removeProductAsync(productId); } }); return true; default: return false; } } }); mViewHolder.textViewCalculatorProductName.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { String text = ((TextView) mViewHolder.textViewCalculatorProductName.getCurrentView()) .getText() .toString(); if (TextUtils.isEmpty(text)) { return; } if (mPopupMenu != null) { mPopupMenu.show(); } } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); mGoogleApiClient = new GoogleApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); locationRequest = LocationRequest.create() .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) .setInterval(20000) .setFastestInterval(10000); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); toID = getIntent().getExtras().getInt("toID"); user = User.getInstance(); friend = user.getFriendsHashMap().get(String.valueOf(toID)); popupMenu = new PopupMenu(this, toolbar, Gravity.RIGHT); popupMenu.setOnMenuItemClickListener(this); popupMenu.inflate(R.menu.popup); ImageButton sendButton = (ImageButton) findViewById(R.id.chat_send); keyboard = (EditText) findViewById(R.id.chat_keyboard); scrollView = (ScrollView) findViewById(R.id.chat_scroll); messagesLayout = (LinearLayout) findViewById(R.id.chat_messages); userImage = (ImageView) findViewById(R.id.chat_user_image); userName = (TextView) findViewById(R.id.chat_user_name); ImageButton attachButton = (ImageButton) findViewById(R.id.chat_attach); sendButton.setOnClickListener(this); attachButton.setOnClickListener(this); changeToolBar(); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String alarms = preferences.getString("message-notification-sound", "default ringtone"); Uri uri = Uri.parse(alarms); ringtone = RingtoneManager.getRingtone(this, uri); if (!isStarted) { messages = new MessageList(); LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(); isStarted = true; service = new Service(); try { queue.put(service); } catch (InterruptedException e) { e.printStackTrace(); } PausableThreadPool executor = new PausableThreadPool(2, 2, 10, TimeUnit.SECONDS, queue); executor.execute(service); threadReceiver = new Thread(Receiver); threadReceiver.start(); } else { while (threadReceiver.isAlive()) { threadReceiver.interrupt(); } threadReceiver = new Thread(Receiver); threadReceiver.start(); } loadDBMessages(); try { scrollView.post( new Runnable() { @Override public void run() { scrollView.fullScroll(View.FOCUS_DOWN); } }); } catch (Exception e) { e.printStackTrace(); } loadImage(); }
@NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { final Context wrapped = ThemeUtils.getDialogThemedContext(getActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(wrapped); final Context context = builder.getContext(); mValidator = new TwidereValidator(context); final LayoutInflater inflater = LayoutInflater.from(context); @SuppressLint("InflateParams") final View view = inflater.inflate(R.layout.dialog_status_quote_retweet, null); final DummyStatusHolderAdapter adapter = new DummyStatusHolderAdapter(context); adapter.setShouldShowAccountsColor(true); final IStatusViewHolder holder = new StatusViewHolder(adapter, view.findViewById(R.id.item_content)); final ParcelableStatus status = getStatus(); assert status != null; builder.setView(view); builder.setTitle(R.string.retweet_quote_confirm_title); if (isMyRetweet(status)) { builder.setPositiveButton(R.string.cancel_retweet, this); } else if (!status.user_is_protected) { builder.setPositiveButton(R.string.retweet, this); } builder.setNeutralButton(R.string.quote, this); builder.setNegativeButton(android.R.string.cancel, null); holder.displayStatus(status, null, false, true); view.findViewById(R.id.item_menu).setVisibility(View.GONE); view.findViewById(R.id.action_buttons).setVisibility(View.GONE); view.findViewById(R.id.item_content).setFocusable(false); view.findViewById(R.id.comment_container) .setVisibility(status.user_is_protected ? View.GONE : View.VISIBLE); final ComposeMaterialEditText mEditComment = (ComposeMaterialEditText) view.findViewById(R.id.edit_comment); mEditComment.setAccountId(status.account_id); final boolean sendByEnter = mPreferences.getBoolean(KEY_QUICK_SEND); final EditTextEnterHandler enterHandler = EditTextEnterHandler.attach( mEditComment, new EditTextEnterHandler.EnterListener() { @Override public boolean shouldCallListener() { return true; } @Override public boolean onHitEnter() { final AsyncTwitterWrapper twitter = mTwitterWrapper; final ParcelableStatus status = getStatus(); if (twitter == null || status == null) return false; retweetOrQuote(twitter, status); dismiss(); return true; } }, sendByEnter); enterHandler.addTextChangedListener( new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void onTextChanged(CharSequence s, int start, int before, int count) { updateTextCount(getDialog(), s, status); } @Override public void afterTextChanged(Editable s) {} }); final View commentMenu = view.findViewById(R.id.comment_menu); mPopupMenu = new PopupMenu(context, commentMenu, Gravity.NO_GRAVITY, R.attr.actionOverflowMenuStyle, 0); commentMenu.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { mPopupMenu.show(); } }); commentMenu.setOnTouchListener(mPopupMenu.getDragToOpenListener()); mPopupMenu.inflate(R.menu.menu_dialog_comment); final Menu menu = mPopupMenu.getMenu(); MenuUtils.setMenuItemAvailability( menu, R.id.quote_original_status, status.retweet_id > 0 || status.quoted_id > 0); mPopupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { if (item.isCheckable()) { item.setChecked(!item.isChecked()); return true; } return false; } }); final Dialog dialog = builder.create(); dialog.setOnShowListener( new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialog) { updateTextCount(dialog, mEditComment.getText(), status); } }); return dialog; }
@Override public void onClick(View v) { if (v.getId() == tv_fullname.getId() || v.getId() == tv_username.getId()) { // GOTO PROFILE WHEN NAME OR USERNAME IS CLICKED Intent i = new Intent(context, ProfileActivity.class); i.putExtra("UserId", userId); context.startActivity(i); } else if (v.getId() == R.id.pt_commentBtn) { Intent i = new Intent(context, CommentActivity.class); i.putExtra("PostId", postId); i.putExtra("FullName", tv_fullname.getText().toString()); i.putExtra("isOwned", owned); context.startActivity(i); ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2); } else if (v.getId() == R.id.pt_shareBtn) { Intent i = new Intent(context, ShareActivity.class); if (share_postId.equals("")) i.putExtra("PostId", postId); else i.putExtra("PostId", share_postId); i.putExtra("OwnerId", schoolId); context.startActivity(i); ((Activity) context).overridePendingTransition(R.animator.animate3, R.animator.animate2); } else if (v.getId() == upvote.getId()) { upvote.setVisibility(View.INVISIBLE); upvote2.setVisibility(View.VISIBLE); Intent intent = new Intent(context, UpvoteService.class); intent.putExtra("userId", schoolId); intent.putExtra("postId", postId); context.startService(intent); } else if (v.getId() == upvote2.getId()) { upvote2.setVisibility(View.INVISIBLE); upvote.setVisibility(View.VISIBLE); Intent intent = new Intent(context, UpvoteService.class); intent.putExtra("userId", schoolId); intent.putExtra("postId", postId); context.startService(intent); } else if (v.getId() == options.getId()) { // Creating the instance of PopupMenu PopupMenu popup = new PopupMenu(context, options); // Inflating the Popup using xml file if (owned) { popup.getMenuInflater().inflate(R.menu.menu_options, popup.getMenu()); } else { popup.getMenuInflater().inflate(R.menu.menu_options2, popup.getMenu()); } // registering popup with OnMenuItemClickListener popup.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { if (item.getTitle().equals("Report")) { Intent i = new Intent(context, ReportActivity.class); i.putExtra("PostId", postId); i.putExtra("ReporterId", schoolId); i.putExtra("ReferenceTable", "post"); context.startActivity(i); } else if (item.getTitle().equals("Edit")) { Intent i = new Intent(context, EditPostActivity.class); i.putExtra("PostId", postId); context.startActivity(i); } else { Intent i = new Intent(context, DeleteService.class); i.putExtra("PostId", postId); i.putExtra("Action", "post"); context.startService(i); } return true; } }); popup.show(); // showing popup menu } else if (v.getId() == fileCV.getId()) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(fileUrl)); context.startActivity(browserIntent); } else if (v.getId() == share_file_name.getId()) { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(shareFileUrl)); context.startActivity(browserIntent); } else { // GOTO VIEW POST Intent i = new Intent(context, PostViewActivity.class); i.putExtra("PostId", postId); context.startActivity(i); } }
@SuppressLint("LongLogTag") @Override public void onClick(View v) { // This is an android.support.v7.widget.PopupMenu; PopupMenu popupMenu = new PopupMenu(mContext, v) { @Override public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) { switch (item.getItemId()) { case R.id.popup_delete: // deleteAlbum(mAlbum); Toast.makeText(mContext, "you click delete", Toast.LENGTH_SHORT).show(); return true; case R.id.popup_rename: // renameAlbum(mAlbum); Toast.makeText(mContext, "you click rename", Toast.LENGTH_SHORT).show(); return true; case R.id.popup_lock: // lockAlbum(mAlbum); Toast.makeText(mContext, "you click lock", Toast.LENGTH_SHORT).show(); return true; case R.id.popup_unlock: // unlockAlbum(mAlbum); Toast.makeText(mContext, "you click unlock", Toast.LENGTH_SHORT).show(); return true; case R.id.popup_set_cover: // setAlbumCover(mAlbum); Toast.makeText(mContext, "you click set cover", Toast.LENGTH_SHORT).show(); return true; default: return super.onMenuItemSelected(menu, item); } } }; popupMenu.inflate(R.menu.popup_menu); // if (mAlbum.isLocked()) { // popupMenu.getMenu().removeItem(R.id.album_overflow_lock); // popupMenu.getMenu().removeItem(R.id.album_overflow_rename); // popupMenu.getMenu().removeItem(R.id.album_overflow_delete); // } else { // popupMenu.getMenu().removeItem(R.id.album_overflow_unlock); // } // Force icons to show Object menuHelper; Class[] argTypes; try { // PopupMenu有一个私有变量mPopup,类型是MenuPopupHelper,有一个方法setForceShowIcon,用于显示icon Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); fMenuHelper.setAccessible(true); menuHelper = fMenuHelper.get(popupMenu); argTypes = new Class[] {boolean.class}; menuHelper .getClass() .getDeclaredMethod("setForceShowIcon", argTypes) .invoke(menuHelper, true); } catch (Exception e) { // Possible exceptions are NoSuchMethodError and NoSuchFieldError // // In either case, an exception indicates something is wrong with the reflection code, or the // structure of the PopupMenu class or its dependencies has changed. // // These exceptions should never happen since we're shipping the AppCompat library in our own // apk, // but in the case that they do, we simply can't force icons to display, so log the error and // show the menu normally. Log.w(TAG, "error forcing menu icons to show", e); popupMenu.show(); return; } popupMenu.show(); // 调整popupMenu的位置偏移量 try { Field fListPopup = menuHelper.getClass().getDeclaredField("mPopup"); fListPopup.setAccessible(true); Object listPopup = fListPopup.get(menuHelper); argTypes = new Class[] {int.class}; Class listPopupClass = listPopup.getClass(); // Get the width of the popup window int width = (Integer) listPopupClass.getDeclaredMethod("getWidth").invoke(listPopup); // Invoke setHorizontalOffset() with the negative width to move left by that distance listPopupClass .getDeclaredMethod("setHorizontalOffset", argTypes) .invoke(listPopup, -width + 100); // Invoke show() to update the window's position listPopupClass.getDeclaredMethod("show").invoke(listPopup); } catch (Exception e) { // Again, an exception here indicates a programming error rather than an exceptional condition // at runtime Log.w(TAG, "Unable to force offset", e); } FadingOutOtherItems(popupMenu); }