Example usage for android.widget PopupMenu getMenu

List of usage examples for android.widget PopupMenu getMenu

Introduction

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

Prototype

public Menu getMenu() 

Source Link

Document

Returns the Menu associated with this popup.

Usage

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();// ww  w. j ava 2  s  .  co 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.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   ww w  .  j  a  v a 2s.  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:com.jwetherell.quick_response_code.EncoderActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.btnshare:
        OnClickShare(null);/* w  w w .  j  av a 2s.com*/
        return true;
    case android.R.id.home:
        onBackPressed();
        return true;
    case R.id.empty:
        Statistics.getInstance(EncoderActivity.this).click();
        View menuItemView = findViewById(R.id.empty);
        PopupMenu popupMenu = new PopupMenu(this, menuItemView);
        popupMenu.inflate(R.menu.menu_contextual_wps);
        for (int i = 0; i < popupMenu.getMenu().size(); i++) {
            MenuItem itemMenu = popupMenu.getMenu().getItem(i);
            SpannableString spanString = new SpannableString(
                    popupMenu.getMenu().getItem(i).getTitle().toString());
            spanString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, spanString.length(), 0);
            itemMenu.setTitle(spanString);
        }
        popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                Statistics.getInstance(EncoderActivity.this).click();
                // TODO Auto-generated method stub
                switch (item.getItemId()) {
                case R.id.wps:
                    Statistics.getInstance(EncoderActivity.this).sendStatistics(TAGS.TAG_31);
                    Intent mIntent = new Intent(EncoderActivity.this, AVActivateWpsActivity.class);
                    mIntent.putExtra("is_5ghz", getIntent().getBooleanExtra("is_5ghz", false));
                    startActivity(mIntent);
                    break;

                default:
                    break;
                }

                return false;
            }
        });
        popupMenu.show();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

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   ww w  .  j  a va  2s  .c o m*/
        @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:nodomain.freeyourgadget.gadgetbridge.activities.appmanager.AbstractAppManagerFragment.java

public boolean openPopupMenu(View view, int position) {
    PopupMenu popupMenu = new PopupMenu(getContext(), view);
    popupMenu.getMenuInflater().inflate(R.menu.appmanager_context, popupMenu.getMenu());
    Menu menu = popupMenu.getMenu();
    final GBDeviceApp selectedApp = appList.get(position);

    if (!selectedApp.isInCache()) {
        menu.removeItem(R.id.appmanager_app_reinstall);
        menu.removeItem(R.id.appmanager_app_delete_cache);
    }/* ww w .j  a  va 2 s  .c o  m*/
    if (!PebbleProtocol.UUID_PEBBLE_HEALTH.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_health_activate);
        menu.removeItem(R.id.appmanager_health_deactivate);
    }
    if (!PebbleProtocol.UUID_WORKOUT.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_hrm_activate);
        menu.removeItem(R.id.appmanager_hrm_deactivate);
    }
    if (!PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        menu.removeItem(R.id.appmanager_weather_activate);
        menu.removeItem(R.id.appmanager_weather_deactivate);
        menu.removeItem(R.id.appmanager_weather_install_provider);
    }
    if (selectedApp.getType() == GBDeviceApp.Type.APP_SYSTEM
            || selectedApp.getType() == GBDeviceApp.Type.WATCHFACE_SYSTEM) {
        menu.removeItem(R.id.appmanager_app_delete);
    }
    if (!selectedApp.isConfigurable()) {
        menu.removeItem(R.id.appmanager_app_configure);
    }

    if (PebbleProtocol.UUID_WEATHER.equals(selectedApp.getUUID())) {
        PackageManager pm = getActivity().getPackageManager();
        try {
            pm.getPackageInfo("ru.gelin.android.weather.notification", PackageManager.GET_ACTIVITIES);
            menu.removeItem(R.id.appmanager_weather_install_provider);
        } catch (PackageManager.NameNotFoundException e) {
            menu.removeItem(R.id.appmanager_weather_activate);
            menu.removeItem(R.id.appmanager_weather_deactivate);
        }
    }

    switch (selectedApp.getType()) {
    case WATCHFACE:
    case APP_GENERIC:
    case APP_ACTIVITYTRACKER:
        break;
    default:
        menu.removeItem(R.id.appmanager_app_openinstore);
    }
    //menu.setHeaderTitle(selectedApp.getName());
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            return onContextItemSelected(item, selectedApp);
        }
    });

    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    popupMenu.show();
    return true;
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@SuppressLint("NewApi")
public OnClickListener onclickPopUpMenu(MenuItem item) {
    //Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(EncoderActivity.this, item.getActionView());
    //Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.menu_contextual_wps, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(EncoderActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        }//from   w  w w . j  ava2s  .  c o  m
    });

    popup.show(); //showing popup menu
    return null;

}

From source file:net.vivekiyer.GAL.CorporateContactRecordFragment.java

@TargetApi(11)
@Override/*www  .  jav a2  s.c o m*/
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.contact_actions:
        if (Utility.isPreHoneycomb()) {
            showContactQuickActions(v);
            return;
        } else {
            PopupMenu popup = new PopupMenu(getActivity(), v);
            popup.setOnMenuItemClickListener(HoneycombListeners.getPopupMenuListener(this));
            MenuInflater inflater = popup.getMenuInflater();

            inflater.inflate(R.menu.contact_actions_menu, popup.getMenu());
            popup.show();
        }
        break;
    case R.id.save_contact:
        this.contactWriter.saveContact(getView().getContext());
    default:
        break;
    }
}

From source file:com.owncloud.android.ui.fragment.FileDetailSharingFragment.java

@OnClick(R.id.overflow_menu_share_link)
public void showLinkOverflowMenu() {
    Context context = getContext();
    if (context != null && ThemeUtils.themingEnabled(context)) {
        // use grey as fallback for elements where custom theming is not available
        context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
    } else {/* w  w w  . ja va2  s  .  c o  m*/
        context = getActivity();
    }

    PopupMenu popup = new PopupMenu(context, overflowMenuShareLink);
    popup.inflate(R.menu.file_detail_sharing_link_menu);
    prepareOptionsMenu(popup.getMenu());
    popup.setOnMenuItemClickListener(this::optionsItemSelected);
    popup.show();
}

From source file:com.giltesa.taskcalendar.activity.Main.java

/**
 * Desde el metodo onOptionsItemSelected(), se tratan los eventos que produzcan los diferentes Items de los Menus.
 * Se tratan tanto los eventos del menu del boton fisico como los producidos por el boton del ActionBar.
 *//*ww  w. j av  a 2s  .c o m*/
@SuppressLint("NewApi")
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    //   Se trata el evento del boton Menu, y de sus SubMenus metidos en un PopupMenu:
    case R.id.main_actionbar_menu:
        PopupMenu popup = new PopupMenu(this, findViewById(R.id.main_actionbar_menu));
        MenuInflater inflater = popup.getMenuInflater();
        inflater.inflate(R.menu.main_menu, popup.getMenu());

        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.main_menu_newtask:
                    // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity:
                    Intent intent = new Intent(context, NewTask.class);
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("isNewTask", true);
                    bundle.putInt("positionSlider", mViewPager.getCurrentItem());
                    intent.putExtra("dataActivity", bundle);
                    startActivityForResult(intent, Main.NEWTASK);
                    return true;

                case R.id.main_menu_settings:
                    startActivity(new Intent(Main.this, Settings.class));
                    return true;

                case R.id.main_menu_exit:
                    finish();
                    return true;

                default:
                    return false;
                }
            }
        });
        popup.show();
        return true;

    case R.id.main_actionbar_search:
        return true;

    case R.id.main_menu_newtask:
        // Se crea un Intent y un Bundle con la informacion a enviar al nuevo Activity:
        Intent intent = new Intent(context, NewTask.class);
        Bundle bundle = new Bundle();
        bundle.putBoolean("isNewTask", true);
        bundle.putInt("positionSlider", mViewPager.getCurrentItem());
        intent.putExtra("dataActivity", bundle);
        startActivityForResult(intent, Main.NEWTASK);
        return true;

    case R.id.main_menu_settings:
        startActivity(new Intent(Main.this, Settings.class));
        return true;

    case R.id.main_menu_exit:
        finish();
        return true;

    default:
        return false;
    }
}

From source file:com.maskyn.fileeditorpro.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  .  jav  a  2s.c  o  m*/

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    //final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = true; //action == Actions.SelectFile;
    mfabOkMode = false;
    folderOpenMode = getIntent().getBooleanExtra("foldermode", false);
    if (folderOpenMode)
        setTitle("Open Folder");

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

    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) {
            if (!mfabOkMode) {
                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();
            }
            if (mfabOkMode) {
                finishWithResult(selectedFile);
            }
        }
    });

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