首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在应用程序中添加签名列

在应用程序中添加签名列
EN

Stack Overflow用户
提问于 2012-11-20 15:19:44
回答 1查看 136关注 0票数 1

我正在用android做一个简单的快递系统。如果在交付过程结束时,客户必须在电话上签名确认他们收到了快递,我该怎么办?如何使用android来完成此操作。任何建议,建议都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-20 15:27:46

执行签名消耗了大量的空间,并且在手机设备上很小的区域不足以在交付过程结束时从客户那里获取签名,这是我的想法。

生成具有递送详细信息的列表。

-->在交付时,单击交付项目将打开一个视图。

-->在这个视图中,客户端可以执行签名。

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

-->从to Deliver删除项目或将项目转移到Deliver项目(这应该是您的另一种查看方法)

这是我的想法

我就是那个任务。对于签名,您可以应用paint方法和signature方法,也可以询问我是否需要帮助。谢谢

代码语言:javascript
复制
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);
    }
}

上面是绘图类

现在像这样在你的活动中添加绘图视图。

代码语言:javascript
复制
//Assigning Drawing Board
        drawView = new DrawView(this);
        setContentView(view);
        drawView.requestFocus();
        linearLayout.addView(drawView);

你可以对你的不同方法的DrawView类进行清除/绘制等更多享受

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13468309

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档