Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
门心叼龙
android-custom-view
提交
259a6ad3
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 搜索 >>
提交
259a6ad3
编写于
10月 12, 2019
作者:
门心叼龙
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code perfect
上级
9ad7ea34
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
504 addition
and
342 deletion
+504
-342
app/src/main/java/com/mxdl/CaptureViewActivity.java
app/src/main/java/com/mxdl/CaptureViewActivity.java
+3
-2
app/src/main/java/com/mxdl/customview/view/CaptureView.java
app/src/main/java/com/mxdl/customview/view/CaptureView.java
+317
-339
app/src/main/java/com/mxdl/customview/view/CenterCaptureView.java
...main/java/com/mxdl/customview/view/CenterCaptureView.java
+182
-0
app/src/main/res/layout/activity_capture_view.xml
app/src/main/res/layout/activity_capture_view.xml
+2
-1
未找到文件。
app/src/main/java/com/mxdl/CaptureViewActivity.java
浏览文件 @
259a6ad3
...
...
@@ -6,10 +6,11 @@ import android.os.Bundle;
import
com.mxdl.customview.R
;
import
com.mxdl.customview.view.CaptureView
;
import
com.mxdl.customview.view.CenterCaptureView
;
public
class
CaptureViewActivity
extends
AppCompatActivity
{
private
CaptureView
mCaptureView
;
private
C
enterC
aptureView
mCaptureView
;
@SuppressLint
(
"WrongViewCast"
)
@Override
...
...
@@ -17,6 +18,6 @@ public class CaptureViewActivity extends AppCompatActivity {
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_capture_view
);
mCaptureView
=
findViewById
(
R
.
id
.
view_cpature
);
mCaptureView
.
initCaptureFrame
();
//
mCaptureView.initCaptureFrame();
}
}
app/src/main/java/com/mxdl/customview/view/CaptureView.java
浏览文件 @
259a6ad3
此差异已折叠。
点击以展开。
app/src/main/java/com/mxdl/customview/view/CenterCaptureView.java
0 → 100644
浏览文件 @
259a6ad3
package
com.mxdl.customview.view
;
import
android.content.Context
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.Paint
;
import
android.graphics.Path
;
import
android.graphics.Rect
;
import
android.graphics.RectF
;
import
android.graphics.drawable.Drawable
;
import
android.os.Build
;
import
android.support.annotation.RequiresApi
;
import
android.util.AttributeSet
;
import
android.view.MotionEvent
;
import
android.view.View
;
import
com.mxdl.customview.R
;
/**
* Description: <CenterCaptureView><br>
* Author: mxdl<br>
* Date: 2019/10/12<br>
* Version: V1.0.0<br>
* Update: <br>
*/
public
class
CenterCaptureView
extends
View
{
private
int
mWidth
;
private
Rect
mScreenRect
=
new
Rect
();
private
Rect
mCaptureRect
=
new
Rect
();
private
Paint
mBorderPaint
=
new
Paint
();
private
Path
mCapturePath
=
new
Path
();
private
Paint
mAreaPaint
=
new
Paint
();
private
Drawable
mAnchorDrawable
;
private
int
mHalfAnchorWidth
;
private
int
mLastX
;
private
int
mLastY
;
private
int
mHitCorner
;
public
CenterCaptureView
(
Context
context
)
{
super
(
context
);
initView
();
}
public
CenterCaptureView
(
Context
context
,
AttributeSet
attrs
)
{
super
(
context
,
attrs
);
initView
();
}
public
CenterCaptureView
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
)
{
super
(
context
,
attrs
,
defStyleAttr
);
initView
();
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
LOLLIPOP
)
public
CenterCaptureView
(
Context
context
,
AttributeSet
attrs
,
int
defStyleAttr
,
int
defStyleRes
)
{
super
(
context
,
attrs
,
defStyleAttr
,
defStyleRes
);
initView
();
}
public
void
initView
()
{
mWidth
=
(
int
)
(
getResources
().
getDisplayMetrics
().
density
*
216
+
0.5f
);
mBorderPaint
.
setStrokeWidth
(
getResources
().
getDisplayMetrics
().
density
*
2
);
mBorderPaint
.
setStyle
(
Paint
.
Style
.
STROKE
);
mBorderPaint
.
setAntiAlias
(
true
);
mBorderPaint
.
setColor
(
Color
.
parseColor
(
"#1E88E5"
));
mAreaPaint
.
setStyle
(
Paint
.
Style
.
FILL_AND_STROKE
);
mAreaPaint
.
setColor
(
Color
.
parseColor
(
"#1E88E5"
));
mAreaPaint
.
setAlpha
(
20
);
mAnchorDrawable
=
getResources
().
getDrawable
(
R
.
mipmap
.
ic_edit_fence_dragger
);
mHalfAnchorWidth
=
mAnchorDrawable
.
getIntrinsicWidth
()
/
2
;
}
@Override
protected
void
onLayout
(
boolean
changed
,
int
left
,
int
top
,
int
right
,
int
bottom
)
{
super
.
onLayout
(
changed
,
left
,
top
,
right
,
bottom
);
mScreenRect
.
set
(
left
,
top
,
right
,
bottom
);
int
captureLeft
=
(
right
-
mWidth
)
/
2
;
int
captureTop
=
(
bottom
-
mWidth
)
/
2
;
int
captureRight
=
captureLeft
+
mWidth
;
int
captureBottom
=
captureTop
+
mWidth
;
mCaptureRect
.
set
(
captureLeft
,
captureTop
,
captureRight
,
captureBottom
);
}
@Override
protected
void
onDraw
(
Canvas
canvas
)
{
super
.
onDraw
(
canvas
);
mCapturePath
.
reset
();
mCapturePath
.
addRect
(
new
RectF
(
mCaptureRect
),
Path
.
Direction
.
CW
);
//画矩形区域
canvas
.
drawRect
(
mCaptureRect
,
mAreaPaint
);
//画矩形边框
canvas
.
drawPath
(
mCapturePath
,
mBorderPaint
);
//画左上锚点
mAnchorDrawable
.
setBounds
(
mCaptureRect
.
left
-
mHalfAnchorWidth
,
mCaptureRect
.
top
-
mHalfAnchorWidth
,
mCaptureRect
.
left
+
mHalfAnchorWidth
,
mCaptureRect
.
top
+
mHalfAnchorWidth
);
mAnchorDrawable
.
draw
(
canvas
);
//画右上锚点
mAnchorDrawable
.
setBounds
(
mCaptureRect
.
right
-
mHalfAnchorWidth
,
mCaptureRect
.
top
-
mHalfAnchorWidth
,
mCaptureRect
.
right
+
mHalfAnchorWidth
,
mCaptureRect
.
top
+
mHalfAnchorWidth
);
mAnchorDrawable
.
draw
(
canvas
);
//画右下锚点
mAnchorDrawable
.
setBounds
(
mCaptureRect
.
right
-
mHalfAnchorWidth
,
mCaptureRect
.
bottom
-
mHalfAnchorWidth
,
mCaptureRect
.
right
+
mHalfAnchorWidth
,
mCaptureRect
.
bottom
+
mHalfAnchorWidth
);
mAnchorDrawable
.
draw
(
canvas
);
//画左下锚点
mAnchorDrawable
.
setBounds
(
mCaptureRect
.
left
-
mHalfAnchorWidth
,
mCaptureRect
.
bottom
-
mHalfAnchorWidth
,
mCaptureRect
.
left
+
mHalfAnchorWidth
,
mCaptureRect
.
bottom
+
mHalfAnchorWidth
);
mAnchorDrawable
.
draw
(
canvas
);
}
@Override
public
boolean
onTouchEvent
(
MotionEvent
event
)
{
int
x
=
(
int
)
event
.
getX
();
int
y
=
(
int
)
event
.
getY
();
switch
(
event
.
getAction
()){
case
MotionEvent
.
ACTION_DOWN
:
mHitCorner
=
getHitCorner
(
x
,
y
);
//如果没有点击在锚点上,则直接返回false
if
(
mHitCorner
==
0
){
return
false
;
}
break
;
case
MotionEvent
.
ACTION_UP
:
mHitCorner
=
0
;
break
;
case
MotionEvent
.
ACTION_MOVE
:
if
(
mHitCorner
==
0
){
return
false
;
}
int
dx
=
x
-
mLastX
;
int
dy
=
y
-
mLastY
;
if
(
mHitCorner
==
7
){
mCaptureRect
.
left
+=
dx
;
mCaptureRect
.
top
+=
dy
;
mCaptureRect
.
right
-=
dx
;
mCaptureRect
.
bottom
-=
dy
;
}
else
if
(
mHitCorner
==
9
){
mCaptureRect
.
left
-=
dx
;
mCaptureRect
.
top
+=
dy
;
mCaptureRect
.
right
+=
dx
;
mCaptureRect
.
bottom
-=
dy
;
}
else
if
(
mHitCorner
==
3
){
mCaptureRect
.
left
-=
dx
;
mCaptureRect
.
top
-=
dy
;
mCaptureRect
.
right
+=
dx
;
mCaptureRect
.
bottom
+=
dy
;
}
else
if
(
mHitCorner
==
1
){
mCaptureRect
.
left
+=
dx
;
mCaptureRect
.
top
-=
dy
;
mCaptureRect
.
right
-=
dx
;
mCaptureRect
.
bottom
+=
dy
;
}
break
;
}
mLastX
=
x
;
mLastY
=
y
;
invalidate
();
return
true
;
}
public
int
getHitCorner
(
float
x
,
float
y
)
{
int
result
=
0
;
if
(
y
>
mCaptureRect
.
top
-
mHalfAnchorWidth
&&
y
<
mCaptureRect
.
top
+
mHalfAnchorWidth
)
{
if
(
x
>
mCaptureRect
.
left
-
mHalfAnchorWidth
&&
x
<
mCaptureRect
.
left
+
mHalfAnchorWidth
)
{
result
=
7
;
}
else
if
(
x
>
mCaptureRect
.
right
-
mHalfAnchorWidth
&&
x
<
mCaptureRect
.
right
+
mHalfAnchorWidth
)
{
result
=
9
;
}
}
else
if
(
y
>
mCaptureRect
.
bottom
-
mHalfAnchorWidth
&&
y
<
mCaptureRect
.
bottom
+
mHalfAnchorWidth
)
{
if
(
x
>
mCaptureRect
.
left
-
mHalfAnchorWidth
&&
x
<
mCaptureRect
.
left
+
mHalfAnchorWidth
)
{
result
=
1
;
}
else
if
(
x
>
mCaptureRect
.
right
-
mHalfAnchorWidth
&&
x
<
mCaptureRect
.
right
+
mHalfAnchorWidth
)
{
result
=
3
;
}
}
return
result
;
}
}
app/src/main/res/layout/activity_capture_view.xml
浏览文件 @
259a6ad3
...
...
@@ -3,7 +3,8 @@
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
>
<com.mxdl.customview.view.CaptureView
<com.mxdl.customview.view.CenterCaptureView
android:id=
"@+id/view_cpature"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录