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: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);
    }/* w w w .j  a  va2s . c o  m*/

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

}

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  a  v  a  2s  .  c o m
            return true;
        }

    });

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

From source file:com.android.contacts.activities.DialtactsActivity.java

@Override
public void onClick(View view) {
    switch (view.getId()) {
    case R.id.searchButton: {
        enterSearchUi();/*from  www  .  j  a  v  a 2s .com*/
        break;
    }
    case R.id.overflow_menu: {
        if (mDialpadFragment != null) {
            PopupMenu popup = mDialpadFragment.constructPopupMenu(view);
            if (popup != null) {
                popup.show();
            }
        } else {
            Log.w(TAG, "DialpadFragment is null during onClick() event for " + view);
        }
        break;
    }
    default: {
        Log.wtf(TAG, "Unexpected onClick event from " + view);
        break;
    }
    }
}

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

private void showAlertMenu(final View view) {
    PopupMenu alertMenu = new PopupMenu(getActivity(), view);

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

    alertMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from   w ww  . jav  a 2 s . c  om
        public boolean onMenuItemClick(MenuItem menuItem) {

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

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

            default:
                return false;
            }
        }
    });

    alertMenu.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 ava 2 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:com.google.reviewit.PagedChangeDetailsFragment.java

private void init() {
    final Change change = getApp().getQueryHandler().getCurrentChange();
    checkArgument(change != null, "No change to display");

    ChangeEntry changeEntry = new ChangeEntry(getContext());
    changeEntry.init(getApp(), change);//from  w  w w . j a  v a  2 s . c o m
    vg(R.id.changeHeader).addView(changeEntry);

    final List<PageFragment> fragments = new ArrayList<>();

    CommitMessageFragment commitMessageFragment = new CommitMessageFragment();
    commitMessageFragment.setChange(change);
    fragments.add(commitMessageFragment);

    FileListFragment fileListFragment = new FileListFragment();
    fileListFragment.setChange(change);
    fragments.add(fileListFragment);

    ApprovalsFragment approvalsFragment = new ApprovalsFragment();
    approvalsFragment.setChange(change);
    fragments.add(approvalsFragment);

    ReplyFragment replyFragment = new ReplyFragment();
    replyFragment.setChange(change);
    fragments.add(replyFragment);

    // TODO add more tabs, e.g. for change messages

    ViewPager pager = ((ViewPager) v(R.id.pager));
    pager.setAdapter(new FragmentPagerAdapter(getChildFragmentManager()) {
        @Override
        public Fragment getItem(int position) {
            return fragments.get(position);
        }

        @Override
        public int getCount() {
            return fragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return getString(fragments.get(position).getTitle());
        }
    });

    SlidingTabLayout tabs = ((SlidingTabLayout) v(R.id.tabs));
    tabs.setTextColor(widgetUtil.color(R.color.tab));
    tabs.setSelectedIndicatorColors(widgetUtil.color(R.color.tab));
    tabs.setBorderColor(widgetUtil.color(R.color.tab));
    tabs.setDividerColors(widgetUtil.color(R.color.tabDivider));
    tabs.setBottomBorderThickness(widgetUtil.dpToPx(1));
    tabs.setSelectedIndicatorThickness(widgetUtil.dpToPx(5));
    tabs.setViewPager(pager);

    final View more = v(R.id.more);
    more.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            PopupMenu popup = new PopupMenu(getContext(), more);
            popup.getMenuInflater().inflate(R.menu.menu_paged_change_details, popup.getMenu());

            popup.getMenu().findItem(R.id.action_abandon).setVisible(
                    change.info.status == ChangeStatus.NEW || change.info.status == ChangeStatus.SUBMITTED);
            popup.getMenu().findItem(R.id.action_restore)
                    .setVisible(change.info.status == ChangeStatus.ABANDONED);

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_abandon:
                        display(AbandonFragment.create(PagedChangeDetailsFragment.class));
                        return true;
                    case R.id.action_restore:
                        display(RestoreFragment.create(PagedChangeDetailsFragment.class));
                        return true;
                    default:
                        return true;
                    }
                }
            });
            popup.show();
        }
    });
}

From source file:me.albertonicoletti.latex.activities.EditorActivity.java

/**
 * Initializes the symbols shortcut bar.
 *//*from  w  w  w.  java 2s  . c o  m*/
private void initSymbols() {
    // It actually only initializes the "+" button, creating a popup menu
    final Button button = (Button) findViewById(R.id.maths_button);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            // Shows a popup menu
            PopupMenu popup = new PopupMenu(EditorActivity.this, button);
            popup.getMenuInflater().inflate(R.menu.menu_maths, popup.getMenu());
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem menuItem) {
                    // On symbol click
                    insertSymbol(menuItem.getTitle().toString());
                    return false;
                }
            });
            popup.show();
        }
    });
}

From source file:sharedcode.turboeditor.activity.SelectFileActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

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

    Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
    setSupportActionBar(toolbar);//  w ww .  j a  v a2  s . co m

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Actions action = (Actions) getIntent().getExtras().getSerializable("action");
    wantAFile = 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.SD_CARD_ROOT);
        file = new File(PreferenceHelper.SD_CARD_ROOT);
    }

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

From source file:com.notalenthack.blaster.CommandActivity.java

@Override
public void onClick(View v) {
    Integer position = (Integer) v.getTag();
    if (v.getId() == R.id.btnEditCommand) {
        final Command cmd = mListAdapter.getCommand(position);
        Log.d(TAG, "Edit button click for position " + position);
        //Creating the instance of PopupMenu
        PopupMenu popup = new PopupMenu(this, v);
        //Inflating the Popup using xml file
        popup.getMenuInflater().inflate(R.menu.edit_delete, popup.getMenu());
        popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
            @Override//from ww w  .j a  v  a 2 s. com
            public boolean onMenuItemClick(MenuItem item) {
                if (item.getItemId() == R.id.edit) {
                    editCommand(cmd);
                } else if (item.getItemId() == R.id.delete) {
                    mListAdapter.deleteCommand(cmd);
                } else {
                    return false;
                }
                saveCommands(); // update commands in pref for presistent
                mListAdapter.notifyDataSetChanged();
                return true;
            }
        });

        // show the popup
        popup.show();

    } else if (v.getId() == R.id.btnCommandAction) {
        Log.d(TAG, "Play button click for position " + position);
        handlePlayCommand(position);
    }
}

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  ww  w  .  j a v a2  s . 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());
}