예제 #1
0
 /// <summary>Invokes the item by calling various listeners or callbacks.</summary>
 /// <remarks>Invokes the item by calling various listeners or callbacks.</remarks>
 /// <returns>true if the invocation was handled, false otherwise</returns>
 public bool invoke()
 {
     if (mClickListener != null && mClickListener.onMenuItemClick(this))
     {
         return(true);
     }
     if (mMenu.dispatchMenuItemSelected(mMenu.getRootMenu(), this))
     {
         return(true);
     }
     if (mItemCallback != null)
     {
         mItemCallback.run();
         return(true);
     }
     if (mIntent != null)
     {
         try
         {
             mMenu.getContext().startActivity(mIntent);
             return(true);
         }
         catch (android.content.ActivityNotFoundException e)
         {
             android.util.Log.e(TAG, "Can't find activity to handle intent; ignoring", e);
         }
     }
     if (mActionProvider != null && mActionProvider.onPerformDefaultAction())
     {
         return(true);
     }
     return(false);
 }
예제 #2
0
 /// <summary>Instantiates this menu item.</summary>
 /// <remarks>Instantiates this menu item.</remarks>
 /// <param name="menu"></param>
 /// <param name="group">
 /// Item ordering grouping control. The item will be added after
 /// all other items whose order is &lt;= this number, and before any
 /// that are larger than it. This can also be used to define
 /// groups of items for batch state changes. Normally use 0.
 /// </param>
 /// <param name="id">Unique item ID. Use 0 if you do not need a unique ID.</param>
 /// <param name="categoryOrder">The ordering for this item.</param>
 /// <param name="title">The text to display for the item.</param>
 internal MenuItemImpl([email protected] menu, int group, int
                       id, int categoryOrder, int ordering, java.lang.CharSequence title, int showAsAction
                       )
 {
     if (sPrependShortcutLabel == null)
     {
         // This is instantiated from the UI thread, so no chance of sync issues
         sPrependShortcutLabel = menu.getContext().getResources().getString([email protected]
                                                                            [email protected]_shortcut_label);
         sEnterShortcutLabel = menu.getContext().getResources().getString([email protected]
                                                                          [email protected]_enter_shortcut_label);
         sDeleteShortcutLabel = menu.getContext().getResources().getString([email protected]
                                                                           [email protected]_delete_shortcut_label);
         sSpaceShortcutLabel = menu.getContext().getResources().getString([email protected]
                                                                          [email protected]_space_shortcut_label);
     }
     mMenu          = menu;
     mId            = id;
     mGroup         = group;
     mCategoryOrder = categoryOrder;
     mOrdering      = ordering;
     mTitle         = title;
     mShowAsAction  = showAsAction;
 }
예제 #3
0
 /// <summary>Shows menu as a dialog.</summary>
 /// <remarks>Shows menu as a dialog.</remarks>
 /// <param name="windowToken">Optional token to assign to the window.</param>
 public virtual void show(android.os.IBinder windowToken)
 {
     // Many references to mMenu, create local reference
     [email protected] menu = mMenu;
     // Get the builder for the dialog
     android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(menu
                                                                                   .getContext());
     mPresenter = new [email protected](builder.getContext
                                                                        (), [email protected]_menu_item_layout);
     mPresenter.setCallback(this);
     mMenu.addMenuPresenter(mPresenter);
     builder.setAdapter(mPresenter.getAdapter(), this);
     // Set the title
     android.view.View headerView = menu.getHeaderView();
     if (headerView != null)
     {
         // Menu's client has given a custom header view, use it
         builder.setCustomTitle(headerView);
     }
     else
     {
         // Otherwise use the (text) title and icon
         builder.setIcon(menu.getHeaderIcon()).setTitle(menu.getHeaderTitle());
     }
     // Set the key listener
     builder.setOnKeyListener(this);
     // Show the menu
     mDialog = builder.create();
     mDialog.setOnDismissListener(this);
     android.view.WindowManagerClass.LayoutParams lp = mDialog.getWindow().getAttributes
                                                           ();
     lp.type = android.view.WindowManagerClass.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
     if (windowToken != null)
     {
         lp.token = windowToken;
     }
     lp.flags |= android.view.WindowManagerClass.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
     mDialog.show();
 }