1 | package org.greenstone.android.tipple.base;
|
---|
2 |
|
---|
3 | import org.greenstone.android.tipple.R;
|
---|
4 | import org.mapsforge.android.maps.MapView;
|
---|
5 |
|
---|
6 | import android.content.Context;
|
---|
7 | import android.graphics.Bitmap;
|
---|
8 | import android.graphics.BitmapFactory;
|
---|
9 | import android.graphics.Canvas;
|
---|
10 | import android.graphics.Matrix;
|
---|
11 | import android.graphics.Paint;
|
---|
12 | import android.graphics.Point;
|
---|
13 | import android.view.Display;
|
---|
14 | import android.view.WindowManager;
|
---|
15 |
|
---|
16 | public class MapViewTipple extends MapView
|
---|
17 | {
|
---|
18 | protected float currentRotation = 0;
|
---|
19 | Context context;
|
---|
20 | SensorFusion sensor_;
|
---|
21 |
|
---|
22 | public MapViewTipple(Context context, SensorFusion sensorFusion) {
|
---|
23 | super(context);
|
---|
24 | this.context = context;
|
---|
25 | sensor_ = sensorFusion;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public void onDraw(Canvas canvas) {
|
---|
30 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
|
---|
31 | Display display = wm.getDefaultDisplay();
|
---|
32 | int width = display.getWidth();
|
---|
33 | int height = display.getHeight();
|
---|
34 | Bitmap rotatedArrow;
|
---|
35 |
|
---|
36 | currentRotation = sensor_.getBearingDegrees();
|
---|
37 |
|
---|
38 | canvas.save();
|
---|
39 | super.onDraw(canvas);
|
---|
40 |
|
---|
41 | Bitmap headingArrow = BitmapFactory.decodeResource(getResources(), R.drawable.arrows);
|
---|
42 | Matrix matrix = new Matrix();
|
---|
43 | matrix.postRotate(currentRotation, headingArrow.getWidth()-20, headingArrow.getHeight()-5);
|
---|
44 | rotatedArrow = Bitmap.createBitmap(headingArrow , 0, 0, headingArrow.getWidth(), headingArrow.getHeight(), matrix, true);
|
---|
45 | matrix.setTranslate(20, 20);
|
---|
46 | rotatedArrow = Bitmap.createBitmap(rotatedArrow , 0, 0, rotatedArrow.getWidth(), rotatedArrow.getHeight(), matrix, true);
|
---|
47 | canvas.drawBitmap(rotatedArrow, matrix, new Paint());
|
---|
48 |
|
---|
49 | //canvas.rotate(currentRotation);
|
---|
50 |
|
---|
51 | canvas.restore();
|
---|
52 | }
|
---|
53 | } |
---|