]> git.gag.com Git - debian/openrocket/commitdiff
Change OpenRocketViewer to tab layout with three tabs: overview, components, and...
authorkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 8 Jan 2012 00:53:35 +0000 (00:53 +0000)
committerkruland2607 <kruland2607@180e2498-e6e9-4542-8430-84ac67f01cd8>
Sun, 8 Jan 2012 00:53:35 +0000 (00:53 +0000)
Added length and mass preferences and wired into the application object initialization of the OpenRocket UnitGroup statics.

There is currently an issue in the Simulation list in that the motors are not being displayed.  This is because currently the motor dao is not wired into the application.

git-svn-id: https://openrocket.svn.sourceforge.net/svnroot/openrocket/trunk@278 180e2498-e6e9-4542-8430-84ac67f01cd8

android/res/layout/openrocketviewer.xml
android/res/values/strings.xml
android/res/xml/preferences.xml
src/net/sf/openrocket/android/Application.java
src/net/sf/openrocket/android/PreferencesActivity.java
src/net/sf/openrocket/android/rocket/OpenRocketViewer.java

index 12634b90b8e62ddc8c373860c7bed7ff6039efb2..6b6a8a2cd30209f30079ea0a97dadab6ec1767a7 100644 (file)
 <?xml version="1.0" encoding="utf-8"?>\r
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
-    android:layout_width="fill_parent"\r
-    android:layout_height="fill_parent"\r
+    android:layout_width="match_parent"\r
+    android:layout_height="match_parent"\r
     android:orientation="vertical" >\r
 \r
-    <TextView\r
-        android:id="@+id/heading"\r
-        android:layout_width="fill_parent"\r
-        android:layout_height="wrap_content"\r
-        android:text="" />\r
-\r
-    <ListView\r
-        android:id="@+id/rocketSimulations"\r
+    <TabHost\r
+        android:id="@+id/openrocketviewerTabHost"\r
         android:layout_width="match_parent"\r
-        android:layout_height="wrap_content" />\r
+        android:layout_height="match_parent"\r
+        android:background="@android:color/black" >\r
+\r
+        <LinearLayout\r
+            android:layout_width="match_parent"\r
+            android:layout_height="match_parent"\r
+            android:orientation="vertical" >\r
+\r
+            <TabWidget\r
+                android:id="@android:id/tabs"\r
+                android:layout_width="match_parent"\r
+                android:layout_height="wrap_content" />\r
+\r
+            <FrameLayout\r
+                android:id="@android:id/tabcontent"\r
+                android:layout_width="match_parent"\r
+                android:layout_height="match_parent" >\r
+\r
+                <LinearLayout\r
+                    android:id="@+id/openrocketviewerOverview"\r
+                    android:layout_width="match_parent"\r
+                    android:layout_height="wrap_content"\r
+                    android:orientation="vertical" >\r
+\r
+                    <TextView\r
+                        android:text='Rocket Name'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerRocketName"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='Designer'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerDesigner"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='CG'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerCG"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='Length'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerLength"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='Mass'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerMass"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='Stage Count'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerStageCount"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    <TextView\r
+                        android:text='Comment'\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="match_parent"\r
+                        />\r
+                    <TextView\r
+                        android:id="@+id/openrocketviewerComment"\r
+                        android:layout_width="match_parent"\r
+                        android:layout_height="wrap_content"\r
+                        android:text="" />\r
+                    </LinearLayout>\r
+\r
+                <ListView\r
+                    android:id="@+id/openrocketviewerComponentList"\r
+                    android:layout_width="match_parent"\r
+                    android:layout_height="wrap_content" />\r
+\r
+                <ListView\r
+                    android:id="@+id/openrocketviewerSimulationList"\r
+                    android:layout_width="match_parent"\r
+                    android:layout_height="wrap_content" />\r
+            </FrameLayout>\r
+        </LinearLayout>\r
+    </TabHost>\r
 \r
 </LinearLayout>
\ No newline at end of file
index 5ff1044950308f12d26b32dd667ad1c2b5047235..d79944fdb14b63d9fb3b4490d7facc3d7a4a6e5a 100644 (file)
     <string name="TCMotorSearchFormSubmit">Submit</string>\r
     <string name="tcdownload">Download from ThrustCurve</string>
     <string name="simulationSeries1Label">Series 1</string>
-    <string name="simulationSeries2Label">Series 2</string>\r
-\r
+    <string name="simulationSeries2Label">Series 2</string>
+    <string name="PreferenceUnitLengthOption">PreferenceUnitLengthOption</string>
+    <string-array name="PreferenceUnitLengthEntries">\r
+        <item >Millimeters</item>\r
+        <item >Centimeters</item>
+        <item >Meters</item>\r
+        <item >Inches</item>
+        <item >Feet</item>
+    </string-array>
+    <string-array name="PreferenceUnitLengthValues">\r
+        <item >mm</item>\r
+        <item >cm</item>
+        <item >m</item>\r
+        <item >in</item>
+        <item >ft</item>
+    </string-array>\r
+    <string name="PreferenceUnitMassOption">PreferenceUnitMassOption</string>\r
+    <string-array name="PreferenceUnitMassEntries">\r
+        <item >Grams</item>\r
+        <item >Kilograms</item>\r
+        <item >Ounces</item>\r
+        <item >Pounds</item>\r
+    </string-array>\r
+    <string-array name="PreferenceUnitMassValues">\r
+        <item >g</item>\r
+        <item >kg</item>\r
+        <item >oz</item>\r
+        <item >lb</item>\r
+    </string-array>\r
+        \r
 </resources>
\ No newline at end of file
index 05fc59c83fcac069606a068a3607c7afde8a3af6..1a37a8df090c8fff8533148a256766250ab71817 100644 (file)
         android:summary="Set the grouping in Motor Browser"
         android:title="Motor Browser Group" />
 
+    <ListPreference
+        android:defaultValue="cm"
+        android:entries="@array/PreferenceUnitLengthEntries"
+        android:entryValues="@array/PreferenceUnitLengthValues"
+        android:key="@string/PreferenceUnitLengthOption"
+        android:summary="Set the length unit"
+        android:title="Unit of Length"
+        />
+    <ListPreference
+        android:defaultValue="g"
+        android:entries="@array/PreferenceUnitMassEntries"
+        android:entryValues="@array/PreferenceUnitMassValues"
+        android:key="@string/PreferenceUnitMassOption"
+        android:summary="Set the mass unit"
+        android:title="Unit of Mass"
+        />
 </PreferenceScreen>
\ No newline at end of file
index 61b368c74bfd7aebdff385fdc86aaa5dd8ddc6ee..6628e5fbc103f31ab92a25b1336c6379eacd8d1c 100644 (file)
@@ -2,6 +2,8 @@ package net.sf.openrocket.android;
 \r
 import java.util.Locale;\r
 \r
+import android.preference.PreferenceManager;\r
+\r
 import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;\r
 import net.sf.openrocket.document.OpenRocketDocument;\r
 import net.sf.openrocket.l10n.DebugTranslator;\r
@@ -54,6 +56,15 @@ public class Application extends android.app.Application {
                initialize();\r
        }\r
 \r
+       /* (non-Javadoc)\r
+        * @see android.app.Application#onCreate()\r
+        */\r
+       @Override\r
+       public void onCreate() {\r
+               super.onCreate();\r
+               PreferencesActivity.initializePreferences(this, PreferenceManager.getDefaultSharedPreferences(this));\r
+       }\r
+\r
        /**\r
         * @return the rocketDocument\r
         */\r
index 4ce05878f7e4abc32bb6e19e9917dfcb067b043a..66f4d7788b01e5606b179f3b14a982a9d30d92f2 100644 (file)
@@ -1,14 +1,48 @@
 package net.sf.openrocket.android;\r
 \r
 import net.sf.openrocket.R;\r
+import net.sf.openrocket.unit.UnitGroup;\r
+import android.content.SharedPreferences;\r
 import android.os.Bundle;\r
+import android.preference.PreferenceManager;\r
 \r
-public class PreferencesActivity extends android.preference.PreferenceActivity {\r
+public class PreferencesActivity extends android.preference.PreferenceActivity \r
+implements SharedPreferences.OnSharedPreferenceChangeListener {\r
 \r
        @Override\r
        protected void onCreate( Bundle savedInstanceState ) {\r
                super.onCreate( savedInstanceState );\r
                addPreferencesFromResource(R.xml.preferences);\r
+               SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
+               prefs.registerOnSharedPreferenceChangeListener(this);\r
+       }\r
+\r
+       /* (non-Javadoc)\r
+        * @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)\r
+        */\r
+       @Override\r
+       public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {\r
+\r
+               initializePreferences(getApplication(), PreferenceManager.getDefaultSharedPreferences(this));\r
+       }\r
+\r
+       /**\r
+        * This method is to be called from Application setup to pull the saved preference\r
+        * values into the various datastructures used in OpenRocket.\r
+        * This method is located in this class because it is probably best to have as much\r
+        * of the code in the same place as possible.\r
+        * @param sharedPreferences\r
+        */\r
+       public static void initializePreferences( android.app.Application app, SharedPreferences sharedPreferences ) {\r
+               \r
+               String unitLength = app.getResources().getString(R.string.PreferenceUnitLengthOption);\r
+               String len = sharedPreferences.getString(unitLength, "cm");\r
+               UnitGroup.UNITS_LENGTH.setDefaultUnit( len );\r
+               \r
+               String unitMass = app.getResources().getString(R.string.PreferenceUnitMassOption);\r
+               String mass = sharedPreferences.getString(unitMass, "g");\r
+               UnitGroup.UNITS_MASS.setDefaultUnit( mass );\r
+               \r
        }\r
        \r
 }\r
index aa00834557c5cdd81310fe4f93f7d3f1cb70d322..1037d1b8940f6ed6b7385e4d02ac6aa5e928481a 100644 (file)
@@ -10,11 +10,19 @@ import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;
 import net.sf.openrocket.android.simulation.SimulationViewer;\r
 import net.sf.openrocket.document.OpenRocketDocument;\r
 import net.sf.openrocket.document.Simulation;\r
+import net.sf.openrocket.rocketcomponent.Rocket;\r
+import net.sf.openrocket.rocketcomponent.RocketComponent;\r
+import net.sf.openrocket.rocketcomponent.RocketUtils;\r
+import net.sf.openrocket.unit.Unit;\r
+import net.sf.openrocket.unit.UnitGroup;\r
+import net.sf.openrocket.util.Coordinate;\r
 import android.app.Activity;\r
 import android.app.ProgressDialog;\r
 import android.content.Intent;\r
+import android.content.SharedPreferences;\r
 import android.net.Uri;\r
 import android.os.Bundle;\r
+import android.preference.PreferenceManager;\r
 import android.util.Log;\r
 import android.view.LayoutInflater;\r
 import android.view.Menu;\r
@@ -26,15 +34,18 @@ import android.widget.AdapterView;
 import android.widget.AdapterView.OnItemClickListener;\r
 import android.widget.ArrayAdapter;\r
 import android.widget.ListView;\r
+import android.widget.TabHost;\r
 import android.widget.TextView;\r
 \r
-public class OpenRocketViewer extends Activity {\r
+public class OpenRocketViewer extends Activity\r
+implements SharedPreferences.OnSharedPreferenceChangeListener\r
+{\r
 \r
        private static final String TAG = "OpenRocketViewer";\r
 \r
        private ProgressDialog progress;\r
 \r
-       private TextView header;\r
+       private ListView componentList;\r
        private ListView simulationList;\r
 \r
        private Application app;\r
@@ -54,8 +65,31 @@ public class OpenRocketViewer extends Activity {
 \r
                setContentView(R.layout.openrocketviewer);\r
 \r
-               header = (TextView) findViewById(R.id.heading);\r
-               simulationList = (ListView) findViewById(R.id.rocketSimulations);\r
+               SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
+               prefs.registerOnSharedPreferenceChangeListener(this);\r
+\r
+               TabHost tabs=(TabHost)findViewById(R.id.openrocketviewerTabHost);\r
+\r
+               tabs.setup();\r
+\r
+               TabHost.TabSpec spec=tabs.newTabSpec("tag1");\r
+\r
+               spec.setContent(R.id.openrocketviewerOverview);\r
+               spec.setIndicator("Overview");\r
+               tabs.addTab(spec);\r
+\r
+               spec=tabs.newTabSpec("tag2");\r
+               spec.setContent(R.id.openrocketviewerComponentList);\r
+               spec.setIndicator("Components");\r
+               tabs.addTab(spec);      \r
+\r
+               spec=tabs.newTabSpec("tag3");\r
+               spec.setContent(R.id.openrocketviewerSimulationList);\r
+               spec.setIndicator("Simulations");\r
+               tabs.addTab(spec);      \r
+\r
+               componentList = (ListView) findViewById(R.id.openrocketviewerComponentList);\r
+               simulationList = (ListView) findViewById(R.id.openrocketviewerSimulationList);\r
 \r
                Intent i = getIntent();\r
                Uri file = i.getData();\r
@@ -118,23 +152,48 @@ public class OpenRocketViewer extends Activity {
 \r
        }\r
 \r
-       private void updateContents() {\r
+       /* (non-Javadoc)\r
+        * @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)\r
+        */\r
+       @Override\r
+       public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {\r
+               // just in case the user changed the units, we redraw.\r
+               PreferencesActivity.initializePreferences(getApplication(), PreferenceManager.getDefaultSharedPreferences(this));\r
+               updateContents();\r
+       }\r
 \r
-               OpenRocketDocument rocket = app.getRocketDocument();\r
-               header.setText( rocket.getRocket().getName());\r
+       private void updateContents() {\r
 \r
-               ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_1,rocket.getSimulations()) {\r
+               OpenRocketDocument rocketDocument = app.getRocketDocument();\r
+               Rocket rocket = rocketDocument.getRocket();\r
+               \r
+               setTitle(rocket.getName());\r
+               \r
+               Unit LengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
+               Unit MassUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
+               \r
+               Coordinate cg = RocketUtils.getCG(rocket);\r
+               double length = RocketUtils.getLength(rocket);\r
+               ((TextView) findViewById(R.id.openrocketviewerRocketName)).setText( rocket.getName());\r
+               ((TextView)findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner());\r
+               ((TextView)findViewById(R.id.openrocketviewerCG)).setText(LengthUnit.toStringUnit(cg.x) );\r
+               ((TextView)findViewById(R.id.openrocketviewerLength)).setText(LengthUnit.toStringUnit(length));\r
+               ((TextView)findViewById(R.id.openrocketviewerMass)).setText(MassUnit.toStringUnit(cg.weight));\r
+               ((TextView)findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount()));\r
+               ((TextView)findViewById(R.id.openrocketviewerComment)).setText(rocket.getComment());\r
+\r
+               ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_2,rocketDocument.getSimulations()) {\r
 \r
                        @Override\r
-                       public View getView(int position, View convertView,\r
-                                       ViewGroup parent) {\r
+                       public View getView(int position, View convertView,     ViewGroup parent) {\r
                                View v = convertView;\r
                                if ( v == null ) {\r
                                        LayoutInflater li = getLayoutInflater();\r
-                                       v = li.inflate(android.R.layout.simple_list_item_1,null);\r
+                                       v = li.inflate(android.R.layout.simple_list_item_2,null);\r
                                }\r
                                Simulation sim = this.getItem(position);\r
                                ((TextView)v.findViewById(android.R.id.text1)).setText( sim.getName() );\r
+                               ((TextView)v.findViewById(android.R.id.text2)).setText( "motors: " + sim.getConfiguration().getMotorConfigurationDescription() + " apogee: " + sim.getSimulatedData().getMaxAltitude() + "m  time: " + sim.getSimulatedData().getFlightTime() + "s");\r
                                return v;\r
                        }\r
 \r
@@ -151,6 +210,27 @@ public class OpenRocketViewer extends Activity {
                });\r
                simulationList.setAdapter(sims);\r
 \r
+               ArrayAdapter<RocketComponent> comps = new ArrayAdapter<RocketComponent>(this, android.R.layout.simple_list_item_1,rocket.getChildren()) {\r
+\r
+                       /* (non-Javadoc)\r
+                        * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)\r
+                        */\r
+                       @Override\r
+                       public View getView(int position, View convertView, ViewGroup parent) {\r
+                               View v = convertView;\r
+                               if ( v == null ) {\r
+                                       LayoutInflater li = getLayoutInflater();\r
+                                       v = li.inflate(android.R.layout.simple_list_item_1,null);\r
+                               }\r
+                               RocketComponent comp = this.getItem(position);\r
+                               ((TextView)v.findViewById(android.R.id.text1)).setText( comp.getName() );\r
+                               return v;\r
+                       }\r
+                       \r
+                       \r
+               };\r
+               componentList.setAdapter(comps);\r
+               \r
                if ( progress.isShowing() ) {\r
                        progress.dismiss();\r
                }\r