diff options
Diffstat (limited to 'client/activity-demo/Piztor/src/com/example/piztor/MyView.java')
-rw-r--r-- | client/activity-demo/Piztor/src/com/example/piztor/MyView.java | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/client/activity-demo/Piztor/src/com/example/piztor/MyView.java b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java index 1627e4c..a213013 100644 --- a/client/activity-demo/Piztor/src/com/example/piztor/MyView.java +++ b/client/activity-demo/Piztor/src/com/example/piztor/MyView.java @@ -1,39 +1,55 @@ package com.example.piztor; -import java.io.*; -import android.content.*; -import android.graphics.*; +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.util.*; -import android.view.*; +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; + private Paint mPaint, oPaint; public Canvas c = null; public Bitmap b = null; - public double scale = 100; + public double scale = 1; public double centerX, centerY; -// Vector<PointF> v; + + + 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>(); + // 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>(); + // v = new Vector<PointF>(); mPaint = new Paint(); mPaint.setColor(Color.RED); mPaint.setStyle(Style.FILL); @@ -42,34 +58,42 @@ public class MyView extends View { @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); - canvas.drawBitmap(b, 0, 0, mPaint); + 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())); + // 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 drawLocation(double x, double y) { + 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); - c.drawRect(x1 - 1, y1 + 1, x1 + 1, y1 - 1, mPaint); + 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(); } - + }
\ No newline at end of file |