@Override
  public boolean onTouchEvent(MotionEvent event) {
    // Call the superclass onTouchEvent first, because sometimes it changes the state to
    // isPressed() on an ACTION_UP
    boolean result = super.onTouchEvent(event);

    switch (event.getAction()) {
      case MotionEvent.ACTION_DOWN:
        // So that the pressed outline is visible immediately on setStayPressed(),
        // we pre-create it on ACTION_DOWN (it takes a small but perceptible amount of time
        // to create it)
        if (mPressedBackground == null) {
          mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
        }

        mLongPressHelper.postCheckForLongPress();
        break;
      case MotionEvent.ACTION_CANCEL:
      case MotionEvent.ACTION_UP:
        // If we've touched down and up on an item, and it's still not "pressed", then
        // destroy the pressed outline
        if (!isPressed()) {
          mPressedBackground = null;
        }

        mLongPressHelper.cancelLongPress();
        break;
      case MotionEvent.ACTION_MOVE:
        if (!Utilities.pointInView(this, event.getX(), event.getY(), mSlop)) {
          mLongPressHelper.cancelLongPress();
        }
        break;
    }
    return result;
  }
  private void init() {
    mLongPressHelper = new CheckLongPressHelper(this);

    mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
    if (mCustomShadowsEnabled) {
      setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
    }
  }
 @Override
 public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (super.onKeyDown(keyCode, event)) {
     // Pre-create shadow so show immediately on click.
     if (mPressedBackground == null) {
       mPressedBackground = mOutlineHelper.createMediumDropShadow(this);
     }
     return true;
   }
   return false;
 }
  /**
   * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
   * Responsibility for the bitmap is transferred to the caller.
   */
  private Bitmap createGlowingOutline(Canvas canvas, int outlineColor, int glowColor) {
    final int padding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS;
    final Bitmap b =
        Bitmap.createBitmap(getWidth() + padding, getHeight() + padding, Bitmap.Config.ARGB_8888);

    canvas.setBitmap(b);
    drawWithPadding(canvas, padding);
    mOutlineHelper.applyExtraThickExpensiveOutlineWithBlur(b, canvas, glowColor, outlineColor);
    canvas.setBitmap(null);

    return b;
  }
Exemplo n.º 5
0
  private void init() {
    mLongPressHelper = new CheckLongPressHelper(this);
    mBackground = getBackground();

    mOutlineHelper = HolographicOutlineHelper.obtain(getContext());

    final Resources res = getContext().getResources();
    mFocusedOutlineColor =
        mFocusedGlowColor =
            mPressedOutlineColor = mPressedGlowColor = res.getColor(R.color.outline_color);

    setShadowLayer(SHADOW_LARGE_RADIUS, 0.0f, SHADOW_Y_OFFSET, SHADOW_LARGE_COLOUR);
  }