summaryrefslogtreecommitdiff
path: root/client/activity-demo/Piztor/src/com/example/piztor/MyView.java
blob: a21301320176b326130eedef386e2459a5eab209 (plain) (blame)
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
99
package com.example.piztor;

import java.io.PrintStream;
import java.util.Vector;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Point;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MyView extends View {
	static PrintStream cout = System.out;
	private Paint mPaint, oPaint;
	public Canvas c = null;
	public Bitmap b = null;
	public double scale = 1;
	public double centerX, centerY;
	
	
	Point myLocation;
	Vector<Point> Location;

	void setup(Canvas c, Bitmap b, double x, double y) {
		this.c = c;
		this.b = b;
		centerX = x;
		centerY = y;
		myLocation = new Point(10, 10);
		Location = new Vector<Point>();
		Location.add(myLocation);
	}

	public MyView(Context context) {
		super(context);
		// v = new Vector<PointF>();
		mPaint = new Paint();
		mPaint.setColor(Color.RED);
		mPaint.setStyle(Style.FILL);
		oPaint = new Paint();
		oPaint.setColor(Color.BLUE);
		oPaint.setStyle(Style.FILL);
	}

	public MyView(Context context, AttributeSet attr) {
		super(context, attr);
		// v = new Vector<PointF>();
		mPaint = new Paint();
		mPaint.setColor(Color.RED);
		mPaint.setStyle(Style.FILL);
	}

	@Override
	protected void onDraw(Canvas canvas) {
		super.onDraw(canvas);
		cout.println(myLocation.x + "   --   " + myLocation.y);
		canvas.drawCircle(myLocation.x, myLocation.y, 5, mPaint);
		//canvas.drawBitmap(b, 0, 0, mPaint);
		/*for (int i = 1; i < Location.size(); i++) {
			canvas.drawCircle(Location.get(i).x, Location.get(i).y, 2, oPaint);
		}*/
		// canvas.restore();
	}

	@Override
	public boolean onTouchEvent(MotionEvent e) {
		// v.add(new PointF(e.getX(), e.getY()));
		c.drawRect(e.getX() - 1, e.getY() + 1, e.getX() + 1, e.getY() - 1,
				mPaint);
		
		invalidate();
		return true;
	}

	void changMyLocation(double x, double y) {
		if (centerX < 0) {
			centerX = x;
			centerY = y;
		}
		int x1 = (int) (getWidth() / 2 + (x - centerX) * scale);
		int y1 = (int) (getHeight() / 2 + (y - centerY) * scale);
		myLocation.x = x1;
		myLocation.y = y1;
		cout.println(x + " " + y);
		invalidate();
	}

	void drawString(String s) {
		mPaint.setTextSize(15);
		c.drawText(s, 0, getHeight() / 2, mPaint);
		invalidate();
	}

}