diff options
author | Mike Beattie <mike@ethernal.org> | 2013-03-10 20:40:13 +1300 |
---|---|---|
committer | Mike Beattie <mike@ethernal.org> | 2013-03-10 20:40:13 +1300 |
commit | b7c82b867b12ca016164725f3736bc5b55048999 (patch) | |
tree | a7c011bbf136cd276ed77b2b3c5899af34fa72bd | |
parent | 8adadf6bd2ba623642675e4beafac4ac98b1916d (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>
-rw-r--r-- | altosdroid/res/layout/tab_map.xml | 120 | ||||
-rw-r--r-- | altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java | 63 |
2 files changed, 174 insertions, 9 deletions
diff --git a/altosdroid/res/layout/tab_map.xml b/altosdroid/res/layout/tab_map.xml index 4737fae0..b9f4e69e 100644 --- a/altosdroid/res/layout/tab_map.xml +++ b/altosdroid/res/layout/tab_map.xml @@ -15,8 +15,122 @@ with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. --> -<fragment xmlns:android="http://schemas.android.com/apk/res/android" - android:id="@+id/map" +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - class="com.google.android.gms.maps.SupportMapFragment"/> + android:orientation="vertical" > + + <LinearLayout + android:id="@+id/map" + android:orientation="horizontal" + android:layout_width="fill_parent" + android:layout_height="0dp" + android:layout_weight="1"> + + </LinearLayout> + + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:baselineAligned="true" + android:orientation="horizontal" > + + <RelativeLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:paddingTop="5dp" > + + <TextView + android:id="@+id/distance_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/distance_label" /> + + <TextView + android:id="@+id/distance_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_below="@+id/distance_label" + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> + </RelativeLayout> + + <RelativeLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:paddingTop="5dp" > + + <TextView + android:id="@+id/bearing_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/bearing_label" /> + + <TextView + android:id="@+id/bearing_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_below="@+id/bearing_label" + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> + </RelativeLayout> + + </LinearLayout> + + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:baselineAligned="true" + android:orientation="horizontal" > + + <RelativeLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:paddingTop="5dp" > + + <TextView + android:id="@+id/lat_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/latitude_label" /> + + <TextView + android:id="@+id/lat_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_below="@id/lat_label" + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> + </RelativeLayout> + + <RelativeLayout + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_weight="1" + android:paddingTop="5dp" > + + <TextView + android:id="@+id/lon_label" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@string/longitude_label" /> + + <TextView + android:id="@+id/lon_value" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_alignParentRight="true" + android:layout_below="@id/lon_label" + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> + </RelativeLayout> + </LinearLayout> +</LinearLayout>
\ No newline at end of file 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) { + } } } |