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: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);/*  w w  w . ja v a2 s  . 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.jrummyapps.busybox.fragments.ScriptsFragment.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final ShellScript script = adapter.getItem(position);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // hack to get the popupmenu color working on Android 6.0+ for custom color schemes
        ContextCompat.getDrawable(getActivity(), R.drawable.bg_popup_dark);
        ContextCompat.getDrawable(getActivity(), R.drawable.bg_popup_light);
    }/*from w w  w  .  j a v a  2 s. c o m*/

    PopupMenu popupMenu = new PopupMenu(getActivity(), view);

    popupMenu.getMenu().add(0, 1, 0, R.string.run).setIcon(R.drawable.ic_play_white_24dp);
    popupMenu.getMenu().add(0, 2, 0, R.string.edit).setIcon(R.drawable.ic_edit_white_24dp);
    popupMenu.getMenu().add(0, 3, 0, R.string.info).setIcon(R.drawable.ic_information_white_24dp);
    popupMenu.getMenu().add(0, 4, 0, R.string.delete).setIcon(R.drawable.ic_delete_white_24dp);

    getRadiant().tint(popupMenu.getMenu()).forceIcons().apply(getActivity());

    Analytics.newEvent("clicked script").put("script_name", script.name).put("script_file", script.path).log();

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case 1: { // run
                Intent intent = new Intent(getActivity(), ScriptExecutorActivity.class);
                intent.putExtra(FileIntents.INTENT_EXTRA_PATH, script.path);
                startActivity(intent);
                return true;
            }
            case 2: { // edit
                Intent intent = new Intent(getActivity(), TextEditorActivity.class);
                intent.putExtra(FileIntents.INTENT_EXTRA_PATH, script.path);
                startActivity(intent);
                return true;
            }
            case 3: { // info
                Intent intent = new Intent(getActivity(), FilePropertiesActivity.class);
                intent.putExtra(FileIntents.INTENT_EXTRA_FILE, new File(script.path));
                intent.putExtra(FilePropertiesActivity.EXTRA_DESCRIPTION, script.info);
                startActivity(intent);
                return true;
            }
            case 4: { // delete
                ShellScriptTable table = Database.getInstance().getTable(ShellScriptTable.NAME);
                boolean deleted = table.delete(script) != 0;
                if (deleted) {
                    adapter.scripts.remove(script);
                    adapter.notifyDataSetChanged();
                    new File(script.path).delete();
                }
                return true;
            }
            default:
                return false;
            }
        }
    });

    popupMenu.show();
}

From source file:org.gateshipone.malp.application.views.NowPlayingView.java

/**
     * Called to open the popup menu on the top right corner.
     *//www.java 2 s .  co m
     * @param v
     */
    private void showAdditionalOptionsMenu(View v) {
        PopupMenu menu = new PopupMenu(getContext(), v);
        // Inflate the menu from a menu xml file
        menu.inflate(R.menu.popup_menu_nowplaying);
        // Set the main NowPlayingView as a listener (directly implements callback)
        menu.setOnMenuItemClickListener(this);

        // Set the checked menu item state if a MPDCurrentStatus is available
        if (null != mLastStatus) {
            MenuItem singlePlaybackItem = menu.getMenu().findItem(R.id.action_toggle_single_mode);
            singlePlaybackItem.setChecked(mLastStatus.getSinglePlayback() == 1);

            MenuItem consumeItem = menu.getMenu().findItem(R.id.action_toggle_consume_mode);
            consumeItem.setChecked(mLastStatus.getConsume() == 1);
        }

        // Check if the current view is the cover or the playlist. If it is the playlist hide its actions.
        // If the viewswitcher only has one child the dual pane layout is used
        if (mViewSwitcher.getDisplayedChild() == 0 && (mViewSwitcher.getChildCount() > 1)) {
            menu.getMenu().setGroupEnabled(R.id.group_playlist_actions, false);
            menu.getMenu().setGroupVisible(R.id.group_playlist_actions, false);
        }
        // Open the menu itself
        menu.show();
    }

From source file:org.catnut.adapter.TweetAdapter.java

private void showPopupMenu(View view) {
    final Bean bean = (Bean) view.getTag();
    PopupMenu popup = new PopupMenu(mContext, view);
    Menu menu = popup.getMenu();//from   w w w  . j a  v  a 2  s .co  m
    popup.getMenuInflater().inflate(R.menu.tweet_overflow, menu);
    MenuItem item = menu.findItem(R.id.action_favorite);
    item.setTitle(bean.favorited ? R.string.cancle_favorite : R.string.favorite);
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.action_favorite:
                mRequestQueue.add(new CatnutRequest(mContext,
                        bean.favorited ? FavoritesAPI.destroy(bean.id) : FavoritesAPI.create(bean.id),
                        new StatusProcessor.FavoriteTweetProcessor(), new Response.Listener<JSONObject>() {
                            @Override
                            public void onResponse(JSONObject response) {
                                Toast.makeText(mContext, bean.favorited ? R.string.cancle_favorite_success
                                        : R.string.favorite_success, Toast.LENGTH_SHORT).show();
                            }
                        }, new Response.ErrorListener() {
                            @Override
                            public void onErrorResponse(VolleyError error) {
                                WeiboAPIError weiboAPIError = WeiboAPIError.fromVolleyError(error);
                                Toast.makeText(mContext, weiboAPIError.error, Toast.LENGTH_LONG).show();
                            }
                        }));
                break;
            case R.id.action_like:
                Toast.makeText(mContext, "sina not provide this option...", Toast.LENGTH_SHORT).show();
                break;
            case android.R.id.copy:
                CatnutUtils.copy2ClipBoard(mContext, mContext.getString(R.string.tweet), bean.text,
                        mContext.getString(R.string.tweet_text_copied));
                break;
            default:
                break;
            }
            return false;
        }
    });
    popup.show();
}

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

@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, final long id) {
    PopupMenu popupMenu = new PopupMenu(view.getContext(), view);
    Menu menu = popupMenu.getMenu();

    Cursor episode = (Cursor) mAdapter.getItem(position);
    if (episode == null) {
        return false;
    }/*from ww  w.java2 s . co  m*/

    // only display the action appropriate for the items current state
    menu.add(0, CONTEXT_CHECKIN_ID, 0, R.string.checkin);
    if (EpisodeTools.isWatched(episode.getInt(ActivityQuery.WATCHED))) {
        menu.add(0, CONTEXT_FLAG_UNWATCHED_ID, 1, R.string.action_unwatched);
    } else {
        menu.add(0, CONTEXT_FLAG_WATCHED_ID, 1, R.string.action_watched);
    }
    if (EpisodeTools.isCollected(episode.getInt(ActivityQuery.COLLECTED))) {
        menu.add(0, CONTEXT_COLLECTION_REMOVE_ID, 2, R.string.action_collection_remove);
    } else {
        menu.add(0, CONTEXT_COLLECTION_ADD_ID, 2, R.string.action_collection_add);
    }

    final int showTvdbId = episode.getInt(ActivityQuery.SHOW_ID);
    final int episodeTvdbId = episode.getInt(ActivityQuery._ID);
    final int seasonNumber = episode.getInt(ActivityQuery.SEASON);
    final int episodeNumber = episode.getInt(ActivityQuery.NUMBER);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case CONTEXT_CHECKIN_ID: {
                checkInEpisode((int) id);
                return true;
            }
            case CONTEXT_FLAG_WATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_FLAG_UNWATCHED_ID: {
                updateEpisodeWatchedState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            case CONTEXT_COLLECTION_ADD_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, true);
                return true;
            }
            case CONTEXT_COLLECTION_REMOVE_ID: {
                updateEpisodeCollectionState(showTvdbId, episodeTvdbId, seasonNumber, episodeNumber, false);
                return true;
            }
            }
            return false;
        }
    });

    popupMenu.show();

    return true;
}

From source file:nl.mpcjanssen.simpletask.Simpletask.java

private void updateRightDrawer() {
    ArrayList<String> names = new ArrayList<String>();
    final ArrayList<ActiveFilter> filters = getSavedFilter();
    Collections.sort(filters, new Comparator<ActiveFilter>() {
        public int compare(@NotNull ActiveFilter f1, @NotNull ActiveFilter f2) {
            return f1.getName().compareToIgnoreCase(f2.getName());
        }/*  www. j  av  a 2 s. c o  m*/
    });
    for (ActiveFilter f : filters) {
        names.add(f.getName());
    }
    m_rightDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, names));
    m_rightDrawerList.setChoiceMode(AbsListView.CHOICE_MODE_NONE);
    m_rightDrawerList.setLongClickable(true);
    m_rightDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mFilter = filters.get(position);
            Intent intent = getIntent();
            mFilter.saveInIntent(intent);
            setIntent(intent);
            mFilter.saveInPrefs(TodoApplication.getPrefs());
            m_adapter.setFilteredTasks();
            if (m_drawerLayout != null) {
                m_drawerLayout.closeDrawer(Gravity.RIGHT);
            }
            finishActionmode();
            updateDrawers();
        }
    });
    m_rightDrawerList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final ActiveFilter filter = filters.get(position);
            final String prefsName = filter.getPrefName();
            PopupMenu popupMenu = new PopupMenu(Simpletask.this, view);
            popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(@NotNull MenuItem item) {
                    int menuid = item.getItemId();
                    switch (menuid) {
                    case R.id.menu_saved_filter_delete:
                        deleteSavedFilter(prefsName);
                        break;
                    case R.id.menu_saved_filter_shortcut:
                        createFilterShortcut(filter);
                        break;
                    case R.id.menu_saved_filter_rename:
                        renameSavedFilter(prefsName);
                        break;
                    case R.id.menu_saved_filter_update:
                        updateSavedFilter(prefsName);
                        break;
                    default:
                        break;
                    }
                    return true;
                }
            });
            MenuInflater inflater = popupMenu.getMenuInflater();
            inflater.inflate(R.menu.saved_filter, popupMenu.getMenu());
            popupMenu.show();
            return true;
        }
    });
}

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);
    }//  w  w  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:fr.shywim.antoinedaniel.ui.fragment.VideoDetailsFragment.java

private void bindSound(View view, Cursor cursor) {
    AppState appState = AppState.getInstance();

    final View card = view;
    final View downloadFrame = view.findViewById(R.id.sound_download_frame);
    final TextView tv = (TextView) view.findViewById(R.id.grid_text);
    final SquareImageView siv = (SquareImageView) view.findViewById(R.id.grid_image);
    final ImageView star = (ImageView) view.findViewById(R.id.ic_sound_fav);
    final ImageView menu = (ImageView) view.findViewById(R.id.ic_sound_menu);

    final String soundName = cursor
            .getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_SOUND_NAME));
    String imgId = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_IMAGE_NAME));
    final String description = cursor.getString(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DESC));
    final boolean favorite = appState.favSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_FAVORITE)) == 1;
    final boolean widget = appState.widgetSounds.contains(soundName)
            || cursor.getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_WIDGET)) == 1;
    final boolean downloaded = cursor
            .getInt(cursor.getColumnIndex(ProviderContract.SoundEntry.COLUMN_DOWNLOADED)) != 0;

    new Handler().post(new Runnable() {
        @Override/*w ww. j  av  a 2s . c o  m*/
        public void run() {
            ContentValues cv = new ContentValues();
            File sndFile = new File(mContext.getExternalFilesDir(null) + "/snd/" + soundName + ".ogg");

            if (downloaded && !sndFile.exists()) {
                cv.put(ProviderContract.SoundEntry.COLUMN_DOWNLOADED, 0);
                mContext.getContentResolver().update(
                        Uri.withAppendedPath(ProviderConstants.SOUND_DOWNLOAD_NOTIFY_URI, soundName), cv, null,
                        null);
            }
        }
    });

    final View.OnClickListener playSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String category = mContext.getString(R.string.ana_cat_sound);
            String action = mContext.getString(R.string.ana_act_play);

            Bundle extras = new Bundle();
            extras.putString(SoundFragment.SOUND_TO_PLAY, soundName);
            extras.putBoolean(SoundFragment.LOOP, SoundUtils.isLoopingSet());
            Intent intent = new Intent(mContext, SoundService.class);
            intent.putExtras(extras);

            mContext.startService(intent);
            AnalyticsUtils.sendEvent(category, action, soundName);
        }
    };

    final View.OnClickListener downloadSound = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            card.setOnClickListener(null);
            RotateAnimation animation = new RotateAnimation(0, 360, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            animation.setInterpolator(new BounceInterpolator());
            animation.setFillAfter(true);
            animation.setFillEnabled(true);
            animation.setDuration(1000);
            animation.setRepeatCount(Animation.INFINITE);
            animation.setRepeatMode(Animation.RESTART);
            downloadFrame.findViewById(R.id.sound_download_icon).startAnimation(animation);

            DownloadService.startActionDownloadSound(mContext, soundName,
                    new SoundUtils.DownloadResultReceiver(new Handler(), downloadFrame, playSound, this));
        }
    };

    if (downloaded) {
        downloadFrame.setVisibility(View.GONE);
        downloadFrame.findViewById(R.id.sound_download_icon).clearAnimation();
        card.setOnClickListener(playSound);
    } else {
        downloadFrame.setAlpha(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleX(1);
        downloadFrame.findViewById(R.id.sound_download_icon).setScaleY(1);
        downloadFrame.setVisibility(View.VISIBLE);
        card.setOnClickListener(downloadSound);
    }

    menu.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final ImageView menuIc = (ImageView) v;
            PopupMenu popup = new PopupMenu(mContext, menuIc);
            Menu menu = popup.getMenu();
            popup.getMenuInflater().inflate(R.menu.sound_menu, menu);

            if (favorite)
                menu.findItem(R.id.action_sound_fav).setTitle("Retirer des favoris");
            if (widget)
                menu.findItem(R.id.action_sound_wid).setTitle("Retirer du widget");

            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                    case R.id.action_sound_fav:
                        SoundUtils.addRemoveFavorite(mContext, soundName);
                        return true;
                    case R.id.action_sound_wid:
                        SoundUtils.addRemoveWidget(mContext, soundName);
                        return true;
                    /*case R.id.action_sound_add:
                       return true;*/
                    case R.id.action_sound_ring:
                        SoundUtils.addRingtone(mContext, soundName, description);
                        return true;
                    case R.id.action_sound_share:
                        AnalyticsUtils.sendEvent(mContext.getString(R.string.ana_cat_soundcontext),
                                mContext.getString(R.string.ana_act_weblink), soundName);
                        ClipboardManager clipboard = (ClipboardManager) mContext
                                .getSystemService(Context.CLIPBOARD_SERVICE);
                        ClipData clip = ClipData.newPlainText("BAD link", "http://bad.shywim.fr/" + soundName);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(mContext, R.string.toast_link_copied, Toast.LENGTH_LONG).show();
                        return true;
                    case R.id.action_sound_delete:
                        SoundUtils.delete(mContext, soundName);
                        return true;
                    default:
                        return false;
                    }
                }
            });

            popup.setOnDismissListener(new PopupMenu.OnDismissListener() {
                @Override
                public void onDismiss(PopupMenu menu) {
                    menuIc.setColorFilter(mContext.getResources().getColor(R.color.text_caption_dark));
                }
            });
            menuIc.setColorFilter(mContext.getResources().getColor(R.color.black));

            popup.show();
        }
    });

    tv.setText(description);
    siv.setTag(imgId);

    if (appState.favSounds.contains(soundName)) {
        star.setVisibility(View.VISIBLE);
    } else if (favorite) {
        star.setVisibility(View.VISIBLE);
        appState.favSounds.add(soundName);
    } else {
        star.setVisibility(View.INVISIBLE);
    }

    File file = new File(mContext.getExternalFilesDir(null) + "/img/" + imgId + ".jpg");
    Picasso.with(mContext).load(file).placeholder(R.drawable.noimg).fit().into(siv);
}

From source file:lewa.support.v7.internal.widget.ActionBarContextView.java

private void initTitle() {
    if (!lewaInitTitle()) {
        if (mTitleLayout == null) {
            LayoutInflater inflater = LayoutInflater.from(getContext());
            inflater.inflate(R.layout.action_bar_title_item_with_spinner, this);
            //inflater.inflate(R.layout.abc_action_bar_title_item, this);
            mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
            // mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
            // mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
            // if (mTitleStyleRes != 0) {
            // mTitleView.setTextAppearance(mContext, mTitleStyleRes);
            // }// w ww  .ja  v a 2 s  .c o  m
            // if (mSubtitleStyleRes != 0) {
            // mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
            // }

            mSpinner = (Button) mTitleLayout.findViewById(R.id.action_bar_spinner);
            mSpinner.setText("One item selected");

            final PopupMenu popMenu = new PopupMenu(mContext, mSpinner);
            final Menu menu = popMenu.getMenu();
            menu.add(Menu.NONE, android.R.id.selectAll, Menu.NONE, android.R.string.selectAll);
            popMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                    if (null != mActionMode) {
                        if (mActionMode instanceof ActionModeImpl) {
                            return ((ActionModeImpl) mActionMode).onMenuItemSelected((MenuBuilder) menu, item);
                        }
                        if (mActionMode instanceof StandaloneActionMode) {
                            return ((StandaloneActionMode) mActionMode).onMenuItemSelected((MenuBuilder) menu,
                                    item);
                        }
                        // Woody Guo @ 2012/12/18: State of the selection menu item
                        // is totally controlled by the calling client
                        /*
                         * mActionMode.setSelectionMode(
                         *         ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                         *         ? ActionMode.SELECT_NONE : ActionMode.SELECT_ALL);
                         * item.setTitle(ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                         *         ? android.R.string.selectAll : R.string.selectNone);
                         * return true;
                         */
                    }
                    return false;
                }
            });

            mSpinner.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    popMenu.getMenu().getItem(0)
                            .setTitle(ActionMode.SELECT_ALL == mActionMode.getSelectionMode()
                                    ? android.R.string.selectAll
                                    : R.string.selectNone);
                    popMenu.show();
                }
            });
        }

        mSpinner.setText(mTitle);
    }
    if (true) {
        if (mTitleView != null) {
            mTitleView.setText(mTitle);
        }
        //mSubtitleView.setText(mSubtitle);
    }
    final boolean hasTitle = !TextUtils.isEmpty(mTitle);
    //final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle);
    //mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE);
    //mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE);
    mTitleLayout.setVisibility(hasTitle ? VISIBLE : GONE);
    if (mTitleLayout.getParent() == null) {
        addView(mTitleLayout);
    }
}

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

@Override
public void onTransactionMenuClick(final View view, final Transaction tx) {
    final boolean txSent = tx.getValue(wallet).signum() < 0;
    final Address txAddress = txSent ? WalletUtils.getToAddressOfSent(tx, wallet)
            : WalletUtils.getWalletAddressOfReceived(tx, wallet);
    final byte[] txSerialized = tx.unsafeBitcoinSerialize();
    final boolean txRotation = tx.getPurpose() == Purpose.KEY_ROTATION;

    final PopupMenu popupMenu = new PopupMenu(activity, view);
    popupMenu.inflate(R.menu.wallet_transactions_context);
    final MenuItem editAddressMenuItem = popupMenu.getMenu()
            .findItem(R.id.wallet_transactions_context_edit_address);
    if (!txRotation && txAddress != null) {
        editAddressMenuItem.setVisible(true);
        final boolean isAdd = AddressBookProvider.resolveLabel(activity, txAddress.toString()) == null;
        final boolean isOwn = wallet.isPubKeyHashMine(txAddress.getHash160());

        if (isOwn)
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add_receive
                    : R.string.edit_address_book_entry_dialog_title_edit_receive);
        else//w ww.ja v  a  2  s  .  c o m
            editAddressMenuItem.setTitle(isAdd ? R.string.edit_address_book_entry_dialog_title_add
                    : R.string.edit_address_book_entry_dialog_title_edit);
    } else {
        editAddressMenuItem.setVisible(false);
    }

    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_show_qr)
            .setVisible(!txRotation && txSerialized.length < SHOW_QR_THRESHOLD_BYTES);
    popupMenu.getMenu().findItem(R.id.wallet_transactions_context_raise_fee)
            .setVisible(RaiseFeeDialogFragment.feeCanBeRaised(wallet, tx));
    popupMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(final MenuItem item) {
            switch (item.getItemId()) {
            case R.id.wallet_transactions_context_edit_address:
                handleEditAddress(tx);
                return true;

            case R.id.wallet_transactions_context_show_qr:
                handleShowQr();
                return true;

            case R.id.wallet_transactions_context_browse:
                if (!txRotation)
                    startActivity(new Intent(Intent.ACTION_VIEW,
                            Uri.withAppendedPath(config.getBlockExplorer(), "tx/" + tx.getHashAsString())));
                else
                    startActivity(new Intent(Intent.ACTION_VIEW, KEY_ROTATION_URI));
                return true;

            case R.id.wallet_transactions_context_raise_fee:
                RaiseFeeDialogFragment.show(getFragmentManager(), tx);
                return true;
            }

            return false;
        }

        private void handleEditAddress(final Transaction tx) {
            EditAddressBookEntryFragment.edit(getFragmentManager(), txAddress);
        }

        private void handleShowQr() {
            final int size = getResources().getDimensionPixelSize(R.dimen.bitmap_dialog_qr_size);
            final Bitmap qrCodeBitmap = Qr.bitmap(Qr.encodeCompressBinary(txSerialized), size);
            BitmapFragment.show(getFragmentManager(), qrCodeBitmap);
        }
    });
    popupMenu.show();
}