Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
carrotech
doodle
提交
e6811781
D
doodle
项目概览
carrotech
/
doodle
与 Fork 源项目一致
从无法访问的项目Fork
通知
5
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
doodle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e6811781
编写于
12月 12, 2016
作者:
H
huangziwei
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
关闭硬件加速,修复快速点击滑动时画笔异常的问题
上级
2e236d3f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
33 addition
and
13 deletion
+33
-13
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
+33
-13
未找到文件。
GraffitiLib/src/main/java/cn/hzw/graffiti/GraffitiView.java
浏览文件 @
e6811781
...
...
@@ -10,7 +10,6 @@ import android.graphics.Paint;
import
android.graphics.Path
;
import
android.graphics.Shader
;
import
android.os.Build
;
import
android.util.Log
;
import
android.view.MotionEvent
;
import
android.view.View
;
...
...
@@ -47,6 +46,7 @@ public class GraffitiView extends View {
private
BitmapShader
mBitmapShaderEraser4C
;
private
Path
mCurrPath
;
// 当前手写的路径
private
Path
mCanvasPath
;
//
private
Path
mTempPath
;
private
CopyLocation
mCopyLocation
;
// 仿制的定位器
private
Paint
mPaint
;
...
...
@@ -111,10 +111,15 @@ public class GraffitiView extends View {
public
GraffitiView
(
Context
context
,
Bitmap
bitmap
,
String
eraser
,
boolean
eraserImageIsResizeable
,
GraffitiListener
listener
)
{
super
(
context
);
//[11,18)对硬件加速支持不完整,clipPath时会crash
/*
//[11,18)对硬件加速支持不完整,clipPath时会crash
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2
&& Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(LAYER_TYPE_SOFTWARE, null);
}*/
// 关闭硬件加速,因为bitmap的Canvas不支持硬件加速
if
(
Build
.
VERSION
.
SDK_INT
>=
11
)
{
setLayerType
(
LAYER_TYPE_SOFTWARE
,
null
);
}
mBitmap
=
bitmap
;
...
...
@@ -165,6 +170,7 @@ public class GraffitiView extends View {
mShaderMatrix4C
=
new
Matrix
();
mMatrixTemp
=
new
Matrix
();
mCanvasPath
=
new
Path
();
mTempPath
=
new
Path
();
mCopyLocation
=
new
CopyLocation
(
150
,
150
);
}
...
...
@@ -187,9 +193,6 @@ public class GraffitiView extends View {
mTouchDownX
=
mTouchX
=
mLastTouchX
=
event
.
getX
();
mTouchDownY
=
mTouchY
=
mLastTouchY
=
event
.
getY
();
mTouchX
+=
VALUE
;
// 为了仅点击时也能出现绘图,模拟滑动一个像素点
mTouchY
+=
VALUE
;
if
(
mPen
==
Pen
.
COPY
&&
mCopyLocation
.
isInIt
(
toX4C
(
mTouchX
),
toY4C
(
mTouchY
)))
{
// 点击copy
mCopyLocation
.
isRelocating
=
true
;
mCopyLocation
.
isCopying
=
false
;
...
...
@@ -208,12 +211,6 @@ public class GraffitiView extends View {
mCanvasPath
.
reset
();
mCanvasPath
.
moveTo
(
toX4C
(
mTouchDownX
),
toY4C
(
mTouchDownY
));
// 为了仅点击时也能出现绘图,必须移动path
mCanvasPath
.
quadTo
(
toX4C
(
mLastTouchX
),
toY4C
(
mLastTouchY
),
toX4C
((
mTouchX
+
mLastTouchX
)
/
2
),
toY4C
((
mTouchY
+
mLastTouchY
)
/
2
));
}
else
{
// 画图形
}
...
...
@@ -229,6 +226,12 @@ public class GraffitiView extends View {
mTouchX
=
event
.
getX
();
mTouchY
=
event
.
getY
();
// 为了仅点击时也能出现绘图,必须移动path
if
(
mTouchDownX
==
mTouchX
&&
mTouchDownY
==
mTouchY
)
{
mTouchX
+=
VALUE
;
mTouchY
+=
VALUE
;
}
if
(
mCopyLocation
.
isRelocating
)
{
// 正在定位location
mCopyLocation
.
updateLocation
(
toX4C
(
mTouchX
),
toY4C
(
mTouchY
));
mCopyLocation
.
isRelocating
=
false
;
...
...
@@ -359,13 +362,30 @@ public class GraffitiView extends View {
canvas
.
drawBitmap
(
mGraffitiBitmap
,
(
mCentreTranX
+
mTransX
)
/
(
mPrivateScale
*
mScale
),
(
mCentreTranY
+
mTransY
)
/
(
mPrivateScale
*
mScale
),
null
);
if
(
mIsPainting
)
{
//画在view的画布上
Path
path
;
float
span
=
0
;
// 为了仅点击时也能出现绘图,必须移动path
if
(
mTouchDownX
==
mTouchX
&&
mTouchDownY
==
mTouchY
)
{
mTempPath
.
reset
();
mTempPath
.
addPath
(
mCanvasPath
);
mTempPath
.
quadTo
(
toX4C
(
mLastTouchX
),
toY4C
(
mLastTouchY
),
toX4C
((
mTouchX
+
mLastTouchX
+
VALUE
)
/
2
),
toY4C
((
mTouchY
+
mLastTouchY
+
VALUE
)
/
2
));
path
=
mTempPath
;
span
=
VALUE
;
}
else
{
path
=
mCanvasPath
;
span
=
0
;
}
// 画触摸的路径
mPaint
.
setStrokeWidth
(
mPaintSize
);
if
(
mShape
==
Shape
.
HAND_WRITE
)
{
// 手写
draw
(
canvas
,
mPen
,
mPaint
,
mCanvasP
ath
,
null
,
true
,
mColor
);
draw
(
canvas
,
mPen
,
mPaint
,
p
ath
,
null
,
true
,
mColor
);
}
else
{
// 画图形
draw
(
canvas
,
mPen
,
mShape
,
mPaint
,
toX4C
(
mTouchDownX
),
toY4C
(
mTouchDownY
),
toX4C
(
mTouchX
),
toY4C
(
mTouchY
),
null
,
true
,
mColor
);
toX4C
(
mTouchDownX
),
toY4C
(
mTouchDownY
),
toX4C
(
mTouchX
+
span
),
toY4C
(
mTouchY
+
span
),
null
,
true
,
mColor
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录