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:osm.custommaps.create.PreviewMapActivity.java

private void prepareUI() {
    saveButton = (Button) findViewById(R.id.save);
    mapModeButton = (ImageButton) findViewById(R.id.mapmode);
    transparencyBar = (SeekBar) findViewById(R.id.transparencyBar);

    saveButton.setOnClickListener(new View.OnClickListener() {
        @Override//from   ww w . jav a2 s . c  om
        public void onClick(View v) {

            computeAndReturnTiepoints();
        }
    });

    mapModeButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            PopupMenu popupMenu = new PopupMenu(getApplicationContext(), view);
            popupMenu.inflate(R.menu.menu_options);

            popupMenu.show();

            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.toString()) {
                    case "Google Satellite":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.GOOGLE_SATELLITE);
                        break;
                    case "Google Maps":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.GOOGLE_MAPS);
                        break;
                    case "Google Terrain":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.GOOGLE_TERRAIN);
                        break;
                    case "Bing Maps":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.BING_MAPS);
                        break;
                    case "Bing Earth":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.BING_EARTH);
                        break;
                    case "Bing Hybrid":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.BING_HYBRID);
                        break;
                    case "Mapquest Aerial":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.MAPQUESTAERIAL_US);
                        break;
                    case "Mapquest OSM":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.MAPQUESTOSM);
                        break;
                    case "Mapnik":
                        mapView.invalidate();
                        mapView.setMaxZoomLevel(20);
                        mapView.setMinZoomLevel(3);
                        mapView.setTileSource(WMSTileSourceFactory.MAPNIK);
                        break;

                    }
                    return false;
                }
            });
        }
    });

    transparencyBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        private void updateImageOverlay(int value) {
            imageOverlay.setTransparency(value);
            mapView.invalidate();
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            updateImageOverlay(seekBar.getProgress());
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
            updateImageOverlay(seekBar.getProgress());
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                updateImageOverlay(seekBar.getProgress());
            }
        }
    });
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

@Override
public void onChannelCoupling(final View view) {
    Log.i(TAG, "onChannelCoupling");

    PopupMenu popup = createPopupMenu(view, R.menu.coupling_menu);
    popup.show();//from   w  ww.  ja va2  s .  com
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean handled = false;
            String coup = "";
            switch (item.getItemId()) {
            case R.id.menu_coupling_ac:
                handled = true;
                coup = getResources().getString(R.string.coupling_ac);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_COUPLING, mId, "AC");

                break;
            case R.id.menu_coupling_dc:
                handled = true;
                coup = getResources().getString(R.string.coupling_dc);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_COUPLING, mId, "DC");
                break;
            case R.id.menu_coupling_gnd:
                handled = true;
                coup = getResources().getString(R.string.coupling_gnd);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_COUPLING, mId, "GND");
                break;
            }
            ((TextView) view.findViewById(R.id.channel_coupling_subtext)).setText(coup);
            //  mPopupWindow.dismiss();
            return handled;
        }
    });
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

@Override
public void onTriggerSource(final View view) {
    Log.i(TAG, "onTriggerSource");

    PopupMenu popup = createPopupMenu(view, R.menu.trigger_source_menu);
    popup.show();/*from  w  w  w  .  jav a 2 s  . c om*/
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean handled = false;
            String ch = "";
            switch (item.getItemId()) {
            case R.id.menu_source_ch1:
                handled = true;
                ch = getResources().getString(R.string.source_ch1);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_TRIGGER_SOURCE, 0, "CHAN1");
                break;
            case R.id.menu_source_ch2:
                handled = true;
                ch = getResources().getString(R.string.source_ch2);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_TRIGGER_SOURCE, 0, "CHAN2");
                break;
            }
            ((TextView) view.findViewById(R.id.trigger_source_subtext)).setText(ch);
            //  mPopupWindow.dismiss();
            return handled;
        }
    });
}

From source file:freed.viewer.gridview.GridViewFragment.java

private void showFileSelectionPopup(View v) {
    PopupMenu popup = new PopupMenu(getContext(), v);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override//from w  w  w .j av a  2  s .  co m
        public boolean onMenuItemClick(MenuItem item) {
            int i = item.getItemId();
            if (i == id.all) {
                filetypeButton.setText(string.ALL);
                formatsToShow = FormatTypes.all;
            } else if (i == id.raw) {
                filetypeButton.setText("RAW");
                formatsToShow = FormatTypes.raw;
            } else if (i == id.bayer) {
                filetypeButton.setText("BAYER");
                formatsToShow = FormatTypes.raw;
            } else if (i == id.dng) {
                filetypeButton.setText("DNG");
                formatsToShow = FormatTypes.dng;
            } else if (i == id.jps) {
                filetypeButton.setText("JPS");
                formatsToShow = FormatTypes.jps;
            } else if (i == id.jpg) {
                filetypeButton.setText("JPG");
                formatsToShow = FormatTypes.jpg;
            } else if (i == id.mp4) {
                filetypeButton.setText("MP4");
                formatsToShow = FormatTypes.mp4;
            }
            //if (savedInstanceFilePath != null)
            viewerActivityInterface.LoadFolder(folderToShow, formatsToShow);

            return false;

        }
    });
    MenuInflater inflater = popup.getMenuInflater();
    inflater.inflate(menu.filetypepopupmenu, popup.getMenu());
    popup.show();
}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

@Override
public void onTriggerSlope(final View view) {
    Log.i(TAG, "onTriggerSlope");

    PopupMenu popup = createPopupMenu(view, R.menu.trigger_slope_menu);
    popup.show();/*from  www  .  j ava2s.  co m*/
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean handled = false;
            switch (item.getItemId()) {
            case R.id.menu_slope_positive: {
                handled = true;
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_TRIGGER_SLOPE, 0, "POS");

                ImageView imageView = (ImageView) view.findViewById(R.id.trigger_slope_subImage);
                imageView.setImageResource(R.drawable.positive_slope);

                break;
            }
            case R.id.menu_slope_negative: {
                handled = true;
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_TRIGGER_SLOPE, 0, "NEG");

                ImageView imageView = (ImageView) view.findViewById(R.id.trigger_slope_subImage);
                imageView.setImageResource(R.drawable.negative_slope);

                break;
            }
            case R.id.menu_slope_both: {
                handled = true;
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_TRIGGER_SLOPE, 0, "ALT");

                ImageView imageView = (ImageView) view.findViewById(R.id.trigger_slope_subImage);
                imageView.setImageResource(R.drawable.both_slope);

                break;
            }
            }
            //  mPopupWindow.dismiss();
            return handled;
        }
    });

}

From source file:de.uni_weimar.mheinz.androidtouchscope.display.HandleView.java

@Override
public void onChannelProbe(final View view) {
    Log.i(TAG, "onChannelProbe");

    PopupMenu popup = createPopupMenu(view, R.menu.probe_menu);
    popup.show();/*w  w  w.  j  av  a  2s .  co m*/
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            boolean handled = false;
            String probe = "";
            switch (item.getItemId()) {
            case R.id.menu_probe_1:
                handled = true;
                probe = getResources().getString(R.string.probe_1X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 1);
                break;
            case R.id.menu_probe_5:
                handled = true;
                probe = getResources().getString(R.string.probe_5X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 5);
                break;
            case R.id.menu_probe_10:
                handled = true;
                probe = getResources().getString(R.string.probe_10X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 10);
                break;
            case R.id.menu_probe_50:
                handled = true;
                probe = getResources().getString(R.string.probe_50X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 50);
                break;
            case R.id.menu_probe_100:
                handled = true;
                probe = getResources().getString(R.string.probe_100X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 100);
                break;
            case R.id.menu_probe_500:
                handled = true;
                probe = getResources().getString(R.string.probe_500X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 500);
                break;
            case R.id.menu_probe_1000:
                handled = true;
                probe = getResources().getString(R.string.probe_1000X);
                mOnDataChanged.doCommand(ScopeInterface.Command.SET_CHANNEL_PROBE, mId, 1000);
                break;
            }
            ((TextView) view.findViewById(R.id.channel_probe_subtext)).setText(probe);
            //  mPopupWindow.dismiss();
            return handled;
        }
    });
}

From source file:org.videolan.vlc2.gui.video.VideoGridFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void onContextPopupMenu(View anchor, final int position) {
    if (!LibVlcUtil.isHoneycombOrLater()) {
        // Call the "classic" context menu
        anchor.performLongClick();/*from w  w w.jav a  2  s  .  c  o m*/
        return;
    }

    PopupMenu popupMenu = new PopupMenu(getActivity(), anchor);
    popupMenu.getMenuInflater().inflate(R.menu.video_list, popupMenu.getMenu());
    Media media = mVideoAdapter.getItem(position);
    setContextMenuItems(popupMenu.getMenu(), media);
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleContextItemSelected(item, position);
        }
    });
    popupMenu.show();
}

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

@Override
protected void updateIcon(TwoLinesProgressViewHolder vh, File item) {
    if (item.isFile()) {
        Drawable drawable = getContext().getResources()
                .getDrawable(MimeTypeManager.getInstance(getContext()).getIcon(item.getName()));
        renditionManager.getPicasso().load(item).placeholder(drawable).error(drawable).into(vh.icon);
        AccessibilityUtils.addContentDescription(vh.icon, R.string.mime_document);
    } else if (item.isDirectory()) {
        vh.icon.setImageDrawable(getContext().getResources().getDrawable(R.drawable.mime_folder));
        AccessibilityUtils.addContentDescription(vh.icon, R.string.mime_folder);
    }//from  ww w.  j a v a  2s .c om

    if (mode == FileExplorerFragment.MODE_LISTING && fragmentRef.get().getActivity() instanceof MainActivity
            && ((downloadPath != null && item.getPath().startsWith(downloadPath)) || (item.isFile()))) {
        vh.choose.setImageResource(R.drawable.ic_more_options);
        vh.choose.setBackgroundResource(R.drawable.alfrescohololight_list_selector_holo_light);
        int d_16 = DisplayUtils.getPixels(getContext(), R.dimen.d_16);
        vh.choose.setPadding(d_16, d_16, d_16, d_16);
        vh.choose.setVisibility(View.VISIBLE);
        AccessibilityUtils.addContentDescription(vh.choose,
                String.format(getContext().getString(R.string.more_options_file), item.getName()));
        vh.choose.setTag(R.id.node_action, item);
        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(getContext(), v);
                getMenu(popup.getMenu(), item);
                popup.setOnDismissListener(new OnDismissListener() {
                    @Override
                    public void onDismiss(PopupMenu menu) {
                        selectedOptionItems.clear();
                    }
                });

                popup.setOnMenuItemClickListener(FileExplorerAdapter.this);

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

From source file:com.atlas.mars.weatherradar.MainActivity.java

@Override
public void onClick(View v) {
    final View _v = v;
    final MainActivity mainActivity = this;
    switch (v.getId()) {
    case R.id.buttonReload:

        /* MyFragment myFragment = (MyFragment)fragmetMap.get(posinion);// (MyFragment)pager.getChildAt(posinion);
        myFragment.reloadImg();*/
        mapFragments.get(posinion).reloadImg();
        //   reloadImg();
        break;//from   w  w w . ja v  a  2 s .  com
    case R.id.buttonMenu:
        PopupMenu popupMenu = new PopupMenu(this, v);
        popupMenu.inflate(R.menu.menu_main);
        popupMenu.show();
        popupMenu.setOnMenuItemClickListener(this);
        break;
    }
}

From source file:org.rm3l.ddwrt.tiles.status.wireless.WirelessIfaceTile.java

public WirelessIfaceTile(@NotNull String iface, @Nullable String parentIface,
        @NotNull SherlockFragment parentFragment, @NotNull Bundle arguments, @Nullable Router router) {
    super(parentFragment, arguments, router, R.layout.tile_status_wireless_iface,
            R.id.tile_status_wireless_iface_togglebutton);
    this.iface = iface;
    this.parentIface = parentIface;
    ((TextView) this.layout.findViewById(R.id.tile_status_wireless_iface_title)).setText(this.iface);

    //Create Options Menu
    final ImageButton tileMenu = (ImageButton) layout.findViewById(R.id.tile_status_wireless_iface_menu);

    final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid());

    if (!isThemeLight) {
        //Set menu background to white
        tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark);
    }/*from  w  w w .  j  a  v a2s . c om*/

    tileMenu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final PopupMenu popup = new PopupMenu(mParentFragmentActivity, v);
            popup.setOnMenuItemClickListener(WirelessIfaceTile.this);
            final MenuInflater inflater = popup.getMenuInflater();

            final Menu menu = popup.getMenu();

            inflater.inflate(R.menu.tile_wireless_iface_options, menu);

            if (wifiEncryptionType == null || (isNullOrEmpty(wifiSsid) && isNullOrEmpty(wifiPassword))) {
                menu.findItem(R.id.tile_status_wireless_iface_qrcode).setEnabled(false);
            }

            popup.show();
        }
    });

}