Example usage for android.widget PopupMenu show

List of usage examples for android.widget PopupMenu show

Introduction

In this page you can find the example usage for android.widget PopupMenu show.

Prototype

public void show() 

Source Link

Document

Show the menu popup anchored to the view specified during construction.

Usage

From source file:com.silentcircle.contacts.editor.RawContactEditorView.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void showAddInformationPopupWindow() {
    final ArrayList<KindSectionView> fields = getSectionViewsWithoutFields();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        showAddInformationPopupWindow(fields);
    } else {//from  w w  w  . j  av  a 2s . c o  m
        final PopupMenu popupMenu = new PopupMenu(getContext(), mAddFieldButton);
        final Menu menu = popupMenu.getMenu();
        for (int i = 0; i < fields.size(); i++) {
            menu.add(Menu.NONE, i, Menu.NONE, fields.get(i).getTitle());
        }

        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                final KindSectionView view = fields.get(item.getItemId());
                if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(view.getKind().mimeType)) {
                    mPhoneticNameAdded = true;
                    updatePhoneticNameVisibility();
                } else {
                    view.addItem();
                }

                // If this was the last section without an entry, we just added one, and therefore
                // there's no reason to show the button.
                if (fields.size() == 1) {
                    mAddFieldButton.setVisibility(GONE);
                }

                return true;
            }
        });
        popupMenu.show();
    }
}

From source file:org.starfishrespect.myconsumption.android.ui.ChartChoiceFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_chart_choice, container, false);

    // Register to the EventBus
    EventBus.getDefault().register(this);

    listViewSensor = (ListView) view.findViewById(R.id.listViewSensors);
    mLinearLayout = (LinearLayout) view.findViewById(R.id.linearLayoutDateSelectionItems);
    mTextView = (TextView) view.findViewById(R.id.textViewUsername);

    spinnerDate = (Spinner) view.findViewById(R.id.spinnerDate);
    spinnerFrequency = (Spinner) view.findViewById(R.id.spinnerFrequency);
    spinnerPrecision = (Spinner) view.findViewById(R.id.spinnerPrecision);

    seekBar = (SeekBar) view.findViewById(R.id.seekBar);
    seekBarPosition = 0;/*from w  w w  .ja  v a  2  s  . c o m*/

    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        // Called when the slider moves to another value
        @Override
        public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
            seekBarPosition = progresValue;
        }

        // Called when you start moving the slider
        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        // Called when it seems that you are done moving the slider
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // Tell ChartViewFragment to update the graph
            EventBus.getDefault().post(new UpdateMovingAverageEvent(seekBarPosition));
        }
    });

    listViewSensor.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            lastLongClickItem = position;
            PopupMenu popup = new PopupMenu(mActivity, view);
            popup.inflate(R.menu.menu_sensor_dropdown);
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_delete_sensor:
                        if (!MiscFunctions.isOnline(mActivity)) {
                            MiscFunctions.makeOfflineDialog(mActivity).show();
                            return false;
                        }
                        deleteSensor(lastLongClickItem);
                        break;
                    case R.id.action_edit_sensor:
                        if (!MiscFunctions.isOnline(mActivity)) {
                            MiscFunctions.makeOfflineDialog(mActivity).show();
                            return false;
                        }
                        editSensor(lastLongClickItem);
                        break;
                    }
                    return false;
                }
            });
            popup.show();
            return false;
        }
    });

    return view;
}

From source file:com.google.android.apps.santatracker.presentquest.MapsActivity.java

private void initializeDebugUI() {
    if (!isDebug()) {
        return;/*from w  w  w  . j av  a2  s.  c o m*/
    }

    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;
        }
    });
}

From source file:com.android.deskclock.DeskClock.java

private void showMenu(View v) {
    PopupMenu popupMenu = new PopupMenu(this, v);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from w ww  .jav a  2  s.  c om*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_item_settings:
                startActivity(new Intent(DeskClock.this, SettingsActivity.class));
                return true;
            case R.id.menu_item_help:
                Intent i = item.getIntent();
                if (i != null) {
                    try {
                        startActivity(i);
                    } catch (ActivityNotFoundException e) {
                        // No activity found to match the intent - ignore
                    }
                }
                return true;
            case R.id.menu_item_night_mode:
                startActivity(new Intent(DeskClock.this, ScreensaverActivity.class));
            default:
                break;
            }
            return true;
        }
    });
    popupMenu.inflate(R.menu.desk_clock_menu);

    Menu menu = popupMenu.getMenu();
    MenuItem help = menu.findItem(R.id.menu_item_help);
    if (help != null) {
        Utils.prepareHelpMenuItem(this, help);
    }
    popupMenu.show();
}

From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java

private void setWatchedToggleState(int unwatchedEpisodes) {
    mWatchedAllEpisodes = unwatchedEpisodes == 0;
    mButtonWatchedAll.setImageResource(mWatchedAllEpisodes
            ? Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchedAll)
            : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableWatchAll));
    // set onClick listener not before here to avoid unexpected actions
    mButtonWatchedAll.setOnClickListener(new OnClickListener() {
        @Override//from  w w  w  .java  2  s.co  m
        public void onClick(View v) {
            PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            if (mWatchedAllEpisodes) {
                popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_NONE_ID, 0, R.string.unmark_all);
            } else {
                popupMenu.getMenu().add(0, CONTEXT_WATCHED_SHOW_ALL_ID, 0, R.string.mark_all);
            }
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case CONTEXT_WATCHED_SHOW_ALL_ID: {
                        onFlagShowWatched(true);
                        fireTrackerEvent("Flag all watched (inline)");
                        return true;
                    }
                    case CONTEXT_WATCHED_SHOW_NONE_ID: {
                        onFlagShowWatched(false);
                        fireTrackerEvent("Flag all unwatched (inline)");
                        return true;
                    }
                    }
                    return false;
                }
            });
            popupMenu.show();
        }
    });
    CheatSheet.setup(mButtonWatchedAll, mWatchedAllEpisodes ? R.string.unmark_all : R.string.mark_all);
}

From source file:com.audiokernel.euphonyrmt.MainMenuActivity.java

private PopupMenu initializeHeaderOverflowPopup(final View headerOverflowMenu) {
    final PopupMenu resultPopupMenu;

    if (headerOverflowMenu == null) {
        resultPopupMenu = null;/*from w ww  .ja v a2s. co m*/
    } else {
        final PopupMenu popupMenu = new PopupMenu(this, headerOverflowMenu);
        popupMenu.getMenuInflater().inflate(R.menu.mpd_mainmenu, popupMenu.getMenu());
        popupMenu.getMenuInflater().inflate(R.menu.mpd_playlistmenu, popupMenu.getMenu());
        popupMenu.getMenu().removeItem(R.id.PLM_EditPL);
        popupMenu.setOnMenuItemClickListener(this);

        headerOverflowMenu.setOnTouchListener(PopupMenuCompat.getDragToOpenListener(popupMenu));

        headerOverflowMenu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                if (mSlidingLayout != null && mSlidingLayout.isPanelExpanded()) {
                    prepareNowPlayingMenu(popupMenu.getMenu());
                    popupMenu.show();
                }
            }
        });

        resultPopupMenu = popupMenu;
    }

    return resultPopupMenu;
}

From source file:com.battlelancer.seriesguide.ui.SeasonsFragment.java

private void setCollectedToggleState(int uncollectedEpisodes) {
    mCollectedAllEpisodes = uncollectedEpisodes == 0;
    mButtonCollectedAll.setImageResource(mCollectedAllEpisodes ? R.drawable.ic_collected_all
            : Utils.resolveAttributeToResourceId(getActivity().getTheme(), R.attr.drawableCollectAll));
    // set onClick listener not before here to avoid unexpected actions
    mButtonCollectedAll.setOnClickListener(new OnClickListener() {
        @Override/*ww  w . j a  v a2 s  .c  om*/
        public void onClick(View v) {
            PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
            if (mCollectedAllEpisodes) {
                popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_NONE_ID, 0, R.string.uncollect_all);
            } else {
                popupMenu.getMenu().add(0, CONTEXT_COLLECTED_SHOW_ALL_ID, 0, R.string.collect_all);
            }
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case CONTEXT_COLLECTED_SHOW_ALL_ID: {
                        onFlagShowCollected(true);
                        fireTrackerEvent("Flag all collected (inline)");
                        return true;
                    }
                    case CONTEXT_COLLECTED_SHOW_NONE_ID: {
                        onFlagShowCollected(false);
                        fireTrackerEvent("Flag all uncollected (inline)");
                        return true;
                    }
                    }
                    return false;
                }
            });
            popupMenu.show();
        }
    });
    CheatSheet.setup(mButtonCollectedAll,
            mCollectedAllEpisodes ? R.string.uncollect_all : R.string.collect_all);
}

From source file:com.javielinux.fragments.MyActivityFragment.java

private void showMenuMoreActions(View v) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        PopupMenu popupMenu = new PopupMenu(getActivity(), v);
        popupMenu.getMenuInflater().inflate(R.menu.my_activity_more_actions, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override//from   w  ww . j a  v a  2s  .c  o m
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.popupmenu_more_actions_saved_tweet) {
                    openSavedTweetColumn();
                } else if (item.getItemId() == R.id.popupmenu_more_actions_trending_topics) {
                    newTrending();
                }
                return true;
            }
        });
        popupMenu.show();
    } else {
        AlertDialogFragment frag = new AlertDialogFragment();
        Bundle args = new Bundle();
        args.putInt(AlertDialogFragment.KEY_ALERT_TITLE, R.string.actions);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_HAS_POSITIVE_BUTTON, false);
        args.putBoolean(AlertDialogFragment.KEY_ALERT_CANCELABLE, false);
        args.putInt(AlertDialogFragment.KEY_ALERT_ARRAY_ITEMS, R.array.popupmenu_my_activity_more_actions);
        frag.setArguments(args);
        frag.setAlertButtonListener(new AlertDialogFragment.AlertButtonListener() {
            @Override
            public void OnAlertButtonOk() {
            }

            @Override
            public void OnAlertButtonCancel() {
            }

            @Override
            public void OnAlertButtonNeutral() {
            }

            @Override
            public void OnAlertItems(int which) {
                if (which == 0) {
                    openSavedTweetColumn();
                } else if (which == 1) {
                    newTrending();
                }
            }
        });
        frag.show(getFragmentManager(), "dialog");
    }
}

From source file:in.tanjo.sushi.MainActivity.java

private void updateMainAdapter() {
    MainAdapter mainAdapter = new MainAdapter(mNoteManager.getActiveNote().getSushis());
    mainAdapter.setOnRecyclerViewAdapterItemClickListener(
            new OnRecyclerViewAdapterItemClickListener<CountableSushi>() {
                @Override/*w w  w.j  ava  2s  .  co m*/
                public void onItemClick(View v, RecyclerView.Adapter adapter, int position,
                        CountableSushi model) {
                    model.setCount(model.getCount() + 1);
                    changeItem(position, model);
                }

                @Override
                public void onItemLongClick(View v, RecyclerView.Adapter adapter, final int position,
                        final CountableSushi model) {
                    PopupMenu popupMenu = new PopupMenu(MainActivity.this, v);
                    popupMenu.getMenuInflater().inflate(R.menu.popup_countable_sushi_model_menu,
                            popupMenu.getMenu());
                    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                            case R.id.popup_menu_sushi_delete:
                                removeItem(position, model);
                                snackbar(model.getName() + "????");
                                break;
                            case R.id.popup_menu_sushi_plus1:
                                model.setCount(model.getCount() + 1);
                                changeItem(position, model);
                                break;
                            case R.id.popup_menu_sushi_minus1:
                                if (model.getCount() - 1 >= 0) {
                                    model.setCount(model.getCount() - 1);
                                }
                                changeItem(position, model);
                                break;
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                }
            });
    mMainRecyclerView.setAdapter(mainAdapter);
}

From source file:tk.eatheat.omnisnitch.ui.SwitchLayout.java

private void handleLongPress(final TaskDescription ad, View view) {
    final PopupMenu popup = new PopupMenu(mContext, view);
    mPopup = popup;//from w  w w  .ja  v  a 2 s .c o  m
    popup.getMenuInflater().inflate(R.menu.recent_popup_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == R.id.recent_remove_item) {
                mRecentsManager.killTask(ad);
            } else if (item.getItemId() == R.id.recent_inspect_item) {
                startApplicationDetailsActivity(ad.getPackageName());
            } else {
                return false;
            }
            return true;
        }
    });
    popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
        public void onDismiss(PopupMenu menu) {
            mPopup = null;
        }
    });
    popup.show();
}