Search in sources :

Example 51 with RectF

use of android.graphics.RectF in project chromeview by pwnall.

the class PopupZoomer method onDraw.

@Override
protected void onDraw(Canvas canvas) {
    if (!isShowing() || mZoomedBitmap == null)
        return;
    if (!acceptZeroSizeView() && (getWidth() == 0 || getHeight() == 0))
        return;
    if (mNeedsToInitDimensions) {
        mNeedsToInitDimensions = false;
        initDimensions();
    }
    canvas.save();
    // Calculate the elapsed fraction of animation.
    float time = (SystemClock.uptimeMillis() - mAnimationStartTime + mTimeLeft) / ((float) ANIMATION_DURATION);
    time = constrain(time, 0, 1);
    if (time >= 1) {
        mAnimating = false;
        if (!isShowing()) {
            hideImmediately();
            return;
        }
    } else {
        invalidate();
    }
    // Fraction of the animation to actally show.
    float fractionAnimation;
    if (mShowing) {
        fractionAnimation = mShowInterpolator.getInterpolation(time);
    } else {
        fractionAnimation = mHideInterpolator.getInterpolation(time);
    }
    // Draw a faded color over the entire view to fade out the original content, increasing
    // the alpha value as fractionAnimation increases.
    // TODO(nileshagrawal): We should use time here instead of fractionAnimation
    // as fractionAnimaton is interpolated and can go over 1.
    canvas.drawARGB((int) (80 * fractionAnimation), 0, 0, 0);
    canvas.save();
    // Since we want the content to appear directly above its counterpart we need to make
    // sure that it starts out at exactly the same size as it appears in the page,
    // i.e. scale grows from 1/mScale to 1. Note that extrusion values are already zoomed
    // with mScale.
    float scale = fractionAnimation * (mScale - 1.0f) / mScale + 1.0f / mScale;
    // Since we want the content to appear directly above its counterpart on the
    // page, we need to remove the mShiftX/Y effect at the beginning of the animation.
    // The unshifting decreases with the animation.
    float unshiftX = -mShiftX * (1.0f - fractionAnimation) / mScale;
    float unshiftY = -mShiftY * (1.0f - fractionAnimation) / mScale;
    // Compute the rect to show.
    RectF rect = new RectF();
    rect.left = mTouch.x - mLeftExtrusion * scale + unshiftX;
    rect.top = mTouch.y - mTopExtrusion * scale + unshiftY;
    rect.right = mTouch.x + mRightExtrusion * scale + unshiftX;
    rect.bottom = mTouch.y + mBottomExtrusion * scale + unshiftY;
    canvas.clipRect(rect);
    // Since the canvas transform APIs all pre-concat the transformations, this is done in
    // reverse order. The canvas is first scaled up, then shifted the appropriate amount of
    // pixels.
    canvas.scale(scale, scale, rect.left, rect.top);
    canvas.translate(mPopupScrollX, mPopupScrollY);
    canvas.drawBitmap(mZoomedBitmap, rect.left, rect.top, null);
    canvas.restore();
    Drawable overlayNineTile = getOverlayDrawable(getContext());
    overlayNineTile.setBounds((int) rect.left - sOverlayPadding.left, (int) rect.top - sOverlayPadding.top, (int) rect.right + sOverlayPadding.right, (int) rect.bottom + sOverlayPadding.bottom);
    // TODO(nileshagrawal): We should use time here instead of fractionAnimation
    // as fractionAnimaton is interpolated and can go over 1.
    int alpha = constrain((int) (fractionAnimation * 255), 0, 255);
    overlayNineTile.setAlpha(alpha);
    overlayNineTile.draw(canvas);
    canvas.restore();
}
Also used : RectF(android.graphics.RectF) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint)

Example 52 with RectF

use of android.graphics.RectF in project platform_frameworks_base by android.

the class SparseRectFArrayTest method testBuilder.

@SmallTest
public void testBuilder() throws Exception {
    final RectF TEMP_RECT = new RectF(10.0f, 20.0f, 30.0f, 40.0f);
    final int TEMP_FLAGS = 0x1234;
    final SparseRectFArrayBuilder builder = new SparseRectFArrayBuilder();
    builder.append(100, TEMP_RECT.left, TEMP_RECT.top, TEMP_RECT.right, TEMP_RECT.bottom, TEMP_FLAGS);
    assertNull(builder.build().get(-1));
    assertNull(builder.build().get(0));
    assertNull(builder.build().get(99));
    assertEquals(0, builder.build().getFlags(99, 0));
    assertEquals(1, builder.build().getFlags(99, 1));
    assertEquals(TEMP_RECT, builder.build().get(100));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 0));
    assertEquals(TEMP_FLAGS, builder.build().getFlags(100, 1));
    assertNull(builder.build().get(101));
    assertEquals(0, builder.build().getFlags(101, 0));
    assertEquals(1, builder.build().getFlags(101, 1));
    // Test if {@link SparseRectFArrayBuilder#reset} resets its internal state.
    builder.reset();
    assertNull(builder.build().get(100));
    builder.reset();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF rect = MANY_RECTS[i];
        if (rect != null) {
            builder.append(i, rect.left, rect.top, rect.right, rect.bottom, i);
        }
    }
    final SparseRectFArray array = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array.get(i));
        if (expectedRect != null) {
            assertEquals(i, array.getFlags(i, 0x1234));
            assertEquals(i, array.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array.getFlags(i, 0x1234));
            assertEquals(0x4321, array.getFlags(i, 0x4321));
        }
    }
    // Make sure the builder reproduces an equivalent object.
    final SparseRectFArray array2 = builder.build();
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array2.get(i));
        if (expectedRect != null) {
            assertEquals(i, array2.getFlags(i, 0x1234));
            assertEquals(i, array2.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array2.getFlags(i, 0x1234));
            assertEquals(0x4321, array2.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array2);
    // Make sure the instance can be marshaled via {@link Parcel}.
    final SparseRectFArray array3 = cloneViaParcel(array);
    for (int i = 0; i < MANY_RECTS.length; i++) {
        final RectF expectedRect = MANY_RECTS[i];
        assertEquals(expectedRect, array3.get(i));
        if (expectedRect != null) {
            assertEquals(i, array3.getFlags(i, 0x1234));
            assertEquals(i, array3.getFlags(i, 0x4321));
        } else {
            assertEquals(0x1234, array3.getFlags(i, 0x1234));
            assertEquals(0x4321, array3.getFlags(i, 0x4321));
        }
    }
    assertEqualRects(array, array3);
    // Make sure the builder can be reset.
    builder.reset();
    assertNull(builder.build().get(0));
}
Also used : RectF(android.graphics.RectF) SparseRectFArrayBuilder(android.view.inputmethod.SparseRectFArray.SparseRectFArrayBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 53 with RectF

use of android.graphics.RectF in project platform_frameworks_base by android.

the class FreeformWorkspaceLayoutAlgorithm method getTransform.

/**
     * Returns the transform for the given task.  Any rect returned will be offset by the actual
     * transform for the freeform workspace.
     */
public TaskViewTransform getTransform(Task task, TaskViewTransform transformOut, TaskStackLayoutAlgorithm stackLayout) {
    if (mTaskRectMap.containsKey(task.key)) {
        final RectF ffRect = mTaskRectMap.get(task.key);
        transformOut.scale = 1f;
        transformOut.alpha = 1f;
        transformOut.translationZ = stackLayout.mMaxTranslationZ;
        transformOut.dimAlpha = 0f;
        transformOut.viewOutlineAlpha = TaskStackLayoutAlgorithm.OUTLINE_ALPHA_MAX_VALUE;
        transformOut.rect.set(ffRect);
        transformOut.rect.offset(stackLayout.mFreeformRect.left, stackLayout.mFreeformRect.top);
        transformOut.visible = true;
        return transformOut;
    }
    return null;
}
Also used : RectF(android.graphics.RectF)

Example 54 with RectF

use of android.graphics.RectF in project platform_frameworks_base by android.

the class FakeShadowDrawable method buildShadowCorners.

private void buildShadowCorners() {
    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);
    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();
    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, startRatio, 1f }, Shader.TileMode.CLAMP));
    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize, new int[] { mShadowStartColor, mShadowStartColor, mShadowEndColor }, new float[] { 0f, .5f, 1f }, Shader.TileMode.CLAMP));
}
Also used : RectF(android.graphics.RectF) Path(android.graphics.Path) LinearGradient(android.graphics.LinearGradient) RadialGradient(android.graphics.RadialGradient)

Example 55 with RectF

use of android.graphics.RectF in project httpclient by pixmob.

the class AnimatorProxy method invalidateAfterUpdate.

private void invalidateAfterUpdate() {
    View view = mView.get();
    if (view == null) {
        return;
    }
    View parent = (View) view.getParent();
    if (parent == null) {
        return;
    }
    view.setAnimation(this);
    final RectF after = mAfter;
    computeRect(after, view);
    after.union(mBefore);
    parent.invalidate((int) FloatMath.floor(after.left), (int) FloatMath.floor(after.top), (int) FloatMath.ceil(after.right), (int) FloatMath.ceil(after.bottom));
}
Also used : RectF(android.graphics.RectF) View(android.view.View)

Aggregations

RectF (android.graphics.RectF)1274 Paint (android.graphics.Paint)451 Rect (android.graphics.Rect)178 Matrix (android.graphics.Matrix)155 Bitmap (android.graphics.Bitmap)150 Path (android.graphics.Path)141 Canvas (android.graphics.Canvas)136 Point (android.graphics.Point)86 ImageView (android.widget.ImageView)78 PorterDuffXfermode (android.graphics.PorterDuffXfermode)51 LinearGradient (android.graphics.LinearGradient)41 View (android.view.View)39 SuppressLint (android.annotation.SuppressLint)35 Drawable (android.graphics.drawable.Drawable)27 PointF (android.graphics.PointF)23 RadialGradient (android.graphics.RadialGradient)21 TextPaint (android.text.TextPaint)21 ArrayList (java.util.ArrayList)21 BitmapDrawable (android.graphics.drawable.BitmapDrawable)20 TypedArray (android.content.res.TypedArray)14