gpt4 book ai didi

java - 在应用程序中添加签名栏

转载 作者:行者123 更新时间:2023-11-30 03:55:11 25 4
gpt4 key购买 nike

我正在使用 android 做一个简单的 express 系统。如果在交付过程结束时客户必须在电话上签名以确认他们收到了 express ,我该怎么办?我如何使用 android 来做到这一点。非常感谢任何意见和建议。

最佳答案

执行签名会占用大量空间,而且手机设备中的小区域不足以在交付过程结束时从客户处获取签名,这是我的想法。

生成包含交付详细信息的列表。

--> 在交货时间点击交付的项目打开 View 。

--> 在该 View 中客户端可以执行签名。

--> 您可以将该签名连同交付详细信息一起保存在数据库中

--> 删除项目或将项目从交付列表转移到已交付项目(这应该是您的另一种 View 方法)

这是我的想法

那个任务。要签名,您可以应用绘画方法和签名方法,如果您也需要帮助,请问我。谢谢

package com.paintexample;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.view.MotionEvent;
import android.view.View;

public class DrawView extends View {

private static final float STROKE_WIDTH = 5f;

/** Need to track this so the dirty region can accommodate the stroke. **/
private static final float HALF_STROKE_WIDTH = STROKE_WIDTH / 2;

private Paint paint = new Paint();
private Path path = new Path();

/** Optimizes painting by invalidating the smallest possible area. */
private float lastTouchX;
private float lastTouchY;
private final RectF dirtyRect = new RectF();

public DrawView(Context context) {
super(context);

paint.setAntiAlias(true);
paint.setColor(Color.BLACK);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeJoin(Paint.Join.ROUND);
paint.setStrokeWidth(STROKE_WIDTH);
}

/** Erases the signature. */
public void clear() {
path.reset();

// Repaints the entire view.
invalidate();
}

@Override
protected void onDraw(Canvas canvas) {
canvas.drawPath(path, paint);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
float eventX = event.getX();
float eventY = event.getY();

switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(eventX, eventY);
lastTouchX = eventX;
lastTouchY = eventY;
// There is no end point yet, so don't waste cycles invalidating.
return true;

case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
// Start tracking the dirty region.
resetDirtyRect(eventX, eventY);

// When the hardware tracks events faster than they are delivered,
// the
// event will contain a history of those skipped points.
int historySize = event.getHistorySize();
Logger.debug("historySize : " + historySize);
for (int i = 0; i < historySize; i++) {
float historicalX = event.getHistoricalX(i);
float historicalY = event.getHistoricalY(i);
expandDirtyRect(historicalX, historicalY);
path.lineTo(historicalX, historicalY);
}

// After replaying history, connect the line to the touch point.
// Logger.debug("eventX " + eventX);
// Logger.debug("eventY " + eventX);
//
// Logger.debug("lastTouchX " + lastTouchX);
// Logger.debug("lastTouchY " + lastTouchY);
//
// if (eventX == lastTouchX && eventY == lastTouchY) {
//
// path.addCircle(eventX, eventY, 20, Path.Direction.CW);
//
// }

path.lineTo(eventX, eventY);

break;

default:
Logger.debug("Ignored touch event: " + event.toString());
return false;
}

// Include half the stroke width to avoid clipping.
invalidate((int) (dirtyRect.left - HALF_STROKE_WIDTH), (int) (dirtyRect.top - HALF_STROKE_WIDTH), (int) (dirtyRect.right + HALF_STROKE_WIDTH), (int) (dirtyRect.bottom + HALF_STROKE_WIDTH));

lastTouchX = eventX;
lastTouchY = eventY;

return true;
}

/** Called when replaying history to ensure the dirty region includes all
* points. */
private void expandDirtyRect(float historicalX, float historicalY) {
if (historicalX < dirtyRect.left) {
dirtyRect.left = historicalX;
} else if (historicalX > dirtyRect.right) {
dirtyRect.right = historicalX;
}
if (historicalY < dirtyRect.top) {
dirtyRect.top = historicalY;
} else if (historicalY > dirtyRect.bottom) {
dirtyRect.bottom = historicalY;
}
}

/** Resets the dirty region when the motion event occurs. */
private void resetDirtyRect(float eventX, float eventY) {

// The lastTouchX and lastTouchY were set when the ACTION_DOWN
// motion event occurred.
dirtyRect.left = Math.min(lastTouchX, eventX);
dirtyRect.right = Math.max(lastTouchX, eventX);
dirtyRect.top = Math.min(lastTouchY, eventY);
dirtyRect.bottom = Math.max(lastTouchY, eventY);
}
}

上面是绘制类

现在像这样在您的 Activity 中添加绘制 View 。

//Assigning Drawing Board
drawView = new DrawView(this);
setContentView(view);
drawView.requestFocus();
linearLayout.addView(drawView);

您可以使用 DrawView 类的不同方法来清除/绘制并享受更多乐趣

关于java - 在应用程序中添加签名栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13468309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com