Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
android-custom-view
提交
5f5633d8
A
android-custom-view
项目概览
门心叼龙
/
android-custom-view
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
android-custom-view
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
5f5633d8
编写于
10月 15, 2019
作者:
门心叼龙
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code perfect
上级
b4153186
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
67 addition
and
25 deletion
+67
-25
app/src/main/java/com/mxdl/customview/view/CricleCaptureView.java
...main/java/com/mxdl/customview/view/CricleCaptureView.java
+61
-22
app/src/main/java/com/mxdl/customview/view/SquareCaptureView.java
...main/java/com/mxdl/customview/view/SquareCaptureView.java
+6
-3
未找到文件。
app/src/main/java/com/mxdl/customview/view/CricleCaptureView.java
浏览文件 @
5f5633d8
...
...
@@ -18,6 +18,8 @@ import android.view.View;
import
com.mxdl.customview.R
;
import
java.util.Random
;
/**
* Description: <CenterCaptureView><br>
* Author: mxdl<br>
...
...
@@ -28,6 +30,7 @@ import com.mxdl.customview.R;
public
class
CricleCaptureView
extends
View
{
public
static
final
String
TAG
=
CricleCaptureView
.
class
.
getSimpleName
();
private
int
mRadius
;
private
int
mRadius1
;
private
Rect
mScreenRect
=
new
Rect
();
private
Rect
mCaptureRect
=
new
Rect
();
private
Paint
mBorderPaint
=
new
Paint
();
...
...
@@ -63,8 +66,9 @@ public class CricleCaptureView extends View {
}
public
void
initView
()
{
setLayerType
(
1
,
null
);
//setLayerType(View.LAYER_TYPE_SOFTWARE
, null);
mRadius
=
(
int
)
(
getResources
().
getDisplayMetrics
().
density
*
216
+
0.5f
)
/
2
;
mRadius1
=
mRadius
;
mBorderPaint
.
setStrokeWidth
(
getResources
().
getDisplayMetrics
().
density
*
2
);
mBorderPaint
.
setStyle
(
Paint
.
Style
.
STROKE
);
mBorderPaint
.
setAntiAlias
(
true
);
...
...
@@ -100,11 +104,13 @@ public class CricleCaptureView extends View {
//Log.v(TAG,"onDraw left:"+mCaptureRect.left+";top:"+mCaptureRect.top+";right:"+mCaptureRect.right+";bottom:"+mCaptureRect.bottom);
canvas
.
save
();
mCapturePath
.
reset
();
mCapturePath
.
addCircle
(
mCricleX
,
mCricleY
,
mRadius
,
Path
.
Direction
.
CW
);
//添加圆形路径
mCapturePath
.
addCircle
(
mCricleX
,
mCricleY
,
mRadius1
,
Path
.
Direction
.
CW
);
//裁切一个圆形的画布区域
canvas
.
clipPath
(
mCapturePath
,
Region
.
Op
.
INTERSECT
);
//画
矩形
区域
//画
整个背景
区域
canvas
.
drawRect
(
mScreenRect
,
mAreaPaint
);
//画
矩形
边框
//画
背景区域的
边框
canvas
.
drawPath
(
mCapturePath
,
mBorderPaint
);
canvas
.
restore
();
...
...
@@ -150,33 +156,66 @@ public class CricleCaptureView extends View {
int
dx
=
x
-
mLastX
;
int
dy
=
y
-
mLastY
;
//为了保证是正方形,以滑动距离远的为标准
if
(
mHitCorner
==
2
||
mHitCorner
==
8
)
{
if
(
Math
.
abs
(
dx
)
>=
Math
.
abs
(
dy
))
{
dy
=
dx
;
}
else
{
dx
=
dy
;
}
if
(
mHitCorner
==
4
)
{
mRadius
-=
dx
;
mCaptureRect
.
left
+=
dx
;
mCaptureRect
.
top
+=
dx
;
mCaptureRect
.
right
-=
dx
;
mCaptureRect
.
bottom
-=
dx
;
}
if
(
mHitCorner
==
2
){
if
(
dy
>
0
){
mRadius
+=
dy
;
}
else
{
mRadius
-=
dy
;
}
if
(
mHitCorner
==
8
)
{
mRadius
-=
dy
;
mCaptureRect
.
left
+=
dy
;
mCaptureRect
.
top
+=
dy
;
mCaptureRect
.
right
-=
dy
;
mCaptureRect
.
bottom
-=
dy
;
}
if
(
mHitCorner
==
6
)
{
mRadius
+=
dx
;
mCaptureRect
.
left
-=
dx
;
mCaptureRect
.
top
-=
d
y
;
mCaptureRect
.
top
-=
d
x
;
mCaptureRect
.
right
+=
dx
;
mCaptureRect
.
bottom
+=
dx
;
}
if
(
mHitCorner
==
2
)
{
mRadius
+=
dy
;
mCaptureRect
.
left
-=
dy
;
mCaptureRect
.
top
-=
dy
;
mCaptureRect
.
right
+=
dy
;
mCaptureRect
.
bottom
+=
dy
;
}
//防止选取越界
int
screenWidth
=
mScreenRect
.
right
-
mScreenRect
.
left
;
int
screenHeight
=
mScreenRect
.
bottom
-
mScreenRect
.
top
;
int
maxRaduis
=
(
screenWidth
-
mHalfAnchorWidth
*
2
)
/
2
;
if
(
Math
.
abs
(
mRadius
)
>
maxRaduis
)
{
if
(
mRadius
>
0
)
{
mRadius
=
maxRaduis
;
}
else
{
mRadius
=
-
maxRaduis
;
}
}
mRadius1
=
Math
.
abs
(
mRadius
);
if
(
mCaptureRect
.
left
<=
mHalfAnchorWidth
)
{
mCaptureRect
.
left
=
mHalfAnchorWidth
;
int
maxWidth
=
screenWidth
-
mHalfAnchorWidth
*
2
;
mCaptureRect
.
right
=
mCaptureRect
.
left
+
maxWidth
;
mCaptureRect
.
top
=
(
screenHeight
-
maxWidth
)
/
2
;
mCaptureRect
.
bottom
=
mCaptureRect
.
top
+
maxWidth
;
}
else
if
(
mCaptureRect
.
left
>=
screenWidth
-
mHalfAnchorWidth
)
{
mCaptureRect
.
left
=
screenWidth
-
mHalfAnchorWidth
;
int
maxWidth
=
screenWidth
-
mHalfAnchorWidth
*
2
;
mCaptureRect
.
top
=
mCricleY
+
maxWidth
/
2
;
mCaptureRect
.
right
=
mHalfAnchorWidth
;
mCaptureRect
.
bottom
=
mCricleY
-
maxWidth
/
2
;
}
boolean
square
=
true
;
if
(
Math
.
abs
(
mCaptureRect
.
right
-
mCaptureRect
.
left
)
!=
Math
.
abs
(
mCaptureRect
.
bottom
-
mCaptureRect
.
top
))
{
square
=
false
;
}
Log
.
v
(
TAG
,
"mHitCorner"
+
mHitCorner
+
";dx:"
+
dx
+
";dy:"
+
dy
+
";width:"
+
(
mCaptureRect
.
right
-
mCaptureRect
.
left
)
+
";height:"
+
(
mCaptureRect
.
bottom
-
mCaptureRect
.
top
)
+
";square:"
+
(
square
?
"ok"
:
"------------------"
));
Log
.
v
(
TAG
,
"mHitCorner"
+
mHitCorner
+
";mRadius:"
+
mRadius
+
";mRadius1:"
+
mRadius1
+
";dx:"
+
dx
+
";dy:"
+
dy
+
";width:"
+
(
mCaptureRect
.
right
-
mCaptureRect
.
left
)
+
";height:"
+
(
mCaptureRect
.
bottom
-
mCaptureRect
.
top
)
+
";square:"
+
(
square
?
"ok"
:
"------------------"
)
+
";rect:"
+
mCaptureRect
.
toString
());
break
;
}
mLastX
=
x
;
...
...
app/src/main/java/com/mxdl/customview/view/SquareCaptureView.java
浏览文件 @
5f5633d8
...
...
@@ -61,7 +61,7 @@ public class SquareCaptureView extends View {
}
public
void
initView
()
{
setLayerType
(
1
,
null
);
setLayerType
(
View
.
LAYER_TYPE_SOFTWARE
,
null
);
mWidth
=
(
int
)
(
getResources
().
getDisplayMetrics
().
density
*
216
+
0.5f
);
mBorderPaint
.
setStrokeWidth
(
getResources
().
getDisplayMetrics
().
density
*
2
);
mBorderPaint
.
setStyle
(
Paint
.
Style
.
STROKE
);
...
...
@@ -94,12 +94,15 @@ public class SquareCaptureView extends View {
//Log.v(TAG,"onDraw left:"+mCaptureRect.left+";top:"+mCaptureRect.top+";right:"+mCaptureRect.right+";bottom:"+mCaptureRect.bottom);
canvas
.
save
();
//路径重新设置
mCapturePath
.
reset
();
//添加了一个当前的矩形区域
mCapturePath
.
addRect
(
new
RectF
(
mCaptureRect
),
Path
.
Direction
.
CW
);
//当前的画布与指定的路径相交
canvas
.
clipPath
(
mCapturePath
,
Region
.
Op
.
INTERSECT
);
//画矩形
区域
//画矩形
背景选区
canvas
.
drawRect
(
mScreenRect
,
mAreaPaint
);
//画矩形边框
//画矩形
背景
边框
canvas
.
drawPath
(
mCapturePath
,
mBorderPaint
);
canvas
.
restore
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录