Go to the documentation of this file.00001 package org.ros.android.jskAndroidGui;
00002
00003 import java.util.ArrayList;
00004
00005 import android.content.Context;
00006 import android.graphics.Canvas;
00007 import android.graphics.Color;
00008 import android.graphics.Paint;
00009 import android.graphics.PixelFormat;
00010 import android.graphics.Point;
00011 import android.graphics.PorterDuff.Mode;
00012 import android.view.SurfaceHolder;
00013 import android.view.SurfaceView;
00014
00015 public class BoundingBoxView extends SurfaceView implements Runnable,
00016 SurfaceHolder.Callback {
00017
00018 private ArrayList<Point> points;
00019 private SurfaceHolder surfaceHolder;
00020 private Thread thread;
00021 private Boolean selected;
00022 private Long selected_time;
00023
00024 public BoundingBoxView(Context context) {
00025 super(context);
00026 surfaceHolder = getHolder();
00027 surfaceHolder.addCallback(this);
00028 surfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
00029 setZOrderOnTop(true);
00030 points = new ArrayList<Point>();
00031 selected = false;
00032 }
00033
00034 public void setSelect() {
00035 selected_time = System.currentTimeMillis();
00036 selected = true;
00037 }
00038
00039 public void drawBox(ArrayList<Point> point_list) {
00040 points = point_list;
00041 }
00042
00043 @Override
00044 public void run() {
00045 Canvas canvas = null;
00046 Paint paint = new Paint();
00047 paint.setStrokeWidth(5);
00048 paint.setARGB(255, 255, 0, 0);
00049
00050 while (thread != null) {
00051 try {
00052 canvas = surfaceHolder.lockCanvas();
00053 paint.setStyle(Paint.Style.FILL);
00054 canvas.drawColor(0, Mode.CLEAR);
00055 canvas.drawColor(Color.TRANSPARENT);
00056
00057 if (points.size() >= 2) {
00058 int size = points.size();
00059 paint.setStyle(Paint.Style.STROKE);
00060 if (selected) {
00061 paint.setColor(Color.BLUE);
00062 paint.setTextSize(55);
00063 canvas.drawText("Get Object Image", points.get(0).x,
00064 points.get(0).y - 30, paint);
00065 } else {
00066 paint.setColor(Color.RED);
00067 }
00068 canvas.drawRect(points.get(0).x, points.get(0).y,
00069 points.get(size - 1).x, points.get(size - 1).y,
00070 paint);
00071 }
00072
00073 if (selected
00074 && System.currentTimeMillis() - selected_time > 2000) {
00075 deleteBox();
00076 }
00077 } catch (Exception e) {
00078
00079 } finally {
00080
00081 surfaceHolder.unlockCanvasAndPost(canvas);
00082 }
00083 }
00084 }
00085
00086 public void deleteBox() {
00087 selected = false;
00088 points.clear();
00089 }
00090
00091 @Override
00092 public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
00093
00094 }
00095
00096 @Override
00097 public void surfaceCreated(SurfaceHolder arg0) {
00098 thread = new Thread(this);
00099 thread.start();
00100 }
00101
00102 @Override
00103 public void surfaceDestroyed(SurfaceHolder arg0) {
00104 thread = null;
00105 }
00106
00107 }