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.LatLng;
28 import android.app.Activity;
29 import android.os.Bundle;
30 import android.support.v4.app.Fragment;
31 import android.support.v4.app.FragmentTransaction;
32 import android.view.LayoutInflater;
33 import android.view.View;
34 import android.view.ViewGroup;
35 import android.widget.TextView;
37 public class TabMap extends Fragment implements AltosDroidTab {
38 AltosDroid mAltosDroid;
40 private SupportMapFragment mMapFragment;
41 private GoogleMap mMap;
42 private boolean mapLoaded = false;
44 private TextView mDistanceView;
45 private TextView mBearingView;
46 private TextView mLatitudeView;
47 private TextView mLongitudeView;
50 public void onAttach(Activity activity) {
51 super.onAttach(activity);
52 mAltosDroid = (AltosDroid) activity;
53 mAltosDroid.registerTab(this);
57 public void onCreate(Bundle savedInstanceState) {
58 super.onCreate(savedInstanceState);
60 mMapFragment = new SupportMapFragment() {
62 public void onActivityCreated(Bundle savedInstanceState) {
63 super.onActivityCreated(savedInstanceState);
71 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
72 View v = inflater.inflate(R.layout.tab_map, container, false);
73 mDistanceView = (TextView)v.findViewById(R.id.distance_value);
74 mBearingView = (TextView)v.findViewById(R.id.bearing_value);
75 mLatitudeView = (TextView)v.findViewById(R.id.lat_value);
76 mLongitudeView = (TextView)v.findViewById(R.id.lon_value);
81 public void onActivityCreated(Bundle savedInstanceState) {
82 super.onActivityCreated(savedInstanceState);
83 getChildFragmentManager().beginTransaction().add(R.id.map, mMapFragment).commit();
87 public void onDestroyView() {
88 super.onDestroyView();
90 mAltosDroid.unregisterTab(this);
93 //Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
94 //FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
95 //ft.remove(fragment);
99 private void setupMap() {
100 mMap = mMapFragment.getMap();
102 mMap.setMyLocationEnabled(true);
103 mMap.getUiSettings().setTiltGesturesEnabled(false);
104 mMap.getUiSettings().setZoomControlsEnabled(false);
105 mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8));
111 public void update_ui(AltosState state) {
112 if (state.from_pad != null) {
113 mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
114 mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
116 mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
117 mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));