2 * Copyright © 2013 Mike Beattie <mike@ethernal.org>
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;
21 import org.altusmetrum.altoslib_1.*;
23 import com.google.android.gms.maps.CameraUpdateFactory;
24 import com.google.android.gms.maps.GoogleMap;
25 import com.google.android.gms.maps.SupportMapFragment;
26 import com.google.android.gms.maps.model.BitmapDescriptorFactory;
27 import com.google.android.gms.maps.model.LatLng;
28 import com.google.android.gms.maps.model.Marker;
29 import com.google.android.gms.maps.model.MarkerOptions;
31 import android.app.Activity;
32 import android.os.Bundle;
33 import android.support.v4.app.Fragment;
34 import android.support.v4.app.FragmentTransaction;
35 import android.view.LayoutInflater;
36 import android.view.View;
37 import android.view.ViewGroup;
38 import android.widget.TextView;
40 public class TabMap extends Fragment implements AltosDroidTab {
41 AltosDroid mAltosDroid;
43 private SupportMapFragment mMapFragment;
44 private GoogleMap mMap;
45 private boolean mapLoaded = false;
47 private Marker mRocketMarker;
48 private Marker mPadMarker;
49 private TextView mDistanceView;
50 private TextView mBearingView;
51 private TextView mLatitudeView;
52 private TextView mLongitudeView;
55 public void onAttach(Activity activity) {
56 super.onAttach(activity);
57 mAltosDroid = (AltosDroid) activity;
58 mAltosDroid.registerTab(this);
62 public void onCreate(Bundle savedInstanceState) {
63 super.onCreate(savedInstanceState);
65 mMapFragment = new SupportMapFragment() {
67 public void onActivityCreated(Bundle savedInstanceState) {
68 super.onActivityCreated(savedInstanceState);
76 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
77 View v = inflater.inflate(R.layout.tab_map, container, false);
78 mDistanceView = (TextView)v.findViewById(R.id.distance_value);
79 mBearingView = (TextView)v.findViewById(R.id.bearing_value);
80 mLatitudeView = (TextView)v.findViewById(R.id.lat_value);
81 mLongitudeView = (TextView)v.findViewById(R.id.lon_value);
86 public void onActivityCreated(Bundle savedInstanceState) {
87 super.onActivityCreated(savedInstanceState);
88 getChildFragmentManager().beginTransaction().add(R.id.map, mMapFragment).commit();
92 public void onDestroyView() {
93 super.onDestroyView();
95 mAltosDroid.unregisterTab(this);
98 //Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
99 //FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
100 //ft.remove(fragment);
104 private void setupMap() {
105 mMap = mMapFragment.getMap();
107 mMap.setMyLocationEnabled(true);
108 mMap.getUiSettings().setTiltGesturesEnabled(false);
109 mMap.getUiSettings().setZoomControlsEnabled(false);
110 mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8));
112 mRocketMarker = mMap.addMarker(
113 // From: http://mapicons.nicolasmollet.com/markers/industry/military/missile-2/
114 new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.rocket))
115 .position(new LatLng(0,0))
119 mPadMarker = mMap.addMarker(
120 new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.pad))
121 .position(new LatLng(0,0))
129 public void update_ui(AltosState state) {
130 if (state.from_pad != null) {
131 mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
132 mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
134 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
135 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
138 mRocketMarker.setPosition(new LatLng(state.gps.lat, state.gps.lon));
139 mRocketMarker.setVisible(true);
141 if (state.state == AltosLib.ao_flight_pad) {
142 mPadMarker.setPosition(new LatLng(state.pad_lat, state.pad_lon));
143 mPadMarker.setVisible(true);