altosdroid: implement tabs interface
authorMike Beattie <mike@ethernal.org>
Thu, 7 Mar 2013 08:33:27 +0000 (21:33 +1300)
committerMike Beattie <mike@ethernal.org>
Thu, 7 Mar 2013 08:33:27 +0000 (21:33 +1300)
Signed-off-by: Mike Beattie <mike@ethernal.org>
altosdroid/res/layout/altosdroid.xml
altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java

index dd277ffb69c13a6e173efb008267a2f08745fa80..ce812414232ad42d681478dd78c2a98fb219317e 100644 (file)
         with this program; if not, write to the Free Software Foundation, Inc.,
         59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 -->
-    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="fill_parent"
-        android:layout_height="wrap_content"
-        android:layout_weight="0" >
-
-        <RelativeLayout
-            android:id="@+id/strut"
-            android:layout_width="10dip"
-            android:layout_height="wrap_content"
-            android:layout_centerHorizontal="true" >
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/callsign_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_toLeftOf="@+id/strut" >
-
-            <TextView
-                android:id="@+id/callsign_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/callsign_label" />
-
-            <TextView
-                android:id="@+id/callsign_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@id/callsign_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/rssi_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_toRightOf="@id/strut"
-            android:layout_alignParentRight="true" >
-
-            <TextView
-                android:id="@+id/rssi_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/rssi_label" />
-
-            <TextView
-                android:id="@+id/rssi_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/rssi_label"
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/serial_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@+id/callsign_container"
-            android:layout_toLeftOf="@+id/strut" >
-
-            <TextView
-                android:id="@+id/serial_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/serial_label" />
-
-            <TextView
-                android:id="@+id/serial_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/serial_label"
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/flight_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@+id/callsign_container"
-            android:layout_toRightOf="@+id/strut"
-            android:layout_alignParentRight="true" >
-
-            <TextView
-                android:id="@+id/flight_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/flight_label" />
-
-            <TextView
-                android:id="@+id/flight_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/flight_label"
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/state_container"
-            android:layout_width="fill_parent"
-            android:layout_height="wrap_content"
-            android:layout_below="@+id/serial_container" >
-
-            <TextView
-                android:id="@+id/state_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/state_label" />
-
-            <TextView
-                android:id="@+id/state_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_below="@+id/state_label"
-                android:layout_centerInParent="true"
-                android:textAppearance="?android:attr/textAppearanceLarge"
-                android:textSize="50dip" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/speed_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_below="@+id/state_container"
-            android:layout_toLeftOf="@+id/strut" >
-
-            <TextView
-                android:id="@+id/speed_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/speed_label" />
-
-            <TextView
-                android:id="@+id/speed_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@id/speed_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/accel_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentRight="true"
-            android:layout_below="@+id/state_container"
-            android:layout_toRightOf="@+id/strut" >
-
-            <TextView
-                android:id="@+id/accel_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/accel_label" />
-
-            <TextView
-                android:id="@+id/accel_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/accel_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/range_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_below="@+id/speed_container"
-            android:layout_toLeftOf="@+id/strut" >
-
-            <TextView
-                android:id="@+id/range_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/range_label" />
-
-            <TextView
-                android:id="@+id/range_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/range_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/height_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentRight="true"
-            android:layout_below="@id/speed_container"
-            android:layout_toRightOf="@id/strut" >
-
-            <TextView
-                android:id="@+id/height_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/height_label" />
-
-            <TextView
-                android:id="@+id/height_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/height_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/elevation_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
-            android:layout_below="@id/range_container"
-            android:layout_toLeftOf="@id/strut" >
-
-            <TextView
-                android:id="@+id/elevation_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/elevation_label" />
-
-            <TextView
-                android:id="@+id/elevation_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/elevation_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/bearing_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_alignParentRight="true"
-            android:layout_below="@+id/range_container"
-            android:layout_toRightOf="@+id/strut" >
-
-            <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>
-
-        <RelativeLayout
-            android:id="@+id/latitude_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@+id/elevation_container" >
-
-            <TextView
-                android:id="@+id/latitude_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/latitude_label" />
-
-            <TextView
-                android:id="@+id/latitude_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/latitude_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-        <RelativeLayout
-            android:id="@+id/longitude_container"
-            android:layout_width="wrap_content"
-            android:layout_height="wrap_content"
-            android:layout_below="@id/latitude_container" >
-
-            <TextView
-                android:id="@+id/longitude_label"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:text="@string/longitude_label" />
-
-            <TextView
-                android:id="@+id/longitude_value"
-                android:layout_width="wrap_content"
-                android:layout_height="wrap_content"
-                android:layout_alignParentRight="true"
-                android:layout_below="@+id/longitude_label"
-                android:text=""
-                android:textAppearance="?android:attr/textAppearanceLarge" />
-
-        </RelativeLayout>
-
-
-        <RelativeLayout
-            android:id="@+id/text_container"
-            android:layout_width="wrap_content"
-            android:layout_height="fill_parent"
-            android:layout_below="@id/longitude_container" >
-
-               <TextView
-                   android:id="@+id/text"
-                   android:layout_width="fill_parent"
-                   android:layout_height="fill_parent"
-                   android:layout_above="@+id/version"
-                   android:scrollbars="vertical"
-                   android:textSize="7dp"
-                   android:typeface="monospace" />
-        
-            <TextView
-                android:id="@+id/version"
-                android:layout_width="fill_parent"
-                android:layout_height="10dip"
-                android:layout_alignParentBottom="true"
-                android:gravity="bottom|right"
-                android:textSize="7dp"
-                android:typeface="monospace" />
-
-        </RelativeLayout>
-
-    </RelativeLayout>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+       android:layout_width="fill_parent"
+       android:layout_height="wrap_content"
+       android:layout_weight="0"
+       android:orientation="vertical" >
+
+       <LinearLayout
+               xmlns:android="http://schemas.android.com/apk/res/android"
+               android:layout_width="fill_parent"
+               android:layout_height="wrap_content"
+               android:layout_weight="0"
+               android:baselineAligned="true"
+               android:orientation="horizontal" >
+
+               <RelativeLayout
+                       android:id="@+id/callsign_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/callsign_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/callsign_label" />
+
+                       <TextView
+                               android:id="@+id/callsign_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/callsign_label"
+                               android:text=""
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+
+               <RelativeLayout
+                       android:id="@+id/serial_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/serial_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/serial_label" />
+
+                       <TextView
+                               android:id="@+id/serial_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/serial_label"
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+
+               <RelativeLayout
+                       android:id="@+id/flight_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/flight_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/flight_label" />
+
+                       <TextView
+                               android:id="@+id/flight_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/flight_label"
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+
+               <RelativeLayout
+                       android:id="@+id/state_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/state_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/state_label" />
+
+                       <TextView
+                               android:id="@+id/state_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/state_label"
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+
+               <RelativeLayout
+                       android:id="@+id/rssi_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/rssi_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/rssi_label" />
+
+                       <TextView
+                               android:id="@+id/rssi_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/rssi_label"
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+
+               <RelativeLayout
+                       android:id="@+id/age_container"
+                       android:layout_width="0dp"
+                       android:layout_height="wrap_content"
+                       android:layout_weight="1" >
+
+                       <TextView
+                               android:id="@+id/age_label"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:text="@string/age_label" />
+
+                       <TextView
+                               android:id="@+id/age_value"
+                               android:layout_width="wrap_content"
+                               android:layout_height="wrap_content"
+                               android:layout_below="@+id/age_label"
+                               android:textAppearance="?android:attr/textAppearanceLarge" />
+               </RelativeLayout>
+       </LinearLayout>
+
+       <TabHost
+               xmlns:android="http://schemas.android.com/apk/res/android"
+               android:id="@android:id/tabhost"
+               android:layout_width="fill_parent"
+               android:layout_height="0dp"
+               android:layout_weight="1" >
+
+               <LinearLayout
+                       android:layout_width="match_parent"
+                       android:layout_height="match_parent"
+                       android:orientation="vertical" >
+
+                       <TabWidget
+                               android:id="@android:id/tabs"
+                               android:layout_width="match_parent"
+                               android:layout_height="wrap_content"
+                               android:layout_weight="0"
+                               android:orientation="horizontal" />
+
+                       <FrameLayout
+                               android:id="@android:id/tabcontent"
+                               android:layout_width="0dp"
+                               android:layout_height="0dp"
+                               android:layout_weight="0" />
+
+                       <android.support.v4.view.ViewPager
+                               android:id="@+id/pager"
+                               android:layout_width="match_parent"
+                               android:layout_height="0dp"
+                               android:layout_weight="1" />
+               </LinearLayout>
+       </TabHost>
+
+       <TextView
+               android:id="@+id/version"
+               android:layout_width="fill_parent"
+               android:layout_height="10dip"
+               android:layout_weight="0"
+               android:gravity="bottom|right"
+               android:textSize="7sp"
+               android:typeface="monospace" />
+
+</LinearLayout>
index 625a2eee430d7f278a023264d47dbd8112911f3a..2777a4d4d2780afd2a3762f23d8e02def7136ead 100644 (file)
@@ -33,18 +33,21 @@ import android.os.Handler;
 import android.os.Message;
 import android.os.Messenger;
 import android.os.RemoteException;
+import android.support.v4.app.FragmentActivity;
+import android.support.v4.view.ViewPager;
 import android.util.Log;
 import android.view.Menu;
 import android.view.MenuInflater;
 import android.view.MenuItem;
 import android.view.Window;
+import android.widget.TabHost;
 import android.widget.TextView;
 import android.widget.Toast;
 import android.app.AlertDialog;
 
 import org.altusmetrum.altoslib_1.*;
 
-public class AltosDroid extends Activity {
+public class AltosDroid extends FragmentActivity {
        // Debugging
        private static final String TAG = "AltosDroid";
        private static final boolean D = true;
@@ -66,18 +69,16 @@ public class AltosDroid extends Activity {
        private TextView mSerialView;
        private TextView mFlightView;
        private TextView mStateView;
-       private TextView mSpeedView;
-       private TextView mAccelView;
-       private TextView mRangeView;
-       private TextView mHeightView;
-       private TextView mElevationView;
-       private TextView mBearingView;
-       private TextView mLatitudeView;
-       private TextView mLongitudeView;
+       private TextView mAgeView;
 
        // field to display the version at the bottom of the screen
        private TextView mVersion;
 
+       // Tabs
+       TabHost     mTabHost;
+       ViewPager   mViewPager;
+       TabsAdapter mTabsAdapter;
+
        // Service
        private boolean mIsBound   = false;
        private Messenger mService = null;
@@ -181,19 +182,10 @@ public class AltosDroid extends Activity {
 
        void update_ui(AltosState state) {
                mCallsignView.setText(state.data.callsign);
-               mRSSIView.setText(String.format("%d", state.data.rssi));
                mSerialView.setText(String.format("%d", state.data.serial));
                mFlightView.setText(String.format("%d", state.data.flight));
                mStateView.setText(state.data.state());
-               mSpeedView.setText(String.format("%6.0f m/s", state.speed()));
-               mAccelView.setText(String.format("%6.0f m/s²", state.acceleration));
-               mRangeView.setText(String.format("%6.0f m", state.range));
-               mHeightView.setText(String.format("%6.0f m", state.height));
-               mElevationView.setText(String.format("%3.0f°", state.elevation));
-               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"));
+               mRSSIView.setText(String.format("%d", state.data.rssi));
 
                mAltosVoice.tell(state);
        }
@@ -233,6 +225,21 @@ public class AltosDroid extends Activity {
                setContentView(R.layout.altosdroid);
                getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
 
+               mTabHost = (TabHost)findViewById(android.R.id.tabhost);
+               mTabHost.setup();
+
+               mViewPager = (ViewPager)findViewById(R.id.pager);
+               mViewPager.setOffscreenPageLimit(4);
+
+               mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);
+
+               mTabsAdapter.addTab(mTabHost.newTabSpec("pad").setIndicator("Pad"), TabPad.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec("ascent").setIndicator("Ascent"), TabAscent.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec("descent").setIndicator("Descent"), TabDescent.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec("landed").setIndicator("Landed"), TabLanded.class, null);
+               mTabsAdapter.addTab(mTabHost.newTabSpec("map").setIndicator("Map"), TabMap.class, null);
+
+
                // Set up the custom title
                mTitle = (TextView) findViewById(R.id.title_left_text);
                mTitle.setText(R.string.app_name);
@@ -249,14 +256,7 @@ public class AltosDroid extends Activity {
                mSerialView    = (TextView) findViewById(R.id.serial_value);
                mFlightView    = (TextView) findViewById(R.id.flight_value);
                mStateView     = (TextView) findViewById(R.id.state_value);
-               mSpeedView     = (TextView) findViewById(R.id.speed_value);
-               mAccelView     = (TextView) findViewById(R.id.accel_value);
-               mRangeView     = (TextView) findViewById(R.id.range_value);
-               mHeightView    = (TextView) findViewById(R.id.height_value);
-               mElevationView = (TextView) findViewById(R.id.elevation_value);
-               mBearingView   = (TextView) findViewById(R.id.bearing_value);
-               mLatitudeView  = (TextView) findViewById(R.id.latitude_value);
-               mLongitudeView = (TextView) findViewById(R.id.longitude_value);
+               mAgeView       = (TextView) findViewById(R.id.age_value);
 
                mAltosVoice = new AltosVoice(this);
        }