/**
  * Sets up the options menu when the menu button is push, dynamic population of the station select
  * menu
  */
 public boolean onPrepareOptionsMenu(Menu menu) {
   menu.clear();
   boolean result = super.onCreateOptionsMenu(menu);
   SubMenu subMenu = menu.addSubMenu(BASE_OPTION_MENU, FM_BAND, Menu.NONE, R.string.band_select);
   subMenu.setIcon(android.R.drawable.ic_menu_mapmode);
   // Populate the band selection menu
   subMenu.add(BAND_SELECTION_MENU, BAND_US, Menu.NONE, R.string.band_us);
   subMenu.add(BAND_SELECTION_MENU, BAND_EU, Menu.NONE, R.string.band_eu);
   subMenu.add(BAND_SELECTION_MENU, BAND_CHINA, Menu.NONE, R.string.band_ch);
   subMenu.add(BAND_SELECTION_MENU, BAND_JAPAN, Menu.NONE, R.string.band_ja);
   subMenu.setGroupCheckable(BAND_SELECTION_MENU, true, true);
   subMenu.getItem(mSelectedBand).setChecked(true);
   return result;
 }
 /**
  * @param menu
  * @param activity
  * @param res
  * @return the added menu item (also for a sub menu, then the menu item in the parent menu is
  *     returned)
  */
 public static MenuItem addMenuItems(Menu menu, Activity activity, Resources res) {
   List<CacheListApp> activeApps = new ArrayList<CacheListApp>();
   for (CacheListApp app : getMultiPointNavigationApps()) {
     if (app.isInstalled(activity)) {
       activeApps.add(app);
     }
   }
   // use a new sub menu, if more than one app is available
   if (activeApps.size() > 1) {
     SubMenu subMenu =
         menu.addSubMenu(0, 101, 0, res.getString(R.string.caches_on_map))
             .setIcon(android.R.drawable.ic_menu_mapmode);
     for (CacheListApp app : activeApps) {
       subMenu.add(0, app.getId(), 0, app.getName());
     }
     return subMenu.getItem();
   } else if (activeApps.size() == 1) {
     return menu.add(0, activeApps.get(0).getId(), 0, activeApps.get(0).getName())
         .setIcon(android.R.drawable.ic_menu_mapmode);
   }
   return null;
 }
Beispiel #3
0
  public boolean bindNativeOverflow(
      android.view.Menu menu,
      android.view.MenuItem.OnMenuItemClickListener listener,
      HashMap<android.view.MenuItem, MenuItemImpl> map) {
    final List<MenuItemImpl> nonActionItems = getNonActionItems();
    if (nonActionItems == null || nonActionItems.size() == 0) {
      return false;
    }

    boolean visible = false;
    menu.clear();
    for (MenuItemImpl nonActionItem : nonActionItems) {
      if (!nonActionItem.isVisible()) {
        continue;
      }
      visible = true;

      android.view.MenuItem nativeItem;
      if (nonActionItem.hasSubMenu()) {
        android.view.SubMenu nativeSub =
            menu.addSubMenu(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());

        SubMenuBuilder subMenu = (SubMenuBuilder) nonActionItem.getSubMenu();
        for (MenuItemImpl subItem : subMenu.getVisibleItems()) {
          android.view.MenuItem nativeSubItem =
              nativeSub.add(
                  subItem.getGroupId(),
                  subItem.getItemId(),
                  subItem.getOrder(),
                  subItem.getTitle());

          nativeSubItem.setIcon(subItem.getIcon());
          nativeSubItem.setOnMenuItemClickListener(listener);
          nativeSubItem.setEnabled(subItem.isEnabled());
          nativeSubItem.setIntent(subItem.getIntent());
          nativeSubItem.setNumericShortcut(subItem.getNumericShortcut());
          nativeSubItem.setAlphabeticShortcut(subItem.getAlphabeticShortcut());
          nativeSubItem.setTitleCondensed(subItem.getTitleCondensed());
          nativeSubItem.setCheckable(subItem.isCheckable());
          nativeSubItem.setChecked(subItem.isChecked());

          if (subItem.isExclusiveCheckable()) {
            nativeSub.setGroupCheckable(subItem.getGroupId(), true, true);
          }

          map.put(nativeSubItem, subItem);
        }

        nativeItem = nativeSub.getItem();
      } else {
        nativeItem =
            menu.add(
                nonActionItem.getGroupId(),
                nonActionItem.getItemId(),
                nonActionItem.getOrder(),
                nonActionItem.getTitle());
      }
      nativeItem.setIcon(nonActionItem.getIcon());
      nativeItem.setOnMenuItemClickListener(listener);
      nativeItem.setEnabled(nonActionItem.isEnabled());
      nativeItem.setIntent(nonActionItem.getIntent());
      nativeItem.setNumericShortcut(nonActionItem.getNumericShortcut());
      nativeItem.setAlphabeticShortcut(nonActionItem.getAlphabeticShortcut());
      nativeItem.setTitleCondensed(nonActionItem.getTitleCondensed());
      nativeItem.setCheckable(nonActionItem.isCheckable());
      nativeItem.setChecked(nonActionItem.isChecked());

      if (nonActionItem.isExclusiveCheckable()) {
        menu.setGroupCheckable(nonActionItem.getGroupId(), true, true);
      }

      map.put(nativeItem, nonActionItem);
    }
    return visible;
  }
  public static void getMenu(
      AlfrescoSession session, Menu menu, Folder parentFolder, boolean extended) {
    MenuItem mi;

    if (parentFolder == null) {
      return;
    }

    Permissions permission =
        session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder);

    if (!extended && parentFolder != null && permission.canAddChildren()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_CREATE_FOLDER,
              Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER,
              R.string.folder_create);
      mi.setIcon(R.drawable.ic_add_folder);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!extended && parentFolder != null && permission.canAddChildren()) {
      SubMenu devCaptureMenu =
          menu.addSubMenu(
              Menu.NONE,
              MenuActionItem.MENU_DEVICE_CAPTURE,
              Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE,
              R.string.upload);
      devCaptureMenu.setIcon(android.R.drawable.ic_menu_add);
      devCaptureMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

      devCaptureMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
          Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
          R.string.take_photo);

      if (AndroidVersion.isICSOrAbove()) {
        devCaptureMenu.add(
            Menu.NONE,
            MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
            Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
            R.string.make_video);
      }

      devCaptureMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
          Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
          R.string.record_audio);
      devCaptureMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_UPLOAD,
          Menu.FIRST + MenuActionItem.MENU_UPLOAD,
          R.string.content_upload);
    }

    if (extended && parentFolder != null && permission.canEdit()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_EDIT,
              Menu.FIRST + MenuActionItem.MENU_EDIT,
              R.string.edit);
      mi.setIcon(R.drawable.ic_edit);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (extended && parentFolder != null && permission.canDelete()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_DELETE_FOLDER,
              Menu.FIRST + MenuActionItem.MENU_DELETE_FOLDER,
              R.string.delete);
      mi.setIcon(R.drawable.ic_delete);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!extended && parentFolder != null) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_REFRESH,
              Menu.FIRST + MenuActionItem.MENU_REFRESH,
              R.string.refresh);
      mi.setIcon(R.drawable.ic_refresh);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
  }
  static MenuItemsResult addImageMenuItems(
      Menu menu,
      int inclusions,
      final Activity activity,
      final Handler handler,
      final Runnable onDelete,
      final MenuInvoker onInvoke) {
    final ArrayList<MenuItem> requiresWriteAccessItems = new ArrayList<MenuItem>();
    final ArrayList<MenuItem> requiresNoDrmAccessItems = new ArrayList<MenuItem>();
    final ArrayList<MenuItem> requiresImageItems = new ArrayList<MenuItem>();
    final ArrayList<MenuItem> requiresVideoItems = new ArrayList<MenuItem>();

    if ((inclusions & INCLUDE_ROTATE_MENU) != 0) {
      SubMenu rotateSubmenu =
          menu.addSubMenu(Menu.NONE, Menu.NONE, POSITION_IMAGE_ROTATE, R.string.rotate)
              .setIcon(android.R.drawable.ic_menu_rotate);
      // Don't show the rotate submenu if the item at hand is read only
      // since the items within the submenu won't be shown anyway. This
      // is really a framework bug in that it shouldn't show the submenu
      // if the submenu has no visible items.
      MenuItem rotateLeft =
          rotateSubmenu
              .add(R.string.rotate_left)
              .setOnMenuItemClickListener(
                  new MenuItem.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                      return onRotateClicked(onInvoke, -90);
                    }
                  })
              .setAlphabeticShortcut('l');

      MenuItem rotateRight =
          rotateSubmenu
              .add(R.string.rotate_right)
              .setOnMenuItemClickListener(
                  new MenuItem.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                      return onRotateClicked(onInvoke, 90);
                    }
                  })
              .setAlphabeticShortcut('r');

      requiresWriteAccessItems.add(rotateSubmenu.getItem());
      requiresWriteAccessItems.add(rotateLeft);
      requiresWriteAccessItems.add(rotateRight);

      requiresImageItems.add(rotateSubmenu.getItem());
      requiresImageItems.add(rotateLeft);
      requiresImageItems.add(rotateRight);
    }

    if ((inclusions & INCLUDE_CROP_MENU) != 0) {
      MenuItem autoCrop = menu.add(Menu.NONE, Menu.NONE, POSITION_IMAGE_CROP, R.string.camera_crop);
      autoCrop.setIcon(android.R.drawable.ic_menu_crop);
      autoCrop.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              return onCropClicked(onInvoke, activity);
            }
          });
      requiresWriteAccessItems.add(autoCrop);
      requiresImageItems.add(autoCrop);
    }

    if ((inclusions & INCLUDE_SET_MENU) != 0) {
      MenuItem setMenu = menu.add(Menu.NONE, Menu.NONE, POSITION_IMAGE_SET, R.string.camera_set);
      setMenu.setIcon(android.R.drawable.ic_menu_set_as);
      setMenu.setOnMenuItemClickListener(
          new MenuItem.OnMenuItemClickListener() {
            public boolean onMenuItemClick(MenuItem item) {
              return onSetAsClicked(onInvoke, activity);
            }
          });
      requiresImageItems.add(setMenu);
    }

    if ((inclusions & INCLUDE_SHARE_MENU) != 0) {
      MenuItem item1 =
          menu.add(Menu.NONE, MENU_IMAGE_SHARE, POSITION_IMAGE_SHARE, R.string.camera_share)
              .setOnMenuItemClickListener(
                  new MenuItem.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                      return onImageShareClicked(onInvoke, activity);
                    }
                  });
      item1.setIcon(android.R.drawable.ic_menu_share);
      MenuItem item = item1;
      requiresNoDrmAccessItems.add(item);
    }

    if ((inclusions & INCLUDE_DELETE_MENU) != 0) {
      MenuItem deleteItem =
          menu.add(Menu.NONE, Menu.NONE, POSITION_IMAGE_TOSS, R.string.camera_toss);
      requiresWriteAccessItems.add(deleteItem);
      deleteItem
          .setOnMenuItemClickListener(
              new MenuItem.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                  return onDeleteClicked(onInvoke, activity, onDelete);
                }
              })
          .setAlphabeticShortcut('d')
          .setIcon(android.R.drawable.ic_menu_delete);
    }

    if ((inclusions & INCLUDE_DETAILS_MENU) != 0) {
      MenuItem detailsMenu =
          menu.add(Menu.NONE, Menu.NONE, POSITION_DETAILS, R.string.details)
              .setOnMenuItemClickListener(
                  new MenuItem.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                      return onDetailsClicked(onInvoke, handler, activity);
                    }
                  });
      detailsMenu.setIcon(R.drawable.ic_menu_view_details);
    }

    if ((inclusions & INCLUDE_SHOWMAP_MENU) != 0) {
      MenuItem showOnMapItem =
          menu.add(Menu.NONE, MENU_IMAGE_SHOWMAP, POSITION_SHOWMAP, R.string.show_on_map);
      showOnMapItem
          .setOnMenuItemClickListener(
              new MenuItem.OnMenuItemClickListener() {
                public boolean onMenuItemClick(MenuItem item) {
                  return onShowMapClicked(onInvoke, handler, activity);
                }
              })
          .setIcon(R.drawable.ic_menu_3d_globe);
      requiresImageItems.add(showOnMapItem);
    }

    if ((inclusions & INCLUDE_VIEWPLAY_MENU) != 0) {
      MenuItem videoPlayItem =
          menu.add(Menu.NONE, Menu.NONE, POSITION_VIEWPLAY, R.string.video_play)
              .setOnMenuItemClickListener(
                  new MenuItem.OnMenuItemClickListener() {
                    public boolean onMenuItemClick(MenuItem item) {
                      return onViewPlayClicked(onInvoke, activity);
                    }
                  });
      videoPlayItem.setIcon(com.android.internal.R.drawable.ic_menu_play_clip);
      requiresVideoItems.add(videoPlayItem);
    }

    return new MenuItemsResult() {
      public void gettingReadyToOpen(Menu menu, IImage image) {
        // protect against null here.  this isn't strictly speaking
        // required but if a client app isn't handling sdcard removal
        // properly it could happen
        if (image == null) {
          return;
        }

        ArrayList<MenuItem> enableList = new ArrayList<MenuItem>();
        ArrayList<MenuItem> disableList = new ArrayList<MenuItem>();
        ArrayList<MenuItem> list;

        list = image.isReadonly() ? disableList : enableList;
        list.addAll(requiresWriteAccessItems);

        list = image.isDrm() ? disableList : enableList;
        list.addAll(requiresNoDrmAccessItems);

        list = ImageManager.isImage(image) ? enableList : disableList;
        list.addAll(requiresImageItems);

        list = ImageManager.isVideo(image) ? enableList : disableList;
        list.addAll(requiresVideoItems);

        for (MenuItem item : enableList) {
          item.setVisible(true);
          item.setEnabled(true);
        }

        for (MenuItem item : disableList) {
          item.setVisible(false);
          item.setEnabled(false);
        }
      }

      // must override abstract method
      public void aboutToCall(MenuItem menu, IImage image) {}
    };
  }
  public static void getMenu(
      AlfrescoSession session, Menu menu, Folder parentFolder, boolean actionMode) {
    MenuItem mi;

    if (parentFolder == null) {
      return;
    }
    Permissions permission = null;
    try {
      permission =
          session.getServiceRegistry().getDocumentFolderService().getPermissions(parentFolder);
    } catch (Exception e) {
      return;
    }

    if (!actionMode) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_SEARCH_FOLDER,
              Menu.FIRST + MenuActionItem.MENU_SEARCH_FOLDER,
              R.string.search);
      mi.setIcon(R.drawable.ic_search);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode && permission.canAddChildren()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_CREATE_FOLDER,
              Menu.FIRST + MenuActionItem.MENU_CREATE_FOLDER,
              R.string.folder_create);
      mi.setIcon(R.drawable.ic_add_folder);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

      SubMenu createMenu =
          menu.addSubMenu(
              Menu.NONE,
              MenuActionItem.MENU_DEVICE_CAPTURE,
              Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE,
              R.string.add_menu);
      createMenu.setIcon(android.R.drawable.ic_menu_add);
      createMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

      createMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_UPLOAD,
          Menu.FIRST + MenuActionItem.MENU_UPLOAD,
          R.string.upload_title);

      createMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_CREATE_DOCUMENT,
          Menu.FIRST + MenuActionItem.MENU_CREATE_DOCUMENT,
          R.string.create_document);

      createMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
          Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_PHOTO,
          R.string.take_photo);

      if (AndroidVersion.isICSOrAbove()) {
        createMenu.add(
            Menu.NONE,
            MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
            Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_CAMERA_VIDEO,
            R.string.make_video);
      }

      createMenu.add(
          Menu.NONE,
          MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
          Menu.FIRST + MenuActionItem.MENU_DEVICE_CAPTURE_MIC_AUDIO,
          R.string.record_audio);
    }

    if (actionMode) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_DETAILS,
              Menu.FIRST + MenuActionItem.MENU_DETAILS,
              R.string.action_view_properties);
      mi.setIcon(R.drawable.ic_details);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canEdit()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_EDIT,
              Menu.FIRST + MenuActionItem.MENU_EDIT,
              R.string.edit);
      mi.setIcon(R.drawable.ic_edit);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (actionMode && permission.canDelete()) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_DELETE,
              Menu.FIRST + MenuActionItem.MENU_DELETE,
              R.string.delete);
      mi.setIcon(R.drawable.ic_delete);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    if (!actionMode) {
      mi =
          menu.add(
              Menu.NONE,
              MenuActionItem.MENU_REFRESH,
              Menu.FIRST + MenuActionItem.MENU_REFRESH,
              R.string.refresh);
      mi.setIcon(R.drawable.ic_refresh);
      mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
  }