/*
* Copyright (C) 2007 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.zyq.main;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Region;
import android.graphics.drawable.Drawable;
import android.view.View;
// This class is used by CropImage to display a highlighted cropping rectangle
// overlayed with the image. There are two coordinate spaces in use. One is
// image, another is screen. computeLayout() uses mMatrix to map from image
// space to screen space.
class HighlightView {
@SuppressWarnings("unused")
private static final String TAG = "HighlightView";
View mContext; // The View displaying the image.
public static final int GROW_NONE = (1 << 0);
public static final int GROW_LEFT_EDGE = (1 << 1);
public static final int GROW_RIGHT_EDGE = (1 << 2);
public static final int GROW_TOP_EDGE = (1 << 3);
public static final int GROW_BOTTOM_EDGE = (1 << 4);
public static final int MOVE = (1 << 5);
public HighlightView(View ctx) {
mContext = ctx;
}
private void init() {
android.content.res.Resources resources = mContext.getResources();
mResizeDrawableWidth = resources.getDrawable(R.drawable.camera_crop_width);
mResizeDrawableHeight = resources.getDrawable(R.drawable.camera_crop_height);
mResizeDrawableDiagonal = resources.getDrawable(R.drawable.indicator_autocrop);
}
boolean mIsFocused;
boolean mHidden;
public boolean hasFocus() {
return mIsFocused;
}
public void setFocus(boolean f) {
mIsFocused = f;
}
public void setHidden(boolean hidden) {
mHidden = hidden;
}
protected void draw(Canvas canvas) {
if (mHidden) {
return;
}
canvas.save();
Path path = new Path();
if (!hasFocus()) {
mOutlinePaint.setColor(0xFF000000);
canvas.drawRect(mDrawRect, mOutlinePaint);
} else {
Rect viewDrawingRect = new Rect();
mContext.getDrawingRect(viewDrawingRect);
if (mCircle) {
float width = mDrawRect.width();
float height = mDrawRect.height();
path.addCircle(mDrawRect.left + (width / 2), mDrawRect.top + (height / 2), width / 2, Path.Direction.CW);
mOutlinePaint.setColor(0xFFEF04D6);
} else {
path.addRect(new RectF(mDrawRect), Path.Direction.CW);
mOutlinePaint.setColor(0xFFFF8A00);
}
canvas.clipPath(path, Region.Op.DIFFERENCE);
canvas.drawRect(viewDrawingRect, hasFocus() ? mFocusPaint : mNoFocusPaint);
canvas.restore();
canvas.drawPath(path, mOutlinePaint);
if (mMode == ModifyMode.Grow) {
if (mCircle) {
int width = mResizeDrawableDiagonal.getIntrinsicWidth();
int height = mResizeDrawableDiagonal.getIntrinsicHeight();
int d = (int) Math.round(Math.cos(/* 45deg */Math.PI / 4D) * (mDrawRect.width() / 2D));
int x = mDrawRect.left + (mDrawRect.width() / 2) + d - width / 2;
int y = mDrawRect.top + (mDrawRect.height() / 2) - d - height / 2;
mResizeDrawableDiagonal.setBounds(x, y, x + mResizeDrawableDiagonal.getIntrinsicWidth(), y
+ mResizeDrawableDiagonal.getIntrinsicHeight());
mResizeDrawableDiagonal.draw(canvas);
} else {
int left = mDrawRect.left + 1;
int right = mDrawRect.right + 1;
int top = mDrawRect.top + 4;
int bottom = mDrawRect.bottom + 3;
int widthWidth = mResizeDrawableWidth.getIntrinsicWidth() / 2;
int widthHeight = mResizeDrawableWidth.getIntrinsicHeight() / 2;
int heightHeight = mResizeDrawableHeight.getIntrinsicHeight() / 2;
int heightWidth = mResizeDrawableHeight.getIntrinsicWidth() / 2;
int xMiddle = mDrawRect.left + ((mDrawRect.right - mDrawRect.left) / 2);
int yMiddle = mDrawRect.top + ((mDrawRect.bottom - mDrawRect.top) / 2);
mResizeDrawableWidth.setBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle
+ widthHeight);
mResizeDrawableWidth.draw(canvas);
mResizeDrawableWidth.setBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle
+ widthHeight);
mResizeDrawableWidth.draw(canvas);
mResizeDrawableHeight.setBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top
+ heightHeight);
mResizeDrawableHeight.draw(canvas);
mResizeDrawableHeight.setBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom
+ heightHeight);
mResizeDrawableHeight.draw(canvas);
}
}
}
}
public void setMode(ModifyMode mode) {
if (mode != mMode) {
mMode = mode;
mContext.invalidate();
}
}
// Determines which edges are hit by touching at (x, y).
public int getHit(float x, float y) {
Rect r = computeLayout();
final float hysteresis = 20F;
int retval = GROW_NONE;
if (mCircle) {
float distX = x - r.centerX();
float distY = y - r.centerY();
int distanceFromCenter = (int) Math.sqrt(distX * distX + distY * distY);
int radius = mDrawRect.width() / 2;
int delta = distanceFromCenter - radius;
if (Math.abs(delta) <= hysteresis) {
if (Math.abs(distY) > Math.abs(distX)) {
if (distY < 0) {
retval = GROW_TOP_EDGE;
} else {
retval = GROW_BOTTOM_EDGE;
}
} else {
if (distX < 0) {
retval = GROW_LEFT_EDGE;
} else {
retval = GROW_RIGHT_EDGE;
}
}
} else if (distanceFromCenter < radius) {
retval = MOVE;
} else {
retval = GROW_NONE;
}
} else {
// verticalCheck makes sure the position is between the top and
// the bottom edge (with some tolerance). Similar for horizCheck.
boolean verticalCheck = (y >= r.top - hysteresis) && (y < r.bottom + hysteresis);
boolean horizCheck = (x >= r.left - hysteresis) && (x < r.right + hysteresis);
// Check whether the position is near some edge(s).
if ((Math.abs(r.left - x) < hysteresis) && verticalCheck) {
retval |= GROW_LEFT_EDGE;
}
if ((Math.abs(r.right - x) < hysteresis) && verticalCheck) {
retval |= GROW_RIGHT_EDGE;
}
if ((Math.abs(r.top - y) < hysteresis) && horizCheck) {
没有合适的资源?快使用搜索试试~ 我知道了~
小程序 区域截图源码.rar
共67个文件
class:35个
java:12个
png:7个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 111 浏览量
2023-02-03
11:47:56
上传
评论
收藏 955KB RAR 举报
温馨提示
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,本人不对所涉及的版权问题或内容负法律责任。如有侵权,请举报或通知本人删除。
资源推荐
资源详情
资源评论
收起资源包目录
小程序 区域截图源码.rar (67个子文件)
Android 区域截图源码
.classpath 273B
.settings
org.eclipse.core.resources.prefs 83B
assets
src
com
zyq
main
HighlightView.java 14KB
CropImageView.java 9KB
Shared.java 4KB
CropImage.java 12KB
ImageViewTouchBase.java 12KB
App.java 3KB
Util.java 11KB
RotateBitmap.java 3KB
Deque.java 4KB
MonitoredActivity.java 3KB
MainActivity.java 4KB
res
drawable-mdpi
icon.png 3KB
drawable-ldpi
camera_crop_width.png 2KB
camera_crop_height.png 2KB
a.jpg 159KB
indicator_autocrop.png 3KB
icon.png 2KB
values
strings.xml 362B
layout
main.xml 383B
crop.xml 2KB
drawable-hdpi
icon.png 4KB
bin
resources.ap_ 179KB
ImageCapture.apk 207KB
classes.dex 50KB
com
zyq
main
RotateBitmap.class 2KB
CropImageView.class 7KB
Util$BackgroundJob$1.class 1KB
Util.class 8KB
MainActivity$TakePictureCallback.class 2KB
HighlightView$ModifyMode.class 1KB
R$string.class 491B
CropImage$4$1.class 1KB
R$layout.class 404B
CropImage$4.class 2KB
ImageViewTouchBase$Recycler.class 267B
R$id.class 459B
ImageViewTouchBase$1.class 837B
MonitoredActivity$LifeCycleAdapter.class 1KB
CropImage$1.class 5KB
R$attr.class 322B
CropImage$2.class 751B
CropImage$5.class 692B
ImageViewTouchBase$2.class 1KB
CropImage$1$1.class 2KB
Util$BackgroundJob.class 2KB
Deque.class 3KB
Shared.class 2KB
MonitoredActivity.class 2KB
App$1.class 910B
R$drawable.class 532B
MainActivity.class 3KB
CropImage.class 9KB
HighlightView.class 9KB
App.class 3KB
ImageViewTouchBase.class 8KB
CropImage$3.class 753B
R.class 489B
MainActivity$SurfaceCallback.class 3KB
MonitoredActivity$LifeCycleListener.class 440B
proguard.cfg 1KB
default.properties 362B
.project 815B
AndroidManifest.xml 1KB
gen
com
zyq
main
R.java 1KB
1-121022115U60-L.png 297KB
共 67 条
- 1
资源评论
大富大贵7
- 粉丝: 324
- 资源: 8868
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功