Beispiel #1
0
 private void configureMenuItem(MenuItem mi, Site site) {
   Drawable icon = LogoManager.getLogo(site.code, LogoManager.Size.DRAWER);
   assert icon != null : "Icon not found for code " + site.code;
   icon.setColorFilter(0x000000, android.graphics.PorterDuff.Mode.ADD);
   mi.setIcon(icon);
   mi.setCheckable(true);
 }
  @Override
  public void onBackPressed() {

    // if drawer is open first close drawer
    if (drawerLayout.isDrawerOpen(Gravity.LEFT)) {
      drawerLayout.closeDrawer(Gravity.LEFT);
    } else {

      int backStackCount = getSupportFragmentManager().getBackStackEntryCount();

      if (backStackCount == 0) {
        // nothing exist in backStack OS handle it
        super.onBackPressed();
      } else {

        getSupportFragmentManager().popBackStack();

        if (!titleStack.isEmpty()) {
          toolbarTitle.setText(titleStack.pop());
        }

        if (backStackCount == 1) {
          previousMenuItem = navigationView.getMenu().findItem(R.id.nav_category);
          previousMenuItem.setChecked(true);
          previousMenuItem.setCheckable(true);
        }
      }
    }
  }
Beispiel #3
0
 private void addMenuCustomItem(Menu m, int id, int order, String name, int icon, int count) {
   MenuItem newItem = m.add(R.id.nav_group_notes, id, order, name);
   newItem.setIcon(icon);
   LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   RobotoTextView countTextView =
       (RobotoTextView) inflater.inflate(R.layout.nav_folder_item, null);
   countTextView.setText(String.valueOf(count));
   newItem.setActionView(countTextView);
   newItem.setCheckable(true);
 }
Beispiel #4
0
 @Override
 public void setGroupCheckable(int group, boolean checkable, boolean exclusive) {
   for (final MenuItem item : mMenuItems) {
     if (item.getGroupId() == group) {
       item.setCheckable(checkable);
       if (exclusive) {
         break;
       }
     }
   }
 }
  private void updateAddonMenuItem(int id, JSONObject options) {
    // Set attribute for the menu item in cache, if available
    if (mAddonMenuItemsCache != null && !mAddonMenuItemsCache.isEmpty()) {
      for (MenuItemInfo item : mAddonMenuItemsCache) {
        if (item.id == id) {
          try {
            item.checkable = options.getBoolean("checkable");
          } catch (JSONException e) {
          }

          try {
            item.checked = options.getBoolean("checked");
          } catch (JSONException e) {
          }

          try {
            item.enabled = options.getBoolean("enabled");
          } catch (JSONException e) {
          }

          try {
            item.visible = options.getBoolean("visible");
          } catch (JSONException e) {
          }
          break;
        }
      }
    }

    if (mMenu == null) return;

    MenuItem menuItem = mMenu.findItem(id);
    if (menuItem != null) {
      try {
        menuItem.setCheckable(options.getBoolean("checkable"));
      } catch (JSONException e) {
      }

      try {
        menuItem.setChecked(options.getBoolean("checked"));
      } catch (JSONException e) {
      }

      try {
        menuItem.setEnabled(options.getBoolean("enabled"));
      } catch (JSONException e) {
      }

      try {
        menuItem.setVisible(options.getBoolean("visible"));
      } catch (JSONException e) {
      }
    }
  }
  private void setupDrawerContent() {
    // set category item as default
    previousMenuItem = navigationView.getMenu().findItem(R.id.nav_category);
    previousMenuItem.setChecked(true);
    previousMenuItem.setCheckable(true);

    navigationView.setNavigationItemSelectedListener(
        new NavigationView.OnNavigationItemSelectedListener() {
          @Override
          public boolean onNavigationItemSelected(MenuItem menuItem) {

            drawerLayout.closeDrawer(Gravity.LEFT);

            if (previousMenuItem.getItemId() == menuItem.getItemId()) return true;

            menuItem.setCheckable(true);
            menuItem.setChecked(true);
            previousMenuItem.setChecked(false);
            previousMenuItem = menuItem;

            switch (menuItem.getItemId()) {
              case R.id.nav_category:
                displayView(CATEGORIES_FRAG, null);
                break;
              case R.id.nav_favorites:
                displayView(FAVORITE_FRAG, null);
                break;
              case R.id.nav_about:
                displayView(ABOUT_FRAG, null);
                break;
              case R.id.nav_feedback:
                displayView(LEARNING_FRAG, null);
                break;
              case R.id.nav_settings:
                displayView(SETTINGS_FRAG, null);
                break;
            }

            return true;
          }
        });
  }
 public void showAudioPopup(View v) {
   PopupMenu popup = new PopupMenu(this, v);
   Menu menu = popup.getMenu();
   menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.enable_background_audio);
   final MenuItem backgroundAudioItem = menu.findItem(0);
   backgroundAudioItem.setCheckable(true);
   backgroundAudioItem.setChecked(enableBackgroundAudio);
   OnMenuItemClickListener clickListener =
       new OnMenuItemClickListener() {
         @Override
         public boolean onMenuItemClick(MenuItem item) {
           if (item == backgroundAudioItem) {
             enableBackgroundAudio = !item.isChecked();
             return true;
           }
           return false;
         }
       };
   configurePopupWithTracks(popup, clickListener, DemoPlayer.TYPE_AUDIO);
   popup.show();
 }
 @Override
 public MenuItem setCheckable(boolean checkable) {
   mNativeItem.setCheckable(checkable);
   return this;
 }
Beispiel #9
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;
  }
Beispiel #10
0
  public void OnSepsButtonClick(final View v) {
    if (isProofing()) {

      //  get the current page
      final int currentPage = mDocView.getDisplayedViewIndex();

      //  buid a popup menu based on the given separations
      final PopupMenu menu = new PopupMenu(this, v);

      //  This makes the popup menu display icons, which by default it does not do.
      //  I worry that this relies on the internals of PopupMenu, which could change.
      try {
        Field[] fields = menu.getClass().getDeclaredFields();
        for (Field field : fields) {
          if ("mPopup".equals(field.getName())) {
            field.setAccessible(true);
            Object menuPopupHelper = field.get(menu);
            Class<?> classPopupHelper = Class.forName(menuPopupHelper.getClass().getName());
            Method setForceIcons = classPopupHelper.getMethod("setForceShowIcon", boolean.class);
            setForceIcons.invoke(menuPopupHelper, true);
            break;
          }
        }
      } catch (Exception e) {
        e.printStackTrace();
      }

      //  get the maximum number of seps on any page.
      //  We use this to dimension an array further down
      int maxSeps = 0;
      int numPages = core.countPages();
      for (int page = 0; page < numPages; page++) {
        int numSeps = core.getNumSepsOnPage(page);
        if (numSeps > maxSeps) maxSeps = numSeps;
      }

      //  if this is the first time, create the "enabled" array
      if (mSepEnabled == null) {
        mSepEnabled = new boolean[numPages][maxSeps];
        for (int page = 0; page < numPages; page++) {
          for (int i = 0; i < maxSeps; i++) mSepEnabled[page][i] = true;
        }
      }

      //  count the seps on this page
      int numSeps = core.getNumSepsOnPage(currentPage);

      //  for each sep,
      for (int i = 0; i < numSeps; i++) {

        //				//  Robin use this to skip separations
        //				if (i==12)
        //					break;

        //  get the name
        Separation sep = core.getSep(currentPage, i);
        String name = sep.name;

        //  make a checkable menu item with that name
        //  and the separation index as the id
        MenuItem item = menu.getMenu().add(0, i, 0, name + "    ");
        item.setCheckable(true);

        //  set an icon that's the right color
        int iconSize = 48;
        int alpha = (sep.rgba >> 24) & 0xFF;
        int red = (sep.rgba >> 16) & 0xFF;
        int green = (sep.rgba >> 8) & 0xFF;
        int blue = (sep.rgba >> 0) & 0xFF;
        int color = (alpha << 24) | (red << 16) | (green << 8) | (blue << 0);

        ShapeDrawable swatch = new ShapeDrawable(new RectShape());
        swatch.setIntrinsicHeight(iconSize);
        swatch.setIntrinsicWidth(iconSize);
        swatch.setBounds(new Rect(0, 0, iconSize, iconSize));
        swatch.getPaint().setColor(color);
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        item.setIcon(swatch);

        //  check it (or not)
        item.setChecked(mSepEnabled[currentPage][i]);

        //  establishing a menu item listener
        item.setOnMenuItemClickListener(
            new OnMenuItemClickListener() {
              @Override
              public boolean onMenuItemClick(MenuItem item) {
                //  someone tapped a menu item.  get the ID
                int sep = item.getItemId();

                //  toggle the sep
                mSepEnabled[currentPage][sep] = !mSepEnabled[currentPage][sep];
                item.setChecked(mSepEnabled[currentPage][sep]);
                core.controlSepOnPage(currentPage, sep, !mSepEnabled[currentPage][sep]);

                //  prevent the menu from being dismissed by these items
                item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
                item.setActionView(new View(v.getContext()));
                item.setOnActionExpandListener(
                    new MenuItem.OnActionExpandListener() {
                      @Override
                      public boolean onMenuItemActionExpand(MenuItem item) {
                        return false;
                      }

                      @Override
                      public boolean onMenuItemActionCollapse(MenuItem item) {
                        return false;
                      }
                    });
                return false;
              }
            });

        //  tell core to enable or disable each sep as appropriate
        //  but don't refresh the page yet.
        core.controlSepOnPage(currentPage, i, !mSepEnabled[currentPage][i]);
      }

      //  add one for done
      MenuItem itemDone = menu.getMenu().add(0, 0, 0, "Done");
      itemDone.setOnMenuItemClickListener(
          new OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem item) {
              //  refresh the view
              mDocView.refresh(false);
              return true;
            }
          });

      //  show the menu
      menu.show();
    }
  }
Beispiel #11
0
  @Override
  public boolean onPrepareOptionsMenu(Menu aMenu) {
    if (aMenu == null) return false;

    if (!checkLaunchState(LaunchState.GeckoRunning))
      aMenu.findItem(R.id.settings).setEnabled(false);

    Tab tab = Tabs.getInstance().getSelectedTab();
    MenuItem bookmark = aMenu.findItem(R.id.bookmark);
    MenuItem forward = aMenu.findItem(R.id.forward);
    MenuItem share = aMenu.findItem(R.id.share);
    MenuItem saveAsPDF = aMenu.findItem(R.id.save_as_pdf);
    MenuItem charEncoding = aMenu.findItem(R.id.char_encoding);
    MenuItem findInPage = aMenu.findItem(R.id.find_in_page);
    MenuItem desktopMode = aMenu.findItem(R.id.desktop_mode);

    // Only show the "Quit" menu item on pre-ICS. In ICS+, it's easy to
    // kill an app through the task switcher.
    aMenu.findItem(R.id.quit).setVisible(Build.VERSION.SDK_INT < 14);

    if (tab == null || tab.getURL() == null) {
      bookmark.setEnabled(false);
      forward.setEnabled(false);
      share.setEnabled(false);
      saveAsPDF.setEnabled(false);
      findInPage.setEnabled(false);
      return true;
    }

    bookmark.setEnabled(!tab.getURL().startsWith("about:reader"));
    bookmark.setCheckable(true);
    bookmark.setChecked(tab.isBookmark());
    bookmark.setIcon(
        tab.isBookmark() ? R.drawable.ic_menu_bookmark_remove : R.drawable.ic_menu_bookmark_add);

    forward.setEnabled(tab.canDoForward());
    desktopMode.setChecked(tab.getDesktopMode());
    desktopMode.setIcon(
        tab.getDesktopMode()
            ? R.drawable.ic_menu_desktop_mode_on
            : R.drawable.ic_menu_desktop_mode_off);

    String url = tab.getURL();
    if (ReaderModeUtils.isAboutReader(url)) {
      String urlFromReader = ReaderModeUtils.getUrlFromAboutReader(url);
      if (urlFromReader != null) url = urlFromReader;
    }

    // Disable share menuitem for about:, chrome:, file:, and resource: URIs
    String scheme = Uri.parse(url).getScheme();
    share.setEnabled(
        !(scheme.equals("about")
            || scheme.equals("chrome")
            || scheme.equals("file")
            || scheme.equals("resource")));

    // Disable save as PDF for about:home and xul pages
    saveAsPDF.setEnabled(
        !(tab.getURL().equals("about:home")
            || tab.getContentType().equals("application/vnd.mozilla.xul+xml")));

    // Disable find in page for about:home, since it won't work on Java content
    findInPage.setEnabled(!tab.getURL().equals("about:home"));

    charEncoding.setVisible(GeckoPreferences.getCharEncodingState());

    return true;
  }
Beispiel #12
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);
  }