From 2a81d637308e680b99d7218ba9e03c9ade6626f1 Mon Sep 17 00:00:00 2001 From: Mike Beattie Date: Thu, 7 Mar 2013 21:33:27 +1300 Subject: [PATCH] altosdroid: implement tabs interface Signed-off-by: Mike Beattie --- altosdroid/res/layout/altosdroid.xml | 528 ++++++------------ .../altusmetrum/AltosDroid/AltosDroid.java | 54 +- 2 files changed, 206 insertions(+), 376 deletions(-) diff --git a/altosdroid/res/layout/altosdroid.xml b/altosdroid/res/layout/altosdroid.xml index dd277ffb..ce812414 100644 --- a/altosdroid/res/layout/altosdroid.xml +++ b/altosdroid/res/layout/altosdroid.xml @@ -15,352 +15,182 @@ with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. --> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java index 625a2eee..2777a4d4 100644 --- a/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java +++ b/altosdroid/src/org/altusmetrum/AltosDroid/AltosDroid.java @@ -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); } -- 2.30.2