altosdroid: programmatically create map fragment
authorMike Beattie <mike@ethernal.org>
Sun, 10 Mar 2013 07:40:13 +0000 (20:40 +1300)
committerMike Beattie <mike@ethernal.org>
Sun, 10 Mar 2013 07:40:13 +0000 (20:40 +1300)
* 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>
altosdroid/res/layout/tab_map.xml
altosdroid/src/org/altusmetrum/AltosDroid/TabMap.java

index 4737fae09980d834e628abf3ebf30a4580a2c473..b9f4e69e7267d3d48dea9fca2d307ac0bf77cddc 100644 (file)
      with this program; if not, write to the Free Software Foundation, Inc.,
      59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 -->
      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"
        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
index b30b4694d069e04e8d81112dbfa3e477fe59458c..7161a3409eacdaec47498eef5ac6ad00b80a5c9d 100644 (file)
 
 package org.altusmetrum.AltosDroid;
 
 
 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.GoogleMap;
+import com.google.android.gms.maps.SupportMapFragment;
+import com.google.android.gms.maps.model.LatLng;
 
 import android.app.Activity;
 import android.os.Bundle;
 
 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.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
+import android.widget.TextView;
 
 public class TabMap extends Fragment implements AltosDroidTab {
        AltosDroid mAltosDroid;
 
 
 public class TabMap extends Fragment implements AltosDroidTab {
        AltosDroid mAltosDroid;
 
+       private SupportMapFragment mMapFragment;
        private GoogleMap mMap;
        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) {
 
        @Override
        public void onAttach(Activity activity) {
@@ -42,12 +53,36 @@ public class TabMap extends Fragment implements AltosDroidTab {
                mAltosDroid.registerTab(this);
        }
 
                mAltosDroid.registerTab(this);
        }
 
+       @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);
        @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;
        }
 
                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();
        @Override
        public void onDestroyView() {
                super.onDestroyView();
@@ -61,12 +96,28 @@ public class TabMap extends Fragment implements AltosDroidTab {
                //ft.commit();
        }
 
                //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) {
        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) {
+               }
        }
 
 }
        }
 
 }