Rewrite the simulation graph component. It is now implemented as a fragment with a menu to configure the serieses and display a list of the flight events.
SimulationChart now implements a flyweight pattern containing the simulationId so it can be serialized allows the os to pause the application and restore most of the state of the graph. Currently the selected serieses are not persisted so the graph gets reset to the default. The simulation view is operated in two different modes. On tablets in landscape the graph appears in the right sidepane and the list on the left. When a new simulation is selected, the old graph is pushed to the back stack. When in portrait mode or on smaller sceens, the simluation graph is in a separate activity.
This commit is contained in:
parent
0560556ba2
commit
90f2dcadfc
@ -74,8 +74,7 @@
|
||||
<activity android:name=".android.motor.MotorHierarchicalBrowser" />
|
||||
<activity android:name=".android.motor.MotorDetails" />
|
||||
<activity android:name=".android.thrustcurve.TCQueryActivity" />
|
||||
<activity android:name=".android.simulation.SimulationViewer" />
|
||||
<activity android:name=".android.simulation.GraphicalActivity" />
|
||||
<activity android:name=".android.simulation.SimulationViewActivity" />
|
||||
<activity android:name=".android.filebrowser.SimpleFileBrowser" />
|
||||
</application>
|
||||
|
||||
|
45
android/res/layout-xlarge-land/openrocketviewer.xml
Normal file
45
android/res/layout-xlarge-land/openrocketviewer.xml
Normal file
@ -0,0 +1,45 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<TabHost
|
||||
android:id="@android:id/tabhost"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_weight="4"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<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"
|
||||
android:layout_weight="0"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="0" />
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1" />
|
||||
</LinearLayout>
|
||||
</TabHost>
|
||||
|
||||
<LinearLayout android:id="@+id/sidepane"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
</LinearLayout>
|
@ -1,71 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TabHost
|
||||
android:id="@+id/simulationConfigurationForm"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="@android:color/black" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TabWidget
|
||||
android:id="@android:id/tabs"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@android:id/tabcontent"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/simulationEventsList"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/simulationSeriesSelection"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/simulationSeries1Label" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/simulationSeries1"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawSelectorOnTop="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/simulationSeries2Label" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/simulationSeries2"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawSelectorOnTop="true" />
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="draw"
|
||||
android:text="Draw" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
</TabHost>
|
||||
|
||||
</LinearLayout>
|
12
android/res/layout/simulation_event_dialog.xml
Normal file
12
android/res/layout/simulation_event_dialog.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<ListView
|
||||
android:id="@+id/simulationEventsList"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
</LinearLayout>
|
13
android/res/layout/simulation_graph_activity.xml
Normal file
13
android/res/layout/simulation_graph_activity.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/sidepane"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" />
|
||||
</LinearLayout>
|
43
android/res/layout/simulation_series_dialog.xml
Normal file
43
android/res/layout/simulation_series_dialog.xml
Normal file
@ -0,0 +1,43 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<!-- shim to get dialog correct size ?? -->
|
||||
<View
|
||||
android:layout_width="2000dp"
|
||||
android:layout_height="0px"
|
||||
android:layout_margin="0px"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/simulationSeries1Label" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/simulationSeries1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawSelectorOnTop="true" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/simulationSeries2Label" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/simulationSeries2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawSelectorOnTop="true" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/simulationOkButton"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="ok" />
|
||||
|
||||
</LinearLayout>
|
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:title="Select Events" android:id="@+id/simulation_select_events_menu_option"/>
|
||||
<item android:title="Select Series" android:id="@+id/simulation_select_series_menu_option"/>
|
||||
<item android:title="Preferences" android:id="@+id/preference_menu_option"/>
|
||||
<item android:title="View Event" android:id="@+id/simulation_select_events_menu_option"/>
|
||||
</menu>
|
||||
|
@ -4,20 +4,26 @@ package net.sf.openrocket.android.rocket;
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.ActivityHelpers;
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.android.simulation.SimulationViewer;
|
||||
import net.sf.openrocket.android.simulation.SimulationChart;
|
||||
import net.sf.openrocket.android.simulation.SimulationFragment;
|
||||
import net.sf.openrocket.android.simulation.SimulationViewActivity;
|
||||
import net.sf.openrocket.android.util.TabsAdapter;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.rocketcomponent.Configuration;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TabHost;
|
||||
|
||||
public class OpenRocketViewer extends FragmentActivity
|
||||
@ -88,20 +94,6 @@ Simulations.OnSimulationSelectedListener
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch ( item.getItemId() ) {
|
||||
/* case android.R.id.home:
|
||||
Intent i = new Intent( this, Main.class );
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(i);
|
||||
return true;
|
||||
*/
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||
Log.d(TAG,"onMenuItemSelected" + item.getItemId());
|
||||
@ -118,9 +110,27 @@ Simulations.OnSimulationSelectedListener
|
||||
|
||||
@Override
|
||||
public void onSimulationSelected(int simulationId) {
|
||||
Intent i = new Intent(this, SimulationViewer.class);
|
||||
i.putExtra("Simulation",simulationId);
|
||||
startActivity(i);
|
||||
View sidepane = findViewById(R.id.sidepane);
|
||||
if ( /* if multi pane */ sidepane != null ) {
|
||||
Simulation sim = app.getRocketDocument().getSimulation(simulationId);
|
||||
SimulationChart chart = new SimulationChart(simulationId);
|
||||
|
||||
Fragment graph = SimulationFragment.newInstance(chart);
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
|
||||
// probably only want to update back stack for first time.
|
||||
ft.addToBackStack("simulationplot");
|
||||
ft.replace(R.id.sidepane, graph);
|
||||
ft.show(graph);
|
||||
ft.commit();
|
||||
|
||||
|
||||
} else {
|
||||
Intent i = new Intent(this, SimulationViewActivity.class);
|
||||
i.putExtra("Simulation",simulationId);
|
||||
startActivity(i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
* Copyright (C) 2009, 2010 SC 4ViewSoft SRL
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import org.achartengine.ChartFactory;
|
||||
import org.achartengine.GraphicalView;
|
||||
import org.achartengine.chart.AbstractChart;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Window;
|
||||
|
||||
/**
|
||||
* An activity that encapsulates a graphical view of the chart.
|
||||
*/
|
||||
public class GraphicalActivity extends Activity {
|
||||
/** The encapsulated graphical view. */
|
||||
private GraphicalView mView;
|
||||
/** The chart to be drawn. */
|
||||
private AbstractChart mChart;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
Bundle extras = getIntent().getExtras();
|
||||
mChart = (AbstractChart) extras.getSerializable(ChartFactory.CHART);
|
||||
mView = new GraphicalView(this, mChart);
|
||||
String title = extras.getString(ChartFactory.TITLE);
|
||||
if (title == null) {
|
||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||
} else if (title.length() > 0) {
|
||||
setTitle(title);
|
||||
}
|
||||
setContentView(mView);
|
||||
}
|
||||
|
||||
}
|
@ -15,15 +15,16 @@
|
||||
*/
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.simulation.FlightDataBranch;
|
||||
import net.sf.openrocket.simulation.FlightDataType;
|
||||
import net.sf.openrocket.simulation.FlightEvent;
|
||||
import net.sf.openrocket.unit.Unit;
|
||||
|
||||
import org.achartengine.ChartFactory;
|
||||
import org.achartengine.chart.LineChart;
|
||||
import org.achartengine.chart.PointStyle;
|
||||
import org.achartengine.chart.XYChart;
|
||||
@ -32,78 +33,76 @@ import org.achartengine.model.XYSeries;
|
||||
import org.achartengine.renderer.XYMultipleSeriesRenderer;
|
||||
import org.achartengine.renderer.XYSeriesRenderer;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint.Align;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Multiple temperature demo chart.
|
||||
* This is really a flyweight object so we can serialize the
|
||||
* values behind a simulation chart. Since OpenRocketDocument, FlightDataBranch,
|
||||
* FlightDataType, Unit and all the other underlying types are not serializable,
|
||||
* we have to resort to persisting just the bare minimum of information.
|
||||
*
|
||||
* This also means without further changes to FlightDataType, we cannot actually
|
||||
* restore the displayed series.
|
||||
*
|
||||
* TODO make FlightDataBranch serializable or at least reconstructable from
|
||||
* from some the name.
|
||||
*
|
||||
*/
|
||||
public class SimulationChart {
|
||||
public class SimulationChart implements Serializable {
|
||||
|
||||
private final static String TAG = "SimulationChart";
|
||||
|
||||
private FlightDataBranch flightDataBranch;
|
||||
private FlightDataType series1;
|
||||
private FlightDataType series2;
|
||||
private final FlightDataType time = FlightDataType.TYPE_TIME;
|
||||
private List<FlightEvent> flightEvents;
|
||||
private String simulationName;
|
||||
|
||||
private final int simulationIndex;
|
||||
private transient FlightDataType series1;
|
||||
private transient FlightDataType series2;
|
||||
|
||||
// Define 4 different colors and point styles to use for the series.
|
||||
// For now only 2 series are supported though.
|
||||
private final static int[] colors = new int[] { Color.BLUE, Color.YELLOW, Color.GREEN, Color.RED };
|
||||
private final static PointStyle[] styles = new PointStyle[] { PointStyle.CIRCLE, PointStyle.DIAMOND,
|
||||
PointStyle.TRIANGLE, PointStyle.SQUARE };
|
||||
|
||||
/**
|
||||
* @param simulationName the simulationName to set
|
||||
*/
|
||||
public void setSimulationName(String simulationName) {
|
||||
this.simulationName = simulationName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flightDataBranch the flightDataBranch to set
|
||||
*/
|
||||
public void setFlightDataBranch(FlightDataBranch flightDataBranch) {
|
||||
this.flightDataBranch = flightDataBranch;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param series1 the series1 to set
|
||||
*/
|
||||
public void setSeries1(FlightDataType series1) {
|
||||
this.series1 = series1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param series2 the series2 to set
|
||||
*/
|
||||
public void setSeries2(FlightDataType series2) {
|
||||
this.series2 = series2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param flightEvents the flightEvents to set
|
||||
*/
|
||||
public void setFlightEvents(List<FlightEvent> flightEvents) {
|
||||
this.flightEvents = flightEvents;
|
||||
public SimulationChart(int simulationIndex) {
|
||||
super();
|
||||
this.simulationIndex = simulationIndex;
|
||||
}
|
||||
|
||||
private static String formatFlightDataTypeAxisLabel( FlightDataType fdt ) {
|
||||
return fdt.getName() + " (" + fdt.getUnitGroup().getDefaultUnit().toString() + ")";
|
||||
}
|
||||
|
||||
public void setSeries1(FlightDataType series1) {
|
||||
this.series1 = series1;
|
||||
}
|
||||
|
||||
public void setSeries2(FlightDataType series2) {
|
||||
this.series2 = series2;
|
||||
}
|
||||
|
||||
public FlightDataBranch getFlightDataBranch( OpenRocketDocument rocketDocument ) {
|
||||
Simulation sim = rocketDocument.getSimulation(simulationIndex);
|
||||
FlightDataBranch flightDataBranch = sim.getSimulatedData().getBranch(0);
|
||||
return flightDataBranch;
|
||||
}
|
||||
/**
|
||||
* Executes the chart demo.
|
||||
*
|
||||
* @param context the context
|
||||
* @return the built intent
|
||||
*/
|
||||
public Intent execute(Context context) {
|
||||
public XYChart buildChart(OpenRocketDocument rocketDocument) {
|
||||
|
||||
Simulation sim = rocketDocument.getSimulation(simulationIndex);
|
||||
FlightDataBranch flightDataBranch = sim.getSimulatedData().getBranch(0);
|
||||
FlightDataType time = FlightDataType.TYPE_TIME;
|
||||
if (series1== null) {
|
||||
series1 = flightDataBranch.getTypes()[1];
|
||||
}
|
||||
if (series2== null) {
|
||||
series2 = flightDataBranch.getTypes()[2];
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO -
|
||||
@ -126,7 +125,7 @@ public class SimulationChart {
|
||||
renderer.setYLabels(10);
|
||||
renderer.setShowGrid(true);
|
||||
renderer.setZoomButtonsVisible(true);
|
||||
renderer.setChartTitle(simulationName);
|
||||
renderer.setChartTitle(sim.getName());
|
||||
|
||||
renderer.setMargins(new int[] { 50, 30, 0, 20 });
|
||||
{
|
||||
@ -199,8 +198,9 @@ public class SimulationChart {
|
||||
|
||||
addXYSeries(dataset, series2.getName(), timevalues, series2values, 1);
|
||||
}
|
||||
Intent intent = getLineChartIntent(context, dataset, renderer,"Simulation");
|
||||
return intent;
|
||||
XYChart chart = new LineChart(dataset, renderer);
|
||||
|
||||
return chart;
|
||||
}
|
||||
|
||||
private static void addXYSeries(XYMultipleSeriesDataset dataset, String titles, List<Double> xValues, List<Double> yValues, int scale) {
|
||||
@ -213,16 +213,6 @@ public class SimulationChart {
|
||||
|
||||
}
|
||||
|
||||
private static Intent getLineChartIntent(Context context, XYMultipleSeriesDataset dataset,
|
||||
XYMultipleSeriesRenderer renderer, String activityTitle) {
|
||||
// checkParameters(dataset, renderer);
|
||||
Intent intent = new Intent(context, GraphicalActivity.class);
|
||||
XYChart chart = new LineChart(dataset, renderer);
|
||||
intent.putExtra(ChartFactory.CHART, chart);
|
||||
intent.putExtra(ChartFactory.TITLE, activityTitle);
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static double computeMaxValueWithPadding( List<Double> list ) {
|
||||
double max = list.get(0);
|
||||
for( double v : list ) {
|
||||
|
@ -0,0 +1,76 @@
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.simulation.FlightEvent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SimulationEventsDialog extends DialogFragment {
|
||||
|
||||
private SimulationChart chart;
|
||||
private ListView eventList;
|
||||
|
||||
public static SimulationEventsDialog newInstance( SimulationChart chart ) {
|
||||
SimulationEventsDialog d = new SimulationEventsDialog();
|
||||
d.chart = chart;
|
||||
return d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.simulation_event_dialog, container, false);
|
||||
|
||||
eventList = (ListView) v.findViewById(R.id.simulationEventsList);
|
||||
|
||||
OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();
|
||||
// Initialize the eventList
|
||||
ArrayAdapter<FlightEvent> events = new ArrayAdapter<FlightEvent>(
|
||||
getActivity(),
|
||||
android.R.layout.simple_list_item_1,
|
||||
chart.getFlightDataBranch(rocketDocument).getEvents() ) {
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView,
|
||||
ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if ( v == null ) {
|
||||
LayoutInflater li = inflater;
|
||||
v = li.inflate(android.R.layout.simple_list_item_1,null);
|
||||
}
|
||||
FlightEvent event = this.getItem(position);
|
||||
((TextView)v.findViewById(android.R.id.text1)).setText( event.getType().toString() + " " + event.getTime() + " (s)" );
|
||||
return v;
|
||||
}
|
||||
|
||||
};
|
||||
// Events are not selectable for plotting right now.
|
||||
//eventList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
eventList.setAdapter(events);
|
||||
return v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null ) {
|
||||
chart = (SimulationChart) savedInstanceState.getSerializable("chart");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle arg0) {
|
||||
super.onSaveInstanceState(arg0);
|
||||
arg0.putSerializable("chart", chart);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
|
||||
import org.achartengine.GraphicalView;
|
||||
import org.achartengine.chart.XYChart;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/**
|
||||
* An activity that encapsulates a graphical view of the chart.
|
||||
*/
|
||||
public class SimulationFragment extends Fragment implements SimulationSeriesDialog.OnConfirmListener {
|
||||
|
||||
SimulationChart chart;
|
||||
|
||||
ViewGroup container;
|
||||
|
||||
/** The encapsulated graphical view. */
|
||||
private GraphicalView mView;
|
||||
/** The chart to be drawn. */
|
||||
private XYChart mChart;
|
||||
|
||||
public static SimulationFragment newInstance( SimulationChart chart ) {
|
||||
SimulationFragment frag = new SimulationFragment();
|
||||
frag.chart = chart;
|
||||
return frag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
setRetainInstance(false);
|
||||
setHasOptionsMenu(true);
|
||||
OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();
|
||||
|
||||
this.container = container;
|
||||
if (savedInstanceState != null ) {
|
||||
chart = (SimulationChart) savedInstanceState.getSerializable("chart");
|
||||
}
|
||||
mChart = chart.buildChart(rocketDocument);
|
||||
mView = new GraphicalView(container.getContext(), mChart);
|
||||
return mView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
// TODO without the clear it seems to create multiple copies
|
||||
// of the menu items on orientation change.
|
||||
menu.clear();
|
||||
inflater.inflate(R.menu.simulation_option_menu, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.simulation_select_series_menu_option:
|
||||
SimulationSeriesDialog seriesDialog = SimulationSeriesDialog.newInstance(chart);
|
||||
seriesDialog.show(getFragmentManager(), "AbraCadaver");
|
||||
seriesDialog.setOnConfirmListener(this);
|
||||
return true;
|
||||
case R.id.simulation_select_events_menu_option:
|
||||
SimulationEventsDialog eventsDialog = SimulationEventsDialog.newInstance(chart);
|
||||
eventsDialog.show(getFragmentManager(), "AbraCadaver");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfirm() {
|
||||
OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();
|
||||
|
||||
mChart = chart.buildChart(rocketDocument);
|
||||
ViewGroup parent = (ViewGroup) mView.getParent();
|
||||
parent.removeView(mView);
|
||||
mView = new GraphicalView(container.getContext(), mChart);
|
||||
parent.addView(mView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putSerializable("chart", chart);
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,113 @@
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.simulation.FlightDataType;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SimulationSeriesDialog extends DialogFragment {
|
||||
|
||||
public interface OnConfirmListener {
|
||||
public void onConfirm();
|
||||
}
|
||||
|
||||
private Spinner series1Spinner;
|
||||
private Spinner series2Spinner;
|
||||
|
||||
private SimulationChart chart;
|
||||
private OnConfirmListener listener;
|
||||
|
||||
public static SimulationSeriesDialog newInstance( SimulationChart chart ) {
|
||||
SimulationSeriesDialog d = new SimulationSeriesDialog();
|
||||
d.chart = chart;
|
||||
return d;
|
||||
}
|
||||
|
||||
public void setOnConfirmListener(OnConfirmListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null ) {
|
||||
chart = (SimulationChart) savedInstanceState.getSerializable("chart");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle arg0) {
|
||||
super.onSaveInstanceState(arg0);
|
||||
arg0.putSerializable("chart", chart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.simulation_series_dialog, container, false);
|
||||
|
||||
OpenRocketDocument rocketDocument = ((Application)getActivity().getApplication()).getRocketDocument();
|
||||
|
||||
Button okButton = (Button) v.findViewById(R.id.simulationOkButton);
|
||||
okButton.setOnClickListener( new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
chart.setSeries1((FlightDataType)series1Spinner.getSelectedItem());
|
||||
chart.setSeries2((FlightDataType)series2Spinner.getSelectedItem());
|
||||
|
||||
if ( listener != null ) {
|
||||
listener.onConfirm();
|
||||
}
|
||||
SimulationSeriesDialog.this.dismiss();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
series1Spinner = (Spinner) v.findViewById(R.id.simulationSeries1);
|
||||
series2Spinner = (Spinner) v.findViewById(R.id.simulationSeries2);
|
||||
|
||||
List<FlightDataType> selectableSeries = new ArrayList<FlightDataType>();
|
||||
for( FlightDataType fdt : chart.getFlightDataBranch(rocketDocument).getTypes() ) {
|
||||
if ( fdt == FlightDataType.TYPE_TIME ) {
|
||||
|
||||
} else {
|
||||
selectableSeries.add(fdt);
|
||||
}
|
||||
}
|
||||
ArrayAdapter<FlightDataType> serieses = new ArrayAdapter<FlightDataType>(getActivity(),android.R.layout.simple_spinner_item,selectableSeries) {
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View v = convertView;
|
||||
if ( v == null ) {
|
||||
LayoutInflater li = inflater;
|
||||
v = li.inflate(android.R.layout.simple_spinner_item,null);
|
||||
}
|
||||
FlightDataType fdt = this.getItem(position);
|
||||
((TextView)v.findViewById(android.R.id.text1)).setText( fdt.toString() );
|
||||
return v;
|
||||
}
|
||||
|
||||
};
|
||||
series1Spinner.setAdapter(serieses);
|
||||
series2Spinner.setAdapter(serieses);
|
||||
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (C) 2009, 2010 SC 4ViewSoft SRL
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
||||
/**
|
||||
* An activity that encapsulates a graphical view of the chart.
|
||||
*/
|
||||
public class SimulationViewActivity extends FragmentActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
//setContentView(R.layout.simulation_graph_activity);
|
||||
int simulationNumber = getIntent().getIntExtra("Simulation", 0);
|
||||
|
||||
final OpenRocketDocument rocketDocument = ((Application)getApplication()).getRocketDocument();
|
||||
|
||||
Simulation sim = rocketDocument.getSimulation(simulationNumber);
|
||||
|
||||
SimulationChart chart = new SimulationChart( simulationNumber);
|
||||
chart.setSeries1(sim.getSimulatedData().getBranch(0).getTypes()[1]);
|
||||
chart.setSeries2(sim.getSimulatedData().getBranch(0).getTypes()[2]);
|
||||
|
||||
Fragment graph = SimulationFragment.newInstance(chart);
|
||||
|
||||
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
|
||||
ft.add(android.R.id.content, graph);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
}
|
@ -1,146 +0,0 @@
|
||||
package net.sf.openrocket.android.simulation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.Application;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.simulation.FlightDataBranch;
|
||||
import net.sf.openrocket.simulation.FlightDataType;
|
||||
import net.sf.openrocket.simulation.FlightEvent;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TabHost;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SimulationViewer extends Activity {
|
||||
|
||||
private final static String TAG = "SimulationViewer";
|
||||
|
||||
private ListView eventList;
|
||||
private Spinner series1Spinner;
|
||||
private Spinner series2Spinner;
|
||||
|
||||
private Simulation sim;
|
||||
private FlightDataBranch data;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Log.d(TAG,"onCreate Bundle = "+ String.valueOf(savedInstanceState));
|
||||
setContentView(R.layout.simulation_detail);
|
||||
|
||||
Intent i = getIntent();
|
||||
int simnumber = i.getIntExtra("Simulation", 0);
|
||||
sim = ((Application)this.getApplication()).getRocketDocument().getSimulation(simnumber);
|
||||
data = sim.getSimulatedData().getBranch(0);
|
||||
|
||||
TabHost tabs=(TabHost)findViewById(R.id.simulationConfigurationForm);
|
||||
|
||||
tabs.setup();
|
||||
|
||||
TabHost.TabSpec spec=tabs.newTabSpec("tag1");
|
||||
|
||||
spec.setContent(R.id.simulationEventsList);
|
||||
spec.setIndicator("Events");
|
||||
tabs.addTab(spec);
|
||||
|
||||
spec=tabs.newTabSpec("tag2");
|
||||
spec.setContent(R.id.simulationSeriesSelection);
|
||||
spec.setIndicator("Series");
|
||||
tabs.addTab(spec);
|
||||
|
||||
eventList = (ListView) findViewById(R.id.simulationEventsList);
|
||||
|
||||
// Initialize the eventList
|
||||
ArrayAdapter<FlightEvent> events = new ArrayAdapter<FlightEvent>(this,android.R.layout.simple_list_item_1,data.getEvents()) {
|
||||
|
||||
@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);
|
||||
}
|
||||
FlightEvent event = this.getItem(position);
|
||||
((TextView)v.findViewById(android.R.id.text1)).setText( event.getType().toString() + " " + event.getTime() + " (s)" );
|
||||
return v;
|
||||
}
|
||||
|
||||
};
|
||||
// Events are not selectable for plotting right now.
|
||||
//eventList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||
eventList.setAdapter(events);
|
||||
|
||||
series1Spinner = (Spinner) findViewById(R.id.simulationSeries1);
|
||||
series2Spinner = (Spinner) findViewById(R.id.simulationSeries2);
|
||||
|
||||
List<FlightDataType> selectableSeries = new ArrayList<FlightDataType>();
|
||||
for( FlightDataType fdt : data.getTypes() ) {
|
||||
if ( fdt == FlightDataType.TYPE_TIME ) {
|
||||
|
||||
} else {
|
||||
selectableSeries.add(fdt);
|
||||
}
|
||||
}
|
||||
ArrayAdapter<FlightDataType> serieses = new ArrayAdapter<FlightDataType>(this,android.R.layout.simple_spinner_item,selectableSeries) {
|
||||
|
||||
@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_spinner_item,null);
|
||||
}
|
||||
FlightDataType fdt = this.getItem(position);
|
||||
((TextView)v.findViewById(android.R.id.text1)).setText( fdt.toString() );
|
||||
return v;
|
||||
}
|
||||
|
||||
};
|
||||
series1Spinner.setAdapter(serieses);
|
||||
series2Spinner.setAdapter(serieses);
|
||||
|
||||
}
|
||||
|
||||
public void draw( View v ) {
|
||||
List<FlightEvent> eventsToShow = new ArrayList<FlightEvent>();
|
||||
/* Events are not selectable for plotting right now.
|
||||
{
|
||||
SparseBooleanArray eventsSelected = eventList.getCheckedItemPositions();
|
||||
List<FlightEvent> flightEvents = data.getEvents();
|
||||
for( int i=0; i< flightEvents.size(); i++ ) {
|
||||
if ( eventsSelected.get(i) ) {
|
||||
eventsToShow.add(flightEvents.get(i) );
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
FlightDataType series1 = (FlightDataType) series1Spinner.getSelectedItem();
|
||||
Log.d(TAG,"sereis1 = " + series1.toString());
|
||||
FlightDataType series2 = (FlightDataType) series2Spinner.getSelectedItem();
|
||||
Log.d(TAG,"series2 = " + series2.toString());
|
||||
|
||||
SimulationChart chart = new SimulationChart();
|
||||
chart.setSimulationName( sim.getName() );
|
||||
chart.setFlightDataBranch(data);
|
||||
chart.setSeries1(series1);
|
||||
chart.setSeries2(series2);
|
||||
chart.setFlightEvents(eventsToShow);
|
||||
|
||||
startActivity(chart.execute(this));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user