/**
  * Configures the necessary {@link Matrix} transformation to `mTextureView`. This method should be
  * called after the camera preview size is determined in setUpCameraOutputs and also the size of
  * `mTextureView` is fixed.
  *
  * @param viewWidth The width of `mTextureView`
  * @param viewHeight The height of `mTextureView`
  */
 private void configureTransform(int viewWidth, int viewHeight) {
   Activity activity = getActivity();
   if (null == mTextureView || null == mPreviewSize || null == activity) {
     return;
   }
   int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
   Matrix matrix = new Matrix();
   RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
   RectF bufferRect = new RectF(0, 0, mPreviewSize.getHeight(), mPreviewSize.getWidth());
   float centerX = viewRect.centerX();
   float centerY = viewRect.centerY();
   if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
     bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY());
     matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL);
     float scale =
         Math.max(
             (float) viewHeight / mPreviewSize.getHeight(),
             (float) viewWidth / mPreviewSize.getWidth());
     matrix.postScale(scale, scale, centerX, centerY);
     matrix.postRotate(90 * (rotation - 2), centerX, centerY);
   } else if (Surface.ROTATION_180 == rotation) {
     matrix.postRotate(180, centerX, centerY);
   }
   mTextureView.setTransform(matrix);
 }
  @Override
  public void draw(Canvas canvas) {
    mBounds.set(getBounds());

    if (mMode == MODE_RATING) {
      float arcAngle = mCurrentValue * 360f;
      final float arcStart = -90f;
      canvas.drawArc(mBounds, arcStart + arcAngle, 360f - arcAngle, true, mBackgroundArcPaint);
      canvas.drawArc(mBounds, arcStart, arcAngle, true, mArcPaint);
    } else if (mMode == MODE_PROMPT) {
      canvas.drawCircle(
          mBounds.centerX(),
          mBounds.centerY(),
          mBounds.height() * BACKGROUND_CIRCLE_RADIUS_RATIO,
          mBackgroundArcPaint);
    }

    canvas.drawCircle(
        mBounds.centerX(),
        mBounds.centerY(),
        mBounds.height() * FOREGROUND_CIRCLE_RADIUS_RATIO,
        mForegroundCirclePaint);

    if (mText != null) {
      canvas.drawText(
          mText,
          mBounds.centerX() - (mTextWidth / 2f),
          mBounds.centerY() + (mTextHeight / 2f),
          mTextPaint);
    }
  }
  @Override
  public void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    int count = mPagesCount;
    if (count == 0) {
      return;
    }
    float cx = canvas.getWidth() >> 1;
    float cy = canvas.getHeight() >> 1;
    int totalCount = 2 * count - 1;
    int halfCount = totalCount / 2;
    float itemWithOffset = mIndicatorElementSize + mIndicatorElementSpacing;
    float halfItemWithOffset = mIndicatorElementSize / 2 + mIndicatorElementSpacing;
    float halfSize = mIndicatorElementSize / 2f;
    float halfSpacing = mIndicatorElementSpacing / 2f;
    float startX = cx - halfCount * (mIndicatorElementSize + mIndicatorElementSpacing);
    float top = cy - halfSize;
    float bottom = cy + halfSize;
    // if we have odd elements - need to set indicators in center
    if (totalCount % 2 != 0) {
      startX -= halfSize + halfSpacing;
    }

    int i;
    for (i = 0; i < totalCount; i++) {
      // skip empty spaces
      if (i % 2 != 0) {
        continue;
      }
      float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * i;
      float right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      mRenderer.draw(canvas, mElementBounds, mIndicatorPaint, false);
    }

    // multiply on 2 because there are spaces between elements
    float activeItemOffset = (mSelectedPosition + mScrolledOffset) * 2;
    float left = startX + (mIndicatorElementSize + mIndicatorElementSpacing) * activeItemOffset;
    float right = left + mIndicatorElementSize;
    mElementBounds.set(left, top, right, bottom);

    canvas.clipRect(mClipBounds);

    canvas.save();
    canvas.rotate(ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
    mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
    canvas.restore();

    if (mIsInfiniteScroll && mSelectedPosition == mPagesCount - 1) { // isInfinite && isEnd
      activeItemOffset = (1f - mScrolledOffset) * 2;
      left = mClipBounds.left - itemWithOffset * activeItemOffset + halfItemWithOffset;
      right = left + mIndicatorElementSize;
      mElementBounds.set(left, top, right, bottom);
      canvas.save();
      canvas.rotate(
          ANGLE_360 * mScrolledOffset, mElementBounds.centerX(), mElementBounds.centerY());
      mRenderer.draw(canvas, mElementBounds, mIndicatorSelectedPaint, true);
      canvas.restore();
    }
  }
Example #4
0
 void drawTestBox(Canvas cv, RectF r, float rot, String text) {
   cv.save();
   cv.translate(r.centerX(), r.centerY());
   cv.rotate((float) (rot * 180 / Math.PI));
   RectF rs = new RectF(-r.width() / 2, -r.height() / 2, r.width() / 2, r.height() / 2);
   cv.drawRect(rs, paintIcon);
   if (text != null) {
     paintText.setTextSize(paintText.getTextSize() - 4);
     cv.drawText(text, rs.centerX(), rs.centerY(), paintText);
     paintText.setTextSize(paintText.getTextSize() + 4);
   }
   cv.restore();
 }
  private void computeGlyphPath() {
    drawableArea.set(getBounds());
    drawableArea.inset(padding, padding);
    glyphPaint.getTextPath(glyph, 0, 1, 0, 0, glyphPath);
    // Add an extra path point to fix the icon remaining blank on a Galaxy Note 2 running 4.1.2.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float centerX = glyphPathBounds.centerX();
    final float centerY = glyphPathBounds.centerY();
    glyphPath.moveTo(centerX, centerY);
    glyphPath.lineTo(centerX + 0.001f, centerY + 0.001f);
    final float areaWidthF = (float) drawableArea.width();
    final float areaHeightF = (float) drawableArea.height();
    final float scaleX = areaWidthF / glyphPathBounds.width();
    final float scaleY = areaHeightF / glyphPathBounds.height();
    final float scaleFactor = Math.min(scaleX, scaleY);
    glyphPathTransform.setScale(scaleFactor, scaleFactor);
    glyphPath.transform(glyphPathTransform);

    // TODO this two pass calculation irks me.
    // It has to be possible to push this into a single Matrix transform; what makes it hard is
    // that the origin of Text is not top-left, but baseline-left so need to account for that.
    glyphPath.computeBounds(glyphPathBounds, false);
    final float areaLeftF = (float) drawableArea.left;
    final float areaTopF = (float) drawableArea.top;
    float transX = areaLeftF - glyphPathBounds.left;
    transX += 0.5f * Math.abs(areaWidthF - glyphPathBounds.width());
    float transY = areaTopF - glyphPathBounds.top;
    transY += 0.5f * Math.abs(areaHeightF - glyphPathBounds.height());
    glyphPath.offset(transX, transY);

    invalidateSelf();
  }
Example #6
0
  @Override
  public void draw(@NonNull Canvas canvas) {
    super.draw(canvas);

    float x =
        (mDrawRect.width() - mThumbRadius * 2) * mThumbPosition + mDrawRect.left + mThumbRadius;
    if (mIsRtl) x = 2 * mDrawRect.centerX() - x;
    float y = mDrawRect.centerY();

    getTrackPath(x, y, mThumbRadius);
    mPaint.setColor(
        ColorUtil.getMiddleColor(getTrackColor(false), getTrackColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawPath(mTrackPath, mPaint);

    if (mShadowSize > 0) {
      int saveCount = canvas.save();
      canvas.translate(x, y + mShadowOffset);
      canvas.drawPath(mShadowPath, mShadowPaint);
      canvas.restoreToCount(saveCount);
    }

    mPaint.setColor(
        ColorUtil.getMiddleColor(getThumbColor(false), getThumbColor(true), mThumbPosition));
    mPaint.setStyle(Paint.Style.FILL);
    canvas.drawCircle(x, y, mThumbRadius, mPaint);
  }
 public void scale(float scale, boolean checkScale) {
   Log.i(
       TAG,
       "Before setScale scale = "
           + scale
           + " getMaxScaleValue = "
           + getMaxScaleValue()
           + " getMinScaleValue = "
           + getMinScaleValue());
   if (checkScale) {
     float scaleValue = mCurrentScaleValue * scale;
     // check max scale value
     if (scale > 1) {
       scale = scaleValue > getMaxScaleValue() ? 1f : scale;
     }
     // check minimal scale value
     if (scale < 1) {
       scale = scaleValue < getMinScaleValue() ? 1f : scale;
     }
     mCurrentScaleValue = mCurrentScaleValue * scale;
   }
   Log.i(TAG, "setScale mCurrentScaleValue = " + mCurrentScaleValue);
   mAnimationMatrix.reset();
   mAnimationMatrix.setScale(scale, scale, mRectF.centerX(), mRectF.centerY());
   mAnimationMatrix.mapRect(mRectF);
   setVetex(mRectF.left, mRectF.top, mRectF.right, mRectF.bottom);
   mOriginalDistance =
       (float)
           Math.sqrt(
               (centerX() - rightBottom[0]) * (centerX() - rightBottom[0])
                   + (centerY() - rightBottom[1]) * (centerY() - rightBottom[1]));
   Log.i(TAG, "After setScale scale = " + scale);
 }
Example #8
0
  private void drawNeedle(Canvas canvas) {
    RectF oval = getOval(canvas, 1);
    float radius = oval.width() * 0.35f + 10;
    RectF smallOval = getOval(canvas, 0.2f);

    float angle = 10 + (float) (getSpeed() / getMaxSpeed() * 160);
    canvas.drawLine(
        (float)
            (oval.centerX() + Math.cos((180 - angle) / 180 * Math.PI) * smallOval.width() * 0.5f),
        (float) (oval.centerY() - Math.sin(angle / 180 * Math.PI) * smallOval.width() * 0.5f),
        (float) (oval.centerX() + Math.cos((180 - angle) / 180 * Math.PI) * (radius)),
        (float) (oval.centerY() - Math.sin(angle / 180 * Math.PI) * (radius)),
        needlePaint);

    canvas.drawArc(smallOval, 180, 180, true, backgroundPaint);
  }
Example #9
0
  @Override
  public void draw(Canvas canvas) {
    canvas.drawRoundRect(mRectF, mRadius, mRadius, mBorderPaint);

    Path path = new Path();
    path.moveTo(mRectF.right - 2 * mOffsetY - mOffsetX, mRectF.bottom);
    path.lineTo(mRectF.right - (2 * mOffsetY + mRadius) / 2 - mOffsetX, mRectF.bottom + mOffsetY);
    path.lineTo(mRectF.right - mRadius - mOffsetX, mRectF.bottom);

    float x = 0;
    float y = mRectF.centerY();

    String text = "One Piece";
    float[] characterWidths = new float[text.length()];
    int characterNum = mTextPaint.getTextWidths(text, characterWidths);

    float textWidth = 0f;
    for (int i = 0; i < characterNum; i++) {
      textWidth += characterWidths[i];
    }
    canvas.save();
    canvas.translate(mRectF.width() / 2 - textWidth / 2, 0);
    canvas.drawText("one piece", x, y, mTextPaint);

    canvas.restore();
    canvas.drawPath(path, mBorderPaint);
  }
 /**
  * Resizes rectangle to have a certain aspect ratio (center remains stationary).
  *
  * @param r rectangle to resize
  * @param w new width aspect
  * @param h new height aspect
  */
 public static void fixAspectRatio(RectF r, float w, float h) {
   float scale = Math.min(r.width() / w, r.height() / h);
   float centX = r.centerX();
   float centY = r.centerY();
   float hw = scale * w / 2;
   float hh = scale * h / 2;
   r.set(centX - hw, centY - hh, centX + hw, centY + hh);
 }
 public void scaleToTranslateY(float scaleY) {
   Log.i(TAG, "setScaleToTranslateY");
   float[] rt = new float[] {rightTop[0], rightTop[1]};
   mAnimationMatrix.reset();
   mAnimationMatrix.setScale(1, scaleY, mRectF.centerX(), mRectF.centerY());
   mAnimationMatrix.mapPoints(rt);
   translate(0, rt[1] - rightTop[1], false);
 }
  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) {
            parent.requestDisallowInterceptTouchEvent(true);
          } else {
            LogManager.getLogger().i(LOG_TAG, "onTouch getParent() returned null");
          }

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Try the Scale/Drag detector
      if (null != mScaleDragDetector) {
        boolean wasScaling = mScaleDragDetector.isScaling();
        boolean wasDragging = mScaleDragDetector.isDragging();

        handled = mScaleDragDetector.onTouchEvent(ev);

        boolean didntScale = !wasScaling && !mScaleDragDetector.isScaling();
        boolean didntDrag = !wasDragging && !mScaleDragDetector.isDragging();

        mBlockParentIntercept = didntScale && didntDrag;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
Example #13
0
  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    measureRect();

    if (mDragHandlerPaint == null) {
      return;
    }
    if (mMarginPaint == null) {
      return;
    }
    if (INNER_RECT) {
      canvas.save();
      canvas.drawLine(
          mBitmapRectPoints[0],
          mBitmapRectPoints[1],
          mBitmapRectPoints[2],
          mBitmapRectPoints[3],
          mMarginPaint);
      canvas.drawLine(
          mBitmapRectPoints[4],
          mBitmapRectPoints[5],
          mBitmapRectPoints[6],
          mBitmapRectPoints[7],
          mMarginPaint);
      canvas.drawLine(
          mBitmapRectPoints[0],
          mBitmapRectPoints[1],
          mBitmapRectPoints[4],
          mBitmapRectPoints[5],
          mMarginPaint);
      canvas.drawLine(
          mBitmapRectPoints[2],
          mBitmapRectPoints[3],
          mBitmapRectPoints[6],
          mBitmapRectPoints[7],
          mMarginPaint);
      canvas.drawCircle(mBitmapRectPoints[0], mBitmapRectPoints[1], mRadius, mDragHandlerPaint);
      canvas.drawCircle(mBitmapRectPoints[2], mBitmapRectPoints[3], mRadius, mDragHandlerPaint);
      canvas.drawCircle(mBitmapRectPoints[4], mBitmapRectPoints[5], mRadius, mDragHandlerPaint);
      canvas.drawCircle(mBitmapRectPoints[6], mBitmapRectPoints[7], mRadius, mDragHandlerPaint);
      canvas.restore();
    } else {
      canvas.save();
      canvas.drawRect(mMarginRectF, mMarginPaint);
      canvas.drawCircle(mMarginRectF.left, mMarginRectF.top, mRadius, mDragHandlerPaint);
      canvas.drawCircle(mMarginRectF.right, mMarginRectF.top, mRadius, mDragHandlerPaint);
      canvas.drawCircle(mMarginRectF.left, mMarginRectF.bottom, mRadius, mDragHandlerPaint);
      canvas.drawCircle(mMarginRectF.right, mMarginRectF.bottom, mRadius, mDragHandlerPaint);
      canvas.restore();
    }

    if (!(mDragPoint.x == INVALID_POINT && mDragPoint.y == INVALID_POINT)) {
      canvas.save();
      canvas.drawCircle(mMarginRectF.centerX(), mMarginRectF.centerY(), mRadius, mDragHandlerPaint);
      canvas.restore();
    }
  }
 /**
  * Checks if a given point is within a rotated rectangle.
  *
  * @param point 2D point to check
  * @param bound rectangle to rotate
  * @param rot angle of rotation about rectangle center
  * @return true if point is within rotated rectangle
  */
 public static boolean pointInRotatedRect(float[] point, RectF bound, float rot) {
   Matrix m = new Matrix();
   float[] p = Arrays.copyOf(point, 2);
   m.setRotate(rot, bound.centerX(), bound.centerY());
   Matrix m0 = new Matrix();
   if (!m.invert(m0)) return false;
   m0.mapPoints(p);
   return inclusiveContains(bound, p[0], p[1]);
 }
 @Override
 public void onDraw(Canvas canvas) {
   if (mDrawCircle) {
     canvas.drawCircle(mAnimateFrom.centerX(), mAnimateFrom.centerY(), mRadius, mPaint);
   } else if (mFill) {
     canvas.drawPaint(mPaint);
   }
   super.onDraw(canvas);
 }
Example #16
0
  @Override
  public void onFaceDetection(Camera.Face[] faces, Camera camera) {
    RectF rectf = new RectF();

    for (Camera.Face face : faces) {
      int centerX = face.rect.centerX();
      int centerY = face.rect.centerY();

      android.graphics.Matrix matrix = new android.graphics.Matrix();
      // Width needs to be divided by 2 because the overlay is for both eyes:
      prepareMatrix(matrix, false, mOverlayView.getWidth() / 2, mOverlayView.getHeight());
      rectf.set(face.rect);
      matrix.mapRect(rectf);

      mOverlayView.show3DRect((int) rectf.centerX(), (int) rectf.centerY());
      mOverlayView.show3DToast("Found face! x = " + rectf.centerX() + ", y = " + rectf.centerY());
    }
  }
  private Path createRiverPath(RectF arcBounds) {
    if (mRiverPath != null) {
      return mRiverPath;
    }

    mRiverPath = new Path();

    RectF rectF =
        new RectF(
            arcBounds.centerX() - mRiverWidth / 2.0f,
            arcBounds.centerY() - mRiverHeight / 2.0f,
            arcBounds.centerX() + mRiverWidth / 2.0f,
            arcBounds.centerY() + mRiverHeight / 2.0f);

    rectF.inset(mStrokeWidth / 2.0f, mStrokeWidth / 2.0f);

    mRiverPath.addRect(rectF, Path.Direction.CW);

    return mRiverPath;
  }
Example #18
0
  @Override
  protected void onDraw(Canvas canvas) {
    if (mDisableCircularTransformation) {
      super.onDraw(canvas);
      return;
    }

    if (mBitmap == null) {
      return;
    }

    if (mFillColor != Color.TRANSPARENT) {
      canvas.drawCircle(
          mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mFillPaint);
    }
    canvas.drawCircle(
        mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mBitmapPaint);
    if (mBorderWidth > 0) {
      canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRadius, mBorderPaint);
    }
  }
  /**
   * Calculates the offset of the touch point from the precise location of the specified handle.<br>
   * Save these values in a member variable since we want to maintain this offset as we drag the
   * handle.
   */
  private void calculateTouchOffset(RectF rect, float touchX, float touchY) {

    float touchOffsetX = 0;
    float touchOffsetY = 0;

    // Calculate the offset from the appropriate handle.
    switch (mType) {
      case TOP_LEFT:
        touchOffsetX = rect.left - touchX;
        touchOffsetY = rect.top - touchY;
        break;
      case TOP_RIGHT:
        touchOffsetX = rect.right - touchX;
        touchOffsetY = rect.top - touchY;
        break;
      case BOTTOM_LEFT:
        touchOffsetX = rect.left - touchX;
        touchOffsetY = rect.bottom - touchY;
        break;
      case BOTTOM_RIGHT:
        touchOffsetX = rect.right - touchX;
        touchOffsetY = rect.bottom - touchY;
        break;
      case LEFT:
        touchOffsetX = rect.left - touchX;
        touchOffsetY = 0;
        break;
      case TOP:
        touchOffsetX = 0;
        touchOffsetY = rect.top - touchY;
        break;
      case RIGHT:
        touchOffsetX = rect.right - touchX;
        touchOffsetY = 0;
        break;
      case BOTTOM:
        touchOffsetX = 0;
        touchOffsetY = rect.bottom - touchY;
        break;
      case CENTER:
        touchOffsetX = rect.centerX() - touchX;
        touchOffsetY = rect.centerY() - touchY;
        break;
      default:
        break;
    }

    mTouchOffset.x = touchOffsetX;
    mTouchOffset.y = touchOffsetY;
  }
Example #20
0
  private void checkMinScale() {
    DraweeView<GenericDraweeHierarchy> draweeView = getDraweeView();
    if (draweeView == null) {
      return;
    }

    if (getScale() < mMinScale) {
      RectF rect = getDisplayRect();
      if (null != rect) {
        draweeView.post(
            new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
      }
    }
  }
  @Override
  public final boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      ViewParent parent = v.getParent();
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (null != parent) parent.requestDisallowInterceptTouchEvent(true);
          else Log.i(LOG_TAG, "onTouch getParent() returned null");

          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }

      if (!handled && null != parent) {
        parent.requestDisallowInterceptTouchEvent(false);
      }

      // Finally, try the Scale/Drag detector
      if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
  @Override
  public int compare(final PageTreeNode node1, final PageTreeNode node2) {
    final int cp = viewState.currentIndex;
    final int viewIndex1 = node1.page.index.viewIndex;
    final int viewIndex2 = node2.page.index.viewIndex;

    final boolean v1 = viewState.isNodeVisible(node1, viewState.getBounds(node1.page));
    final boolean v2 = viewState.isNodeVisible(node2, viewState.getBounds(node2.page));

    final RectF s1 = node1.pageSliceBounds;
    final RectF s2 = node2.pageSliceBounds;

    int res = 0;

    if (viewIndex1 == cp && viewIndex2 == cp) {
      res = CompareUtils.compare(s1.top, s2.top);
      if (res == 0) {
        res = CompareUtils.compare(s1.left, s2.left);
      }
    } else if (v1 && !v2) {
      res = -1;
    } else if (!v1 && v2) {
      res = 1;
    } else {
      final float d1 = viewIndex1 + s1.centerY() - (cp + 0.5f);
      final float d2 = viewIndex2 + s2.centerY() - (cp + 0.5f);
      final int dist1 = Math.abs((int) (d1 * node1.childrenZoomThreshold));
      final int dist2 = Math.abs((int) (d2 * node2.childrenZoomThreshold));
      res = CompareUtils.compare(dist1, dist2);
      if (res == 0) {
        res = -CompareUtils.compare(viewIndex1, viewIndex2);
      }
    }

    return res;
  }
Example #23
0
    private void drawSlowIndicator(float startAngle, Canvas canvas) {
      Paint circlePaint = new Paint();
      circlePaint.setAntiAlias(true);
      circlePaint.setColor(Color.parseColor("#A8D7A7"));
      circlePaint.setStrokeWidth(7);
      circlePaint.setStyle(Paint.Style.STROKE);
      canvas.drawPath(getArcPath(), circlePaint);

      int restoreCount = canvas.save();
      canvas.translate(rectF.centerX(), rectF.centerY());
      circlePaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(getBallPath(startAngle + 90), circlePaint);
      canvas.drawPath(getBallPath(startAngle + 90 + 30 + 90), circlePaint);
      canvas.drawPath(getBallPath(startAngle + 90 + 30 + 90 + 30 + 90), circlePaint);
      canvas.restoreToCount(restoreCount);
    }
Example #24
0
  private void drawAlphaPanel(Canvas canvas) {

    if (!mShowAlphaPanel || mAlphaRect == null || mAlphaPattern == null) return;

    final RectF rect = mAlphaRect;

    if (BORDER_WIDTH_PX > 0) {
      mBorderPaint.setColor(mBorderColor);
      canvas.drawRect(
          rect.left - BORDER_WIDTH_PX,
          rect.top - BORDER_WIDTH_PX,
          rect.right + BORDER_WIDTH_PX,
          rect.bottom + BORDER_WIDTH_PX,
          mBorderPaint);
    }

    mAlphaPattern.draw(canvas);

    float[] hsv = new float[] {mHue, mSat, mVal};
    int color = Color.HSVToColor(hsv);
    int acolor = Color.HSVToColor(0, hsv);

    mAlphaShader =
        new LinearGradient(
            rect.left, rect.top, rect.right, rect.top, color, acolor, TileMode.CLAMP);

    mAlphaPaint.setShader(mAlphaShader);

    canvas.drawRect(rect, mAlphaPaint);

    if (mAlphaSliderText != null && mAlphaSliderText != "") {
      canvas.drawText(
          mAlphaSliderText, rect.centerX(), rect.centerY() + 4 * mDensity, mAlphaTextPaint);
    }

    float rectWidth = 4 * mDensity / 2;

    Point p = alphaToPoint(mAlpha);

    RectF r = new RectF();
    r.left = p.x - rectWidth;
    r.right = p.x + rectWidth;
    r.top = rect.top - RECTANGLE_TRACKER_OFFSET;
    r.bottom = rect.bottom + RECTANGLE_TRACKER_OFFSET;

    canvas.drawRoundRect(r, 2, 2, mHueTrackerPaint);
  }
 /**
  * Resizes rectangle to have a certain aspect ratio (center remains stationary) while constraining
  * it to remain within the original rect.
  *
  * @param r rectangle to resize
  * @param w new width aspect
  * @param h new height aspect
  */
 public static void fixAspectRatioContained(RectF r, float w, float h) {
   float origW = r.width();
   float origH = r.height();
   float origA = origW / origH;
   float a = w / h;
   float finalW = origW;
   float finalH = origH;
   if (origA < a) {
     finalH = origW / a;
     r.top = r.centerY() - finalH / 2;
     r.bottom = r.top + finalH;
   } else {
     finalW = origH * a;
     r.left = r.centerX() - finalW / 2;
     r.right = r.left + finalW;
   }
 }
Example #26
0
  @SuppressLint("ClickableViewAccessibility")
  @Override
  public boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (mZoomEnabled && hasDrawable((ImageView) v)) {
      getViewParentsFromImageView(v);
      switch (ev.getAction()) {
        case ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          setParentDisallowInterceptTouchEvent(true);
          // If we're flinging, and the user presses down, cancel
          // fling
          cancelFling();
          break;

        case ACTION_CANCEL:
        case ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < mMinScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), mMinScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Try the Scale/Drag detector
      if (null != mScaleDragDetector && mScaleDragDetector.onTouchEvent(ev)) {
        handled = true;
      }

      // Check to see if the user double tapped
      if (null != mGestureDetector && mGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
Example #27
0
  @Override
  protected void onLayout(boolean changed, int l, int t, int r, int b) {
    if (angleChanged) {
      final RectF layoutRect = tempRectF1;
      final RectF layoutRectRotated = tempRectF2;
      layoutRect.set(0, 0, r - l, b - t);
      rotateMatrix.setRotate(angle, layoutRect.centerX(), layoutRect.centerY());
      rotateMatrix.mapRect(layoutRectRotated, layoutRect);
      layoutRectRotated.round(viewRectRotated);
      angleChanged = false;
    }

    final View view = getView();
    if (view != null) {
      view.layout(
          viewRectRotated.left, viewRectRotated.top, viewRectRotated.right, viewRectRotated.bottom);
    }
  }
  @Override
  public final boolean onTouch(View v, MotionEvent ev) {
    boolean handled = false;

    if (isZoomEnabled) {
      switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
          // First, disable the Parent from intercepting the touch
          // event
          if (v.getParent() != null) {
            v.getParent().requestDisallowInterceptTouchEvent(true);
          }

          // If we're flinging, and the user presses down, cancel
          // fling
          if (currentFlingRunnable != null) {
            currentFlingRunnable.cancelFling();
            currentFlingRunnable = null;
          }
          break;

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
          // If the user has zoomed less than min scale, zoom back
          // to min scale
          if (getScale() < minScale) {
            RectF rect = getDisplayRect();
            if (null != rect) {
              v.post(
                  new AnimatedZoomRunnable(getScale(), minScale, rect.centerX(), rect.centerY()));
              handled = true;
            }
          }
          break;
      }

      // Finally, try the scale/drag/tap detector
      if ((multiGestureDetector != null) && multiGestureDetector.onTouchEvent(ev)) {
        handled = true;
      }
    }

    return handled;
  }
 @Override
 public void onFaceDetection(Camera.Face[] faces, Camera camera) {
   Log.v("FaceDetection", "face detected: " + faces.length);
   for (int i = 0; i < faces.length; i++) {
     if (faces[0].score > 10) {
       RectF rect = new RectF(faces[i].rect);
       Log.i(
           "FaceDetection",
           " Face " + i + " Location X: " + rect.centerX() + "Y: " + rect.centerY());
       // Need mirror for front camera.
       matrix.setScale(-1, 1);
       matrix.postRotate(displayRotation);
       matrix.postScale(surfaceView.getWidth() / 2000f, surfaceView.getHeight() / 2000f);
       matrix.postTranslate(surfaceView.getWidth() / 2f, surfaceView.getHeight() / 2f);
       matrix.mapRect(rect);
       drawFocusRect(rect, Color.GREEN);
     }
   }
 }
Example #30
0
    private void drawSeekbar(Canvas canvas, float startAngle) {
      Paint circlePaint = new Paint();
      circlePaint.setAntiAlias(true);
      circlePaint.setColor(Color.parseColor("#FF4444"));
      circlePaint.setStrokeWidth(7);
      circlePaint.setStyle(Paint.Style.STROKE);

      Path path = new Path();
      path.addArc(rectF, 0, startAngle);
      canvas.drawPath(path, circlePaint);

      int restoreCount = canvas.save();

      canvas.translate(rectF.centerX(), rectF.centerY());
      circlePaint.setStyle(Paint.Style.FILL);
      canvas.drawPath(getBallPath(startAngle), circlePaint);

      canvas.restoreToCount(restoreCount);
    }