Example usage for android.widget PopupMenu inflate

List of usage examples for android.widget PopupMenu inflate

Introduction

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

Prototype

public void inflate(@MenuRes int menuRes) 

Source Link

Document

Inflate a menu resource into this PopupMenu.

Usage

From source file:systems.soapbox.ombuds.client.ui.BlockListFragment.java

@Override
public void onBlockMenuClick(final View view, final StoredBlock block) {
    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.blocks_context);

    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override//from ww w  .j  ava  2 s . com
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.blocks_context_browse:
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.withAppendedPath(config.getBlockExplorer(),
                        "block/" + block.getHeader().getHashAsString())));
                return true;
            }
            return false;
        }
    });
    popupMenu.show();
}

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.
 *///from  ww  w  .j  ava 2 s  .co  m
@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:com.tcity.android.ui.overview.project.ProjectOverviewActivity.java

void projectOptionsClick(@NotNull String id, @NotNull View anchor) {
    PopupMenu menu = new PopupMenu(this, anchor);

    menu.inflate(R.menu.menu_concept);

    menu.setOnMenuItemClickListener(new PopupMenuListener(WebLocator.getProjectUrl(id, new Preferences(this))));

    menu.show();/* w  ww . j  ava2 s .  c  o  m*/
}

From source file:com.tcity.android.ui.overview.project.ProjectOverviewActivity.java

void buildConfigurationOptionsClick(@NotNull String id, @NotNull View anchor) {
    PopupMenu menu = new PopupMenu(this, anchor);

    menu.inflate(R.menu.menu_concept);

    menu.setOnMenuItemClickListener(//w  ww  .ja  v  a 2  s.com
            new PopupMenuListener(WebLocator.getBuildConfigurationUrl(id, new Preferences(this))));

    menu.show();
}

From source file:com.battlelancer.seriesguide.ui.MoviesSearchFragment.java

@Override
public void onPopupMenuClick(View v, final int movieTmdbId) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.movies_popup_menu);

    // check if movie is already in watchlist or collection
    boolean isInWatchlist = false;
    boolean isInCollection = false;
    Cursor movie = getActivity().getContentResolver().query(
            SeriesGuideContract.Movies.buildMovieUri(movieTmdbId),
            new String[] { SeriesGuideContract.Movies.IN_WATCHLIST, SeriesGuideContract.Movies.IN_COLLECTION },
            null, null, null);//from w ww  .  ja  va  2s .co m
    if (movie != null) {
        if (movie.moveToFirst()) {
            isInWatchlist = movie.getInt(0) == 1;
            isInCollection = movie.getInt(1) == 1;
        }
        movie.close();
    }

    Menu menu = popupMenu.getMenu();
    menu.findItem(R.id.menu_action_movies_watchlist_add).setVisible(!isInWatchlist);
    menu.findItem(R.id.menu_action_movies_watchlist_remove).setVisible(isInWatchlist);
    menu.findItem(R.id.menu_action_movies_collection_add).setVisible(!isInCollection);
    menu.findItem(R.id.menu_action_movies_collection_remove).setVisible(isInCollection);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_action_movies_watchlist_add: {
                MovieTools.addToWatchlist(getActivity(), movieTmdbId);
                fireTrackerEvent("Add to watchlist");
                return true;
            }
            case R.id.menu_action_movies_watchlist_remove: {
                MovieTools.removeFromWatchlist(getActivity(), movieTmdbId);
                fireTrackerEvent("Remove from watchlist");
                return true;
            }
            case R.id.menu_action_movies_collection_add: {
                MovieTools.addToCollection(getActivity(), movieTmdbId);
                fireTrackerEvent("Add to collection");
                return true;
            }
            case R.id.menu_action_movies_collection_remove: {
                MovieTools.removeFromCollection(getActivity(), movieTmdbId);
                fireTrackerEvent("Remove from collection");
                return true;
            }
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:com.owncloud.android.ui.adapter.UserListAdapter.java

private void onOverflowIconClicked(View view, AppCompatCheckBox allowEditsCheckBox, OCShare share) {
    // use grey as fallback for elements where custom theming is not available
    if (ThemeUtils.themingEnabled(context)) {
        context.getTheme().applyStyle(R.style.FallbackThemingTheme, true);
    }//from   w  w w.j a v a 2  s .  co m
    PopupMenu popup = new PopupMenu(context, view);
    popup.inflate(R.menu.file_detail_sharing_menu);

    prepareOptionsMenu(popup.getMenu(), share);

    popup.setOnMenuItemClickListener(
            item -> optionsItemSelected(popup.getMenu(), item, allowEditsCheckBox, share));
    popup.show();
}

From source file:fr.outadev.splatcompanion.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Instantiate fragments
    fragmentRegularBattles = new FragmentRegularBattles();
    fragmentRankedBattles = new FragmentRankedBattles();

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    ViewPager viewPager = (ViewPager) findViewById(R.id.pager);

    // Setup view pager to display the different fragments
    viewPager.setAdapter(new SectionPagerAdapter(getSupportFragmentManager()));
    tabLayout.setupWithViewPager(viewPager);

    countdown = (TextView) findViewById(R.id.txt_countdown);
    progressSpinner = (ProgressBar) findViewById(R.id.progress_spinner);

    // Set up the overflow button, using a popup menu
    final ImageButton buttonOverflow = (ImageButton) findViewById(R.id.overflow_button);
    final PopupMenu menu = new PopupMenu(this, buttonOverflow);
    menu.inflate(R.menu.menu_main);

    menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override/*from  www  .j a va  2s .  c o m*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_item_refresh:
                (new FetchRotationSchedule()).execute(true);
                return true;
            case R.id.menu_item_about:
                startActivity(new Intent(ActivityMain.this, ActivityAbout.class));
                return true;
            default:
                return false;
            }
        }

    });

    buttonOverflow.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            menu.show();
        }

    });
}

From source file:com.aman.stockcalculator.Calculator.java

private PopupMenu constructPopupMenu() {
    final PopupMenu popupMenu = new PopupMenu(this, mOverflowMenuButton);
    final Menu menu = popupMenu.getMenu();
    popupMenu.inflate(R.menu.menu);
    popupMenu.setOnMenuItemClickListener(this);
    onPrepareOptionsMenu(menu);/*from   w  w w  .  j av  a2 s.  c  o  m*/
    return popupMenu;
}

From source file:com.battlelancer.seriesguide.ui.EpisodesFragment.java

@Override
public void onPopupMenuClick(View v, final int episodeTvdbId, final int episodeNumber, final long releaseTimeMs,
        final boolean isWatched, final boolean isCollected) {
    PopupMenu popupMenu = new PopupMenu(v.getContext(), v);
    popupMenu.inflate(R.menu.episodes_popup_menu);

    Menu menu = popupMenu.getMenu();
    menu.findItem(R.id.menu_action_episodes_watched).setVisible(!isWatched);
    menu.findItem(R.id.menu_action_episodes_not_watched).setVisible(isWatched);
    menu.findItem(R.id.menu_action_episodes_collection_add).setVisible(!isCollected);
    menu.findItem(R.id.menu_action_episodes_collection_remove).setVisible(isCollected);

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from w ww  .  j  a v  a  2  s  .c om*/
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.menu_action_episodes_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag watched");
                return true;
            }
            case R.id.menu_action_episodes_not_watched: {
                onFlagEpisodeWatched(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag unwatched");
                return true;
            }
            case R.id.menu_action_episodes_collection_add: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, true);
                fireTrackerEventContextMenu("Flag collected");
                return true;
            }
            case R.id.menu_action_episodes_collection_remove: {
                onFlagEpisodeCollected(episodeTvdbId, episodeNumber, false);
                fireTrackerEventContextMenu("Flag uncollected");
                return true;
            }
            case R.id.menu_action_episodes_watched_previous: {
                onMarkUntilHere(releaseTimeMs);
                fireTrackerEventContextMenu("Flag previously aired");
                return true;
            }
            case R.id.menu_action_episodes_manage_lists: {
                ManageListsDialogFragment.showListsDialog(episodeTvdbId, ListItemTypes.EPISODE,
                        getFragmentManager());
                fireTrackerEventContextMenu("Manage lists");
                return true;
            }
            }
            return false;
        }
    });
    popupMenu.show();
}

From source file:com.arcgis.android.samples.localdata.localrasterdata.FileBrowserFragment.java

private void initializeFileListView() {
    ListView lView = (ListView) (getView().findViewById(R.id.fileListView));
    lView.setBackgroundColor(Color.LTGRAY);
    LinearLayout.LayoutParams lParam = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.MATCH_PARENT);//from  w  ww.  j  av  a2 s. c o  m
    lParam.setMargins(15, 5, 15, 5);
    lView.setAdapter(this.adapter);
    lView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            chosenFile = fileList.get(position).file;
            final File sel = new File(path + "/" + chosenFile);
            if (sel.isDirectory()) {
                // Directory
                if (sel.canRead()) {
                    // Adds chosen directory to list
                    pathDirsList.add(chosenFile);
                    path = new File(sel + "");
                    loadFileList();
                    adapter.notifyDataSetChanged();
                    updateCurrentDirectoryTextView();
                } else {
                    showToast("Path does not exist or cannot be read");
                }
            } else {
                // File picked or an empty directory message clicked
                if (!mDirectoryShownIsEmpty) {
                    // show a popup menu to allow users to open a raster layer for
                    // different purpose including basemap layer, operational layer,
                    // elevation data source for BlendRenderer, or some combinations.
                    PopupMenu popupMenu = new PopupMenu(getActivity(), view);
                    popupMenu.inflate(R.menu.file_browser_popup_menu);
                    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {

                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                            case R.id.menu_raster_base_layer:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.BASEMAP_LAYER);
                                break;
                            case R.id.menu_raster_operational_layer:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.OPERATIONAL_LAYER);
                                break;
                            case R.id.menu_raster_elevation_source:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.ELEVATION_SOURCE);
                                break;
                            case R.id.menu_raster_base_elevation:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.BASEMAP_LAYER_AND_ELEVATION_SOURCE);
                                break;
                            case R.id.menu_raster_operational_elevation:
                                returnFileFinishActivity(sel.getAbsolutePath(),
                                        RasterLayerAction.OPERATIONAL_LAYER_AND_ELEVATION_SOURCE);
                                break;
                            }
                            return true;
                        }
                    });
                    popupMenu.show();
                }
            }
        }
    });

}