1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
package info.ups.fr.puzzlegame_template;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
/**
* Created by leocances on 24/03/15.
*/
public class Piece extends Drawable implements View.OnTouchListener{
private static final String TAG_LOG = "TouchActivity";
private static final boolean LOG = true;
private int id, idG;
private int x, y;
private Bitmap image;
public Piece(int id, int x, int y, Bitmap image) {
this.id = id;
this.x = x;
this.y = y;
this.image = image;
}
public Piece(int id, int idG, Bitmap image) {
this.id = id;
this.idG = idG;
this.image = image;
}
public int getX() { return this.x;}
public int getY() { return this.y;}
public int getId() { return this.id;}
public int getIdG() {return this.idG;}
public Bitmap getImage() {return this.image;}
@Override
public void draw(Canvas canvas) {
canvas.drawBitmap(image, x, y, null);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
x += 10;
v.invalidate();
log("x : " + x + "\ty : " + y);
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
break;
}
return true;
}
@Override
public void setAlpha(int alpha) {}
@Override
public void setColorFilter(ColorFilter cf) {}
@Override
public int getOpacity() {return 0;}
private String stringValue(MotionEvent event) {
final int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
return "ACTION_DOWN";
case MotionEvent.ACTION_MOVE:
return "ACTION_MOVE";
case MotionEvent.ACTION_UP:
return "ACTION_UP";
case MotionEvent.ACTION_CANCEL:
return "ACTION_CANCEL";
}
return "";
}
private static void log(String message){
if (LOG) {
Log.d(TAG_LOG, message);
}
}
} |
Partager