2 * Copyright © 2015 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.AltosDroid;
23 import org.altusmetrum.altoslib_7.*;
25 import android.app.Activity;
26 import android.graphics.*;
27 import android.os.Bundle;
28 import android.support.v4.app.Fragment;
29 import android.support.v4.app.FragmentTransaction;
30 import android.view.*;
31 import android.widget.*;
32 import android.location.Location;
33 import android.content.*;
34 import android.util.*;
36 public class AltosMapView extends View implements ScaleGestureDetector.OnScaleGestureListener {
37 ScaleGestureDetector scale_detector;
45 if (a != null && b != null) {
46 AltosPointDouble a_screen = tab.map.transform.screen(a);
47 AltosPointDouble b_screen = tab.map.transform.screen(b);
48 tab.paint.setColor(0xff8080ff);
49 tab.canvas.drawLine((float) a_screen.x, (float) a_screen.y,
50 (float) b_screen.x, (float) b_screen.y,
55 void set_a(AltosLatLon a) {
59 void set_b(AltosLatLon b) {
67 Line line = new Line();
69 private void draw_bitmap(AltosLatLon lat_lon, Bitmap bitmap, int off_x, int off_y) {
70 if (lat_lon != null && tab.map != null && tab.map.transform != null) {
71 AltosPointInt pt = new AltosPointInt(tab.map.transform.screen(lat_lon));
73 tab.canvas.drawBitmap(bitmap, pt.x - off_x, pt.y - off_y, tab.paint);
77 private void draw_positions() {
78 line.set_a(tab.map.last_position);
81 draw_bitmap(tab.pad, tab.pad_bitmap, tab.pad_off_x, tab.pad_off_y);
83 Rocket[] rockets = tab.rockets.values().toArray(new Rocket[0]);
86 for (Rocket rocket : rockets)
88 draw_bitmap(tab.here, tab.here_bitmap, tab.here_off_x, tab.here_off_y);
91 @Override public void invalidate() {
97 @Override public void invalidate(int l, int t, int r, int b) {
98 Rect rect = new Rect();
104 protected void onDraw(Canvas view_canvas) {
105 tab.canvas = view_canvas;
106 tab.paint = new Paint(Paint.ANTI_ALIAS_FLAG);
107 tab.paint.setStrokeWidth(tab.stroke_width);
108 tab.paint.setStrokeCap(Paint.Cap.ROUND);
109 tab.paint.setStrokeJoin(Paint.Join.ROUND);
110 tab.paint.setTextSize(40);
116 public boolean onScale(ScaleGestureDetector detector) {
117 float f = detector.getScaleFactor();
119 tab.map.set_zoom(tab.map.get_zoom() - 1);
123 tab.map.set_zoom(tab.map.get_zoom() + 1);
129 public boolean onScaleBegin(ScaleGestureDetector detector) {
133 public void onScaleEnd(ScaleGestureDetector detector) {
137 public boolean dispatchTouchEvent(MotionEvent event) {
138 scale_detector.onTouchEvent(event);
140 if (scale_detector.isInProgress()) {
145 if (event.getAction() == MotionEvent.ACTION_UP) {
151 if (event.getAction() == MotionEvent.ACTION_DOWN) {
152 tab.map.touch_start((int) event.getX(), (int) event.getY(), true);
153 } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
154 tab.map.touch_continue((int) event.getX(), (int) event.getY(), true);
159 public void set_tab(TabMapOffline tab) {
163 public AltosMapView(Context context, AttributeSet attrs) {
164 super(context, attrs);
165 scale_detector = new ScaleGestureDetector(context, this);