L
linuxanton
Neues Mitglied
- 0
Hi,
Aufgabe ist folgende: ich habe eine Karte, Grundriss o.ä., die sich je nach Drehung des Geräts mitdreht. Meine Karte ist also immer genordet und die Richtung, in die ich schaue, stimmt mit der Richtung auf meinem Gerät überein.
So: jetzt will ich aber an bestimmten Stellen kleine Icons auf die Karte legen (nennen wir es einfach mal Points of Interest). Die Punkte bewegen sich also mit der Karte mit, die sich um ihren Mittelpunkt dreht. Bis hierher denke ich, habe ich das im Griff. Hier mal ein paar Snippets:
Bitmap ist mein Hintergrund, die Karte, bobbelmatrix ist einfach ein Point of Interest.
Und jetzt die Frage: Wie bekomme ich ein Click- oder TouchEvent hin, dass ich eindeutig sagen kann, ich habe auf meinen POI (bobbel) geclickt oder daneben? Bin mir nicht sicher, ob mein Gesamtansatz so zielführend ist oder ob es eine bessere Lösung gibt.
Danke schon mal.
linuxanton
Aufgabe ist folgende: ich habe eine Karte, Grundriss o.ä., die sich je nach Drehung des Geräts mitdreht. Meine Karte ist also immer genordet und die Richtung, in die ich schaue, stimmt mit der Richtung auf meinem Gerät überein.
So: jetzt will ich aber an bestimmten Stellen kleine Icons auf die Karte legen (nennen wir es einfach mal Points of Interest). Die Punkte bewegen sich also mit der Karte mit, die sich um ihren Mittelpunkt dreht. Bis hierher denke ich, habe ich das im Griff. Hier mal ein paar Snippets:
Code:
public class CompassView extends ImageView {
private static final AtomicBoolean drawing = new AtomicBoolean(false);
private static final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
private static int parentWidth = 0;
private static int parentHeight = 0;
private static Matrix matrix = null;
private static Bitmap bitmap = null;
private static Bitmap bobbel = null;
private static Matrix bobbelmatrix = null;
private int bobbelX, bobbelY, bobbelcenterX, bobbelcenterY;
public CompassView(Context context) {
super(context);
initialize();
}
public CompassView(Context context, AttributeSet attr) {
super(context,attr);
initialize();
}
private void initialize() {
matrix = new Matrix();
bobbelmatrix = new Matrix();
bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.grundriss);
bobbel = BitmapFactory.decodeResource(getResources(), R.drawable.bobbel);
}
/**
* {@inheritDoc}
*/
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int ausdehnung=0;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
ausdehnung = bitmap.getWidth();
if(bitmap.getHeight()>ausdehnung)
{
ausdehnung=bitmap.getHeight();
}
parentWidth=ausdehnung;
parentHeight=ausdehnung;
/*parentWidth = MeasureSpec.getSize(widthMeasureSpec);
parentHeight = MeasureSpec.getSize(heightMeasureSpec);*/
setMeasuredDimension(parentWidth, parentHeight);
}
/**
* {@inheritDoc}
*/
@Override
protected void onDraw(Canvas canvas) {
if (canvas==null) throw new NullPointerException();
if (!drawing.compareAndSet(false, true)) return;
float bearing = GlobalData.getBearing();
/* if (bitmap.getWidth()>canvasWidth || bitmap.getHeight()>canvasHeight) {
//Resize the bitmap to the size of the canvas
bitmap = Bitmap.createScaledBitmap(bitmap, (int)(bitmapWidth*.9), (int)(bitmapHeight*.9), true);
}*/
int bitmapX = bitmap.getWidth()/2;
int bitmapY = bitmap.getHeight()/2;
int parentX = parentWidth/2;
int parentY = parentHeight/2;
int centerX = parentX-bitmapX;
int centerY = parentY-bitmapY;
int rotation = (int)(360-bearing);
matrix.reset();
//Rotate the bitmap around it's center point so it's always pointing north
matrix.setRotate(rotation, bitmapX, bitmapY);
//Move the bitmap to the center of the canvas
matrix.postTranslate(centerX, centerY);
canvas.drawBitmap(bitmap, matrix, paint);
bobbelX=bobbel.getWidth()/2;
bobbelY=bobbel.getHeight()/2;
bobbelcenterX = parentX-bobbelX;
bobbelcenterY = parentY-bobbelY;
bobbelmatrix.reset();
bobbelmatrix.setRotate(rotation,bobbelX,bobbelY);
bobbelmatrix.postTranslate(bobbelcenterX, bobbelcenterY);
canvas.drawBitmap(bobbel, bobbelmatrix, paint);
drawing.set(false);
}
Bitmap ist mein Hintergrund, die Karte, bobbelmatrix ist einfach ein Point of Interest.
Und jetzt die Frage: Wie bekomme ich ein Click- oder TouchEvent hin, dass ich eindeutig sagen kann, ich habe auf meinen POI (bobbel) geclickt oder daneben? Bin mir nicht sicher, ob mein Gesamtansatz so zielführend ist oder ob es eine bessere Lösung gibt.
Danke schon mal.
linuxanton