</intent-filter>\r
</activity>\r
<activity\r
- android:name=".android.rocket.OpenRocketViewer"\r
+ android:name=".android.rocket.OpenRocketLoader"\r
android:label="@string/app_name" >\r
\r
<!--\r
Combining the <data> elements into a single field did not result in a working \r
application. The first intent-filter (with mimeType wildcard) convinces the \r
file browser to associate the correct launcher icon. the second intent-filter \r
- is actually invoked when a file is selected.\r\r\r
+ is actually invoked when a file is selected.\r\r\r\r
-->\r
<!-- this intent filter convinces the file browser to display icons -->\r
<intent-filter>\r
android:scheme="file" />\r
</intent-filter>\r
</activity>\r
+ <activity\r
+ android:name=".android.rocket.OpenRocketViewer"\r
+ android:label="@string/app_name" />\r
<activity android:name=".android.PreferencesActivity" >\r
<intent-filter>\r
<action android:name="net.sf.openrocket.android.PreferencesActivity" />\r
<category android:name="android.intent.category.PREFERENCE" />\r
</intent-filter>\r
</activity>\r
- <activity\r
- android:name=".android.motor.MotorHierarchicalBrowser"\r
- android:label="@string/MotorListTitle" />\r
+ <activity android:name=".android.motor.MotorHierarchicalBrowser" />\r
<activity android:name=".android.motor.MotorDetails" />\r
- <activity\r
- android:name=".android.thrustcurve.TCQueryActivity"\r
- android:label="@string/MotorListTitle" />\r
+ <activity android:name=".android.thrustcurve.TCQueryActivity" />\r
<activity android:name=".android.simulation.SimulationViewer" />\r
<activity android:name=".android.simulation.GraphicalActivity" />\r
<activity android:name=".android.filebrowser.SimpleFileBrowser" />\r
- </application>\r
+ </application>\r
\r
</manifest>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>\r
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+<TabHost\r
+ xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:id="@android:id/tabhost"\r
android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:orientation="vertical" >\r
+ android:layout_height="match_parent">\r
\r
- <TabHost\r
- android:id="@+id/openrocketviewerTabHost"\r
+ <LinearLayout\r
+ android:orientation="vertical"\r
android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:background="@android:color/black" >\r
+ android:layout_height="match_parent">\r
\r
- <LinearLayout\r
+ <TabWidget\r
+ android:id="@android:id/tabs"\r
+ android:orientation="horizontal"\r
android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:orientation="vertical" >\r
+ android:layout_height="wrap_content"\r
+ android:layout_weight="0"/>\r
\r
- <TabWidget\r
- android:id="@android:id/tabs"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content" />\r
+ <FrameLayout\r
+ android:id="@android:id/tabcontent"\r
+ android:layout_width="0dp"\r
+ android:layout_height="0dp"\r
+ android:layout_weight="0"/>\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:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Designer" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerDesigner"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Length" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerLength"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Empty Mass" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerMass"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Stage Count" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerStageCount"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <Spinner android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:id="@+id/openrocketviewerConfigurationSpinner" \r
- />\r
- \r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Lift off weight" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerLiftOffWeight"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="CG" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerCG"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="CP" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerCP"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- <TextView\r
- android:layout_width="match_parent"\r
- android:layout_height="match_parent"\r
- android:text="Stability margin" />\r
-\r
- <TextView\r
- android:id="@+id/openrocketviewerStabilityMargin"\r
- android:layout_width="match_parent"\r
- android:layout_height="wrap_content"\r
- android:text="" />\r
-\r
- </LinearLayout>\r
-\r
- <pl.polidea.treeview.TreeViewList\r
- android:id="@+id/openrocketviewerComponentTree"\r
- android:layout_width="fill_parent"\r
- android:layout_height="fill_parent"\r
- android:scrollbars="vertical"\r
- android:smoothScrollbar="true" />\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
+ <android.support.v4.view.ViewPager\r
+ android:id="@+id/pager"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="0dp"\r
+ android:layout_weight="1"/>\r
\r
-</LinearLayout>
\ No newline at end of file
+ </LinearLayout>\r
+</TabHost>\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<pl.polidea.treeview.TreeViewList xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:id="@+id/openrocketviewerComponentTree"\r
+ android:layout_width="fill_parent"\r
+ android:layout_height="fill_parent"\r
+ android:scrollbars="vertical"\r
+ android:smoothScrollbar="true" />\r
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"\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:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Designer" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerDesigner"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Length" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerLength"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Empty Mass" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerMass"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Stage Count" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerStageCount"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <Spinner\r
+ android:id="@+id/openrocketviewerConfigurationSpinner"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Lift off weight" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerLiftOffWeight"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="CG" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerCG"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="CP" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerCP"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+\r
+ <TextView\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="Stability margin" />\r
+\r
+ <TextView\r
+ android:id="@+id/openrocketviewerStabilityMargin"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content"\r
+ android:text="" />\r
+ </LinearLayout>\r
+\r
+</ScrollView>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="match_parent"\r
+ android:orientation="vertical" >\r
+\r
+ <ListView\r
+ android:id="@+id/openrocketviewerSimulationList"\r
+ android:layout_width="match_parent"\r
+ android:layout_height="wrap_content" />\r
+\r
+</LinearLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >\r
+\r
+ <item\r
+ android:id="@+id/main_menu_open"\r
+ android:title="Open"/>\r
+ <item\r
+ android:id="@+id/main_menu_motor"\r
+ android:title="Motor"/>\r
+ <item\r
+ android:id="@+id/main_menu_preferences"\r
+ android:title="@string/Preferences"\r
+ android:icon="@drawable/ic_menu_preferences"/>\r
+\r
+</menu>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>\r
<menu xmlns:android="http://schemas.android.com/apk/res/android" >\r
-
- <item android:title="Motor List" android:id="@+id/motor_list_menu_option"/>\r
- <item android:title="Preferences" android:id="@+id/preference_menu_option"/>\r
- \r
+\r
+ <item\r
+ android:id="@+id/motor_list_menu_option"\r
+ android:title="Motor List"/>\r
+ <item\r
+ android:id="@+id/preference_menu_option"\r
+ android:title="@string/Preferences"\r
+ android:icon="@drawable/ic_menu_preferences"/>\r
\r
</menu>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>\r
+<resources>\r
+\r
+ <string name="PreferenceMotorBrowserGroupingOption">PreferenceMotorBrowserGroupingOption</string>\r
+\r
+ <string name="PreferenceUseInternalFileBrowserOption">PreferenceUseInternalFileBrowserOpion</string>\r
+ \r
+ <string-array name="PreferenceMotorBrowserGroupingValues">\r
+ <item>0</item>\r
+ <item>1</item>\r
+ <item>2</item>\r
+ <item>3</item>\r
+ </string-array>\r
+\r
+ <string name="PreferenceUnitLengthOption">PreferenceUnitLengthOption</string>\r
+\r
+ <string-array name="PreferenceUnitLengthValues">\r
+ <item>mm</item>\r
+ <item>cm</item>\r
+ <item>m</item>\r
+ <item>in</item>\r
+ <item>ft</item>\r
+ </string-array>\r
+\r
+ <string name="PreferenceUnitMassOption">PreferenceUnitMassOption</string>\r
+\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
+ <string name="PreferenceUnitVelocityOption">PreferenceUnitVelocityOption</string>\r
+\r
+ <string-array name="PreferenceUnitVelocityValues">\r
+ <item>m/s</item>\r
+ <item>km/h</item>\r
+ <item>ft/s</item>\r
+ <item>mph</item>\r
+ </string-array>\r
+\r
+ <string name="PreferenceUnitDistanceOption">PreferenceUnitDistanceOption</string>\r
+\r
+ <string-array name="PreferenceUnitDistanceValues">\r
+ <item>m</item>\r
+ <item>km</item>\r
+ <item>ft</item>\r
+ <item>yd</item>\r
+ <item>mi</item>\r
+ <item>nmi</item>\r
+ </string-array>\r
+\r
+</resources>
\ No newline at end of file
<string name="app_name">OpenRocket</string>\r
<string name="save">Save</string>\r
<string name="MotorListTitle">Motor List</string>\r
- <string name="PreferenceMotorBrowserGroupingOption">PreferenceMotorBrowserGroupingOption</string>\r
+ <string name="Preferences">Preferences</string>\r
\r
<string-array name="PreferenceMotorBrowserGroupingEntries">\r
<item>Case</item>\r
<item>Impulse</item>\r
<item>Manufacturer</item>\r
</string-array>\r
- <string-array name="PreferenceMotorBrowserGroupingValues">\r
- <item>0</item>\r
- <item>1</item>\r
- <item>2</item>\r
- <item>3</item>\r
- </string-array>\r
\r
<string name="TCMotorSearchFormImpulse">Impulse</string>\r
\r
<string name="tcdownload">Download from ThrustCurve</string>\r
<string name="simulationSeries1Label">Series 1</string>\r
<string name="simulationSeries2Label">Series 2</string>\r
- <string name="PreferenceUnitLengthOption">PreferenceUnitLengthOption</string>\r
\r
+ <string name="motorbrowsergrouptitle">Motor Browser Grouping</string>\r
+ <string name="useinternalfilebrowsertitle">Use Internal File Browser</string>\r
+ <string name="useinternalfilebrowsersummary">uncheck to use system file browser if available</string>\r
+ \r
<string-array name="PreferenceUnitLengthEntries">\r
<item>Millimeters</item>\r
<item>Centimeters</item>\r
<item>Inches</item>\r
<item>Feet</item>\r
</string-array>\r
- <string-array name="PreferenceUnitLengthValues">\r
- <item>mm</item>\r
- <item>cm</item>\r
- <item>m</item>\r
- <item>in</item>\r
- <item>ft</item>\r
- </string-array>\r
-\r
- <string name="PreferenceUnitMassOption">PreferenceUnitMassOption</string>\r
-\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
- <string name="PreferenceUnitVelocityOption">PreferenceUnitVelocityOption</string>\r
-\r
<string-array name="PreferenceUnitVelocityEntries">\r
<item>Meters/Second</item>\r
<item>Kilometers/Hour</item>\r
<item>Feet/Second</item>\r
<item>Miles/Hour</item>\r
</string-array>\r
- <string-array name="PreferenceUnitVelocityValues">\r
- <item>m/s</item>\r
- <item>km/h</item>\r
- <item>ft/s</item>\r
- <item>mph</item>\r
- </string-array>\r
-\r
- <string name="PreferenceUnitDistanceOption">PreferenceUnitDistanceOption</string>\r
-\r
<string-array name="PreferenceUnitDistanceEntries">\r
<item>Meters</item>\r
<item>Kilometers</item>\r
<item>Miles</item>\r
<item>Nautical Miles</item>\r
</string-array>\r
- <string-array name="PreferenceUnitDistanceValues">\r
- <item>m</item>\r
- <item>km</item>\r
- <item>ft</item>\r
- <item>yd</item>\r
- <item>mi</item>\r
- <item>nmi</item>\r
- </string-array>\r
\r
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
-
android:key="preferences"
android:title="Pref Title"
android:summary="pref summary"
-
-
<ListPreference
android:defaultValue="1"
android:entries="@array/PreferenceMotorBrowserGroupingEntries"
android:entryValues="@array/PreferenceMotorBrowserGroupingValues"
android:key="@string/PreferenceMotorBrowserGroupingOption"
android:summary="Set the grouping in Motor Browser"
- android:title="Motor Browser Group" />
+ android:title="@string/motorbrowsergrouptitle" />
- <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"
+ <CheckBoxPreference
+ android:defaultValue="false"
+ android:title="@string/useinternalfilebrowsertitle"
+ android:key="@string/PreferenceUseInternalFileBrowserOption"
+ android:summary="@string/useinternalfilebrowsersummary"
/>
- <ListPreference
- android:defaultValue="m/s"
- android:entries="@array/PreferenceUnitVelocityEntries"
- android:entryValues="@array/PreferenceUnitVelocityValues"
- android:key="@string/PreferenceUnitVelocityOption"
- android:summary="Set the velocity unit"
- android:title="Unit for Velocity"
- />
- <ListPreference
- android:defaultValue="m"
- android:entries="@array/PreferenceUnitDistanceEntries"
- android:entryValues="@array/PreferenceUnitDistanceValues"
- android:key="@string/PreferenceUnitDistanceOption"
- android:summary="Set the distance unit"
- android:title="Unit for Distance and Altitude"
- />
-
+
+ <PreferenceScreen
+ android:key="UnitPrefences"
+ android:summary="Configure units"
+ android:title="Units" >
+ <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" />
+ <ListPreference
+ android:defaultValue="m/s"
+ android:entries="@array/PreferenceUnitVelocityEntries"
+ android:entryValues="@array/PreferenceUnitVelocityValues"
+ android:key="@string/PreferenceUnitVelocityOption"
+ android:summary="Set the velocity unit"
+ android:title="Unit for Velocity" />
+ <ListPreference
+ android:defaultValue="m"
+ android:entries="@array/PreferenceUnitDistanceEntries"
+ android:entryValues="@array/PreferenceUnitDistanceValues"
+ android:key="@string/PreferenceUnitDistanceOption"
+ android:summary="Set the distance unit"
+ android:title="Unit for Distance and Altitude" />
+ </PreferenceScreen>
+
</PreferenceScreen>
\ No newline at end of file
--- /dev/null
+package net.sf.openrocket.android;\r
+\r
+import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;\r
+import android.app.Activity;\r
+import android.content.Intent;\r
+\r
+public abstract class ActivityHelpers {\r
+\r
+ \r
+ public static void browseMotors( Activity parent ) {\r
+ Intent i = new Intent(parent, MotorHierarchicalBrowser.class);\r
+ parent.startActivity(i);\r
+ \r
+ }\r
+\r
+ public static void startPreferences( Activity parent ) {\r
+ Intent intent = new Intent(parent, PreferencesActivity.class);\r
+ parent.startActivity(intent);\r
+\r
+ }\r
+}\r
\r
import net.sf.openrocket.R;\r
import net.sf.openrocket.android.filebrowser.SimpleFileBrowser;\r
-import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;\r
-import android.app.Activity;\r
import android.content.ActivityNotFoundException;\r
import android.content.Intent;\r
+import android.content.SharedPreferences;\r
+import android.content.res.Resources;\r
import android.net.Uri;\r
import android.os.Bundle;\r
+import android.preference.PreferenceManager;\r
+import android.support.v4.app.FragmentActivity;\r
+import android.view.Menu;\r
+import android.view.MenuInflater;\r
+import android.view.MenuItem;\r
import android.view.View;\r
\r
-public class Main extends Activity {\r
+public class Main extends FragmentActivity {\r
\r
private static final int PICK_ORK_FILE_RESULT = 1;\r
\r
setContentView(R.layout.main);\r
}\r
\r
+ @Override\r
+ public boolean onCreateOptionsMenu(Menu menu) {\r
+ MenuInflater inflater = getMenuInflater();\r
+ inflater.inflate(R.menu.main_menu, menu);\r
+ return true;\r
+ }\r
+\r
+ @Override\r
+ public boolean onOptionsItemSelected(MenuItem item) {\r
+ switch( item.getItemId() ) {\r
+ case R.id.main_menu_motor:\r
+ ActivityHelpers.browseMotors(this);\r
+ return true;\r
+ case R.id.main_menu_open:\r
+ pickOrkFiles();\r
+ return true;\r
+ case R.id.main_menu_preferences:\r
+ ActivityHelpers.startPreferences(this);\r
+ return true;\r
+ }\r
+ return super.onOptionsItemSelected(item);\r
+ }\r
+\r
/* (non-Javadoc)\r
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)\r
*/\r
super.onActivityResult(requestCode, resultCode, data);\r
}\r
\r
- public void pickOrkFiles( View v ) {\r
- try {\r
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
- intent.setType("file/*");\r
- startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
- } catch ( ActivityNotFoundException ex ) { \r
- // No activity for ACTION_GET_CONTENT use internal file browser\r
+ private void pickOrkFiles( ) {\r
+ Resources resources = this.getResources();\r
+ String key = resources.getString(R.string.PreferenceUseInternalFileBrowserOption);\r
+ SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);\r
+\r
+ boolean useinternalbrowser = pref.getBoolean(key, false);\r
+\r
+ if ( useinternalbrowser ) {\r
Intent intent = new Intent(Main.this, SimpleFileBrowser.class);\r
startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
- }\r
+ } else {\r
+ try {\r
+ Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
+ intent.setType("file/*");\r
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
+ } catch ( ActivityNotFoundException ex ) { \r
+ // No activity for ACTION_GET_CONTENT use internal file browser\r
+ // update the preference value.\r
+ pref.edit().putBoolean(key, false).commit();\r
+ // fire our browser\r
+ Intent intent = new Intent(Main.this, SimpleFileBrowser.class);\r
+ startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
+ }\r
+ } \r
+ }\r
+ public void pickOrkFiles( View v ) {\r
+ pickOrkFiles();\r
}\r
\r
public void browseMotors( View v ) {\r
- Intent i = new Intent(Main.this, MotorHierarchicalBrowser.class);\r
- startActivity(i);\r
+ ActivityHelpers.browseMotors(this);\r
}\r
\r
}\r
UnitGroup.UNITS_DISTANCE.setDefaultUnit( distance );\r
\r
}\r
+\r
+ @Override\r
+ protected void onStop() {\r
+ initializePreferences(getApplication(), PreferenceManager.getDefaultSharedPreferences(this));\r
+ super.onStop();\r
+ }\r
+ \r
+ \r
\r
}\r
private ScaleGestureDetector mScaleDetector;\r
private float mScaleFactor = 1.f;\r
\r
- @Override\r
- public void onAttach(Activity activity) {\r
- super.onAttach(activity);\r
- Log.d(TAG,"onAttach");\r
- }\r
-\r
@Override\r
public void onCreate(Bundle savedInstanceState) {\r
Log.d(TAG,"onCreate");\r
--- /dev/null
+package net.sf.openrocket.android.rocket;\r
+\r
+import net.sf.openrocket.R;\r
+import net.sf.openrocket.android.Application;\r
+import net.sf.openrocket.android.rocket.RocketComponentTreeAdapter.RocketComponentWithId;\r
+import net.sf.openrocket.document.OpenRocketDocument;\r
+import net.sf.openrocket.rocketcomponent.Rocket;\r
+import net.sf.openrocket.rocketcomponent.RocketComponent;\r
+import pl.polidea.treeview.InMemoryTreeStateManager;\r
+import pl.polidea.treeview.TreeBuilder;\r
+import pl.polidea.treeview.TreeStateManager;\r
+import pl.polidea.treeview.TreeViewList;\r
+import android.os.Bundle;\r
+import android.support.v4.app.Fragment;\r
+import android.view.LayoutInflater;\r
+import android.view.View;\r
+import android.view.ViewGroup;\r
+import android.widget.ListAdapter;\r
+\r
+public class Component extends Fragment {\r
+\r
+ private TreeViewList componentTree;\r
+\r
+ @Override\r
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
+ Bundle savedInstanceState) {\r
+ View v = inflater.inflate(R.layout.rocket_component, container, false);\r
+ componentTree = (TreeViewList) v.findViewById(R.id.openrocketviewerComponentTree);\r
+\r
+ return v;\r
+ }\r
+\r
+ @Override\r
+ public void onActivityCreated(Bundle savedInstanceState) {\r
+ super.onActivityCreated(savedInstanceState);\r
+\r
+ final OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();\r
+ componentTree.setAdapter( buildAdapter( rocketDocument.getRocket() ) );\r
+ }\r
+ \r
+ private ListAdapter buildAdapter( Rocket rocket ) {\r
+\r
+ TreeStateManager<RocketComponentWithId> manager = new InMemoryTreeStateManager<RocketComponentWithId>();\r
+ TreeBuilder<RocketComponentWithId> treeBuilder = new TreeBuilder<RocketComponentWithId>(manager);\r
+\r
+ int depth = buildRecursive( rocket, treeBuilder, 0 );\r
+ return new RocketComponentTreeAdapter(this.getActivity(), manager, depth+1);\r
+ }\r
+\r
+ long id = 0;\r
+ private int buildRecursive( RocketComponent comp, TreeBuilder<RocketComponentWithId> builder, int depth ) {\r
+\r
+\r
+ int maxDepth = depth;\r
+\r
+ RocketComponentWithId rcid = new RocketComponentWithId(comp, id++);\r
+\r
+ // Add this component.\r
+ builder.sequentiallyAddNextNode(rcid, depth);\r
+\r
+ if ( comp.allowsChildren() ) {\r
+\r
+ for( RocketComponent child : comp.getChildren() ) {\r
+ int childDepth = buildRecursive( child, builder, depth+1);\r
+ if ( childDepth > maxDepth) {\r
+ maxDepth = childDepth;\r
+ }\r
+ }\r
+\r
+ }\r
+\r
+ return maxDepth;\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+package net.sf.openrocket.android.rocket;\r
+\r
+import java.io.File;\r
+\r
+import net.sf.openrocket.R;\r
+import net.sf.openrocket.android.Application;\r
+import net.sf.openrocket.document.OpenRocketDocument;\r
+import android.app.ProgressDialog;\r
+import android.content.Context;\r
+import android.content.Intent;\r
+import android.net.Uri;\r
+import android.os.Bundle;\r
+import android.support.v4.app.FragmentActivity;\r
+import android.util.AttributeSet;\r
+import android.util.Log;\r
+import android.view.View;\r
+\r
+public class OpenRocketLoader extends FragmentActivity {\r
+ private static final String TAG = "OpenRocketLoader";\r
+\r
+ private ProgressDialog progress;\r
+\r
+ @Override\r
+ protected void onCreate(Bundle savedInstanceState) {\r
+ super.onCreate(savedInstanceState);\r
+ setContentView(R.layout.main);\r
+ Intent i = getIntent();\r
+ Uri file = i.getData();\r
+ loadOrkFile(file);\r
+ }\r
+\r
+ @Override\r
+ protected void onDestroy() {\r
+ if ( progress != null ) {\r
+ if ( progress.isShowing() ) {\r
+ progress.dismiss();\r
+ }\r
+ progress = null;\r
+ }\r
+ super.onDestroy();\r
+ }\r
+\r
+ private void loadOrkFile( Uri file ) {\r
+ Log.d(TAG,"Use ork file: " + file);\r
+ String path = file.getPath();\r
+ File orkFile = new File(path);\r
+ progress = ProgressDialog.show(this, "Loading file", "");\r
+\r
+ final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {\r
+\r
+ /* (non-Javadoc)\r
+ * @see android.os.AsyncTask#onPostExecute(java.lang.Object)\r
+ */\r
+ @Override\r
+ protected void onPostExecute(OpenRocketDocument result) {\r
+ super.onPostExecute(result);\r
+ ((Application)OpenRocketLoader.this.getApplication()).setRocketDocument( result );\r
+ Log.d(TAG,"Finished loading " + OpenRocketLoader.this);\r
+ finishedLoading();\r
+ }\r
+\r
+ };\r
+\r
+ task.execute(orkFile);\r
+\r
+ }\r
+ \r
+ private void finishedLoading() {\r
+ if ( progress.isShowing() ) {\r
+ progress.dismiss();\r
+ }\r
+ \r
+ Intent i = new Intent(this,OpenRocketViewer.class);\r
+ startActivity(i);\r
+ finish();\r
+ }\r
+\r
+\r
+}\r
package net.sf.openrocket.android.rocket;\r
\r
\r
-import java.io.File;\r
-\r
import net.sf.openrocket.R;\r
-import net.sf.openrocket.aerodynamics.AerodynamicCalculator;\r
-import net.sf.openrocket.aerodynamics.BarrowmanCalculator;\r
-import net.sf.openrocket.aerodynamics.FlightConditions;\r
-import net.sf.openrocket.aerodynamics.WarningSet;\r
+import net.sf.openrocket.android.ActivityHelpers;\r
import net.sf.openrocket.android.Application;\r
-import net.sf.openrocket.android.PreferencesActivity;\r
-import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;\r
-import net.sf.openrocket.android.rocket.RocketComponentTreeAdapter.RocketComponentWithId;\r
-import net.sf.openrocket.android.simulation.SimulationViewer;\r
+import net.sf.openrocket.android.util.TabsAdapter;\r
import net.sf.openrocket.document.OpenRocketDocument;\r
-import net.sf.openrocket.document.Simulation;\r
-import net.sf.openrocket.masscalc.BasicMassCalculator;\r
-import net.sf.openrocket.masscalc.MassCalculator;\r
-import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;\r
import net.sf.openrocket.rocketcomponent.Configuration;\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 pl.polidea.treeview.InMemoryTreeStateManager;\r
-import pl.polidea.treeview.TreeBuilder;\r
-import pl.polidea.treeview.TreeStateManager;\r
-import pl.polidea.treeview.TreeViewList;\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.support.v4.app.FragmentActivity;\r
+import android.support.v4.view.ViewPager;\r
import android.util.Log;\r
-import android.view.LayoutInflater;\r
import android.view.Menu;\r
import android.view.MenuInflater;\r
import android.view.MenuItem;\r
-import android.view.View;\r
-import android.view.ViewGroup;\r
-import android.widget.AdapterView;\r
-import android.widget.AdapterView.OnItemClickListener;\r
-import android.widget.ArrayAdapter;\r
-import android.widget.ListAdapter;\r
-import android.widget.ListView;\r
-import android.widget.Spinner;\r
import android.widget.TabHost;\r
-import android.widget.TextView;\r
\r
-public class OpenRocketViewer extends Activity\r
+public class OpenRocketViewer extends FragmentActivity\r
implements SharedPreferences.OnSharedPreferenceChangeListener\r
{\r
\r
private static final String TAG = "OpenRocketViewer";\r
\r
- private ProgressDialog progress;\r
-\r
- private Spinner configurationSpinner;\r
- private TreeViewList componentTree;\r
- private ListView simulationList;\r
- \r
- /* Calculation of CP and CG */\r
- private AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();\r
- private MassCalculator massCalculator = new BasicMassCalculator();\r
-\r
OpenRocketDocument rocketDocument;\r
Configuration rocketConfiguration;\r
\r
private Application app;\r
\r
- private final static int PICK_ORK_FILE_RESULT = 1;\r
+ TabHost mTabHost;\r
+ ViewPager mViewPager;\r
+ TabsAdapter mTabsAdapter;\r
\r
- /* (non-Javadoc)\r
- * @see android.app.Activity#onCreate(android.os.Bundle)\r
- */\r
@Override\r
protected void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
\r
- Log.d(TAG,"In onCreate");\r
-\r
app = (Application) this.getApplication();\r
\r
setContentView(R.layout.openrocketviewer);\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
+ mTabHost = (TabHost)findViewById(android.R.id.tabhost);\r
+ mTabHost.setup();\r
\r
- spec.setContent(R.id.openrocketviewerOverview);\r
- spec.setIndicator("Overview");\r
- tabs.addTab(spec);\r
+ mViewPager = (ViewPager)findViewById(R.id.pager);\r
\r
- spec=tabs.newTabSpec("tag2");\r
- spec.setContent(R.id.openrocketviewerComponentTree);\r
- spec.setIndicator("Components");\r
- tabs.addTab(spec); \r
+ mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager);\r
\r
- spec=tabs.newTabSpec("tag3");\r
- spec.setContent(R.id.openrocketviewerSimulationList);\r
- spec.setIndicator("Simulations");\r
- tabs.addTab(spec); \r
+ mTabsAdapter.addTab(mTabHost.newTabSpec("overview").setIndicator("Overview"),\r
+ Overview.class, null);\r
+ mTabsAdapter.addTab(mTabHost.newTabSpec("components").setIndicator("Components"),\r
+ Component.class, null);\r
+ mTabsAdapter.addTab(mTabHost.newTabSpec("simulations").setIndicator("Simulations"),\r
+ Simulations.class, null);\r
\r
- configurationSpinner = (Spinner) findViewById(R.id.openrocketviewerConfigurationSpinner);\r
- componentTree = (TreeViewList) findViewById(R.id.openrocketviewerComponentTree);\r
- simulationList = (ListView) findViewById(R.id.openrocketviewerSimulationList);\r
-\r
- Intent i = getIntent();\r
- Uri file = i.getData();\r
-\r
- if ( file == null ) {\r
- Intent intent = new Intent(Intent.ACTION_GET_CONTENT);\r
- intent.setType("file/*");\r
- startActivityForResult(intent,PICK_ORK_FILE_RESULT);\r
-\r
- } else {\r
- loadOrkFile(file);\r
+ if (savedInstanceState != null) {\r
+ mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab"));\r
}\r
}\r
\r
@Override\r
- protected void onDestroy() {\r
- if ( progress != null ) {\r
- if ( progress.isShowing() ) {\r
- progress.dismiss();\r
- }\r
- progress = null;\r
- }\r
- super.onDestroy();\r
- }\r
-\r
- @Override\r
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {\r
- // TODO Auto-generated method stub\r
- switch(requestCode){\r
- case PICK_ORK_FILE_RESULT:\r
- if(resultCode==RESULT_OK){\r
- Uri file = data.getData();\r
- loadOrkFile(file);\r
- }\r
- break;\r
- }\r
- }\r
-\r
- private void loadOrkFile( Uri file ) {\r
- Log.d(TAG,"Use ork file: " + file);\r
- String path = file.getPath();\r
- File orkFile = new File(path);\r
- progress = ProgressDialog.show(this, "Loading file", "");\r
-\r
- final OpenRocketLoaderTask task = new OpenRocketLoaderTask() {\r
-\r
- /* (non-Javadoc)\r
- * @see android.os.AsyncTask#onPostExecute(java.lang.Object)\r
- */\r
- @Override\r
- protected void onPostExecute(OpenRocketDocument result) {\r
- super.onPostExecute(result);\r
- app.setRocketDocument( result );\r
- updateContents();\r
- }\r
-\r
- };\r
-\r
- task.execute(orkFile);\r
-\r
+ protected void onSaveInstanceState(Bundle outState) {\r
+ super.onSaveInstanceState(outState);\r
+ outState.putString("tab", mTabHost.getCurrentTabTag());\r
}\r
\r
/* (non-Javadoc)\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
- private void updateContents() {\r
-\r
- rocketDocument = app.getRocketDocument();\r
- rocketConfiguration = rocketDocument.getDefaultConfiguration();\r
- Rocket rocket = rocketDocument.getRocket();\r
-\r
- setTitle(rocket.getName());\r
-\r
- String[] motorConfigs = rocket.getMotorConfigurationIDs();\r
- ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item);\r
- for( String config: motorConfigs ) {\r
- spinnerAdapter.add(rocket.getMotorConfigurationNameOrDescription(config));\r
- }\r
- \r
- configurationSpinner.setAdapter(spinnerAdapter);\r
- configurationSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {\r
-\r
- /* (non-Javadoc)\r
- * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long)\r
- */\r
- @Override\r
- public void onItemSelected(AdapterView<?> arg0, View arg1,\r
- int arg2, long arg3) {\r
-\r
- String selectedConfigId = rocketDocument.getRocket().getMotorConfigurationIDs()[arg2];\r
- rocketConfiguration.setMotorConfigurationID(selectedConfigId);\r
- Coordinate cp = aerodynamicCalculator.getWorstCP(rocketConfiguration,\r
- new FlightConditions(rocketConfiguration),\r
- new WarningSet());\r
- \r
- Coordinate cg = massCalculator.getCG(rocketConfiguration, MassCalcType.LAUNCH_MASS);\r
-\r
- Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
- Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
- Unit stabilityUnit = UnitGroup.stabilityUnits(rocketConfiguration).getDefaultUnit();\r
-\r
- ((TextView)findViewById(R.id.openrocketviewerCP)).setText(lengthUnit.toStringUnit(cp.x));\r
- ((TextView)findViewById(R.id.openrocketviewerCG)).setText(lengthUnit.toStringUnit(cg.x));\r
- ((TextView)findViewById(R.id.openrocketviewerLiftOffWeight)).setText(massUnit.toStringUnit(cg.weight));\r
- ((TextView)findViewById(R.id.openrocketviewerStabilityMargin)).setText(stabilityUnit.toStringUnit(cp.x-cg.x));\r
-\r
- }\r
-\r
- /* (non-Javadoc)\r
- * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView)\r
- */\r
- @Override\r
- public void onNothingSelected(AdapterView<?> arg0) {\r
- ((TextView)findViewById(R.id.openrocketviewerCP)).setText("");\r
- ((TextView)findViewById(R.id.openrocketviewerCG)).setText("");\r
- ((TextView)findViewById(R.id.openrocketviewerLiftOffWeight)).setText("");\r
- ((TextView)findViewById(R.id.openrocketviewerStabilityMargin)).setText("");\r
- }\r
- \r
- });\r
- \r
- Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
- Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
-\r
- Coordinate cg = RocketUtils.getCG(rocket, MassCalcType.NO_MOTORS);\r
- double length = RocketUtils.getLength(rocket);\r
- ((TextView)findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner());\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
-\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, ViewGroup parent) {\r
- View v = convertView;\r
- if ( v == null ) {\r
- LayoutInflater li = getLayoutInflater();\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
- StringBuilder sb = new StringBuilder();\r
- sb.append("motors: ").append(sim.getConfiguration().getMotorConfigurationDescription());\r
- Unit distanceUnit = UnitGroup.UNITS_DISTANCE.getDefaultUnit();\r
- sb.append(" apogee: ").append( distanceUnit.toStringUnit(sim.getSimulatedData().getMaxAltitude()));\r
- sb.append(" time: ").append(sim.getSimulatedData().getFlightTime()).append("s");\r
- ((TextView)v.findViewById(android.R.id.text2)).setText( sb.toString() );\r
- return v;\r
- }\r
-\r
- };\r
- simulationList.setOnItemClickListener( new OnItemClickListener() {\r
- @Override\r
- public void onItemClick(AdapterView l, View v, int position, long id) {\r
- Intent i = new Intent(OpenRocketViewer.this, SimulationViewer.class);\r
- Log.d(TAG,"onItemClick simulation number " + id );\r
- i.putExtra("Simulation",(int)id);\r
- startActivity(i);\r
- }\r
-\r
- });\r
- simulationList.setAdapter(sims);\r
-\r
- componentTree.setAdapter( buildAdapter( rocket ) );\r
-\r
- if ( progress.isShowing() ) {\r
- progress.dismiss();\r
- }\r
+ // TODO = updateContents(); redraw all children..\r
}\r
\r
@Override\r
return true;\r
}\r
\r
+ @Override\r
+ public boolean onOptionsItemSelected(MenuItem item) {\r
+ switch ( item.getItemId() ) {\r
+ /* case android.R.id.home:\r
+ Intent i = new Intent( this, Main.class );\r
+ i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\r
+ startActivity(i);\r
+ return true;\r
+ */\r
+ default:\r
+ return super.onOptionsItemSelected(item);\r
+ }\r
+ }\r
+\r
@Override\r
public boolean onMenuItemSelected(int featureId, MenuItem item) {\r
Log.d(TAG,"onMenuItemSelected" + item.getItemId());\r
switch(item.getItemId()) {\r
case R.id.motor_list_menu_option:\r
- startMotorBrowser();\r
+ ActivityHelpers.browseMotors(this);\r
return true;\r
case R.id.preference_menu_option:\r
- Intent intent = new Intent().setClass(this, PreferencesActivity.class);\r
- this.startActivity(intent);\r
+ ActivityHelpers.startPreferences(this);\r
return true;\r
}\r
return super.onMenuItemSelected(featureId, item);\r
}\r
\r
- public void startMotorBrowser() {\r
- Log.d(TAG,"motorBrowserButton clicked");\r
- Intent i = new Intent(OpenRocketViewer.this, MotorHierarchicalBrowser.class);\r
- startActivity(i);\r
- }\r
-\r
- private ListAdapter buildAdapter( Rocket rocket ) {\r
- /*\r
- final int[] DEMO_NODES = new int[] { 0, 0, 1, 1, 1, 2, 2, 1,\r
- 1, 2, 1, 0, 0, 0, 1, 2, 3, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1 };\r
- final int LEVEL_NUMBER = 4;\r
-\r
- TreeStateManager<Long> manager = new InMemoryTreeStateManager<Long>();\r
- final TreeBuilder<Long> treeBuilder = new TreeBuilder<Long>(manager);\r
- for (int i = 0; i < DEMO_NODES.length; i++) {\r
- treeBuilder.sequentiallyAddNextNode((long) i, DEMO_NODES[i]);\r
- }\r
-\r
- return new SimpleStandardAdapter(this, manager, LEVEL_NUMBER);\r
- */\r
- \r
- TreeStateManager<RocketComponentWithId> manager = new InMemoryTreeStateManager<RocketComponentWithId>();\r
- TreeBuilder<RocketComponentWithId> treeBuilder = new TreeBuilder<RocketComponentWithId>(manager);\r
- \r
- int depth = buildRecursive( rocket, treeBuilder, 0 );\r
- return new RocketComponentTreeAdapter(this, manager, depth+1);\r
- }\r
- \r
- long id = 0;\r
- private int buildRecursive( RocketComponent comp, TreeBuilder<RocketComponentWithId> builder, int depth ) {\r
- \r
- \r
- int maxDepth = depth;\r
- \r
- RocketComponentWithId rcid = new RocketComponentWithId(comp, id++);\r
- \r
- // Add this component.\r
- builder.sequentiallyAddNextNode(rcid, depth);\r
- \r
- if ( comp.allowsChildren() ) {\r
- \r
- for( RocketComponent child : comp.getChildren() ) {\r
- int childDepth = buildRecursive( child, builder, depth+1);\r
- if ( childDepth > maxDepth) {\r
- maxDepth = childDepth;\r
- }\r
- }\r
- \r
- }\r
- \r
- return maxDepth;\r
- }\r
-\r
-\r
}\r
--- /dev/null
+package net.sf.openrocket.android.rocket;\r
+\r
+import net.sf.openrocket.R;\r
+import net.sf.openrocket.aerodynamics.AerodynamicCalculator;\r
+import net.sf.openrocket.aerodynamics.BarrowmanCalculator;\r
+import net.sf.openrocket.aerodynamics.FlightConditions;\r
+import net.sf.openrocket.aerodynamics.WarningSet;\r
+import net.sf.openrocket.android.Application;\r
+import net.sf.openrocket.document.OpenRocketDocument;\r
+import net.sf.openrocket.masscalc.BasicMassCalculator;\r
+import net.sf.openrocket.masscalc.MassCalculator;\r
+import net.sf.openrocket.masscalc.MassCalculator.MassCalcType;\r
+import net.sf.openrocket.rocketcomponent.Configuration;\r
+import net.sf.openrocket.rocketcomponent.Rocket;\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.os.Bundle;\r
+import android.support.v4.app.Fragment;\r
+import android.util.Log;\r
+import android.view.LayoutInflater;\r
+import android.view.View;\r
+import android.view.ViewGroup;\r
+import android.widget.AdapterView;\r
+import android.widget.ArrayAdapter;\r
+import android.widget.Spinner;\r
+import android.widget.TextView;\r
+\r
+public class Overview extends Fragment {\r
+\r
+ /* Calculation of CP and CG */\r
+ private AerodynamicCalculator aerodynamicCalculator = new BarrowmanCalculator();\r
+ private MassCalculator massCalculator = new BasicMassCalculator();\r
+\r
+ private Spinner configurationSpinner;\r
+\r
+\r
+ @Override\r
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
+ Bundle savedInstanceState) {\r
+ Log.d("Overview", "Created View");\r
+ View v = inflater.inflate(R.layout.rocket_overview, container, false);\r
+ configurationSpinner = (Spinner) v.findViewById(R.id.openrocketviewerConfigurationSpinner);\r
+\r
+ return v;\r
+ }\r
+\r
+ \r
+ @Override\r
+ public void onActivityCreated(Bundle savedInstanceState) {\r
+ super.onActivityCreated(savedInstanceState);\r
+\r
+ final OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();\r
+ final Configuration rocketConfiguration = rocketDocument.getDefaultConfiguration();\r
+ Rocket rocket = rocketDocument.getRocket();\r
+\r
+ String[] motorConfigs = rocket.getMotorConfigurationIDs();\r
+ ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_spinner_item);\r
+ for( String config: motorConfigs ) {\r
+ spinnerAdapter.add(rocket.getMotorConfigurationNameOrDescription(config));\r
+ }\r
+\r
+ Log.d("Overview", "spinnerAdapter = " + spinnerAdapter);\r
+ Log.d("Overview", "configurationSpinner = " + configurationSpinner);\r
+ \r
+ configurationSpinner.setAdapter(spinnerAdapter);\r
+ configurationSpinner.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener() {\r
+\r
+ /* (non-Javadoc)\r
+ * @see android.widget.AdapterView.OnItemSelectedListener#onItemSelected(android.widget.AdapterView, android.view.View, int, long)\r
+ */\r
+ @Override\r
+ public void onItemSelected(AdapterView<?> arg0, View arg1,\r
+ int arg2, long arg3) {\r
+\r
+ String selectedConfigId = rocketDocument.getRocket().getMotorConfigurationIDs()[arg2];\r
+ rocketConfiguration.setMotorConfigurationID(selectedConfigId);\r
+ Coordinate cp = aerodynamicCalculator.getWorstCP(rocketConfiguration,\r
+ new FlightConditions(rocketConfiguration),\r
+ new WarningSet());\r
+\r
+ Coordinate cg = massCalculator.getCG(rocketConfiguration, MassCalcType.LAUNCH_MASS);\r
+\r
+ Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
+ Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
+ Unit stabilityUnit = UnitGroup.stabilityUnits(rocketConfiguration).getDefaultUnit();\r
+\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText(lengthUnit.toStringUnit(cp.x));\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText(lengthUnit.toStringUnit(cg.x));\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText(massUnit.toStringUnit(cg.weight));\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText(stabilityUnit.toStringUnit(cp.x-cg.x));\r
+\r
+ }\r
+\r
+ /* (non-Javadoc)\r
+ * @see android.widget.AdapterView.OnItemSelectedListener#onNothingSelected(android.widget.AdapterView)\r
+ */\r
+ @Override\r
+ public void onNothingSelected(AdapterView<?> arg0) {\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerCP)).setText("");\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerCG)).setText("");\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerLiftOffWeight)).setText("");\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerStabilityMargin)).setText("");\r
+ }\r
+\r
+ });\r
+\r
+ Unit lengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();\r
+ Unit massUnit = UnitGroup.UNITS_MASS.getDefaultUnit();\r
+\r
+ Coordinate cg = RocketUtils.getCG(rocket, MassCalcType.NO_MOTORS);\r
+ double length = RocketUtils.getLength(rocket);\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner());\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerLength)).setText(lengthUnit.toStringUnit(length));\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerMass)).setText(massUnit.toStringUnit(cg.weight));\r
+ ((TextView)getActivity().findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount()));\r
+\r
+\r
+ }\r
+\r
+\r
+}\r
--- /dev/null
+package net.sf.openrocket.android.rocket;\r
+\r
+import net.sf.openrocket.R;\r
+import net.sf.openrocket.android.Application;\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.unit.Unit;\r
+import net.sf.openrocket.unit.UnitGroup;\r
+import android.content.Intent;\r
+import android.os.Bundle;\r
+import android.support.v4.app.Fragment;\r
+import android.util.Log;\r
+import android.view.LayoutInflater;\r
+import android.view.View;\r
+import android.view.ViewGroup;\r
+import android.widget.AdapterView;\r
+import android.widget.AdapterView.OnItemClickListener;\r
+import android.widget.ArrayAdapter;\r
+import android.widget.ListView;\r
+import android.widget.TextView;\r
+\r
+public class Simulations extends Fragment {\r
+\r
+ private ListView simulationList;\r
+\r
+ @Override\r
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,\r
+ Bundle savedInstanceState) {\r
+ View v = inflater.inflate(R.layout.rocket_simulations, container, false);\r
+ simulationList = (ListView) v.findViewById(R.id.openrocketviewerSimulationList);\r
+\r
+ return v;\r
+ }\r
+\r
+ @Override\r
+ public void onActivityCreated(Bundle savedInstanceState) {\r
+ super.onActivityCreated(savedInstanceState);\r
+\r
+ final OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();\r
+ Log.d("sim","activity = " + this.getActivity());\r
+\r
+ ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this.getActivity(),android.R.layout.simple_list_item_2,rocketDocument.getSimulations()) {\r
+\r
+ @Override\r
+ public View getView(int position, View convertView, ViewGroup parent) {\r
+ View v = convertView;\r
+ if ( v == null ) {\r
+ LayoutInflater li = getActivity().getLayoutInflater();\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
+ StringBuilder sb = new StringBuilder();\r
+ sb.append("motors: ").append(sim.getConfiguration().getMotorConfigurationDescription());\r
+ Unit distanceUnit = UnitGroup.UNITS_DISTANCE.getDefaultUnit();\r
+ sb.append(" apogee: ").append( distanceUnit.toStringUnit(sim.getSimulatedData().getMaxAltitude()));\r
+ sb.append(" time: ").append(sim.getSimulatedData().getFlightTime()).append("s");\r
+ ((TextView)v.findViewById(android.R.id.text2)).setText( sb.toString() );\r
+ return v;\r
+ }\r
+\r
+ };\r
+ simulationList.setOnItemClickListener( new OnItemClickListener() {\r
+ @Override\r
+ public void onItemClick(AdapterView l, View v, int position, long id) {\r
+ Intent i = new Intent(getActivity(), SimulationViewer.class);\r
+ i.putExtra("Simulation",(int)id);\r
+ startActivity(i);\r
+ }\r
+\r
+ });\r
+ simulationList.setAdapter(sims);\r
+\r
+ }\r
+\r
+}\r
--- /dev/null
+package net.sf.openrocket.android.util;\r
+\r
+import java.util.ArrayList;\r
+\r
+import android.content.Context;\r
+import android.os.Bundle;\r
+import android.support.v4.app.Fragment;\r
+import android.support.v4.app.FragmentActivity;\r
+import android.support.v4.app.FragmentPagerAdapter;\r
+import android.support.v4.view.ViewPager;\r
+import android.view.View;\r
+import android.view.ViewGroup;\r
+import android.widget.TabHost;\r
+import android.widget.TabWidget;\r
+\r
+//This class was copied from:\r
+//http://developer.android.com/resources/samples/Support4Demos/src/com/example/android/supportv4/app/FragmentTabsPager.html\r
+//With the following copyright & license.\r
+\r
+/*\r
+* Copyright (C) 2011 The Android Open Source Project\r
+*\r
+* Licensed under the Apache License, Version 2.0 (the "License");\r
+* you may not use this file except in compliance with the License.\r
+* You may obtain a copy of the License at\r
+*\r
+* http://www.apache.org/licenses/LICENSE-2.0\r
+*\r
+* Unless required by applicable law or agreed to in writing, software\r
+* distributed under the License is distributed on an "AS IS" BASIS,\r
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+* See the License for the specific language governing permissions and\r
+* limitations under the License.\r
+*/\r
+\r
+/**\r
+ * This is a helper class that implements the management of tabs and all\r
+ * details of connecting a ViewPager with associated TabHost. It relies on a\r
+ * trick. Normally a tab host has a simple API for supplying a View or\r
+ * Intent that each tab will show. This is not sufficient for switching\r
+ * between pages. So instead we make the content part of the tab host\r
+ * 0dp high (it is not shown) and the TabsAdapter supplies its own dummy\r
+ * view to show as the tab content. It listens to changes in tabs, and takes\r
+ * care of switch to the correct paged in the ViewPager whenever the selected\r
+ * tab changes.\r
+ */\r
+public class TabsAdapter extends FragmentPagerAdapter\r
+ implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {\r
+ private final Context mContext;\r
+ private final TabHost mTabHost;\r
+ private final ViewPager mViewPager;\r
+ private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();\r
+\r
+ static final class TabInfo {\r
+ private final String tag;\r
+ private final Class<?> clss;\r
+ private final Bundle args;\r
+\r
+ TabInfo(String _tag, Class<?> _class, Bundle _args) {\r
+ tag = _tag;\r
+ clss = _class;\r
+ args = _args;\r
+ }\r
+ }\r
+\r
+ static class DummyTabFactory implements TabHost.TabContentFactory {\r
+ private final Context mContext;\r
+\r
+ public DummyTabFactory(Context context) {\r
+ mContext = context;\r
+ }\r
+\r
+ @Override\r
+ public View createTabContent(String tag) {\r
+ View v = new View(mContext);\r
+ v.setMinimumWidth(0);\r
+ v.setMinimumHeight(0);\r
+ return v;\r
+ }\r
+ }\r
+\r
+ public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager pager) {\r
+ super(activity.getSupportFragmentManager());\r
+ mContext = activity;\r
+ mTabHost = tabHost;\r
+ mViewPager = pager;\r
+ mTabHost.setOnTabChangedListener(this);\r
+ mViewPager.setAdapter(this);\r
+ mViewPager.setOnPageChangeListener(this);\r
+ }\r
+\r
+ public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle args) {\r
+ tabSpec.setContent(new DummyTabFactory(mContext));\r
+ String tag = tabSpec.getTag();\r
+\r
+ TabInfo info = new TabInfo(tag, clss, args);\r
+ mTabs.add(info);\r
+ mTabHost.addTab(tabSpec);\r
+ notifyDataSetChanged();\r
+ }\r
+\r
+ @Override\r
+ public int getCount() {\r
+ return mTabs.size();\r
+ }\r
+\r
+ @Override\r
+ public Fragment getItem(int position) {\r
+ TabInfo info = mTabs.get(position);\r
+ return Fragment.instantiate(mContext, info.clss.getName(), info.args);\r
+ }\r
+\r
+ @Override\r
+ public void onTabChanged(String tabId) {\r
+ int position = mTabHost.getCurrentTab();\r
+ mViewPager.setCurrentItem(position);\r
+ }\r
+\r
+ @Override\r
+ public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {\r
+ }\r
+\r
+ @Override\r
+ public void onPageSelected(int position) {\r
+ // Unfortunately when TabHost changes the current tab, it kindly\r
+ // also takes care of putting focus on it when not in touch mode.\r
+ // The jerk.\r
+ // This hack tries to prevent this from pulling focus out of our\r
+ // ViewPager.\r
+ TabWidget widget = mTabHost.getTabWidget();\r
+ int oldFocusability = widget.getDescendantFocusability();\r
+ widget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);\r
+ mTabHost.setCurrentTab(position);\r
+ widget.setDescendantFocusability(oldFocusability);\r
+ }\r
+\r
+ @Override\r
+ public void onPageScrollStateChanged(int state) {\r
+ }\r
+}\r