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:com.example.javier.MaterialDesignApp.PlayerActivity.java

public void showAudioPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
    final MenuItem backgroundAudioItem = menu.findItem(0);
    backgroundAudioItem.setCheckable(true);
    backgroundAudioItem.setChecked(enableBackgroundAudio);
    OnMenuItemClickListener clickListener = new OnMenuItemClickListener() {
        @Override// w w  w  . j a  v a  2  s .c  o m
        public boolean onMenuItemClick(MenuItem item) {
            if (item == backgroundAudioItem) {
                enableBackgroundAudio = !item.isChecked();
                return true;
            }
            return false;
        }
    };
    configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
    popup.show();
}

From source file:com.example.javier.MaterialDesignApp.PlayerActivity.java

public void showVerboseLogPopup(View v) {
    PopupMenu popup = new PopupMenu(this, v);
    Menu menu = popup.getMenu();
    menu.add(Menu.NONE, 0, Menu.NONE, R.string.logging_normal);
    menu.add(Menu.NONE, 1, Menu.NONE, R.string.logging_verbose);
    menu.setGroupCheckable(Menu.NONE, true, true);
    menu.findItem((VerboseLogUtil.areAllTagsEnabled()) ? 1 : 0).setChecked(true);
    popup.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override/*  www.  j a v  a  2 s  .c  o  m*/
        public boolean onMenuItemClick(MenuItem item) {
            if (item.getItemId() == 0) {
                VerboseLogUtil.setEnableAllTags(false);
            } else {
                VerboseLogUtil.setEnableAllTags(true);
            }
            return true;
        }
    });
    popup.show();
}

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

/**
 * Called when a previously created loader has finished its load.  Note
 * that normally an application is <em>not</em> allowed to commit fragment
 * transactions while in this call, since it can happen after an
 * activity's state is saved.  See {@link android.support.v4.app.FragmentManager#beginTransaction()
 * FragmentManager.openTransaction()} for further discussion on this.
 * <p/>/*from w  w  w  .  j a v  a  2  s  .com*/
 * <p>This function is guaranteed to be called prior to the release of
 * the last data that was supplied for this Loader.  At this point
 * you should remove all use of the old data (since it will be released
 * soon), but should not do your own release of the data since its Loader
 * owns it and will take care of that.  The Loader will take care of
 * management of its data so you don't have to.  In particular:
 * <p/>
 * <ul>
 * <li> <p>The Loader will monitor for changes to the data, and report
 * them to you through new calls here.  You should not monitor the
 * data yourself.  For example, if the data is a {@link android.database.Cursor}
 * and you place it in a {@link android.widget.CursorAdapter}, use
 * the {@link android.widget.CursorAdapter#CursorAdapter(android.content.Context,
 * android.database.Cursor, int)} constructor <em>without</em> passing
 * in either {@link android.widget.CursorAdapter#FLAG_AUTO_REQUERY}
 * or {@link android.widget.CursorAdapter#FLAG_REGISTER_CONTENT_OBSERVER}
 * (that is, use 0 for the flags argument).  This prevents the CursorAdapter
 * from doing its own observing of the Cursor, which is not needed since
 * when a change happens you will get a new Cursor throw another call
 * here.
 * <li> The Loader will release the data once it knows the application
 * is no longer using it.  For example, if the data is
 * a {@link android.database.Cursor} from a {@link android.content.CursorLoader},
 * you should not call close() on it yourself.  If the Cursor is being placed in a
 * {@link android.widget.CursorAdapter}, you should use the
 * {@link android.widget.CursorAdapter#swapCursor(android.database.Cursor)}
 * method so that the old Cursor is not closed.
 * </ul>
 *
 * @param loader The Loader that has finished.
 * @param data   The data generated by the Loader.
 */
@Override
public void onLoadFinished(Loader<ClientDevices> loader, ClientDevices data) {
    Log.d(LOG_TAG, "onLoadFinished: loader=" + loader + " / data=" + data);

    layout.findViewById(R.id.tile_status_wireless_clients_loading_view).setVisibility(View.GONE);
    layout.findViewById(R.id.tile_status_wireless_clients_layout_list_container).setVisibility(View.VISIBLE);
    layout.findViewById(R.id.tile_status_wireless_clients_togglebutton_container).setVisibility(View.VISIBLE);

    if (data == null || (data.getDevices().isEmpty()
            && !(data.getException() instanceof DDWRTTileAutoRefreshNotAllowedException))) {
        data = new ClientDevices().setException(new DDWRTNoDataException("No Data!"));
    }

    @NotNull
    final TextView errorPlaceHolderView = (TextView) this.layout
            .findViewById(R.id.tile_status_wireless_clients_error);

    @Nullable
    final Exception exception = data.getException();

    if (!(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {

        if (exception == null) {
            errorPlaceHolderView.setVisibility(View.GONE);
        }

        final GridLayout clientsContainer = (GridLayout) this.layout
                .findViewById(R.id.tile_status_wireless_clients_layout_list_container);
        clientsContainer.removeAllViews();
        clientsContainer.setBackgroundColor(
                mParentFragmentActivity.getResources().getColor(android.R.color.transparent));

        final Set<Device> devices = data.getDevices(MAX_CLIENTS_TO_SHOW_IN_TILE);
        final int themeBackgroundColor = getThemeBackgroundColor(mParentFragmentActivity, mRouter.getUuid());
        final boolean isThemeLight = isThemeLight(mParentFragmentActivity, mRouter.getUuid());
        for (final Device device : devices) {

            final CardView cardView = (CardView) mParentFragmentActivity.getLayoutInflater()
                    .inflate(R.layout.tile_status_wireless_client, null);

            //Create Options Menu
            final ImageButton tileMenu = (ImageButton) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_menu);

            if (!isThemeLight) {
                //Set menu background to white
                tileMenu.setImageResource(R.drawable.abs__ic_menu_moreoverflow_normal_holo_dark);
            }

            cardView.setCardBackgroundColor(themeBackgroundColor);

            //Add padding to CardView on v20 and before to prevent intersections between the Card content and rounded corners.
            cardView.setPreventCornerOverlap(true);
            //Add padding in API v21+ as well to have the same measurements with previous versions.
            cardView.setUseCompatPadding(true);

            final TextView deviceName = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_name);
            final String name = device.getName();
            deviceName.setText(name);

            final TextView deviceMac = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_mac);
            final String macAddress = device.getMacAddress();
            deviceMac.setText(macAddress);

            final TextView deviceIp = (TextView) cardView
                    .findViewById(R.id.tile_status_wireless_client_device_ip);
            final String ipAddress = device.getIpAddress();
            final boolean isThisDevice = (ipAddress != null && ipAddress.equals(mCurrentIpAddress));
            deviceIp.setText(ipAddress);
            if (isThisDevice) {
                final View thisDevice = cardView.findViewById(R.id.tile_status_wireless_client_device_this);
                if (isThemeLight) {
                    //Set text color to blue
                    ((TextView) thisDevice)
                            .setTextColor(mParentFragmentActivity.getResources().getColor(R.color.blue));
                }
                thisDevice.setVisibility(View.VISIBLE);
            }

            cardView.setOnClickListener(new DeviceOnClickListener(device));

            clientsContainer.addView(cardView);

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

                    final Menu menu = popup.getMenu();

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

                    if (isThisDevice) {
                        //WOL not needed as this is the current device
                        menu.findItem(R.id.tile_status_wireless_client_wol).setEnabled(false);
                    }

                    popup.show();
                }
            });
        }

        final Button showMore = (Button) this.layout.findViewById(R.id.tile_status_wireless_clients_show_more);
        //Whether to display 'Show more' button
        if (data.getDevicesCount() > MAX_CLIENTS_TO_SHOW_IN_TILE) {
            showMore.setVisibility(View.VISIBLE);
            showMore.setOnClickListener(this);
        } else {
            showMore.setVisibility(View.GONE);
        }

    }

    if (exception != null && !(exception instanceof DDWRTTileAutoRefreshNotAllowedException)) {
        //noinspection ThrowableResultOfMethodCallIgnored
        final Throwable rootCause = Throwables.getRootCause(exception);
        errorPlaceHolderView.setText("Error: " + (rootCause != null ? rootCause.getMessage() : "null"));
        final Context parentContext = this.mParentFragmentActivity;
        errorPlaceHolderView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(final View v) {
                //noinspection ThrowableResultOfMethodCallIgnored
                if (rootCause != null) {
                    Toast.makeText(parentContext, rootCause.getMessage(), Toast.LENGTH_LONG).show();
                }
            }
        });
        errorPlaceHolderView.setVisibility(View.VISIBLE);
    }

    doneWithLoaderInstance(this, loader, R.id.tile_status_wireless_clients_togglebutton_title,
            R.id.tile_status_wireless_clients_togglebutton_separator);

    Log.d(LOG_TAG, "onLoadFinished(): done loading!");
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_addChannel_youtube(final View anchor) {
    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_addchannel_youtube, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override/*from ww  w  .  j a  v a  2 s.co  m*/
        public boolean onMenuItemClick(MenuItem item) {
            onOpt_addChannel_youtubeEditDiag(item);
            return true;
        }
    });
    popup.show();
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_category(final View anchor) {
    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_category, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override//from   w  w w . ja  v a2s  .  c o  m
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.add:
                onOpt_category_add(anchor);
                break;
            case R.id.rename:
                onOpt_category_rename(anchor);
                break;
            case R.id.delete:
                onOpt_category_delete(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}

From source file:com.cerema.cloud2.ui.fragment.OCFileListFragment.java

private void showFileAction(int fileIndex) {
    Bundle args = getArguments();//from  w  ww.  ja  v  a 2  s .  com
    PopupMenu pm = new PopupMenu(getActivity(), null);
    Menu menu = pm.getMenu();

    boolean allowContextualActions = (args == null) ? true
            : args.getBoolean(ARG_ALLOW_CONTEXTUAL_ACTIONS, true);

    if (allowContextualActions) {
        MenuInflater inflater = getActivity().getMenuInflater();

        inflater.inflate(R.menu.file_actions_menu, menu);
        OCFile targetFile = (OCFile) mAdapter.getItem(fileIndex);

        if (mContainerActivity.getStorageManager() != null) {
            FileMenuFilter mf = new FileMenuFilter(targetFile,
                    mContainerActivity.getStorageManager().getAccount(), mContainerActivity, getActivity());
            mf.filter(menu);
        }

        /// TODO break this direct dependency on FileDisplayActivity... if possible
        MenuItem item = menu.findItem(R.id.action_open_file_with);
        FileFragment frag = ((FileDisplayActivity) getActivity()).getSecondFragment();
        if (frag != null && frag instanceof FileDetailFragment
                && frag.getFile().getFileId() == targetFile.getFileId()) {
            item = menu.findItem(R.id.action_see_details);
            if (item != null) {
                item.setVisible(false);
                item.setEnabled(false);
            }
        }

        FileActionsDialogFragment dialog = FileActionsDialogFragment.newInstance(menu, fileIndex,
                targetFile.getFileName());
        dialog.setTargetFragment(this, 0);
        dialog.show(getFragmentManager(), FileActionsDialogFragment.FTAG_FILE_ACTIONS);
    }
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_moreMenu(final View anchor) {
    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_more_menu, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override// ww w.  jav  a 2  s  .  co m
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.about:
                onOpt_moreMenu_about(anchor);
                break;
            case R.id.license:
                onOpt_moreMenu_license(anchor);
                break;
            case R.id.media_delete_all:
                onOpt_moreMenu_deleteAllDnFiles(anchor);
                break;
            case R.id.media_delete_used_all:
                onOpt_moreMenu_deleteAllUsedDnFiles(anchor);
                break;
            case R.id.feedback_opinion:
                onOpt_moreMenu_feedbackOpinion(anchor);
                break;
            case R.id.db_management:
                onOpt_moreMenu_dbManagement(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}

From source file:net.lp.actionbarpoirot.actions.UiAction.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
void addActionItemToLeftNavBar(C context) {
    if (UiUtilities.isGoogleTV(context.getApplicationContext())) {
        try {//from ww  w .ja va 2  s.c o m
            final LeftNavBar leftNavBar = ((LeftNavBar) ((ActivityHelperHoneycomb) context.getActivityHelper())
                    .getActionBar());
            final PopupMenu tempMenu = new PopupMenu(context, leftNavBar.getCustomView());// TODO: Should not use
            // MenuItem and
            // onCreateOptionsMenu, but
            // build an own stack of
            // methods for the
            // LeftNavBar.
            leftNavBar.addActionItem(onCreateOptionsMenu(tempMenu.getMenu(), context), this);
        } catch (ClassCastException ce) {
            if (PoirotWindow.DEBUG)
                Log.d(TAG, "ClassCastException with LeftNavBar", ce);
        }
    }
}

From source file:net.lp.actionbarpoirot.actions.UiAction.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void addActionItemToLeftNavBar(C context, ActivityHelper activityHelper) {
    if (UiUtilities.isGoogleTV(context.getApplicationContext())) {
        try {//  w w w  .  ja  v  a 2s .  c o  m
            final LeftNavBar leftNavBar = ((LeftNavBar) ((ActivityHelperHoneycomb) activityHelper)
                    .getActionBar());
            final PopupMenu tempMenu = new PopupMenu(context, leftNavBar.getCustomView());// TODO: Should not use
            // MenuItem and
            // onCreateOptionsMenu, but
            // build an own stack of
            // methods for the
            // LeftNavBar.
            leftNavBar.addActionItem(onCreateOptionsMenu(tempMenu.getMenu(), context), this);
        } catch (ClassCastException ce) {
            if (PoirotWindow.DEBUG)
                Log.d(TAG, "ClassCastException with LeftNavBar", ce);
        }
    }
}

From source file:free.yhc.feeder.ChannelListActivity.java

private void onOpt_addChannel(final View anchor) {
    if (0 == mAb.getNavigationItemCount()) {
        eAssert(false);//from w  ww.  ja v  a  2s .c o m
        return;
    }

    if (0 > mAb.getSelectedNavigationIndex()) {
        UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_select_category_to_add);
        return;
    }

    if (!Utils.isNetworkAvailable()) {
        // TODO Handling error
        UiHelper.showTextToast(ChannelListActivity.this, R.string.warn_network_unavailable);
        return;
    }

    PopupMenu popup = new PopupMenu(this, anchor);
    popup.getMenuInflater().inflate(R.menu.popup_addchannel, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            switch (item.getItemId()) {
            case R.id.predefined:
                onOpt_addChannel_predefined(anchor);
                break;
            case R.id.url:
                onOpt_addChannel_url(anchor);
                break;
            case R.id.youtube:
                onOpt_addChannel_youtube(anchor);
                break;
            default:
                eAssert(false);
            }
            return true;
        }
    });
    popup.show();
}