下面列出了android.view.animation.LinearInterpolator#android.graphics.RectF 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public RectF moveToNext(final ProgressCallback callback) {
final IViewController ctrl = base.getDocumentController();
final int firstVisiblePage = ctrl.getFirstVisiblePage();
final int lastVisiblePage = ctrl.getLastVisiblePage();
if (currentPage == null) {
return searchFirstFrom(firstVisiblePage, callback);
}
final Matches m = getMatches(currentPage.index.docIndex);
if (m == null) {
return searchFirstFrom(currentPage.index.viewIndex, callback);
}
if (firstVisiblePage <= currentPage.index.viewIndex && currentPage.index.viewIndex <= lastVisiblePage) {
currentMatchIndex++;
final List<? extends RectF> mm = m.getMatches();
if (0 <= currentMatchIndex && currentMatchIndex < LengthUtils.length(mm)) {
return mm.get(currentMatchIndex);
} else {
return searchFirstFrom(currentPage.index.viewIndex + 1, callback);
}
} else {
return searchFirstFrom(firstVisiblePage, callback);
}
}
@Override
protected void initConfig(int x, int y) {
mPaint = new Paint();
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setStrokeWidth(mStrokeWidth);
mPaint.setAntiAlias(true);
mPaint.setColor(Config.WHITE);
mPaint.setStrokeCap(Paint.Cap.SQUARE);
mRectF = new RectF(x - MAX_RADIUS_CIRCLE
, y - MAX_RADIUS_CIRCLE - MAX_RADIUS_CIRCLE / 2
, x + MAX_RADIUS_CIRCLE
, y + MAX_RADIUS_CIRCLE / 2);
mFirPoint = new Point(x, y - 2 * MAX_RADIUS_CIRCLE);
mSecPoint = new Point(mFirPoint);
mThiPoint = new Point(x, y + MAX_RADIUS_CIRCLE / 2 + MAX_RADIUS_CIRCLE / 4);
mFourPoint = new Point(mThiPoint);
mFifPoint = new Point(mThiPoint);
}
private void setUpLeftPath(RectF rect, Path path){
path.moveTo(mArrowWidth + rect.left + mAngle, rect.top);
path.lineTo(rect.width() - mAngle, rect.top);
path.arcTo(new RectF(rect.right - mAngle , rect.top, rect.right,
mAngle + rect.top), 270, 90);
path.lineTo(rect.right, rect.bottom - mAngle);
path.arcTo(new RectF(rect.right - mAngle , rect.bottom - mAngle,
rect.right, rect.bottom), 0, 90);
path.lineTo(rect.left + mArrowWidth + mAngle, rect.bottom);
path.arcTo(new RectF(rect.left + mArrowWidth, rect.bottom - mAngle ,
mAngle + rect.left + mArrowWidth, rect.bottom), 90, 90);
path.lineTo(rect.left + mArrowWidth, mArrowHeight + mArrowPosition);
path.lineTo(rect.left, mArrowPosition + mArrowHeight / 2);
path.lineTo(rect.left + mArrowWidth, mArrowPosition);
path.lineTo(rect.left + mArrowWidth, rect.top + mAngle);
path.arcTo(new RectF(rect.left + mArrowWidth, rect.top, mAngle
+ rect.left + mArrowWidth, mAngle + rect.top), 180, 90);
path.close();
}
private void createFramedPhotoBorder(int size) {
Drawable imageDrawable = (image != null) ? new BitmapDrawable(
getResources(), image) : placeholder;
Bitmap output = Bitmap
.createBitmap(size, size, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
RectF outerRect = new RectF(0, 0, size, size);
float cornerRadius = size / 20f;
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.RED);
canvas.drawRoundRect(outerRect, cornerRadius, cornerRadius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
imageDrawable.setBounds(0, 0, size, size);
// Save the layer to apply the paint
canvas.saveLayer(outerRect, paint, Canvas.ALL_SAVE_FLAG);
imageDrawable.draw(canvas);
canvas.restore();
framedPhoto = output;
}
/**
*
* @param imageView
* @param width
* @param height
*/
public static final void updateImageViewMatrix(ImageView imageView, float width, float height) {
Drawable drawable = imageView.getDrawable();
if(drawable == null) {
throw new NullPointerException("ImageView drawable is null");
}
Matrix matrix = imageView.getImageMatrix();
if(!matrix.isIdentity()) {
float[] values = new float[9];
matrix.getValues(values);
RectF src = new RectF();
src.left = 0;
src.top = 0;
src.right = width;
src.bottom = height;
RectF dst = new RectF();
dst.left = values[Matrix.MTRANS_X];
dst.top = values[Matrix.MTRANS_Y];
dst.right = dst.left + (drawable.getIntrinsicWidth() * values[Matrix.MSCALE_X]);
dst.bottom = dst.top + (drawable.getIntrinsicHeight() * values[Matrix.MSCALE_Y]);
matrix.setRectToRect(src, dst, Matrix.ScaleToFit.CENTER);
}
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
float size = Math.min(w, h) - tableWidth * 2;
//油表的位置方框
mTableRectF = new RectF(0, 0, size, size);
mPath.reset();
//在油表路径中增加一个从起始弧度
mPath.addArc(mTableRectF, 60, 240);
//计算路径的长度
PathMeasure pathMeasure = new PathMeasure(mPath, false);
float length = pathMeasure.getLength();
float step = length / 60;
dashPathEffect = new DashPathEffect(new float[]{step / 3, step * 2 / 3}, 0);
float radius = size / 2;
mColorShader = new SweepGradient(radius, radius,SWEEP_GRADIENT_COLORS,null);
//设置指针的路径位置
mPointerPath.reset();
mPointerPath.moveTo(radius, radius - 20);
mPointerPath.lineTo(radius, radius + 20);
mPointerPath.lineTo(radius * 2 - tableWidth, radius);
mPointerPath.close();
}
public static Bitmap getRoundedCornerBitmap(Bitmap input,
float cornerRadius, int w, int h) {
Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, w, h);
final RectF rectF = new RectF(rect);
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, cornerRadius, cornerRadius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(input, 0, 0, paint);
return output;
}
@Override
public void draw(Canvas canvas) {
final boolean positionChanged = adapterPositionChanged();
if (rippleOverlay) {
if (!positionChanged) {
rippleBackground.draw(canvas);
}
super.draw(canvas);
if (!positionChanged) {
if (rippleRoundedCorners != 0) {
Path clipPath = new Path();
RectF rect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
clipPath.addRoundRect(rect, rippleRoundedCorners, rippleRoundedCorners, Path.Direction.CW);
canvas.clipPath(clipPath);
}
canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
}
} else {
if (!positionChanged) {
rippleBackground.draw(canvas);
canvas.drawCircle(currentCoords.x, currentCoords.y, radius, paint);
}
super.draw(canvas);
}
}
/**
* Configures the necessary {@link android.graphics.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(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final 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);
final float scale =
Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.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);
}
textureView.setTransform(matrix);
}
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap, int pixels) {
if (bitmap == null) {
bitmap = BitmapFactory.decodeResource(Common.getInstance().getResources(),
R.drawable.ic_placeholder);
}
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = pixels;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
/**
* Update the icon drawable position or target render view position.
*/
void updateIconPosition()
{
mView.mIconDrawable = mView.mPromptOptions.getIconDrawable();
if (mView.mIconDrawable != null)
{
final RectF mFocalBounds = mView.mPromptOptions.getPromptFocal().getBounds();
mView.mIconDrawableLeft = mFocalBounds.centerX()
- (mView.mIconDrawable.getIntrinsicWidth() / 2);
mView.mIconDrawableTop = mFocalBounds.centerY()
- (mView.mIconDrawable.getIntrinsicHeight() / 2);
}
else if (mView.mTargetRenderView != null)
{
final int[] viewPosition = new int[2];
mView.getLocationInWindow(viewPosition);
final int[] targetPosition = new int[2];
mView.mTargetRenderView.getLocationInWindow(targetPosition);
mView.mIconDrawableLeft = targetPosition[0] - viewPosition[0] - mView.mTargetRenderView.getScrollX();
mView.mIconDrawableTop = targetPosition[1] - viewPosition[1] - mView.mTargetRenderView.getScrollY();
}
}
public void loadLine(int num,boolean clockwise)
{
int rocknum = num;
if(rocknum == 0)
rocknum = 1;
PointF position1 = OB_Maths.locationForRect(0.5f,0.01f,objectDict.get(String.format("rock%d", rocknum )).frame());
PointF position2 = OB_Maths.locationForRect(0.5f,0.01f,objectDict.get(String.format("rock%d", rocknum+1 )).frame());
OBPath curveLine = new OBPath();
Path path = new Path();
float radius = Math.abs(position1.x -position2.x)/2.0f;
path.addArc(new RectF(position1.x,position1.y-radius,position2.x,position1.y+radius),clockwise ? 180 : 0, clockwise ? 180 : -180);
curveLine.setPath(path);
curveLine.sizeToBoundingBox();
if(num == 0)
curveLine.setRight ( curveLine.right()-curveLine.width());
curveLine.setLineWidth((float)Math.ceil(applyGraphicScale(6)));
curveLine.setStrokeColor( clockwise ? OBUtils.colorFromRGBString("255,252,0") : OBUtils.colorFromRGBString("255,83,0"));
curveLine.setZPosition(0.8f);
curveLine.hide();
attachControl(curveLine);
curveLine.sizeToBoundingBoxIncludingStroke();
objectDict.put(String.format("line_%d_%d",clockwise ? 1 : 2, num),curveLine);
}
/**
* Use touch-icon or higher-resolution favicon and round the corners.
* @param context Context used to get resources.
* @param touchIcon Touch icon bitmap.
* @param canvas Canvas that holds the touch icon.
*/
private static void drawTouchIconToCanvas(
Context context, Bitmap touchIcon, Canvas canvas) {
Rect iconBounds = new Rect(0, 0, canvas.getWidth(), canvas.getHeight());
Rect src = new Rect(0, 0, touchIcon.getWidth(), touchIcon.getHeight());
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setFilterBitmap(true);
canvas.drawBitmap(touchIcon, src, iconBounds, paint);
// Convert dp to px.
int borderRadii = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
TOUCHICON_BORDER_RADII, context.getResources().getDisplayMetrics());
Path path = new Path();
path.setFillType(Path.FillType.INVERSE_WINDING);
RectF rect = new RectF(iconBounds);
rect.inset(INSET_DIMENSION_FOR_TOUCHICON, INSET_DIMENSION_FOR_TOUCHICON);
path.addRoundRect(rect, borderRadii, borderRadii, Path.Direction.CW);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
canvas.drawPath(path, paint);
}
private void initPainters() {
// Ring Rectangle objects
ringOverall = new RectF();
ringInnerThird = new RectF();
ringInnerSecond = new RectF();
ringInnerFirst = new RectF();
// Init rectangles used by texts
rectOverallText = new Rect();
rectInnerThirdText = new Rect();
rectInnerSecondText = new Rect();
rectInnerFirstText = new Rect();
// Auxiliary rect to get the width size used by text
auxRect = new Rect();
// Ring Paint
ringPaint = new Paint();
ringPaint.setAntiAlias(true);
ringPaint.setStyle(Paint.Style.STROKE);
ringPaint.setStrokeCap(Paint.Cap.ROUND);
// Text Paint
textPaint = new TextPaint();
textPaint.setTextSize(textSize);
textPaint.setAntiAlias(true);
}
public static Bitmap getBitmap(Context context, int width, int height, int svgRawResourceId) {
Bitmap bitmap = Bitmap.createBitmap(width, height,
Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setColor(Color.BLACK);
if (svgRawResourceId > 0) {
SVG svg = SVGParser.getSVGFromInputStream(
context.getResources().openRawResource(svgRawResourceId), width, height);
canvas.drawPicture(svg.getPicture());
} else {
canvas.drawRect(new RectF(0.0f, 0.0f, width, height), paint);
}
return bitmap;
}
/**
* Configures the necessary {@link android.graphics.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(final int viewWidth, final int viewHeight) {
final Activity activity = getActivity();
if (null == textureView || null == previewSize || null == activity) {
return;
}
final int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
final Matrix matrix = new Matrix();
final RectF viewRect = new RectF(0, 0, viewWidth, viewHeight);
final RectF bufferRect = new RectF(0, 0, previewSize.getHeight(), previewSize.getWidth());
final float centerX = viewRect.centerX();
final 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);
final float scale =
Math.max(
(float) viewHeight / previewSize.getHeight(),
(float) viewWidth / previewSize.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);
}
textureView.setTransform(matrix);
}
/** Center move only changes the position of the crop window without changing the size. */
private void moveCenter(
RectF rect, float x, float y, RectF bounds, int viewWidth, int viewHeight, float snapRadius) {
float dx = x - rect.centerX();
float dy = y - rect.centerY();
if (rect.left + dx < 0
|| rect.right + dx > viewWidth
|| rect.left + dx < bounds.left
|| rect.right + dx > bounds.right) {
dx /= 1.05f;
mTouchOffset.x -= dx / 2;
}
if (rect.top + dy < 0
|| rect.bottom + dy > viewHeight
|| rect.top + dy < bounds.top
|| rect.bottom + dy > bounds.bottom) {
dy /= 1.05f;
mTouchOffset.y -= dy / 2;
}
rect.offset(dx, dy);
snapEdgesToBounds(rect, bounds, snapRadius);
}
private void makeDefault() {
if (rotateBitmap == null) {
return;
}
HighlightView hv = new HighlightView(imageView);
final int width = rotateBitmap.getWidth();
final int height = rotateBitmap.getHeight();
Rect imageRect = new Rect(0, 0, width, height);
// Make the default size about 4/5 of the width or height
int cropWidth = Math.min(width, height) * 4 / 5;
@SuppressWarnings("SuspiciousNameCombination")
int cropHeight = cropWidth;
if (aspectX != 0 && aspectY != 0) {
if (aspectX > aspectY) {
cropHeight = cropWidth * aspectY / aspectX;
} else {
cropWidth = cropHeight * aspectX / aspectY;
}
}
int x = (width - cropWidth) / 2;
int y = (height - cropHeight) / 2;
RectF cropRect = new RectF(x, y, x + cropWidth, y + cropHeight);
hv.setup(imageView.getUnrotatedMatrix(), imageRect, cropRect, aspectX != 0 && aspectY != 0);
imageView.add(hv);
}
@Override
public SceneOverlayLayer getUpdatedSceneOverlayTree(RectF viewport, RectF visibleViewport,
LayerTitleCache layerTitleCache, ResourceManager resourceManager, float yOffset) {
mSceneLayer.update(resourceManager, this,
getSearchBarControl(),
getPeekPromoControl(),
getPromoControl(),
getImageControl());
return mSceneLayer;
}
/**
* Function to init image view settings
*/
private void init() {
this.context = super.getContext();
mRects = new ArrayList<RectF>();
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
mPaint.setColor(Color.argb(150, 146, 144, 248));
setOnLongClickListener(this);
setOnTouchListener(this);
}
/**
* Helper method that maps the supplied Matrix to the current Drawable
*
* @param matrix - Matrix to map Drawable against
* @return RectF - Displayed Rectangle
*/
private RectF getDisplayRect(Matrix matrix) {
Drawable d = mImageView.getDrawable();
if (d != null) {
mDisplayRect.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
matrix.mapRect(mDisplayRect);
return mDisplayRect;
}
return null;
}
public CropView(Context context) {
super(context);
previousAreaRect = new RectF();
initialAreaRect = new RectF();
presentationMatrix = new Matrix();
tempRect = new CropRectangle();
tempMatrix = new Matrix();
animating = false;
backView = new View(context);
backView.setBackgroundColor(0xff000000);
backView.setVisibility(INVISIBLE);
addView(backView);
imageView = new ImageView(context);
imageView.setDrawingCacheEnabled(true);
imageView.setScaleType(ImageView.ScaleType.MATRIX);
addView(imageView);
detector = new CropGestureDetector(context);
detector.setOnGestureListener(this);
areaView = new CropAreaView(context);
areaView.setListener(this);
addView(areaView);
}
private void drawDiagonalFromTopLeftRoundRect(Canvas canvas, Paint paint, float right,
float bottom) {
canvas.drawRoundRect(new RectF(margin, margin, margin + diameter, margin + diameter), radius,
radius, paint);
canvas.drawRoundRect(new RectF(right - diameter, bottom - diameter, right, bottom), radius,
radius, paint);
canvas.drawRect(new RectF(margin, margin + radius, right - diameter, bottom), paint);
canvas.drawRect(new RectF(margin + diameter, margin, right, bottom - radius), paint);
}
protected float box_intersection(RectF a, RectF b)
{
float w = overlap((a.left + a.right) / 2, a.right - a.left,
(b.left + b.right) / 2, b.right - b.left);
float h = overlap((a.top + a.bottom) / 2, a.bottom - a.top,
(b.top + b.bottom) / 2, b.bottom - b.top);
if(w < 0 || h < 0) return 0;
float area = w*h;
return area;
}
@Override
public RectF getBounds(Object styleable) {
View view = (View) styleable;
Rect r = new Rect();
view.getDrawingRect(r);
return new RectF(r);
}
private static void drawRect(Canvas canvas, RectF rect, int color, float stroke) {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(stroke);
rectF.inset(0.5f * stroke, 0.5f * stroke);
paint.setColor(color);
canvas.drawRect(rect, paint);
}
protected void onRectChanged(RectF rectf)
{
e = (rectf.height() - mPaddingTop - mPaddingBottom - DynamicDetailChartOld.a(c)) / (float)value;
a();
i = new RectF(rectf);
float f1 = i.width() / 2.0F;
RectF rectf1 = i;
rectf1.top = rectf1.top - f1;
}
/**
* Sets the image bounds, in view-absolute coordinates.
*/
@Override
public void setImageBounds(RectF imageBounds) {
if (!imageBounds.equals(mImageBounds)) {
mImageBounds.set(imageBounds);
onTransformChanged();
}
}
public CollapsingTextHelper(View view) {
this.view = view;
textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);
tmpPaint = new TextPaint(textPaint);
collapsedBounds = new Rect();
expandedBounds = new Rect();
currentBounds = new RectF();
}
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
paint.setColor(backgroundColor);
canvas.drawRoundRect(rect, cornerRadius, cornerRadius, paint);
paint.setColor(textColor);
canvas.drawText(text, start, end, x, y, paint);
}