Exemple #1
0
 @Override
 public boolean hasVisibleItems() {
   for (final MenuItem item : mMenuItems) {
     if (item.isVisible()) return true;
   }
   return false;
 }
 public boolean onSubMenuSelected(SubMenuBuilder submenubuilder) {
   if (submenubuilder.hasVisibleItems()) {
     MenuPopupHelper menupopuphelper = new MenuPopupHelper(mContext, submenubuilder, mAnchorView);
     menupopuphelper.setCallback(mPresenterCallback);
     boolean flag1 = false;
     int j = submenubuilder.size();
     int i = 0;
     label0:
     do {
       label1:
       {
         boolean flag = flag1;
         if (i < j) {
           MenuItem menuitem = submenubuilder.getItem(i);
           if (!menuitem.isVisible() || menuitem.getIcon() == null) {
             break label1;
           }
           flag = true;
         }
         menupopuphelper.setForceShowIcon(flag);
         if (menupopuphelper.tryShow()) {
           if (mPresenterCallback != null) {
             mPresenterCallback.onOpenSubMenu(submenubuilder);
           }
           return true;
         }
         break label0;
       }
       i++;
     } while (true);
   }
   return false;
 }
  @Override
  public boolean onSubMenuSelected(SubMenuBuilder subMenu) {
    if (subMenu.hasVisibleItems()) {
      MenuPopupHelper subPopup = new MenuPopupHelper(mContext, subMenu, mAnchorView);
      subPopup.setCallback(mPresenterCallback);

      boolean preserveIconSpacing = false;
      final int count = subMenu.size();
      for (int i = 0; i < count; i++) {
        MenuItem childItem = subMenu.getItem(i);
        if (childItem.isVisible() && childItem.getIcon() != null) {
          preserveIconSpacing = true;
          break;
        }
      }
      subPopup.setForceShowIcon(preserveIconSpacing);

      if (subPopup.tryShow()) {
        if (mPresenterCallback != null) {
          mPresenterCallback.onOpenSubMenu(subMenu);
        }
        return true;
      }
    }
    return false;
  }
Exemple #4
0
 public void show() {
   if (mPopupMenu != null) {
     mPopupMenu.dismiss();
   }
   removeAllViews();
   for (final MenuItem item : ((MenuImpl) mMenu).getMenuItems()) {
     if (item.isVisible()) {
       addMenuButton(item);
     }
   }
   invalidate();
 }
  @Override
  public void onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    boolean isJoined = (mChannel != null) && mChannel.isJoined();
    menu.findItem(R.id.info).setVisible(isJoined);
    menu.findItem(R.id.members).setVisible(isJoined);
    menu.findItem(R.id.part_channel).setVisible(isJoined);

    // User must part channel before archiving/deleting
    for (int id : new int[] {R.id.archive, R.id.delete}) {
      MenuItem item = menu.findItem(id);
      item.setVisible(item.isVisible() && (!isJoined));
    }
  }
 /** 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;
 }
 /** {@inheritDoc} */
 @Override
 public void invalidate() {
   mMenuItemArrayAdapter.clear();
   List<MenuItem> items = new ArrayList<MenuItem>();
   for (int i = 0; i < mMenu.size(); i++) {
     MenuItem item = mMenu.getItem(i);
     if (item.isVisible()) {
       items.add(item);
     }
   }
   Collections.sort(
       items,
       new Comparator<MenuItem>() {
         @Override
         public int compare(MenuItem a, MenuItem b) {
           return a.getOrder() - b.getOrder();
         }
       });
   for (MenuItem item : items) {
     mMenuItemArrayAdapter.add(item);
   }
 }
  private static void process4096Response(final String data) {

    final String[] buf = data.substring(data.indexOf(EIGHT_REGISTERS), data.length()).split(" ");

    if (ModbusRTU.validCRC(buf, REGISTER_4096_LENGTH)) {
      imgStatus.setBackgroundColor(Color.GREEN);
      dataArray.clear();

      final int rpm = Integer.parseInt(buf[3] + buf[4], 16);
      final int map = Integer.parseInt(buf[5] + buf[6], 16);
      final int mat = getTemperatureValue(buf[7] + buf[8]);
      final int wat = getTemperatureValue(buf[9] + buf[10]);

      final float afr = Integer.parseInt(buf[14], 16) / 10f;
      final float referenceAfr = Integer.parseInt(buf[13], 16) / 10f;

      tps = Integer.parseInt(buf[17] + buf[18], 16);

      iatNeedle.setValue(mat);
      waterNeedle.setValue(Integer.parseInt(buf[9] + buf[10], 16) * 9 / 5 + 32);
      mapNeedle.setValue(map);

      {
        float afrVal = afr * 100;
        float targetAfrVal = targetAFR * 100;

        if (afrVal > AFR_MAX) afrVal = AFR_MAX;
        if (afrVal < AFR_MIN) afrVal = AFR_MIN;

        if (targetAfrVal > AFR_MAX) targetAfrVal = AFR_MAX;
        if (targetAfrVal < AFR_MIN) targetAfrVal = AFR_MIN;

        afrNeedle.setValue(AFR_MAX - afrVal + AFR_MIN);
        targetAfrNeedle.setValue(AFR_MAX - targetAfrVal + AFR_MIN);
      }

      if (rpm >= 200) lastRPM = rpm;
      dataArray.add(String.format("RPM\n%d", lastRPM));
      rpmNeedle.setValue(lastRPM);

      dataArray.add(String.format("MAP\n%d kPa", map));
      dataArray.add(String.format("MAT\n%d\u00B0 %s", mat, getTemperatureSymbol()));
      dataArray.add(String.format("AFR\n%.1f (%.1f)", afr, referenceAfr));
      dataArray.add("TAFR\n" + (targetAFR != 0f ? String.format("%.1f", targetAFR) : "--.-"));
      dataArray.add(String.format("WAT\n%d\u00B0 %s", wat, getTemperatureSymbol()));

      // alarm stuff
      if (gridData.getChildAt(3) != null && gridData.getChildAt(5) != null) {
        // water temperature
        gridData.getChildAt(5).setBackgroundColor(Color.TRANSPARENT);
        if (waterTempPref) {
          if (wat < minimumWaterTemp) gridData.getChildAt(5).setBackgroundColor(Color.BLUE);
          if (wat > maximumWaterTemp) gridData.getChildAt(5).setBackgroundColor(Color.RED);
        }

        // afr vs target alarm
        gridData.getChildAt(3).setBackgroundColor(Color.TRANSPARENT);
        if (afrNotEqualTargetPref) {
          final float threshold = targetAFR * (afrNotEqualTargetTolerance * .01f);
          if (Math.abs(targetAFR - afr) >= threshold) {
            if (afr > targetAFR) {
              gridData.getChildAt(3).setBackgroundColor(Color.RED);
            } else {
              gridData.getChildAt(3).setBackgroundColor(Color.BLUE);
            }

            if (afrAlarmLogging) {
              LogItem newItem = afrAlarmLogItems.newLogItem();
              newItem.setAfr(afr);
              newItem.setReferenceAfr(referenceAfr);
              newItem.setMap(map);
              newItem.setMat(mat);
              newItem.setRpm(rpm);
              newItem.setTargetAfr(targetAFR);
              newItem.setWat(wat);

              afrAlarmLogItems.getItems().add(newItem);

              if (!menuShareLog.isVisible()) {
                menuShareLog.setVisible(true);
              }
            }
          }
        }
      }

      if (DEBUG_MODE) Log.d(TAG, "Processed " + lastRegister + " response: " + data);
      sendRequest(REGISTER_4140_PLUS_SIX);
      return;

    } else {
      if (DEBUG_MODE) Log.d(TAG, "bad CRC for " + lastRegister + ": " + data);
      imgStatus.setBackgroundColor(Color.RED);
      sendRequest();
    }
  }
 @Override
 public boolean isVisible() {
   return mNativeItem.isVisible();
 }
Exemple #10
0
  /**
   * Creates and shows the app menu anchored to the specified view.
   *
   * @param context The context of the AppMenu (ensure the proper theme is set on this context).
   * @param anchorView The anchor {@link View} of the {@link ListPopupWindow}.
   * @param isByPermanentButton Whether or not permanent hardware button triggered it. (oppose to
   *     software button or keyboard).
   * @param screenRotation Current device screen rotation.
   * @param visibleDisplayFrame The display area rect in which AppMenu is supposed to fit in.
   * @param screenHeight Current device screen height.
   * @param footerResourceId The resource id for a view to add to the end of the menu list. Can be 0
   *     if no such view is required.
   */
  void show(
      Context context,
      View anchorView,
      boolean isByPermanentButton,
      int screenRotation,
      Rect visibleDisplayFrame,
      int screenHeight,
      int footerResourceId) {
    mPopup = new ListPopupWindow(context, null, android.R.attr.popupMenuStyle);
    mPopup.setModal(true);
    mPopup.setAnchorView(anchorView);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);

    int footerHeight = 0;
    if (footerResourceId != 0) {
      mPopup.setPromptPosition(ListPopupWindow.POSITION_PROMPT_BELOW);
      View promptView = LayoutInflater.from(context).inflate(footerResourceId, null);
      mPopup.setPromptView(promptView);
      int measureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
      promptView.measure(measureSpec, measureSpec);
      footerHeight = promptView.getMeasuredHeight();
    }
    mPopup.setOnDismissListener(
        new OnDismissListener() {
          @Override
          public void onDismiss() {
            if (mPopup.getAnchorView() instanceof ImageButton) {
              ((ImageButton) mPopup.getAnchorView()).setSelected(false);
            }

            if (mMenuItemEnterAnimator != null) mMenuItemEnterAnimator.cancel();

            mHandler.appMenuDismissed();
            mHandler.onMenuVisibilityChanged(false);
          }
        });

    // Some OEMs don't actually let us change the background... but they still return the
    // padding of the new background, which breaks the menu height.  If we still have a
    // drawable here even though our style says @null we should use this padding instead...
    Drawable originalBgDrawable = mPopup.getBackground();

    // Need to explicitly set the background here.  Relying on it being set in the style caused
    // an incorrectly drawn background.
    if (isByPermanentButton) {
      mPopup.setBackgroundDrawable(
          ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.menu_bg));
    } else {
      mPopup.setBackgroundDrawable(
          ApiCompatibilityUtils.getDrawable(context.getResources(), R.drawable.edge_menu_bg));
      mPopup.setAnimationStyle(R.style.OverflowMenuAnim);
    }

    // Turn off window animations for low end devices, and on Android M, which has built-in menu
    // animations.
    if (SysUtils.isLowEndDevice() || Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
      mPopup.setAnimationStyle(0);
    }

    Rect bgPadding = new Rect();
    mPopup.getBackground().getPadding(bgPadding);

    int popupWidth =
        context.getResources().getDimensionPixelSize(R.dimen.menu_width)
            + bgPadding.left
            + bgPadding.right;

    mPopup.setWidth(popupWidth);

    mCurrentScreenRotation = screenRotation;
    mIsByPermanentButton = isByPermanentButton;

    // Extract visible items from the Menu.
    int numItems = mMenu.size();
    List<MenuItem> menuItems = new ArrayList<MenuItem>();
    for (int i = 0; i < numItems; ++i) {
      MenuItem item = mMenu.getItem(i);
      if (item.isVisible()) {
        menuItems.add(item);
      }
    }

    Rect sizingPadding = new Rect(bgPadding);
    if (isByPermanentButton && originalBgDrawable != null) {
      Rect originalPadding = new Rect();
      originalBgDrawable.getPadding(originalPadding);
      sizingPadding.top = originalPadding.top;
      sizingPadding.bottom = originalPadding.bottom;
    }

    // A List adapter for visible items in the Menu. The first row is added as a header to the
    // list view.
    mAdapter = new AppMenuAdapter(this, menuItems, LayoutInflater.from(context));
    mPopup.setAdapter(mAdapter);

    setMenuHeight(menuItems.size(), visibleDisplayFrame, screenHeight, sizingPadding, footerHeight);
    setPopupOffset(mPopup, mCurrentScreenRotation, visibleDisplayFrame, sizingPadding);
    mPopup.setOnItemClickListener(this);
    mPopup.show();
    mPopup.getListView().setItemsCanFocus(true);
    mPopup.getListView().setOnKeyListener(this);

    mHandler.onMenuVisibilityChanged(true);

    if (mVerticalFadeDistance > 0) {
      mPopup.getListView().setVerticalFadingEdgeEnabled(true);
      mPopup.getListView().setFadingEdgeLength(mVerticalFadeDistance);
    }

    // Don't animate the menu items for low end devices.
    if (!SysUtils.isLowEndDevice() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      mPopup
          .getListView()
          .addOnLayoutChangeListener(
              new View.OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(
                    View v,
                    int left,
                    int top,
                    int right,
                    int bottom,
                    int oldLeft,
                    int oldTop,
                    int oldRight,
                    int oldBottom) {
                  mPopup.getListView().removeOnLayoutChangeListener(this);
                  runMenuItemEnterAnimations();
                }
              });
    }
  }
 @Override
 public boolean isVisible() {
   return mMenuItem.isVisible();
 }
  /**
   * Reorders the specified {@link Menu}, taking into account the user's Archive/Delete preference.
   */
  public static void reorderMenu(
      final Context context, final Account account, final Menu menu, final int maxItems) {
    final String removalAction =
        MailPrefs.get(context)
            .getRemovalAction(account.supportsCapability(AccountCapabilities.ARCHIVE));
    final boolean showArchive =
        MailPrefs.RemovalActions.ARCHIVE.equals(removalAction)
            || MailPrefs.RemovalActions.ARCHIVE_AND_DELETE.equals(removalAction);
    final boolean showDelete =
        MailPrefs.RemovalActions.DELETE.equals(removalAction)
            || MailPrefs.RemovalActions.ARCHIVE_AND_DELETE.equals(removalAction);

    // Do a first pass to extract necessary information on what is safe to display
    boolean archiveVisibleEnabled = false;
    boolean deleteVisibleEnabled = false;
    for (int i = 0; i < menu.size(); i++) {
      final MenuItem menuItem = menu.getItem(i);
      final int itemId = menuItem.getItemId();
      final boolean visible = menuItem.isVisible();
      final boolean enabled = menuItem.isEnabled();

      if (itemId == R.id.archive || itemId == R.id.remove_folder) {
        archiveVisibleEnabled |= (visible & enabled);
      } else if (itemId == R.id.delete || itemId == R.id.discard_drafts) {
        deleteVisibleEnabled |= (visible & enabled);
      }
    }

    int actionItems = 0;

    for (int i = 0; i < menu.size(); i++) {
      final MenuItem menuItem = menu.getItem(i);
      final int itemId = menuItem.getItemId();

      // We only want to promote it if it's visible and has an icon
      if (menuItem.isVisible() && menuItem.getIcon() != null) {
        if (itemId == R.id.archive || itemId == R.id.remove_folder) {
          /*
           * If this is disabled, and we want to show both archive and delete, we will
           * hide archive (rather than showing it disabled), and take up one of our
           * spaces. If we only want to show archive, we'll hide it, but not take up
           * a space.
           */
          if (!menuItem.isEnabled() && showArchive) {
            menuItem.setVisible(false);

            if (showDelete) {
              actionItems++;
            }
          } else {
            /*
             * We show this if the following are all true:
             * 1. The user wants to display archive, or delete is not visible
             * 2. We have room for it
             */
            if ((showArchive || !deleteVisibleEnabled) && actionItems < maxItems) {
              menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
              actionItems++;
            }
          }
        } else if (itemId == R.id.delete || itemId == R.id.discard_drafts) {
          /*
           * We show this if the following are all true:
           * 1. The user wants to display delete, or archive is not visible
           * 2. We have room for it
           */
          if ((showDelete || !archiveVisibleEnabled) && actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        } else if (itemId == R.id.change_folders) {
          final boolean showChangeFolder =
              account.supportsCapability(AccountCapabilities.MULTIPLE_FOLDERS_PER_CONV);
          menuItem.setVisible(showChangeFolder);

          if (showChangeFolder && actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        } else if (itemId == R.id.search) {
          menuItem.setShowAsAction(
              MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
          actionItems++;
        } else {
          if (actionItems < maxItems) {
            menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
            actionItems++;
          }
        }
      }
    }
  }