use of android.graphics.RectF in project platform_frameworks_base by android.
the class GradientDrawable method buildRing.
private Path buildRing(GradientState st) {
if (mRingPath != null && (!st.mUseLevelForShape || !mPathIsDirty))
return mRingPath;
mPathIsDirty = false;
float sweep = st.mUseLevelForShape ? (360.0f * getLevel() / 10000.0f) : 360f;
RectF bounds = new RectF(mRect);
float x = bounds.width() / 2.0f;
float y = bounds.height() / 2.0f;
float thickness = st.mThickness != -1 ? st.mThickness : bounds.width() / st.mThicknessRatio;
// inner radius
float radius = st.mInnerRadius != -1 ? st.mInnerRadius : bounds.width() / st.mInnerRadiusRatio;
RectF innerBounds = new RectF(bounds);
innerBounds.inset(x - radius, y - radius);
bounds = new RectF(innerBounds);
bounds.inset(-thickness, -thickness);
if (mRingPath == null) {
mRingPath = new Path();
} else {
mRingPath.reset();
}
final Path ringPath = mRingPath;
// think 360 means draw the entire oval
if (sweep < 360 && sweep > -360) {
ringPath.setFillType(Path.FillType.EVEN_ODD);
// inner top
ringPath.moveTo(x + radius, y);
// outer top
ringPath.lineTo(x + radius + thickness, y);
// outer arc
ringPath.arcTo(bounds, 0.0f, sweep, false);
// inner arc
ringPath.arcTo(innerBounds, sweep, -sweep, false);
ringPath.close();
} else {
// add the entire ovals
ringPath.addOval(bounds, Path.Direction.CW);
ringPath.addOval(innerBounds, Path.Direction.CCW);
}
return ringPath;
}
use of android.graphics.RectF in project platform_frameworks_base by android.
the class RoundRectShape method onResize.
@Override
protected void onResize(float w, float h) {
super.onResize(w, h);
RectF r = rect();
mPath.reset();
if (mOuterRadii != null) {
mPath.addRoundRect(r, mOuterRadii, Path.Direction.CW);
} else {
mPath.addRect(r, Path.Direction.CW);
}
if (mInnerRect != null) {
mInnerRect.set(r.left + mInset.left, r.top + mInset.top, r.right - mInset.right, r.bottom - mInset.bottom);
if (mInnerRect.width() < w && mInnerRect.height() < h) {
if (mInnerRadii != null) {
mPath.addRoundRect(mInnerRect, mInnerRadii, Path.Direction.CCW);
} else {
mPath.addRect(mInnerRect, Path.Direction.CCW);
}
}
}
}
use of android.graphics.RectF in project platform_frameworks_base by android.
the class DataUsageGraph method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
final RectF r = mTmpRect;
final Paint p = mTmpPaint;
final int w = getWidth();
final int h = getHeight();
final boolean overLimit = mLimitLevel > 0 && mUsageLevel > mLimitLevel;
float usageRight = w * (mUsageLevel / (float) mMaxLevel);
if (overLimit) {
// compute the gap
usageRight = w * (mLimitLevel / (float) mMaxLevel) - (mMarkerWidth / 2);
usageRight = Math.min(Math.max(usageRight, mMarkerWidth), w - mMarkerWidth * 2);
// draw overlimit
r.set(usageRight + mMarkerWidth, 0, w, h);
p.setColor(mOverlimitColor);
canvas.drawRect(r, p);
} else {
// draw track
r.set(0, 0, w, h);
p.setColor(mTrackColor);
canvas.drawRect(r, p);
}
// draw usage
r.set(0, 0, usageRight, h);
p.setColor(mUsageColor);
canvas.drawRect(r, p);
// draw warning marker
float warningLeft = w * (mWarningLevel / (float) mMaxLevel) - mMarkerWidth / 2;
warningLeft = Math.min(Math.max(warningLeft, 0), w - mMarkerWidth);
r.set(warningLeft, 0, warningLeft + mMarkerWidth, h);
p.setColor(mWarningColor);
canvas.drawRect(r, p);
}
use of android.graphics.RectF in project platform_frameworks_base by android.
the class CropView method onTouchEvent.
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
final boolean pointerUp = action == MotionEvent.ACTION_POINTER_UP;
final int skipIndex = pointerUp ? event.getActionIndex() : -1;
// Determine focal point
float sumX = 0, sumY = 0;
final int count = event.getPointerCount();
for (int i = 0; i < count; i++) {
if (skipIndex == i)
continue;
sumX += event.getX(i);
sumY += event.getY(i);
}
final int div = pointerUp ? count - 1 : count;
float x = sumX / div;
float y = sumY / div;
if (action == MotionEvent.ACTION_DOWN) {
mFirstX = x;
mFirstY = y;
mTouchDownTime = System.currentTimeMillis();
if (mTouchCallback != null) {
mTouchCallback.onTouchDown();
}
} else if (action == MotionEvent.ACTION_UP) {
ViewConfiguration config = ViewConfiguration.get(getContext());
float squaredDist = (mFirstX - x) * (mFirstX - x) + (mFirstY - y) * (mFirstY - y);
float slop = config.getScaledTouchSlop() * config.getScaledTouchSlop();
long now = System.currentTimeMillis();
if (mTouchCallback != null) {
// only do this if it's a small movement
if (squaredDist < slop && now < mTouchDownTime + ViewConfiguration.getTapTimeout()) {
mTouchCallback.onTap();
}
mTouchCallback.onTouchUp();
}
}
if (!mTouchEnabled) {
return true;
}
synchronized (mLock) {
mScaleGestureDetector.onTouchEvent(event);
switch(action) {
case MotionEvent.ACTION_MOVE:
float[] point = mTempPoint;
point[0] = (mLastX - x) / mRenderer.scale;
point[1] = (mLastY - y) / mRenderer.scale;
mInverseRotateMatrix.mapPoints(point);
mCenterX += point[0];
mCenterY += point[1];
updateCenter();
invalidate();
break;
}
if (mRenderer.source != null) {
// Adjust position so that the wallpaper covers the entire area
// of the screen
final RectF edges = mTempEdges;
getEdgesHelper(edges);
final float scale = mRenderer.scale;
float[] coef = mTempCoef;
coef[0] = 1;
coef[1] = 1;
mRotateMatrix.mapPoints(coef);
float[] adjustment = mTempAdjustment;
mTempAdjustment[0] = 0;
mTempAdjustment[1] = 0;
if (edges.left > 0) {
adjustment[0] = edges.left / scale;
} else if (edges.right < getWidth()) {
adjustment[0] = (edges.right - getWidth()) / scale;
}
if (edges.top > 0) {
adjustment[1] = (float) Math.ceil(edges.top / scale);
} else if (edges.bottom < getHeight()) {
adjustment[1] = (edges.bottom - getHeight()) / scale;
}
for (int dim = 0; dim <= 1; dim++) {
if (coef[dim] > 0)
adjustment[dim] = (float) Math.ceil(adjustment[dim]);
}
mInverseRotateMatrix.mapPoints(adjustment);
mCenterX += adjustment[0];
mCenterY += adjustment[1];
updateCenter();
}
}
mLastX = x;
mLastY = y;
return true;
}
use of android.graphics.RectF in project platform_frameworks_base by android.
the class WallpaperCropActivity method getMaxCropRect.
protected static RectF getMaxCropRect(int inWidth, int inHeight, int outWidth, int outHeight, boolean leftAligned) {
RectF cropRect = new RectF();
// Get a crop rect that will fit this
if (inWidth / (float) inHeight > outWidth / (float) outHeight) {
cropRect.top = 0;
cropRect.bottom = inHeight;
cropRect.left = (inWidth - (outWidth / (float) outHeight) * inHeight) / 2;
cropRect.right = inWidth - cropRect.left;
if (leftAligned) {
cropRect.right -= cropRect.left;
cropRect.left = 0;
}
} else {
cropRect.left = 0;
cropRect.right = inWidth;
cropRect.top = (inHeight - (outHeight / (float) outWidth) * inWidth) / 2;
cropRect.bottom = inHeight - cropRect.top;
}
return cropRect;
}
Aggregations