Example usage for android.widget PopupMenu setOnMenuItemClickListener

List of usage examples for android.widget PopupMenu setOnMenuItemClickListener

Introduction

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

Prototype

public void setOnMenuItemClickListener(OnMenuItemClickListener listener) 

Source Link

Document

Sets a listener that will be notified when the user selects an item from the menu.

Usage

From source file:com.scooter1556.sms.androidtv.fragment.AudioPlayerFragment.java

public void showOptionsMenu(View v) {
    PopupMenu popup = new PopupMenu(getActivity(), v);

    // This activity implements OnMenuItemClickListener
    popup.setOnMenuItemClickListener(this);
    popup.inflate(R.menu.menu_playlist_item);
    popup.show();/*from  www. j  a va  2s . c om*/
}

From source file:sharedcode.wyeditor.ui.activity.SelectFileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    currentFolder = PreferenceHelper.defaultFolder(this);

    ThemeUtils.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_select_file);

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);/*from w ww  .  j a  v a2s.c  o m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = true; //action == Actions.SelectFile;

    listView = (ListView) findViewById(android.R.id.list);
    listView.setOnItemClickListener(this);
    listView.setTextFilterEnabled(true);

    FloatingActionButton mFab = (FloatingActionButton) findViewById(R.id.fabbutton);
    mFab.setColor(getResources().getColor(R.color.fab_light));
    mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add));

    mFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(SelectFileActivity.this, v);

            popup.getMenuInflater().inflate(R.menu.popup_new_file, popup.getMenu());

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    int i = item.getItemId();
                    if (i == R.id.im_new_file) {
                        EditTextDialog.newInstance(EditTextDialog.Actions.NewFile)
                                .show(getFragmentManager().beginTransaction(), "dialog");
                        return true;
                    } else if (i == R.id.im_new_folder) {
                        EditTextDialog.newInstance(EditTextDialog.Actions.NewFolder)
                                .show(getFragmentManager().beginTransaction(), "dialog");
                        return true;
                    } else {
                        return false;
                    }
                }
            });

            popup.show();
        }
    });

    mFab.listenTo(listView);

    String lastNavigatedPath = PreferenceHelper.getWorkingFolder(this);

    File file = new File(lastNavigatedPath);

    if (!file.exists()) {
        PreferenceHelper.setWorkingFolder(this, PreferenceHelper.defaultFolder(this));
        file = new File(PreferenceHelper.defaultFolder(this));
    }

    new UpdateList().execute(file.getAbsolutePath());
}

From source file:org.messic.android.smartphone.activities.main.fragments.downloaded.DownloadedFragment.java

@Override
public void onMoreAction(View caller, View anchor, final DownloadedAlbumViewHolder holder) {
    // Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(DownloadedFragment.this.getActivity(), anchor);

    // Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.activity_downloaded_menu_album, popup.getMenu());

    // registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_album_item_remove:
                removeAlbum(holder.album, holder);
                break;
            case R.id.menu_album_item_play:
                presenter.playAction(holder.album);
                break;
            case R.id.menu_album_item_playnow:
                presenter.longPlayAction(holder.album);
                break;
            }/*from   w w  w . j av a2s  . c o  m*/
            return true;
        }

    });

    popup.show();// showing popup menu
}

From source file:org.apache.cordova.navigationmenu.NavigationMenu.java

/**
 * Displays popup menu./*from ww w .  ja  v  a 2 s  .c  o  m*/
 *
 * @param items   The array of objects which describes menu items.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void showPopup(JSONArray items) {
    final PopupMenu popup = new PopupMenu(this.webView.getContext(), this.webView);

    PopupMenu.OnMenuItemClickListener handler = new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            int itemId = item.getItemId();
            webView.sendJavascript("menu.popupItemClick && menu.popupItemClick(" + itemId + ");");
            return false;
        }
    };
    popup.setOnMenuItemClickListener(handler);
    Menu popupMenu = popup.getMenu();
    for (int i = 0; i < items.length(); i++) {
        JSONObject menuItem = items.optJSONObject(i);
        if (menuItem != null) {
            appendItem(popupMenu, menuItem);
        }
    }

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        public void run() {
            popup.show();
        }
    });

}

From source file:org.hawkular.client.android.fragment.AlertsFragment.java

private void showAlertMenu(final View alertView, final int alertPosition) {
    PopupMenu alertMenu = new PopupMenu(getActivity(), alertView);

    alertMenu.getMenuInflater().inflate(R.menu.popup_alerts, alertMenu.getMenu());

    alertMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from   w  w  w .j a v a2  s.  c  om
        public boolean onMenuItemClick(MenuItem menuItem) {
            Alert alert = getAlertsAdapter().getItem(alertPosition);

            switch (menuItem.getItemId()) {
            case R.id.menu_resolve:
                BackendClient.of(AlertsFragment.this).resolveAlert(alert, new AlertActionCallback());
                return true;

            case R.id.menu_acknowledge:
                BackendClient.of(AlertsFragment.this).acknowledgeAlert(alert, new AlertActionCallback());
                return true;

            default:
                return false;
            }
        }
    });

    alertMenu.show();
}

From source file:de.enlightened.peris.ForumSettingsFragment.java

private void setupHomeButton(final SharedPreferences appPreferences) {
    //Home Page button
    final LinearLayout forumSettingHome = (LinearLayout) getActivity().findViewById(R.id.forum_setting_home);
    forumSettingHome.setOnClickListener(new View.OnClickListener() {
        @Override//from  www.  j  a v a 2s  . c om
        @SuppressWarnings("checkstyle:requirethis")
        public void onClick(final View v) {
            final PopupMenu popup = new PopupMenu(getActivity(), v);
            final MenuInflater inflater = popup.getMenuInflater();
            inflater.inflate(R.menu.home_page_selection, popup.getMenu());
            popup.setOnMenuItemClickListener(forumHomeSelectedListener);
            popup.show();
        }
    });

    //Home Page Display Text
    final String currentServerId = this.application.getSession().getServer().serverId;
    final String keyName = currentServerId + "_home_page";
    String valueName = getString(R.string.subforum_id);
    String displayName = "Forum Index";

    valueName = appPreferences.getString(keyName, getString(R.string.subforum_id));

    if (valueName.contentEquals(getString(R.string.subforum_id))) {
        displayName = "Forum Index";
    }
    if (valueName.contentEquals("forum_favs")) {
        displayName = "Favorites";
    }
    if (valueName.contentEquals("timeline")) {
        displayName = "Timeline";
    }
    if (valueName.contentEquals("participated")) {
        displayName = "Participated Topics";
    }
    if (valueName.contentEquals("favs")) {
        displayName = "Subscribed Topics";
    }
    if (valueName.contentEquals("unread")) {
        displayName = "Unread Topics";
    }

    final TextView forumSettingHomeCurrent = (TextView) this.getActivity()
            .findViewById(R.id.forum_setting_home_current);
    forumSettingHomeCurrent.setText(displayName);
}

From source file:org.messic.android.smartphone.activities.main.MainActivity.java

private void openSettings() {
    View anchor = findViewById(R.id.action_settings);

    // Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(this, anchor);

    // Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.activity_main_menu, popup.getMenu());

    // registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_base_item_removedatabase:
                emptyDatabaseAction();/*from   w ww.  j a  va2s .co  m*/
                break;
            case R.id.menu_base_item_logout:
                presenter.logout();

                Intent intent = new Intent(MainActivity.this, LoginActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);
                finish(); // call this to finish the current activity

                break;
            case R.id.menu_base_item_clearplaylist:
                presenter.clearQueue();
                break;
            case R.id.menu_base_item_playrandom:
                presenter.addRandomSongsToPlaylist();
                break;
            case R.id.menu_base_item_showlicense:
                Intent browserIntent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse("http://www.gnu.org/licenses/gpl-3.0-standalone.html"));
                startActivity(browserIntent);

                break;
            }
            return true;
        }
    });

    popup.show();// showing popup menu
}

From source file:org.alfresco.mobile.android.application.fragments.fileexplorer.LibraryCursorAdapter.java

@Override
protected void updateIcon(TwoLinesViewHolder vh, Cursor cursor) {
    String data = cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA));
    File f = new File(data);

    switch (mediaTypeId) {
    case MediaStore.Files.FileColumns.MEDIA_TYPE_IMAGE:
        vh.icon.setImageResource(R.drawable.mime_img);
        renditionManager.getPicasso().load(f).resize(150, 150).centerCrop().placeholder(R.drawable.mime_256_img)
                .error(R.drawable.mime_256_img).into(vh.icon);
        break;/*from  www  .  ja  v  a  2  s.c  o  m*/
    case MediaStore.Files.FileColumns.MEDIA_TYPE_VIDEO:
        vh.icon.setImageResource(R.drawable.mime_video);
        break;
    case MediaStore.Files.FileColumns.MEDIA_TYPE_AUDIO:
        vh.icon.setImageResource(R.drawable.mime_audio);
        break;
    default:
        Uri uri = Uri.parse(cursor.getString(cursor.getColumnIndex(MediaStore.Files.FileColumns.DATA)));
        vh.icon.setImageResource(MimeTypeManager.getInstance(context).getIcon(uri.getLastPathSegment()));
        break;
    }

    if (mode == FileExplorerFragment.MODE_LISTING && fragmentRef.get().getActivity() instanceof MainActivity) {
        vh.choose.setImageResource(R.drawable.ic_more_options);
        vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light);
        int d_16 = DisplayUtils.getPixels(context, R.dimen.d_16);
        vh.choose.setPadding(d_16, d_16, d_16, d_16);
        vh.choose.setVisibility(View.VISIBLE);
        vh.choose.setTag(R.id.node_action, f);
        vh.choose.setOnClickListener(new OnClickListener() {

            @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
            @Override
            public void onClick(View v) {
                File item = (File) v.getTag(R.id.node_action);
                selectedOptionItems.add(item);
                PopupMenu popup = new PopupMenu(context, v);
                getMenu(popup.getMenu(), item);
                popup.setOnDismissListener(new OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        selectedOptionItems.clear();
                    }
                });

                popup.setOnMenuItemClickListener(LibraryCursorAdapter.this);

                popup.show();
            }
        });
    } else {
        UIUtils.setBackground(vh.choose, null);
        vh.choose.setVisibility(View.GONE);
    }
}

From source file:de.aw.monma.actions.FragmentWPList.java

/**
 * Bei Click wird das contextmenu gezeigt. In den jeweiligen extras sind folgende Informationen
 * enthalten: WPID, AMOUNT, WPNAME des gewaehlten Wertpapiers.
 */// w  w w. ja  v a2  s . c om
@Override
public void onRecyclerItemClick(View view, int position, WertpapierListItem item) {
    super.onRecyclerItemClick(view, position, item);
    Intent intent = new Intent();
    intent.putExtra(WPID, item.getID());
    intent.putExtra(WPNAME, item.getWPName());
    intent.putExtra(ACCOUNTID, NOID);
    intent.putExtra(AMOUNT, item.getGewinn());
    PopupMenu popUpMenu = new PopupMenu(getActivity(), view);
    popUpMenu.inflate(R.menu.context_fragment_wpuebersicht);
    popUpMenu.inflate(R.menu.context_fragment_wpliste);
    Menu menu = popUpMenu.getMenu();
    for (int i = 0; i < menu.size(); i++) {
        menu.getItem(i).setIntent(intent);
    }
    popUpMenu.setOnMenuItemClickListener(this);
    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 ww  .jav  a 2  s .  c  om

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