回复
鸿蒙开源组件——手势绘制图案
jacksky
发布于 2022-1-10 17:23
浏览
0收藏
FreeDrawView
项目介绍
- 项目名称:自定义画板
- 所属系列:openharmony的第三方组件适配移植
- 功能:根据手势绘制图案,获取绘制的图片
- 项目移植状态:主功能完成
- 调用差异:无
- 开发版本:sdk6,DevEco Studio2.2 Beta1
- 基线版本:Release1.1.2
效果演示
安装教程
1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}
}
2.在entry模块的build.gradle文件中,
dependencies {
implementation('com.gitee.chinasoft_ohos:FreeDrawView:0.0.1-SNAPSHOT')
......
}
在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
使用说明
使用该库非常简单,只需查看提供的示例的源代码。 在布局文件中加入控件,代码实例如下
<com.rm.freedrawview.FreeDrawView
ohos:id="$+id:free_draw_view"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:background_element="$color:white"
app:paintAlpha="255"
app:paintColor="@color/black"
app:paintWidth="4vp"
app:resizeBehaviour="crop"/>
java 文件中使用
public class AbilityDrawSlice extends AbilitySlice {
FreeDrawView mSignatureView;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_Ability_draw);
((AbilityDraw) getAbility()).setAbilityCall(this);
mSignatureView = (FreeDrawView) findComponentById(ResourceTable.Id_free_draw_view);
// Setup the View
mSignatureView.setPaintColor(Color.BLACK);
mSignatureView.setPaintWidthPx(12);
mSignatureView.setPaintWidthDp(6);
mSignatureView.setPaintAlpha(255);// from 0 to 255
mSignatureView.setResizeBehaviour(ResizeBehaviour.CROP);// Must be one of ResizeBehaviour
// values;
// This listener will be notified every time the path done and undone count changes
mSignatureView.setPathRedoUndoCountChangeListener(new PathRedoUndoCountChangeListener() {
@Override
public void onUndoCountChanged(int undoCount) {
// The undoCount is the number of the paths that can be undone
}
@Override
public void onRedoCountChanged(int redoCount) {
// The redoCount is the number of path removed that can be redrawn
}
});
// This listener will be notified every time a new path has been drawn
mSignatureView.setOnPathDrawnListener(new PathDrawnListener() {
@Override
public void onNewPathDrawn() {
// The user has finished drawing a path
}
@Override
public void onPathStart() {
// The user has started drawing a path
}
});
// This will take a screenshot of the current drawn content of the view
mSignatureView.getDrawScreenshot(new FreeDrawView.DrawCreatorListener() {
@Override
public void onDrawCreated(Bitmap draw) {
// The draw Bitmap is the drawn content of the View
}
@Override
public void onDrawCreationError() {
// Something went wrong creating the bitmap, should never
// happen unless the async task has been canceled
}
});
}
@Override
public void onSaveAbilityState(PacMap outState) {
mFreeDrawView.onSaveAbilityState(outState);
}
@Override
public void onRestoreAbilityState(PacMap inState) {
setBackgroundColor(mSideView, mFreeDrawView.getPaintColor());
mFreeDrawView.onRestoreAbilityState(inState);
}
}
自定义属性
XML Attribute | Java method | Description | Default value |
paintColor | setPaintColor(@ColorInt int checked) | Set the color of the paint | Color.BLACK |
paintWidth | setPaintWidthPx(@FloatRange(from = 0) float widthPx) | Set the width of the paint in pixels | 4dp |
setPaintWidthDp(float dp) | Set the width of the paint in dp | 4dp | |
paintAlpha | setPaintAlpha(@IntRange(from = 0, to = 255) int alpha) | Set the alpha of the paint | 255 |
resizeBehaviour | setResizeBehaviour(ResizeBehaviour newBehaviour) | The behaviour of the view every time it is resized (on rotation for example) one of [clear, fitXY, crop] | ResizeBehaviour.CROP |
公共方法
public void undoLast()
撤回上一条public void redoLast()
恢复上一条public void undoAll()
撤回所有public void redoAll()
恢复所有public void clearHistory()
清除历史看记录public void clearDraw()
清除所有绘制public void clearDrawAndHistory()
清除所有绘制和历史记录public int getPathCount(boolean includeCurrentlyDrawingPath)
获取绘制的数量setOnPathDrawnListener(PathDrawnListener listener)
设置监听setPathRedoUndoCountChangeListener(PathRedoUndoCountChangeListener listener)
设置监听removePathDrawnListener()
移除监听removePathRedoUndoCountChangeListener()
移除监听
测试信息
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
版本迭代
- 0.0.1-SNAPSHOT
版权和许可信息
Copyright 2017 Riccardo Moro.
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.
FreeDrawView-master.zip 856.56K 12次下载
已于2022-1-10 17:23:47修改
赞
收藏
回复
相关推荐