Change OpenRocketViewer to tab layout with three tabs: overview, components, and simulations. Overview is populated with some high level data about the rocket - length, mass, cg, etc. Components will be populated with the tree of rocket components. Simulations contains the list of stored simulations.

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.
This commit is contained in:
Kevin Ruland 2012-01-08 00:53:35 +00:00
parent 195ad4933b
commit 10dd89f569
6 changed files with 294 additions and 24 deletions

View File

@ -1,18 +1,119 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/heading"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="" />
<TabHost
android:id="@+id/openrocketviewerTabHost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black" >
<ListView
android:id="@+id/rocketSimulations"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/openrocketviewerOverview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:text='Rocket Name'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerRocketName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='Designer'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerDesigner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='CG'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerCG"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='Length'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerLength"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='Mass'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerMass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='Stage Count'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerStageCount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:text='Comment'
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/openrocketviewerComment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
<ListView
android:id="@+id/openrocketviewerComponentList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ListView
android:id="@+id/openrocketviewerSimulationList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>

View File

@ -96,5 +96,33 @@
<string name="tcdownload">Download from ThrustCurve</string>
<string name="simulationSeries1Label">Series 1</string>
<string name="simulationSeries2Label">Series 2</string>
<string name="PreferenceUnitLengthOption">PreferenceUnitLengthOption</string>
<string-array name="PreferenceUnitLengthEntries">
<item >Millimeters</item>
<item >Centimeters</item>
<item >Meters</item>
<item >Inches</item>
<item >Feet</item>
</string-array>
<string-array name="PreferenceUnitLengthValues">
<item >mm</item>
<item >cm</item>
<item >m</item>
<item >in</item>
<item >ft</item>
</string-array>
<string name="PreferenceUnitMassOption">PreferenceUnitMassOption</string>
<string-array name="PreferenceUnitMassEntries">
<item >Grams</item>
<item >Kilograms</item>
<item >Ounces</item>
<item >Pounds</item>
</string-array>
<string-array name="PreferenceUnitMassValues">
<item >g</item>
<item >kg</item>
<item >oz</item>
<item >lb</item>
</string-array>
</resources>

View File

@ -14,4 +14,20 @@
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>

View File

@ -2,6 +2,8 @@ package net.sf.openrocket.android;
import java.util.Locale;
import android.preference.PreferenceManager;
import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.l10n.DebugTranslator;
@ -54,6 +56,15 @@ public class Application extends android.app.Application {
initialize();
}
/* (non-Javadoc)
* @see android.app.Application#onCreate()
*/
@Override
public void onCreate() {
super.onCreate();
PreferencesActivity.initializePreferences(this, PreferenceManager.getDefaultSharedPreferences(this));
}
/**
* @return the rocketDocument
*/

View File

@ -1,14 +1,48 @@
package net.sf.openrocket.android;
import net.sf.openrocket.R;
import net.sf.openrocket.unit.UnitGroup;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
public class PreferencesActivity extends android.preference.PreferenceActivity {
public class PreferencesActivity extends android.preference.PreferenceActivity
implements SharedPreferences.OnSharedPreferenceChangeListener {
@Override
protected void onCreate( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
addPreferencesFromResource(R.xml.preferences);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
}
/* (non-Javadoc)
* @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
initializePreferences(getApplication(), PreferenceManager.getDefaultSharedPreferences(this));
}
/**
* This method is to be called from Application setup to pull the saved preference
* values into the various datastructures used in OpenRocket.
* This method is located in this class because it is probably best to have as much
* of the code in the same place as possible.
* @param sharedPreferences
*/
public static void initializePreferences( android.app.Application app, SharedPreferences sharedPreferences ) {
String unitLength = app.getResources().getString(R.string.PreferenceUnitLengthOption);
String len = sharedPreferences.getString(unitLength, "cm");
UnitGroup.UNITS_LENGTH.setDefaultUnit( len );
String unitMass = app.getResources().getString(R.string.PreferenceUnitMassOption);
String mass = sharedPreferences.getString(unitMass, "g");
UnitGroup.UNITS_MASS.setDefaultUnit( mass );
}
}

View File

@ -10,11 +10,19 @@ import net.sf.openrocket.android.motor.MotorHierarchicalBrowser;
import net.sf.openrocket.android.simulation.SimulationViewer;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import net.sf.openrocket.rocketcomponent.Rocket;
import net.sf.openrocket.rocketcomponent.RocketComponent;
import net.sf.openrocket.rocketcomponent.RocketUtils;
import net.sf.openrocket.unit.Unit;
import net.sf.openrocket.unit.UnitGroup;
import net.sf.openrocket.util.Coordinate;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
@ -26,15 +34,18 @@ import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
public class OpenRocketViewer extends Activity {
public class OpenRocketViewer extends Activity
implements SharedPreferences.OnSharedPreferenceChangeListener
{
private static final String TAG = "OpenRocketViewer";
private ProgressDialog progress;
private TextView header;
private ListView componentList;
private ListView simulationList;
private Application app;
@ -54,8 +65,31 @@ public class OpenRocketViewer extends Activity {
setContentView(R.layout.openrocketviewer);
header = (TextView) findViewById(R.id.heading);
simulationList = (ListView) findViewById(R.id.rocketSimulations);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.registerOnSharedPreferenceChangeListener(this);
TabHost tabs=(TabHost)findViewById(R.id.openrocketviewerTabHost);
tabs.setup();
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
spec.setContent(R.id.openrocketviewerOverview);
spec.setIndicator("Overview");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag2");
spec.setContent(R.id.openrocketviewerComponentList);
spec.setIndicator("Components");
tabs.addTab(spec);
spec=tabs.newTabSpec("tag3");
spec.setContent(R.id.openrocketviewerSimulationList);
spec.setIndicator("Simulations");
tabs.addTab(spec);
componentList = (ListView) findViewById(R.id.openrocketviewerComponentList);
simulationList = (ListView) findViewById(R.id.openrocketviewerSimulationList);
Intent i = getIntent();
Uri file = i.getData();
@ -118,23 +152,48 @@ public class OpenRocketViewer extends Activity {
}
/* (non-Javadoc)
* @see android.content.SharedPreferences.OnSharedPreferenceChangeListener#onSharedPreferenceChanged(android.content.SharedPreferences, java.lang.String)
*/
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
// just in case the user changed the units, we redraw.
PreferencesActivity.initializePreferences(getApplication(), PreferenceManager.getDefaultSharedPreferences(this));
updateContents();
}
private void updateContents() {
OpenRocketDocument rocket = app.getRocketDocument();
header.setText( rocket.getRocket().getName());
OpenRocketDocument rocketDocument = app.getRocketDocument();
Rocket rocket = rocketDocument.getRocket();
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_1,rocket.getSimulations()) {
setTitle(rocket.getName());
Unit LengthUnit = UnitGroup.UNITS_LENGTH.getDefaultUnit();
Unit MassUnit = UnitGroup.UNITS_MASS.getDefaultUnit();
Coordinate cg = RocketUtils.getCG(rocket);
double length = RocketUtils.getLength(rocket);
((TextView) findViewById(R.id.openrocketviewerRocketName)).setText( rocket.getName());
((TextView)findViewById(R.id.openrocketviewerDesigner)).setText(rocket.getDesigner());
((TextView)findViewById(R.id.openrocketviewerCG)).setText(LengthUnit.toStringUnit(cg.x) );
((TextView)findViewById(R.id.openrocketviewerLength)).setText(LengthUnit.toStringUnit(length));
((TextView)findViewById(R.id.openrocketviewerMass)).setText(MassUnit.toStringUnit(cg.weight));
((TextView)findViewById(R.id.openrocketviewerStageCount)).setText(String.valueOf(rocket.getStageCount()));
((TextView)findViewById(R.id.openrocketviewerComment)).setText(rocket.getComment());
ArrayAdapter<Simulation> sims = new ArrayAdapter<Simulation>(this,android.R.layout.simple_list_item_2,rocketDocument.getSimulations()) {
@Override
public View getView(int position, View convertView,
ViewGroup parent) {
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if ( v == null ) {
LayoutInflater li = getLayoutInflater();
v = li.inflate(android.R.layout.simple_list_item_1,null);
v = li.inflate(android.R.layout.simple_list_item_2,null);
}
Simulation sim = this.getItem(position);
((TextView)v.findViewById(android.R.id.text1)).setText( sim.getName() );
((TextView)v.findViewById(android.R.id.text2)).setText( "motors: " + sim.getConfiguration().getMotorConfigurationDescription() + " apogee: " + sim.getSimulatedData().getMaxAltitude() + "m time: " + sim.getSimulatedData().getFlightTime() + "s");
return v;
}
@ -151,6 +210,27 @@ public class OpenRocketViewer extends Activity {
});
simulationList.setAdapter(sims);
ArrayAdapter<RocketComponent> comps = new ArrayAdapter<RocketComponent>(this, android.R.layout.simple_list_item_1,rocket.getChildren()) {
/* (non-Javadoc)
* @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if ( v == null ) {
LayoutInflater li = getLayoutInflater();
v = li.inflate(android.R.layout.simple_list_item_1,null);
}
RocketComponent comp = this.getItem(position);
((TextView)v.findViewById(android.R.id.text1)).setText( comp.getName() );
return v;
}
};
componentList.setAdapter(comps);
if ( progress.isShowing() ) {
progress.dismiss();
}