3 Star 3 Fork 1

CHINASOFT5_OHOS / FreeDrawView

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

FreeDrawView

项目介绍

  • 项目名称:自定义画板
  • 所属系列:openharmony的第三方组件适配移植
  • 功能:根据手势绘制图案,获取绘制的图片
  • 项目移植状态:主功能完成
  • 调用差异:无
  • 开发版本:sdk6,DevEco Studio2.2 Beta1
  • 基线版本:Release1.1.2

效果演示

输入图片说明

安装教程

1.在项目根目录下的build.gradle文件中,

allprojects {
    repositories {
        maven {
            url 'https://s01.oss.sonatype.org/content/repositories/releases/'
        }
    }
}

2.在entry模块的build.gradle文件中,

 dependencies {
    implementation('com.gitee.chinasoft_ohos:FreeDrawView:1.0.1')
    ......  
 }

在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功能与原组件基本无差异

版本迭代

  • 1.0.1
  • 1.0.0
  • 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.

空文件

简介

根据手势绘制图案,获取绘制的图片 展开 收起
Java
取消

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/chinasoft5_ohos/FreeDrawView.git
git@gitee.com:chinasoft5_ohos/FreeDrawView.git
chinasoft5_ohos
FreeDrawView
FreeDrawView
master

搜索帮助