android⼿写签批_Android_Android实现⼿写签名,本⽂实例
为⼤家分享了A。。。
Android实现⼿写签名
本⽂实例为⼤家分享了Android⼿写签名的实现⽅法,产品要求⽤户可以在app上签协议。。所以得弄个⼿写签名版,参考了⼀些资料⾃⼰写了个PaintView去继承View,实现签名功能。
package com.****.*****.widget;
t.Context;
aphics.Bitmap;
aphics.Canvas;
aphics.Color;
aphics.Paint;
aphics.Path;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
/**
* This view implements the drawing canvas.
*
* It handles all of the input events and drawing functions.
* 签名版
*/
public class PaintView extends View {
private Paint paint;
private Canvas cacheCanvas;
private Bitmap cachebBitmap;
private Path path;
private OnMoveLisener lisener;
public void setSize(int width,int height,OnMoveLisener lisener) {
this.lisener=lisener;
init(width,height);
}
public PaintView(Context context, AttributeSet attrs) {
super(context, attrs);
//init(0,0);
}
public Bitmap getCachebBitmap() {
return cachebBitmap;
}
private void init(int width,int height) {
paint = new Paint();
paint.setAntiAlias(true);
paint.setStrokeWidth(3);
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.BLACK);
path = new Path();
cachebBitmap = ateBitmap(width, height, Bitmap.Config.ARGB_8888); cacheCanvas = new Canvas(cachebBitmap);
cacheCanvas.drawColor(Color.WHITE);
}
public void clear() {
if (cacheCanvas != null) {
paint.setColor(Color.WHITE);
cacheCanvas.drawPaint(paint);
paint.setColor(Color.BLACK);
cacheCanvas.drawColor(Color.WHITE);
invalidate();
}
}
@Override
protected void onDraw(Canvas canvas) {
// canvas.drawColor(BRUSH_COLOR);
canvas.drawBitmap(cachebBitmap, 0, 0, null);
canvas.drawPath(path, paint);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
int curW = cachebBitmap != null ? Width() : 0;
int curH = cachebBitmap != null ? Height() : 0;
if (curW >= w && curH >= h) {
return;
}
if (curW < w)
curW = w;
if (curH < h)
curH = h;
Bitmap newBitmap = ateBitmap(curW, curH, Bitmap.Config.ARGB_8888); Canvas newCanvas = new Canvas();
newCanvas.setBitmap(newBitmap);
if (cachebBitmap != null) {
android获取真正的签名newCanvas.drawBitmap(cachebBitmap, 0, 0, null);
}
cachebBitmap = newBitmap;
cacheCanvas = newCanvas;
}
private float cur_x, cur_y;
@Override
public boolean onTouchEvent(MotionEvent event) {
getParent().requestDisallowInterceptTouchEvent(true);// 通知⽗控件勿拦截本控件touch事件float x = X();
float y = Y();
switch (Action()) {
case MotionEvent.ACTION_DOWN: {
cur_x = x;
cur_y = y;
break;
}
case MotionEvent.ACTION_MOVE: {
path.quadTo(cur_x, cur_y, x, y);
cur_x = x;
cur_y = y;
lisener.hideWords();//隐藏提醒的⽂字
break;
}
case MotionEvent.ACTION_UP: {
cacheCanvas.drawPath(path, paint);
break;
}
}
invalidate();
return true;
}
public interface OnMoveLisener{
void hideWords();//主界⾯回调后隐藏提⽰⽂字
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助。相关阅读:
jQuery中的pushStack实现原理和应⽤实例
最好的8个Java RESTful框架
Android开发之ImageLoader使⽤详解
winxp⽂件夹属性不到"安全"选项卡该怎么办?
iOS 9 更新之Safari⼴告(Content Blocker)开发教程
c#注册客户端事件⽰例
javascript实现禁⽌复制⽹页内容汇总
C#递归算法之归并排序
C++获得⽂件状态信息的⽅法
pre标签的css代码,防⽌代码pre中代码过长等问题
浅谈JavaScript中⼩数和⼤整数的精度丢失
Win8.1升级Win10系统到99%弹出错误代码80240031的故障原因及解决⽅法MFC对话框⾃定义消息映射的⽅法
jQuery满意度星级评价插件特效代码分享

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。