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

The following examples show how to use android.support.v7.widget.PopupMenu#inflate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostViewActivity.java    From quill with MIT License 6 votes vote down vote up
@Override
public void onClick(View view) {
    if (view.getId() == R.id.post_image_edit_layout) {
        PopupMenu popupMenu = new PopupMenu(this, mPostImageLayoutManager.getRootLayout());
        popupMenu.inflate(R.menu.insert_image);
        if (TextUtils.isEmpty(mPost.getFeatureImage())) {
            MenuItem removeImageItem = popupMenu.getMenu().findItem(R.id.action_image_remove);
            removeImageItem.setVisible(false);
        }
        popupMenu.setOnMenuItemClickListener(item -> {
            if (item.getItemId() == R.id.action_insert_image_url) {
                mPostEditFragment.onInsertImageUrlClicked(getInsertImageDoneAction());
            } else if (item.getItemId() == R.id.action_insert_image_upload) {
                mPostEditFragment.onInsertImageUploadClicked(getInsertImageDoneAction());
            } else if (item.getItemId() == R.id.action_image_remove) {
                getInsertImageDoneAction().call("");
            }
            return true;
        });
        popupMenu.show();
    }
}
 
Example 2
Source File: MoverRecycleFragment.java    From Mover with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onItemLongClick(RecyclerView parent, View view, int position, long id) {

    int viewType = mWatchMeAdapter.getItemViewType(position);

    switch (viewType){
        case WatchMeAdapterNew.TYPE_HEADER_FIRST:
            getJobManager().addJob(new FetchAvailableVideoQualities("p3xpwfHm"));
            return true;

        case WatchMeAdapterNew.TYPE_VIDEO:
        case WatchMeAdapterNew.TYPE_VIDEO_LAST:

            mSelectedVideoPosition = position;

            PopupMenu popupMenu = new PopupMenu(view.getContext(), view, Gravity.TOP);
            popupMenu.setOnMenuItemClickListener(mOnMenuItemClickListener);
            popupMenu.inflate(R.menu.video_item_menu);
            popupMenu.show();
            return true;
    }

    return false;
}
 
Example 3
Source File: CategoriesFragment.java    From OmniList with GNU Affero General Public License v3.0 6 votes vote down vote up
private void popCategoryMenu(View v, int position, Category category) {
    PopupMenu popupM = new PopupMenu(getContext(), v);
    popupM.inflate(R.menu.category_pop_menu);
    configPopMenu(popupM);
    popupM.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
            case R.id.action_archive:
                update(category, status, Status.ARCHIVED);
                break;
            case R.id.action_trash:
                update(category, status, Status.TRASHED);
                break;
            case R.id.action_move_out:
                update(category, status, Status.NORMAL);
                break;
            case R.id.action_edit:
                showEditor(position, mAdapter.getItem(position));
                break;
            case R.id.action_delete:
                showDeleteDialog(position, mAdapter.getItem(position));
                break;
        }
        return true;
    });
    popupM.show();
}
 
Example 4
Source File: ConnectionAdapter.java    From EMQ-Android-Toolkit with Apache License 2.0 6 votes vote down vote up
private void showMenu(View v, final int position, final Connection connection) {
    final PopupMenu popupMenu = new PopupMenu(mContext, v);
    popupMenu.inflate(R.menu.menu_connection_item);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_edit:
                    ConnectionActivity.openActivity(mContext, connection);

                    return true;
                case R.id.action_delete:
                    MQTTManager.getInstance().removeClient(connection.getId());
                    RealmHelper.getInstance().deleteTopic(Subscription.class,connection.getId());
                    RealmHelper.getInstance().delete(connection);
                    notifyItemRemoved(position);
                    notifyItemRangeChanged(position, getItemCount());
                    return true;
                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 5
Source File: BookCardEventsCallback.java    From IslamicLibraryAndroid with GNU General Public License v3.0 6 votes vote down vote up
public void onMoreButtonClicked(@NonNull final BookInfo bookInfo, @NonNull View v) {
    PopupMenu popup = new PopupMenu(context, v);
    popup.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
            case R.id.book_overflow_delete_book:
                DialogFragment confirmBatchDownloadDialogFragment = new ConfirmBookDeleteDialogFragment();

                Bundle confirmDeleteDialogFragmentBundle = new Bundle();
                confirmDeleteDialogFragmentBundle.putInt(ConfirmBookDeleteDialogFragment.KEY_NUMBER_OF_BOOKS_TO_DELETE, 1);
                confirmDeleteDialogFragmentBundle.putInt(BooksInformationDBContract.BookInformationEntery.COLUMN_NAME_ID, bookInfo.getBookId());
                confirmDeleteDialogFragmentBundle.putString(BooksInformationDBContract.BookInformationEntery.COLUMN_NAME_TITLE, bookInfo.getName());

                confirmBatchDownloadDialogFragment.setArguments(confirmDeleteDialogFragmentBundle);
                confirmBatchDownloadDialogFragment.show(context.getSupportFragmentManager(), "ConfirmBookDeleteDialogFragment");
                return true;
            default:
                return false;
        }
    });
    popup.inflate(R.menu.book_card_overflow);
    if (bookInfo.getDownloadStatus() < DownloadsConstants.STATUS_DOWNLOAD_COMPLETED) {
        popup.getMenu().removeItem(R.id.book_overflow_delete_book);
    }
    popup.show();
}
 
Example 6
Source File: PopupMenuActivity.java    From MaterialDesignDemo with MIT License 6 votes vote down vote up
public void showPopupMenu(View view) throws NoSuchFieldException, IllegalAccessException {
    PopupMenu popupMenu = new PopupMenu(this, view);
    //设置 PopupMenu 的显示菜单项
    popupMenu.inflate(R.menu.main);
    // popupMenu.getMenuInflater().inflate(R.menu.main, popupMenu.getMenu());//与一行没什么区别
    //默认 PopupMenu 不显示条目icon,可以通过反射来强制使其显示icon
    Field field = popupMenu.getClass().getDeclaredField("mPopup");
    field.setAccessible(true);
    MenuPopupHelper mHelper = (MenuPopupHelper) field.get(popupMenu);
    mHelper.setForceShowIcon(true);
    //设置 PopupMenu 的条目点击事件(点击后会自动dismiss)
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getApplicationContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    //显示 PopupMenu
    popupMenu.show();
}
 
Example 7
Source File: DashboardItemAddFragment.java    From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    long dashboardId = getArguments().getLong(Dashboard$Table.ID);
    mDashboard = new Select()
            .from(Dashboard.class)
            .where(Condition.column(Dashboard$Table
                    .ID).is(dashboardId))
            .querySingle();

    ButterKnife.bind(this, view);

    InputMethodManager imm = (InputMethodManager)
            getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(mFilter.getWindowToken(), 0);

    mAdapter = new DashboardItemSearchDialogAdapter(
            LayoutInflater.from(getActivity()));
    mListView.setAdapter(mAdapter);
    mDialogLabel.setText(getString(R.string.add_dashboard_item));

    mResourcesMenu = new PopupMenu(getActivity(),mFilter, Gravity.END);
    mResourcesMenu.inflate(R.menu.menu_filter_resources);
    mResourcesMenu.setOnMenuItemClickListener(this);
}
 
Example 8
Source File: UiUtils.java    From droidddle with Apache License 2.0 5 votes vote down vote up
public static <T extends Parcelable> void setupOverflowEditMenu(Activity context, View anchor,
                                                                OnOperationListener<T> listener, int res, final T data, final int position) {
    final PopupMenu menu = new PopupMenu(context, anchor);
    menu.inflate(res);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.action_edit:
                    if (listener != null) {
                        listener.update(data, position);
                    }
                    return true;
                case R.id.action_delete:
                    if (listener != null) {
                        listener.delete(data, position);
                    }
                    return true;
            }
            return false;
        }
    });
    anchor.setOnTouchListener(menu.getDragToOpenListener());
    anchor.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            menu.show();
        }
    });
}
 
Example 9
Source File: MenuV4.java    From ui with Apache License 2.0 5 votes vote down vote up
private void showPopupMenu(View v){
		PopupMenu popupM = new PopupMenu(this, v);
		popupM.inflate(R.menu.popup);
		popupM.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

			@Override
			public boolean onMenuItemClick(MenuItem item) {
				Toast.makeText(getApplicationContext(), item.toString(),Toast.LENGTH_LONG).show();
				label1.append("\n you clicked "+item.toString());
				return true;
			}
		});

		popupM.show();
}
 
Example 10
Source File: TimerViewHolder.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
public TimerViewHolder(ViewGroup parent, OnListItemInteractionListener<Timer> listener,
                       AsyncTimersTableUpdateHandler asyncTimersTableUpdateHandler) {
    super(parent, R.layout.item_timer, listener);
    Log.d(TAG, "New TimerViewHolder");
    mAsyncTimersTableUpdateHandler = asyncTimersTableUpdateHandler;
    mStartIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_start_24dp);
    mPauseIcon = ContextCompat.getDrawable(getContext(), R.drawable.ic_pause_24dp);

    // TODO: This is bad! Use a Controller/Presenter instead...
    // or simply pass in an instance of FragmentManager to the ctor.
    AppCompatActivity act = (AppCompatActivity) getContext();
    mAddLabelDialogController = new AddLabelDialogController(
            act.getSupportFragmentManager(),
            new AddLabelDialog.OnLabelSetListener() {
                @Override
                public void onLabelSet(String label) {
                    mController.updateLabel(label);
                }
            });

    // The item layout is inflated in the super ctor, so we can safely reference our views.
    mPopupMenu = new PopupMenu(getContext(), mMenuButton);
    mPopupMenu.inflate(R.menu.menu_timer_viewholder);
    mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
                case R.id.action_delete:
                    mController.deleteTimer();
                    return true;
            }
            return false;
        }
    });
}
 
Example 11
Source File: PrayerFragment.java    From android with Apache License 2.0 5 votes vote down vote up
@OnClick(R.id.btn_settings)
void onSettingsButtonClicked() {
    PopupMenu menu = new PopupMenu(getActivity(), mSettingsButton);
    mSettingsButton.setOnTouchListener(menu.getDragToOpenListener());

    menu.inflate(R.menu.menu_main);
    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return onOptionsItemSelected(item);
        }
    });

    menu.show();
}
 
Example 12
Source File: NotesFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
@Override
public void onLongClicked(View view, final int position) {
    final Context context = getContext();
    PopupMenu popupMenu = new PopupMenu(context, view);
    popupMenu.inflate(R.menu.menu_delete);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

                case R.id.note_delete:
                    new AlertDialog.Builder(context)
                            .setTitle("Delete Note")
                            .setMessage("Are you sure you want to delete the note?")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    NotesDatabase.getInstance(context).deleteNoteAt(position);
                                    adapter.notifyItemRemoved(position);
                                    refreshLayout();
                                }
                            })
                            .setNegativeButton(android.R.string.no, null)
                            .show();
                    return true;

                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 13
Source File: CalendarFragment.java    From memoir with Apache License 2.0 5 votes vote down vote up
@Override
public void onLongClicked(View view, int position) {
    final int finalPosition = position - 1;
    final Context context = getContext();
    PopupMenu popupMenu = new PopupMenu(context, view);
    popupMenu.inflate(R.menu.menu_delete);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

                case R.id.note_delete:
                    new AlertDialog.Builder(context)
                            .setTitle("Delete Note")
                            .setMessage("Are you sure you want to delete the note?")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    NotesDatabase.getInstance(context).deleteNoteAt(finalPosition);
                                    adapter.notifyItemRemoved(finalPosition);
                                }
                            })
                            .setNegativeButton(android.R.string.no, null)
                            .show();
                    return true;

                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 14
Source File: CommentsStoreAdapter.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public void showPopup(final Activity activity, View view, final int commentId, String author, boolean showReply) {
        PopupMenu popup = new PopupMenu(view.getContext(), view);
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                if (!AptoideUtils.AccountUtils.isLoggedInOrAsk(activity)) return false;
                if (!(activity instanceof AddCommentVoteCallback)) {
                    throw new IllegalStateException("activity is not an instanceof AddCommentVoteCallback");
                }

                int i = item.getItemId();
                if (i == R.id.menu_vote_up) {
                    ((AddCommentVoteCallback) activity).voteComment(commentId, AddApkCommentVoteRequest.CommentVote.up);
//                    FlurryAgent.logEvent("App_View_Voted_Up");
                    return true;
                } else if (i == R.id.menu_vote_down) {
                    ((AddCommentVoteCallback) activity).voteComment(commentId, AddApkCommentVoteRequest.CommentVote.down);
//                    FlurryAgent.logEvent("App_View_Voted_Down");
                    return true;
                }
                return false;
            }
        });
        popup.inflate(R.menu.menu_comments);
        popup.show();
        if (!showReply) {
            popup.getMenu().findItem(R.id.menu_reply).setVisible(false);
        }
    }
 
Example 15
Source File: ServerAdapter.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
private void onServerOptionsClick(final Server server, View optionsButton) {
    PopupMenu popupMenu = new PopupMenu(getContext(), optionsButton);
    popupMenu.inflate(getPopupMenuResource());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            return onPopupItemClick(server, menuItem);
        }
    });
    popupMenu.show();
}
 
Example 16
Source File: TicketGroupListAdapter.java    From Ticket-Analysis with MIT License 5 votes vote down vote up
public void setData(String codeGroup, int realPosition) {
    CodeGroupAdapter codeGroupAdapter = new CodeGroupAdapter(mContext, codeGroup);
    rvCodeGroup.setLayoutManager(new GridLayoutManager(mContext, 7));
    rvCodeGroup.setAdapter(codeGroupAdapter);
    PopupMenu popupMenu = new PopupMenu(mContext, tvOperate);
    popupMenu.inflate(R.menu.operate_menu);
    popupMenu.setOnMenuItemClickListener(item -> {
        // TODO Auto-generated method stub
        switch (item.getItemId()) {
            case R.id.copy:
                ClipboardManager clipboardManager = (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE);
                clipboardManager.setPrimaryClip(ClipData.newPlainText(null, codeGroup));
                ToastUtil.showToast("已经复制到剪切板");
                break;
            case R.id.delete:
                if (mCodeGroups.contains(codeGroup)) {
                    int index = mCodeGroups.indexOf(codeGroup);
                    mCodeGroups.remove(index);
                    notifyItemRemoved(index);
                }
                break;
            default:
                break;
        }
        return false;
    });
    tvOperate.setOnClickListener(v -> {
        popupMenu.show();
    });
}
 
Example 17
Source File: SubscriptionRecyclerViewAdapter.java    From EMQ-Android-Toolkit with Apache License 2.0 5 votes vote down vote up
ViewHolder(View view) {
    super(view);
    ButterKnife.bind(this, itemView);
    popMenu = new PopupMenu(itemView.getContext(), moreImage);
    popMenu.inflate(R.menu.menu_subscription);


}
 
Example 18
Source File: ReminderPickerDialog.java    From OmniList with GNU Affero General Public License v3.0 5 votes vote down vote up
private void showTimePicker(View v) {
    PopupMenu popupM = new PopupMenu(Objects.requireNonNull(getContext()), v);
    popupM.inflate(R.menu.time_picker_menu);
    ViewUtils.forceShowIcon(popupM);
    popupM.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()){
            case R.id.item_morning:
                alarm.setHour(9);
                alarm.setMinute(0);
                break;
            case R.id.item_noon:
                alarm.setHour(12);
                alarm.setMinute(0);
                break;
            case R.id.item_afternoon:
                alarm.setHour(15);
                alarm.setMinute(0);
                break;
            case R.id.item_evening:
                alarm.setHour(18);
                alarm.setMinute(0);
                break;
            case R.id.item_night:
                alarm.setHour(21);
                alarm.setMinute(0);
                break;
            case R.id.item_custom:
                showCustomTimeDialog();
                return true;
            case R.id.item_clear_time: break; // invisible
        }
        displayAlarmInfo();
        return true;
    });
    popupM.show();
}
 
Example 19
Source File: ViewActivity.java    From memoir with Apache License 2.0 4 votes vote down vote up
@OnClick(R.id.location_holder)
public void onLocationClicked() {
    final Activity activity = this;
    PopupMenu popupMenu = new PopupMenu(this, locationHolder);
    if (note.location.placeName.length() == 0) {
        popupMenu.inflate(R.menu.menu_location);
    } else {
        popupMenu.inflate(R.menu.menu_location_remove);
    }
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {

                case R.id.location_remove:
                    new AlertDialog.Builder(activity)
                            .setTitle("Remove Location")
                            .setMessage("Are you sure you want to remove the location?")
                            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    note.location.placeName = "";
                                    note.location.latitude = 0;
                                    note.location.latitude = 0;
                                    refreshLayout();
                                }
                            })
                            .setNegativeButton(android.R.string.no, null)
                            .show();
                    return true;

                case R.id.location_detect:
                    if (!isLocationEnabled()) {
                        Toast.makeText(getApplicationContext(), R.string.note_location_enable, Toast.LENGTH_SHORT).show();
                        Intent onGPS = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                        startActivity(onGPS);
                    } else if (mGoogleApiClient == null || !mGoogleApiClient.isConnected()) {
                        Toast.makeText(getApplicationContext(), R.string.location_play_error, Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(getApplicationContext(), R.string.location_wait, Toast.LENGTH_SHORT).show();
                        getCurrentLocation();
                    }
                    return true;

                case R.id.location_select:
                    backgroundTint.setVisibility(View.VISIBLE);
                    progressCircle.setVisibility(View.VISIBLE);
                    loadingText.setVisibility(View.GONE);
                    try {
                        PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
                        startActivityForResult(builder.build(activity), PLACE_PICKER_REQUEST);
                    } catch (Exception ex) {
                        Toast.makeText(getApplicationContext(), R.string.location_play_error, Toast.LENGTH_SHORT).show();
                        backgroundTint.setVisibility(View.GONE);
                        progressCircle.setVisibility(View.GONE);
                    }
                    return true;

                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}
 
Example 20
Source File: PrinterViewHolder.java    From octoandroid with GNU General Public License v3.0 4 votes vote down vote up
@OnClick(R.id.printer_settings_button) void printerSettingsClicked(View v) {
    PopupMenu popup = new PopupMenu(v.getContext(), v);
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.activity_printer_list_item_menu);
    popup.show();
}