Ejemplo n.º 1
0
  private void init() {
    Resources res = getContext().getResources();

    mHandler = new Handler();
    mDelayedCancel =
        new Runnable() {
          @Override
          public void run() {
            cancelCircle(false);
          }
        };

    mAnimationOut = new CircleViewAnimation(this, 0, 0);
    mAnimationOut.setInterpolator(new AccelerateDecelerateInterpolator());
    mAnimationOut.setDuration(res.getInteger(android.R.integer.config_mediumAnimTime));

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.WHITE);
    mPaint.setStrokeWidth(2);

    mRadiusTarget = res.getDimension(R.dimen.circle_radius_target);
    mRadiusDecreaseThreshold = res.getDimension(R.dimen.circle_radius_decrease_threshold);

    mDrawable = res.getDrawable(R.drawable.ic_unlock);
    mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());

    setRadius(0);
  }
Ejemplo n.º 2
0
  public boolean onTouchEvent2(MotionEvent event) {
    // Cancel current circle on two-fingers touch (or more.)
    if (event.getPointerCount() > 1) {
      cancelCircle(false);
      return false;
    }

    // If current circle is canceled then
    // ignore all actions except of touch down (to reset state.)
    if (mCanceled && event.getActionMasked() != MotionEvent.ACTION_DOWN) return false;

    final float x = event.getX();
    final float y = event.getY();
    switch (event.getActionMasked()) {
      case MotionEvent.ACTION_DOWN:
        clearAnimation();

        // Initialize circle
        mRadiusMax = 0;
        mPoint[0] = x;
        mPoint[1] = y;
        mCanceled = false;

        mHandler.removeCallbacks(mDelayedCancel);
        mHandler.postDelayed(mDelayedCancel, 1000);
        mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_START);
      case MotionEvent.ACTION_MOVE:
        setRadius((float) Math.hypot(x - mPoint[0], y - mPoint[1]));

        // Cancel the circle if it's decreasing.
        if (mRadiusMax - mRadius > mRadiusDecreaseThreshold) {
          mRadiusAimed = false;
          cancelCircle(false);
          break;
        }

        if (calculateRatio() == 1) {
          if (!mRadiusAimed) {
            mRadiusAimed = true;
            performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
          }
        } else if (mRadiusAimed) {
          mRadiusAimed = false;
          performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
        }
        break;
      case MotionEvent.ACTION_UP:
        if (mRadiusAimed) {
          mCallback.onCircleEvent(mRadius, calculateRatio(), ACTION_UNLOCK);
        }
      case MotionEvent.ACTION_CANCEL:
        mHandler.removeCallbacks(mDelayedCancel);
        cancelCircle(mRadiusAimed);
        break;
      default:
        return super.onTouchEvent(event);
    }
    return false;
  }
  @Override
  protected void applyTransformation(float interpolatedTime, Transformation t) {
    super.applyTransformation(interpolatedTime, t);
    float value = (from + (to - from) * interpolatedTime);

    if (mChangeDrawnRadius) {
      mCircleView.setRadiusDrawn(value);
    } else {
      mCircleView.setRadius(value);
    }
  }
Ejemplo n.º 4
0
 public void setRadiusTarget(float radiusTarget) {
   mRadiusTarget = radiusTarget;
   setRadius(mRadius);
 }