// region Menu
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_uart, menu);

    // Mqtt
    mMqttMenuItem = menu.findItem(R.id.action_mqttsettings);
    mMqttMenuItemAnimationHandler = new Handler();
    mMqttMenuItemAnimationRunnable.run();

    // DisplayMode
    MenuItem displayModeMenuItem = menu.findItem(R.id.action_displaymode);
    displayModeMenuItem.setTitle(
        String.format(
            getString(R.string.uart_action_displaymode_format),
            getString(
                mIsTimestampDisplayMode
                    ? R.string.uart_displaymode_timestamp
                    : R.string.uart_displaymode_text)));
    SubMenu displayModeSubMenu = displayModeMenuItem.getSubMenu();
    if (mIsTimestampDisplayMode) {
      MenuItem displayModeTimestampMenuItem =
          displayModeSubMenu.findItem(R.id.action_displaymode_timestamp);
      displayModeTimestampMenuItem.setChecked(true);
    } else {
      MenuItem displayModeTextMenuItem = displayModeSubMenu.findItem(R.id.action_displaymode_text);
      displayModeTextMenuItem.setChecked(true);
    }

    // DataMode
    MenuItem dataModeMenuItem = menu.findItem(R.id.action_datamode);
    dataModeMenuItem.setTitle(
        String.format(
            getString(R.string.uart_action_datamode_format),
            getString(
                mShowDataInHexFormat
                    ? R.string.uart_format_hexadecimal
                    : R.string.uart_format_ascii)));
    SubMenu dataModeSubMenu = dataModeMenuItem.getSubMenu();
    if (mShowDataInHexFormat) {
      MenuItem dataModeHexMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_hex);
      dataModeHexMenuItem.setChecked(true);
    } else {
      MenuItem dataModeAsciiMenuItem = dataModeSubMenu.findItem(R.id.action_datamode_ascii);
      dataModeAsciiMenuItem.setChecked(true);
    }

    // Echo
    MenuItem echoMenuItem = menu.findItem(R.id.action_echo);
    echoMenuItem.setTitle(R.string.uart_action_echo);
    echoMenuItem.setChecked(mIsEchoEnabled);

    // Eol
    MenuItem eolMenuItem = menu.findItem(R.id.action_eol);
    eolMenuItem.setTitle(R.string.uart_action_eol);
    eolMenuItem.setChecked(mIsEolEnabled);

    return true;
  }
Esempio n. 2
0
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   super.onPrepareOptionsMenu(menu);
   hackForSubmenus = menu;
   if (progress != null && (actionBarCompat == null || actionBarCompat.hasMenuButton()))
     return false; // not safe/useful until game is loaded
   MenuItem item;
   item = menu.findItem(R.id.solve);
   item.setEnabled(solveEnabled);
   if (actionBarCompat != null) item.setVisible(solveEnabled);
   MenuItem undoItem = menu.findItem(R.id.undo), redoItem = menu.findItem(R.id.redo);
   undoItem.setEnabled(undoEnabled);
   redoItem.setEnabled(redoEnabled);
   undoItem.setIcon(
       undoEnabled ? R.drawable.sym_keyboard_undo : R.drawable.sym_keyboard_undo_disabled);
   redoItem.setIcon(
       redoEnabled ? R.drawable.sym_keyboard_redo : R.drawable.sym_keyboard_redo_disabled);
   item = menu.findItem(R.id.type);
   item.setEnabled(!gameTypes.isEmpty() || customVisible);
   if (actionBarCompat != null) item.setVisible(item.isEnabled());
   typeMenu = item.getSubMenu();
   for (Integer i : gameTypes.keySet()) {
     if (menu.findItem(i) == null) typeMenu.add(R.id.typeGroup, i, Menu.NONE, gameTypes.get(i));
   }
   MenuItem customItem = menu.findItem(R.id.custom);
   customItem.setVisible(customVisible);
   typeMenu.setGroupCheckable(R.id.typeGroup, true, true);
   if (currentType < 0) customItem.setChecked(true);
   else if (currentType < gameTypes.size())
     menu.findItem((Integer) gameTypes.keySet().toArray()[currentType]).setChecked(true);
   menu.findItem(R.id.thisgame)
       .setTitle(
           MessageFormat.format(getString(R.string.help_on_game), new Object[] {this.getTitle()}));
   return true;
 }
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.first_launch, menu);
    mJobPicker = (MenuItem) menu.findItem(R.id.action_pick_job);
    mLinePicker = (MenuItem) menu.findItem(R.id.action_pick_line);
    mJobPicker.setEnabled(false);
    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
      mJobPicker.setShowAsAction(
          MenuItem.SHOW_AS_ACTION_NEVER); // just a hack to make the arrow line up
    }

    // populate the line picker with line numbers from the database
    List<Integer> lineNumberList = new ArrayList<Integer>();
    lineNumberList = mModel.getLineNumbers();

    Menu pickLineSubMenu = mLinePicker.getSubMenu();
    pickLineSubMenu.clear();

    for (int i = 0; i < lineNumberList.size(); i++) {
      // don't have access to View.generateViewId(), so fake a random ID
      pickLineSubMenu.add(
          LINE_LIST_MENU_GROUP,
          (Menu.FIRST + lineNumberList.get(i)),
          Menu.FLAG_APPEND_TO_GROUP,
          "Line  " + String.valueOf(lineNumberList.get(i)));
    }

    return super.onCreateOptionsMenu(menu);
  }
Esempio n. 4
0
 @Override
 public SubMenu getSubMenu() {
   if (hasSubMenu() && (mSubMenu == null)) {
     mSubMenu = new SubMenuWrapper(mNativeItem.getSubMenu());
   }
   return mSubMenu;
 }
Esempio n. 5
0
  public void restoreActionViewStates(Bundle states) {
    if (states == null) {
      return;
    }

    SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
      final MenuItem item = getItem(i);
      final View v = item.getActionView();
      if (v != null && v.getId() != View.NO_ID) {
        v.restoreHierarchyState(viewStates);
      }
      if (item.hasSubMenu()) {
        final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
        // subMenu.restoreActionViewStates(states);
      }
    }

    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
      MenuItem itemToExpand = findItem(expandedId);
      if (itemToExpand != null) {
        itemToExpand.expandActionView();
      }
    }
  }
Esempio n. 6
0
  public boolean performItemAction(MenuItem item, int flags) {
    MenuItemImpl itemImpl = (MenuItemImpl) item;

    if (itemImpl == null || !itemImpl.isEnabled()) {
      return false;
    }

    boolean invoked = itemImpl.invoke();

    // if (itemImpl.hasCollapsibleActionView()) {
    //    invoked |= itemImpl.expandActionView();
    //    if (invoked) close(true);
    // } else
    if (item.hasSubMenu()) {
      close(false);

      final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
      final ActionProvider provider = item.getActionProvider();
      if (provider != null && provider.hasSubMenu()) {
        provider.onPrepareSubMenu(subMenu);
      }
      invoked |= dispatchSubMenuSelected(subMenu);
      if (!invoked) close(true);
    } else {
      if ((flags & FLAG_PERFORM_NO_CLOSE) == 0) {
        close(true);
      }
    }

    return invoked;
  }
  protected void createFileMenu(final ContextMenu menu, final String path) {
    final BookSettings bs = SettingsManager.getBookSettings(path);
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.book_menu, menu);
    menu.setHeaderTitle(path);
    menu.findItem(R.id.bookmenu_recentgroup).setVisible(bs != null);
    menu.findItem(R.id.bookmenu_openbookshelf).setVisible(false);
    menu.findItem(R.id.bookmenu_openbookfolder).setVisible(false);

    final MenuItem om = menu.findItem(R.id.bookmenu_open);
    final SubMenu osm = om != null ? om.getSubMenu() : null;
    if (osm == null) {
      return;
    }
    osm.clear();

    final List<Bookmark> list = new ArrayList<Bookmark>();
    list.add(new Bookmark(true, getString(R.string.bookmark_start), PageIndex.FIRST, 0, 0));
    list.add(new Bookmark(true, getString(R.string.bookmark_end), PageIndex.LAST, 0, 1));
    if (bs != null) {
      if (LengthUtils.isNotEmpty(bs.bookmarks)) {
        list.addAll(bs.bookmarks);
      }
      list.add(
          new Bookmark(
              true, getString(R.string.bookmark_current), bs.currentPage, bs.offsetX, bs.offsetY));
    }

    Collections.sort(list);
    for (final Bookmark b : list) {
      addBookmarkMenuItem(osm, b);
    }
  }
Esempio n. 8
0
  public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
      final MenuItem item = getItem(i);
      final View v = item.getActionView();
      if (v != null && v.getId() != View.NO_ID) {
        if (viewStates == null) {
          viewStates = new SparseArray<Parcelable>();
        }
        v.saveHierarchyState(viewStates);
        if (item.isActionViewExpanded()) {
          outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
        }
      }
      if (item.hasSubMenu()) {
        final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
        // subMenu.saveActionViewStates(outStates);
      }
    }

    if (viewStates != null) {
      outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
  }
 public void setMenuIconsTint(Menu menu, int color) {
   for (int i = 0; i < menu.size(); i++) {
     MenuItem item = menu.getItem(i);
     if (item.hasSubMenu()) {
       SubMenu submenu = item.getSubMenu();
       setMenuIconsTint(submenu, color);
     }
     Drawable d = item.getIcon();
     d.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
   }
 }
Esempio n. 10
0
 @Override
 public void removeItem(int id) {
   final List<MenuItem> items_to_remove = new ArrayList<MenuItem>();
   for (final MenuItem item : mMenuItems) {
     if (item.hasSubMenu()) {
       item.getSubMenu().removeItem(id);
     } else if (item.getItemId() == id) {
       items_to_remove.add(item);
     }
   }
   mMenuItems.removeAll(items_to_remove);
 }
Esempio n. 11
0
  @Override
  public MenuItem findItem(int id) {
    for (final MenuItem item : mMenuItems) {
      if (item.getItemId() == id) return item;
      else if (item.hasSubMenu()) {
        final MenuItem possibleItem = item.getSubMenu().findItem(id);

        if (possibleItem != null) return possibleItem;
      }
    }
    return null;
  }
Esempio n. 12
0
 @Override
 public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
   mDidAction = true;
   dismiss();
   final MenuItem item = mAdapter.getItem(position);
   if (item.hasSubMenu()) {
     showMenu(item.getSubMenu());
   } else {
     if (mItemClickListener != null) {
       mItemClickListener.onMenuItemClick(item);
     }
   }
 }
 /** Returns the visible and enabled menu items in the specified menu. This method is recursive. */
 private List<MenuItem> getVisibleAndEnabledMenuItems(Menu menu) {
   List<MenuItem> menuItems = new ArrayList<MenuItem>();
   for (int i = 0; (menu != null) && (i < menu.size()); i++) {
     MenuItem menuItem = menu.getItem(i);
     if (menuItem.isVisible() && menuItem.isEnabled()) {
       Menu subMenu = menuItem.getSubMenu();
       if (subMenu != null) {
         menuItems.addAll(getVisibleAndEnabledMenuItems(subMenu));
       } else {
         menuItems.add(menuItem);
       }
     }
   }
   return menuItems;
 }
Esempio n. 14
0
 private static void tintMenuItemIcon(
     Menu menu, ColorStateList menuTintList, ColorStateList subMenuTintList) {
   for (int i = 0, size = menu.size(); i < size; ++i) {
     MenuItem menuItem = menu.getItem(i);
     Drawable icon = menuItem.getIcon();
     if (icon != null) {
       icon = tintDrawable(icon, menuTintList);
       menuItem.setIcon(icon);
     }
     SubMenu subMenu = menuItem.getSubMenu();
     if (subMenu != null) {
       tintMenuItemIcon(subMenu, subMenuTintList, subMenuTintList);
     }
   }
 }
Esempio n. 15
0
 @Override
 public SubMenu getSubMenu() {
   return new SubMenuWrapper(mMenuItem.getSubMenu());
 }
Esempio n. 16
0
  private void addAddonMenuItem(final MenuItemInfo info) {
    if (mMenu == null) {
      if (mAddonMenuItemsCache == null) mAddonMenuItemsCache = new Vector<MenuItemInfo>();

      mAddonMenuItemsCache.add(info);
      return;
    }

    Menu menu;
    if (info.parent == 0) {
      menu = mMenu;
    } else {
      MenuItem parent = mMenu.findItem(info.parent);
      if (parent == null) return;

      if (!parent.hasSubMenu()) {
        mMenu.removeItem(parent.getItemId());
        menu = mMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle());
        if (parent.getIcon() != null) ((SubMenu) menu).getItem().setIcon(parent.getIcon());
      } else {
        menu = parent.getSubMenu();
      }
    }

    final MenuItem item = menu.add(Menu.NONE, info.id, Menu.NONE, info.label);
    item.setOnMenuItemClickListener(
        new MenuItem.OnMenuItemClickListener() {
          @Override
          public boolean onMenuItemClick(MenuItem item) {
            Log.i(LOGTAG, "menu item clicked");
            GeckoAppShell.sendEventToGecko(
                GeckoEvent.createBroadcastEvent(
                    "Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET)));
            return true;
          }
        });

    if (info.icon != null) {
      if (info.icon.startsWith("data")) {
        BitmapDrawable drawable = new BitmapDrawable(BitmapUtils.getBitmapFromDataURI(info.icon));
        item.setIcon(drawable);
      } else if (info.icon.startsWith("jar:") || info.icon.startsWith("file://")) {
        GeckoAppShell.getHandler()
            .post(
                new Runnable() {
                  public void run() {
                    try {
                      URL url = new URL(info.icon);
                      InputStream is = (InputStream) url.getContent();
                      try {
                        Drawable drawable = Drawable.createFromStream(is, "src");
                        item.setIcon(drawable);
                      } finally {
                        is.close();
                      }
                    } catch (Exception e) {
                      Log.w(LOGTAG, "Unable to set icon", e);
                    }
                  }
                });
      }
    }

    item.setCheckable(info.checkable);
    item.setChecked(info.checked);
    item.setEnabled(info.enabled);
    item.setVisible(info.visible);
  }