Ejemplo n.º 1
0
 public boolean onActionItemClicked(ActionMode mode, MenuItem mi) {
   AbsMenuBridge item = items.get(mi.getItemId());
   if (item != null) {
     return item.onOptionsItemSelected(mi);
   }
   return false;
 }
Ejemplo n.º 2
0
 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
   if (titleChanged) {
     titleChanged = false;
     mode.setTitle(Utility.evalValue(mTitleObservable, CharSequence.class));
   }
   if (invalidated) {
     invalidated = false;
     for (AbsMenuBridge item : items.values()) {
       item.onPrepareOptionItem(menu);
     }
     return true;
   }
   return false;
 }
Ejemplo n.º 3
0
  public boolean onCreateActionMode(ActionMode mode, Menu menu) {

    mActionMode = mode;

    // First inflate the menu - default action
    mode.getMenuInflater().inflate(mMenuResId, menu);

    // Now, parse the menu
    XmlResourceParser parser = mContext.getResources().getXml(mMenuResId);
    try {
      int eventType = parser.getEventType();
      while (eventType != XmlResourceParser.END_DOCUMENT) {
        if (eventType == XmlResourceParser.START_TAG) {
          int id = parser.getAttributeResourceValue(Binder.ANDROID_NAMESPACE, "id", -1);
          MenuItem mi = menu.findItem(id);
          if (mi != null) {
            String nodeName = parser.getName();
            if (id > 0) {
              AttributeSet attrs = Xml.asAttributeSet(parser);
              AbsMenuBridge item = null;
              if ("item".equals(nodeName)) {
                item = new MenuItemBridge(id, attrs, mContext, mModel, this);
              } else if ("group".equals(nodeName)) {
                item = new MenuGroupBridge(id, attrs, mContext, mModel, this);
              }
              if (item != null) {
                items.put(id, item);
              }
            }
          }
        }
        eventType = parser.next();
      }
    } catch (XmlPullParserException e) {
      e.printStackTrace();
    } catch (IOException ex) {
      ex.printStackTrace();
    }

    for (AbsMenuBridge item : items.values()) {
      item.onCreateOptionItem(menu);
      item.onPrepareOptionItem(menu);
    }
    return true;
  }