public void setInfo(String itemKey, boolean isVertical) {
   ButtonInfo item = NavbarEditor.buttonMap.get(itemKey);
   setTag(itemKey);
   final Resources res = getResources();
   setContentDescription(res.getString(item.contentDescription));
   mCode = item.keyCode;
   boolean isSmallButton = ArrayUtils.contains(NavbarEditor.smallButtonIds, getId());
   Drawable keyD;
   if (isSmallButton) {
     keyD = res.getDrawable(item.sideResource);
   } else if (!isVertical) {
     keyD = res.getDrawable(item.portResource);
   } else {
     keyD = res.getDrawable(item.landResource);
   }
   // Reason for setImageDrawable vs setImageResource is because setImageResource calls relayout()
   // w/o
   // any checks. setImageDrawable performs size checks and only calls relayout if necessary. We
   // rely on this
   // because otherwise the setX/setY attributes which are post layout cause it to mess up the
   // layout.
   setImageDrawable(keyD);
   if (itemKey.equals(NavbarEditor.NAVBAR_EMPTY)) {
     if (isSmallButton) {
       setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.INVISIBLE);
     } else {
       setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.GONE);
     }
   } else if (itemKey.equals(NavbarEditor.NAVBAR_CONDITIONAL_MENU)) {
     setVisibility(NavigationBarView.getEditMode() ? View.VISIBLE : View.INVISIBLE);
   } else if (itemKey.equals(NavbarEditor.NAVBAR_HOME)) {
     mSupportsLongpress = false;
   }
 }
  private void applyMode(int mode, boolean animate, boolean force) {
    // apply to key buttons
    final float alpha = alphaForMode(mode);
    setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_HOME, alpha, animate);
    setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_RECENT, alpha, animate);
    setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_CONDITIONAL_MENU, alpha, animate);
    setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_ALWAYS_MENU, alpha, animate);
    setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_MENU_BIG, alpha, animate);
    setKeyButtonViewQuiescentAlpha(mView.getSearchLight(), KEYGUARD_QUIESCENT_ALPHA, animate);
    setKeyButtonViewQuiescentAlpha(mView.getCameraButton(), KEYGUARD_QUIESCENT_ALPHA, animate);
    applyBackButtonQuiescentAlpha(mode, animate);

    // apply to lights out
    applyLightsOut(mode == MODE_LIGHTS_OUT, animate, force);
  }
  private void applyLightsOut(boolean lightsOut, boolean animate, boolean force) {
    if (!force && lightsOut == mLightsOut) return;

    mLightsOut = lightsOut;

    final View navButtons = mView.getCurrentView().findViewById(R.id.nav_buttons);
    final View lowLights = mView.getCurrentView().findViewById(R.id.lights_out);

    // ok, everyone, stop it right there
    navButtons.animate().cancel();
    lowLights.animate().cancel();

    final float navButtonsAlpha = lightsOut ? 0f : 1f;
    final float lowLightsAlpha = lightsOut ? 1f : 0f;

    if (!animate) {
      navButtons.setAlpha(navButtonsAlpha);
      lowLights.setAlpha(lowLightsAlpha);
      lowLights.setVisibility(lightsOut ? View.VISIBLE : View.GONE);
    } else {
      final int duration = lightsOut ? LIGHTS_OUT_DURATION : LIGHTS_IN_DURATION;
      navButtons.animate().alpha(navButtonsAlpha).setDuration(duration).start();

      lowLights.setOnTouchListener(mLightsOutListener);
      if (lowLights.getVisibility() == View.GONE) {
        lowLights.setAlpha(0f);
        lowLights.setVisibility(View.VISIBLE);
      }
      lowLights
          .animate()
          .alpha(lowLightsAlpha)
          .setDuration(duration)
          .setInterpolator(new AccelerateInterpolator(2.0f))
          .setListener(
              lightsOut
                  ? null
                  : new AnimatorListenerAdapter() {
                    @Override
                    public void onAnimationEnd(Animator _a) {
                      lowLights.setVisibility(View.GONE);
                    }
                  })
          .start();
    }
  }
 @Override
 public void run() {
   ViewParent parent = getParent();
   while (parent != null && !(parent instanceof NavigationBarView)) {
     parent = parent.getParent();
   }
   if (parent != null) {
     ((NavigationBarView) parent).onNavButtonTouched();
   }
 }
 public void applyBackButtonQuiescentAlpha(int mode, boolean animate) {
   float backAlpha = 0;
   backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getSearchLight());
   backAlpha = maxVisibleQuiescentAlpha(backAlpha, mView.getCameraButton());
   backAlpha =
       maxVisibleQuiescentAlpha(backAlpha, mView.findViewWithTag(NavbarEditor.NAVBAR_HOME));
   backAlpha =
       maxVisibleQuiescentAlpha(backAlpha, mView.findViewWithTag(NavbarEditor.NAVBAR_RECENT));
   backAlpha =
       maxVisibleQuiescentAlpha(
           backAlpha, mView.findViewWithTag(NavbarEditor.NAVBAR_CONDITIONAL_MENU));
   backAlpha =
       maxVisibleQuiescentAlpha(backAlpha, mView.findViewWithTag(NavbarEditor.NAVBAR_ALWAYS_MENU));
   backAlpha =
       maxVisibleQuiescentAlpha(backAlpha, mView.findViewWithTag(NavbarEditor.NAVBAR_MENU_BIG));
   if (backAlpha > 0) {
     setKeyButtonViewQuiescentAlpha(NavbarEditor.NAVBAR_BACK, backAlpha, animate);
   }
 }
  public boolean onTouchEvent(MotionEvent ev) {
    if (NavigationBarView.getEditMode()) {
      return false;
    }
    final int action = ev.getAction();
    int x, y;

    switch (action) {
      case MotionEvent.ACTION_DOWN:
        // Slog.d("KeyButtonView", "press");
        mDownTime = SystemClock.uptimeMillis();
        setPressed(true);
        if (mCode != 0) {
          sendEvent(KeyEvent.ACTION_DOWN, 0, mDownTime);
        } else {
          // Provide the same haptic feedback that the system offers for virtual keys.
          performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        }
        if (mSupportsLongpress) {
          removeCallbacks(mCheckLongPress);
          postDelayed(mCheckLongPress, ViewConfiguration.getLongPressTimeout());
        }
        break;
      case MotionEvent.ACTION_MOVE:
        x = (int) ev.getX();
        y = (int) ev.getY();
        setPressed(
            x >= -mTouchSlop
                && x < getWidth() + mTouchSlop
                && y >= -mTouchSlop
                && y < getHeight() + mTouchSlop);
        break;
      case MotionEvent.ACTION_CANCEL:
        setPressed(false);
        if (mCode != 0) {
          sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
        }
        if (mSupportsLongpress) {
          removeCallbacks(mCheckLongPress);
        }
        break;
      case MotionEvent.ACTION_UP:
        final boolean doIt = isPressed();
        setPressed(false);
        if (mCode != 0) {
          if (doIt) {
            sendEvent(KeyEvent.ACTION_UP, 0);
            sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
            playSoundEffect(SoundEffectConstants.CLICK);
          } else {
            sendEvent(KeyEvent.ACTION_UP, KeyEvent.FLAG_CANCELED);
          }
        } else {
          // no key code, just a regular ImageView
          if (doIt) {
            performClick();
          }
        }
        if (mSupportsLongpress) {
          removeCallbacks(mCheckLongPress);
        }
        break;
    }

    return true;
  }
 @Override
 public void setContentVisible(boolean visible) {
   final float alpha = visible ? 1 : 0;
   fadeContent(mView.getCameraButton(), alpha);
   fadeContent(mView.getSearchLight(), alpha);
 }