Example usage for android.app Activity onPrepareOptionsMenu

List of usage examples for android.app Activity onPrepareOptionsMenu

Introduction

In this page you can find the example usage for android.app Activity onPrepareOptionsMenu.

Prototype

public boolean onPrepareOptionsMenu(Menu menu) 

Source Link

Document

Prepare the Screen's standard options menu to be displayed.

Usage

From source file:com.vuze.android.remote.AndroidUtilsUI.java

public static boolean popupContextMenu(final Activity activity, String title) {
    MenuBuilder menuBuilder = new MenuBuilder(activity);

    if (title != null) {
        try {//  w w  w.  j av  a  2s  .  c  om
            Method mSetHeaderTitle = menuBuilder.getClass().getDeclaredMethod("setHeaderTitleInt",
                    CharSequence.class);
            if (mSetHeaderTitle != null) {
                mSetHeaderTitle.setAccessible(true);
                mSetHeaderTitle.invoke(menuBuilder, title);
            }
        } catch (Throwable ignore) {
        }
    }

    if (!activity.onCreateOptionsMenu(menuBuilder)) {
        return false;
    }

    activity.onPrepareOptionsMenu(menuBuilder);

    menuBuilder.setCallback(new MenuBuilder.Callback() {
        @Override
        public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
            return activity.onOptionsItemSelected(item);
        }

        @Override
        public void onMenuModeChange(MenuBuilder menu) {

        }
    });

    MenuDialogHelper menuDialogHelper = new MenuDialogHelper(menuBuilder);
    menuDialogHelper.show(null);

    return true;
}