Example usage for android.widget PopupMenu.OnMenuItemClickListener PopupMenu.OnMenuItemClickListener

List of usage examples for android.widget PopupMenu.OnMenuItemClickListener PopupMenu.OnMenuItemClickListener

Introduction

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

Prototype

PopupMenu.OnMenuItemClickListener

Source Link

Usage

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;/*  ww  w.  j  av a2s. 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.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 w w . j  a va  2s  .c  om
            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:com.javielinux.fragments.MyActivityFragment.java

private void showMenuOptions(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_options, popupMenu.getMenu());
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override//from   www . ja va 2s . c  o  m
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.popupmenu_more_options_size) {
                    showSizeText();
                } else if (item.getItemId() == R.id.popupmenu_more_options_theme) {
                    showThemeDialog();
                } else if (item.getItemId() == R.id.popupmenu_more_options_preferences) {
                    Intent i = new Intent(getActivity(), Preferences.class);
                    startActivity(i);
                } else if (item.getItemId() == R.id.popupmenu_more_options_exit) {
                    showDialogExit();
                }
                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_options);
        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) {
                    showSizeText();
                } else if (which == 1) {
                    Intent i = new Intent(getActivity(), Preferences.class);
                    startActivity(i);
                } else if (which == 2) {
                    showThemeDialog();
                } else if (which == 3) {
                    showDialogExit();
                }
            }
        });
        frag.show(getFragmentManager(), "dialog");
    }
}

From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java

private void showViewMenu() {
    View menuView = findViewById(R.id.action_view);
    PopupMenu popup = new PopupMenu(menuView.getContext(), menuView);

    final List<IExperimentSensor> experimentRuns = getActiveSensors();
    for (int i = 0; i < experimentRuns.size(); i++) {
        IExperimentSensor experiment = experimentRuns.get(i);

        MenuItem item = popup.getMenu().add(1, i, i, experiment.getClass().getSimpleName());
        item.setCheckable(true);// ww  w .  j  a  v a  2  s  . co m
    }
    popup.getMenu().setGroupCheckable(1, true, true);
    IExperimentSensor currentExperimentSensor = experiment.getCurrentExperimentSensor();
    if (currentExperimentSensor != null)
        popup.getMenu().getItem(experimentRuns.indexOf(currentExperimentSensor)).setChecked(true);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int itemPosition = menuItem.getItemId();
            IExperimentSensor experimentRun = experimentRuns.get(itemPosition);
            setCurrentSensor(experimentRun);
            pager.requestLayout();
            pager.setCurrentItem(itemPosition, true);
            return true;
        }
    });

    popup.show();
}

From source file:nz.ac.auckland.lablet.ExperimentRunViewManager.java

/**
 * Show a menu to enable or disable sensors.
 *///from   ww w.ja  v a2s  . c  om
private void showSensorMenu() {
    View menuView = findViewById(R.id.action_sensors);
    PopupMenu popup = new PopupMenu(menuView.getContext(), menuView);

    final List<ISensorPlugin> plugins = ExperimentPluginFactory.getFactory().getSensorPlugins();
    for (int i = 0; i < plugins.size(); i++) {
        ISensorPlugin plugin = plugins.get(i);

        MenuItem item = popup.getMenu().add(1, i, i, plugin.getSensorName());
        item.setCheckable(true);

        if (getExperiment(plugin) != null)
            item.setChecked(true);
    }

    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            ISensorPlugin plugin = plugins.get(menuItem.getItemId());
            IExperimentSensor experimentSensor = getExperiment(plugin);
            if (experimentSensor != null)
                removeExperimentRun(experimentSensor);
            else
                addExperiment(plugin);
            return true;
        }
    });

    popup.show();
}

From source file:com.inde.shiningdays.MainActivity.java

private void showPopupMenu() {
    final View menuItemView = findViewById(R.id.action_menumore); // SAME ID AS MENU ID
    PopupMenu popupMenu = new PopupMenu(this, menuItemView);
    popupMenu.inflate(R.menu.more_popup_menu);

    String currentSortRule = getCurrentSortRule();
    if (CountDown.SORT_END_DATE_ASC.equals(currentSortRule)) {
        popupMenu.getMenu().findItem(R.id.sort_end_date_asc).setChecked(true);
    } else if (CountDown.DEFAULT_SORT_ORDER.equals(currentSortRule)) {
        popupMenu.getMenu().findItem(R.id.sort_update_date_desc).setChecked(true);
    }/* ww w .ja v  a  2 s  .c o  m*/

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            String rule = "";
            switch (item.getItemId()) {
            case R.id.sort_end_date_asc:
                rule = CountDown.SORT_END_DATE_ASC;
                updateCurrentSortRule(rule);
                selectItem(currentTypePosition, rule);
                return true;
            case R.id.sort_update_date_desc:
                rule = CountDown.DEFAULT_SORT_ORDER;
                updateCurrentSortRule(rule);
                selectItem(currentTypePosition, rule);
                return true;
            case R.id.action_setting:
                Intent intent = new Intent(menuItemView.getContext(), MenuMore.class);
                startActivity(intent);
            default:
                return true;
            }
        }
    });
    popupMenu.show();
}

From source file:com.javielinux.tweettopics2.TweetTopicsActivity.java

private void showMenuColumnsOptions(View view) {
    final List<String> list = new ArrayList<String>();
    final List<Long> types = new ArrayList<Long>();

    ArrayList<Entity> userEntityList = DataFramework.getInstance().getEntityList("users",
            "service is null or service = \"twitter.com\"");
    for (Entity user : userEntityList) {
        list.add(getString(R.string.addColumnUser, user.getString("name")));
        types.add(user.getId());/*  w w  w .j  a va2 s .c o m*/
    }
    list.add(getString(R.string.addTrendingTopic));
    types.add(1001L);
    list.add(getString(R.string.addSavedTweet));
    types.add(1002L);
    list.add(getString(R.string.sortColumns));
    types.add(1003L);
    list.add(getString(R.string.removeColumns));
    types.add(1004L);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        PopupMenu popupMenu = new PopupMenu(this, view);
        int count = 0;
        for (String item : list) {
            popupMenu.getMenu().add(Menu.NONE, count, Menu.NONE, item);
            count++;
        }
        popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

            @Override
            public boolean onMenuItemClick(MenuItem item) {
                long id = types.get(item.getItemId());
                String title = list.get(item.getItemId());
                switch ((int) id) {
                case 1001:
                    newTrending();
                    break;
                case 1002:
                    openSavedTweetColumn();
                    break;
                case 1003:
                    goToSortColumns();
                    break;
                case 1004:
                    goToRemoveColumns();
                    break;
                default:
                    showActionBarIndicatorAndMovePager(-1);
                    showDialogAddColumnUser(title, id);
                    break;
                }
                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.putStringArrayList(AlertDialogFragment.KEY_ALERT_ARRAY_STRING_ITEMS, (ArrayList<String>) list);
        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) {
                long id = types.get(which);
                String title = list.get(which);
                switch ((int) id) {
                case 1001:
                    newTrending();
                    break;
                case 1002:
                    openSavedTweetColumn();
                    break;
                case 1003:
                    goToSortColumns();
                    break;
                case 1004:
                    goToRemoveColumns();
                    break;
                default:
                    showActionBarIndicatorAndMovePager(-1);
                    showDialogAddColumnUser(title, id);
                    break;
                }
            }
        });
        frag.show(getSupportFragmentManager(), "dialog");
    }
}