<?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
<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
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
\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
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
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
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
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
\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
\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
});\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