Cuadro para poder firmar un parte

  • Respuestas:1
Samuel Cortés Gutiérrez
  • Posts del Foro: 2

27 jun. 2014 13:25:53 vía Web

Hola buenas a todos, acabo de registrarme en la comunidad de foreros de android y llevo dos meses y he realizado una aplicacion para crear partes, subirlos a un servidor y comprobar los campos con el servidor por medio de json y php entre otros detalles. El caso es que necesito un cuadro para que el cliente firme... Donde podria buscar o si alguien tan amable me pasara algun enlace o algun trozo de codigo?

Muchas gracias a todos.

Contestar
Ricardo Lahosa Laguna
  • Posts del Foro: 2

27 jul. 2014 10:13:15 vía Web

Yo utilizo este código:

public class DrawView extends View implements OnTouchListener {
List<Point> points = new ArrayList<Point>();
Paint paint = new Paint();
private int Gx=0;
private int Gy=0;

public DrawView(Context context) {
    super(context);
    setFocusable(true);
    setFocusableInTouchMode(true);

    this.setBackgroundColor(Color.WHITE);
    this.setOnTouchListener(this);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(Color.BLUE);
    paint.setStrokeWidth(4);
    paint.setAntiAlias(true);
}

@Override
public void onDraw(Canvas canvas) {
    for (Point point : points) {
        if ((Gx==0) &amp;&amp; (Gy==0)) {
            canvas.drawPoint(point.x, point.y, paint);
        } else {
            if ((point.x!=0) &amp;&amp; (point.y!=0)) {
            canvas.drawLine(Gx, Gy, point.x, point.y, paint);}
        }
        Gx = (int) point.x;
        Gy = (int) point.y;
    }
    Gx = 0;
    Gy = 0;     
}

public boolean onTouch(View view, MotionEvent event) {
    Point point = new Point();
    point.x = event.getX();
    point.y = event.getY();

    int action = event.getAction();
    switch (action) {
    case MotionEvent.ACTION_MOVE:
        break;
    case MotionEvent.ACTION_DOWN:
        Gx = 0;
        Gy = 0;         
        break;
    case MotionEvent.ACTION_UP:
        Gx = 0;
        Gy = 0;     
        point.x = 0;
        point.y = 0;
    default:
    }
    points.add(point);
    invalidate();
    return true;
}

public void Nueva() {
    points.clear();                 
    try {
        this.bringToFront();
        this.clearFocus();
    } catch( Exception e ) { 

    } 
}

}

class Point {
float x, y;

@Override
public String toString() {
    return x + ", " + y;
}

}

Con este código llamo a la función.
drawView = new DrawView(this);
setContentView(drawView);
drawView.requestFocus();

Espero que te sirva.

Contestar