summaryrefslogtreecommitdiff
path: root/altosdroid/src
diff options
context:
space:
mode:
authorMike Beattie <mike@ethernal.org>2013-03-10 20:40:13 +1300
committerMike Beattie <mike@ethernal.org>2013-03-10 20:40:13 +1300
commitb7c82b867b12ca016164725f3736bc5b55048999 (patch)
treea7c011bbf136cd276ed77b2b3c5899af34fa72bd /altosdroid/src
parent8adadf6bd2ba623642675e4beafac4ac98b1916d (diff)
altosdroid: programmatically create map fragment
* Allows reliable fetching of a GoogleMap handle. * Set map options, initial location (NCR North for now, temporarily) * Add some info fields below map, and update them accordingly Signed-off-by: Mike Beattie <mike@ethernal.org>
Diffstat (limited to 'altosdroid/src')
-rw-r--r--altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java63
1 files changed, 57 insertions, 6 deletions
diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java
index b30b4694..7161a340 100644
--- a/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java
+++ b/altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java
@@ -17,9 +17,13 @@
package org.altusmetrum.AltosDroid;
-import org.altusmetrum.altoslib_1.AltosState;
+import org.altusmetrum.altoslib_1.*;
+
+import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
+import com.google.android.gms.maps.SupportMapFragment;
+import com.google.android.gms.maps.model.LatLng;
import android.app.Activity;
import android.os.Bundle;
@@ -28,12 +32,19 @@ import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.TextView;
public class TabMap extends Fragment implements AltosDroidTab {
AltosDroid mAltosDroid;
+ private SupportMapFragment mMapFragment;
private GoogleMap mMap;
+ private boolean mapLoaded = false;
+ private TextView mDistanceView;
+ private TextView mBearingView;
+ private TextView mLatitudeView;
+ private TextView mLongitudeView;
@Override
public void onAttach(Activity activity) {
@@ -43,12 +54,36 @@ public class TabMap extends Fragment implements AltosDroidTab {
}
@Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ mMapFragment = new SupportMapFragment() {
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ setupMap();
+ }
+ };
+
+ }
+
+ @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_map, container, false);
+ mDistanceView = (TextView)v.findViewById(R.id.distance_value);
+ mBearingView = (TextView)v.findViewById(R.id.bearing_value);
+ mLatitudeView = (TextView)v.findViewById(R.id.lat_value);
+ mLongitudeView = (TextView)v.findViewById(R.id.lon_value);
return v;
}
@Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+ getChildFragmentManager().beginTransaction().add(R.id.map, mMapFragment).commit();
+ }
+
+ @Override
public void onDestroyView() {
super.onDestroyView();
@@ -61,12 +96,28 @@ public class TabMap extends Fragment implements AltosDroidTab {
//ft.commit();
}
+ private void setupMap() {
+ mMap = mMapFragment.getMap();
+ if (mMap != null) {
+ mMap.setMyLocationEnabled(true);
+ mMap.getUiSettings().setTiltGesturesEnabled(false);
+ mMap.getUiSettings().setZoomControlsEnabled(false);
+ mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(40.8,-104.7),8));
+
+ mapLoaded = true;
+ }
+ }
+
public void update_ui(AltosState state) {
-// mRangeView.setText(String.format("%6.0f m", state.range));
-// if (state.from_pad != null)
-// mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
-// mLatitudeView.setText(pos(state.gps.lat, "N", "S"));
-// mLongitudeView.setText(pos(state.gps.lon, "W", "E"));
+ if (state.from_pad != null) {
+ mDistanceView.setText(String.format("%6.0f m", state.from_pad.distance));
+ mBearingView.setText(String.format("%3.0f°", state.from_pad.bearing));
+ }
+ mLatitudeView.setText(AltosDroid.pos(state.gps.lat, "N", "S"));
+ mLongitudeView.setText(AltosDroid.pos(state.gps.lon, "W", "E"));
+
+ if (mapLoaded) {
+ }
}
}