Show events and times on the chart. The achartengine needs some work to get the labels in a better place. Enhance the SimulationSeriesDialog to allow selection of events.

This commit is contained in:
Kevin Ruland 2012-06-30 19:08:13 +00:00
parent 3f957e56d3
commit c5122ebef5
5 changed files with 107 additions and 18 deletions

View File

@ -5,11 +5,13 @@
android:orientation="vertical" >
<!-- shim to get dialog correct size ?? -->
<!--
<View
android:layout_width="200dp"
android:layout_height="0px"
android:layout_margin="0px"
android:orientation="horizontal" />
-->
<TextView
android:layout_width="match_parent"
@ -33,10 +35,16 @@
android:layout_height="wrap_content"
android:drawSelectorOnTop="true" />
<ListView
android:id="@+id/simulationEventsList"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<Button
android:id="@+id/simulationOkButton"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_height="45dp"
android:layout_gravity="center_horizontal"
android:text="ok" />

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingLeft="8dip"
android:paddingRight="8dip"
/>

View File

@ -10,8 +10,9 @@
<string name="Download">Download</string>
<string name="About">About</string>
<string name="Preferences">Preferences</string>
<string name="select_series">Select Series</string>
<string name="select_series">Change Plot</string>
<string name="view_events">View Events</string>
<string name="simulationPlotDialogTitle">Select Series And Events</string>
<string-array name="PreferenceMotorBrowserGroupingEntries">
<item>Case</item>

View File

@ -17,13 +17,16 @@ package net.sf.openrocket.android.simulation;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.openrocket.android.util.AndroidLogWrapper;
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.chart.LineChart;
@ -55,6 +58,7 @@ public class SimulationChart implements Serializable {
private final int simulationIndex;
private transient FlightDataType series1;
private transient FlightDataType series2;
private transient Map<Double,String> events;
// Define 4 different colors and point styles to use for the series.
// For now only 2 series are supported though.
@ -79,6 +83,10 @@ public class SimulationChart implements Serializable {
this.series2 = series2;
}
public void setEvents( Map<Double,String> events ) {
this.events = events;
}
public FlightDataBranch getFlightDataBranch( OpenRocketDocument rocketDocument ) {
Simulation sim = rocketDocument.getSimulation(simulationIndex);
FlightDataBranch flightDataBranch = sim.getSimulatedData().getBranch(0);
@ -102,6 +110,13 @@ public class SimulationChart implements Serializable {
series2 = flightDataBranch.getTypes()[2];
}
if ( events == null ) {
events = new HashMap<Double,String>();
for ( FlightEvent event : flightDataBranch.getEvents() ) {
events.put(event.getTime(), event.getType().toString() );
}
}
/*
* TODO -
* Figure out why you can pan all over the place even where there are no visible points.
@ -124,6 +139,12 @@ public class SimulationChart implements Serializable {
renderer.setShowGrid(true);
renderer.setZoomButtonsVisible(true);
renderer.setChartTitle(sim.getName());
renderer.setShowCustomTextGrid(true);
renderer.setXLabelsAlign(Align.RIGHT);
renderer.setXLabelsAngle(90); // rotate right
for( Map.Entry<Double,String> event : events.entrySet() ) {
renderer.addXTextLabel(event.getKey(), event.getValue());
}
renderer.setMargins(new int[] { 50, 30, 0, 20 });
{

View File

@ -1,19 +1,27 @@
package net.sf.openrocket.android.simulation;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.openrocket.R;
import net.sf.openrocket.android.CurrentRocketHolder;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.simulation.FlightDataBranch;
import net.sf.openrocket.simulation.FlightDataType;
import net.sf.openrocket.simulation.FlightEvent;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.SparseBooleanArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
@ -23,6 +31,7 @@ public class SimulationSeriesDialog extends DialogFragment {
public void onConfirm();
}
private ListView eventList;
private Spinner series1Spinner;
private Spinner series2Spinner;
@ -40,23 +49,17 @@ public class SimulationSeriesDialog extends DialogFragment {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
public Dialog onCreateDialog(Bundle savedInstanceState) {
if (savedInstanceState != null ) {
chart = (SimulationChart) savedInstanceState.getSerializable("chart");
}
}
@Override
public void onSaveInstanceState(Bundle arg0) {
super.onSaveInstanceState(arg0);
arg0.putSerializable("chart", chart);
}
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.simulationPlotDialogTitle);
@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.simulation_series_dialog, container, false);
final LayoutInflater inflater = getActivity().getLayoutInflater();
View v = inflater.inflate(R.layout.simulation_series_dialog, null);
builder.setView(v);
OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
@ -65,6 +68,19 @@ public class SimulationSeriesDialog extends DialogFragment {
@Override
public void onClick(View v) {
Map<Double,String> eventsToShow = new HashMap<Double,String>();
{
SparseBooleanArray eventsSelected = eventList.getCheckedItemPositions();
List<FlightEvent> flightEvents = chart.getFlightDataBranch(CurrentRocketHolder.getCurrentRocket().getRocketDocument()).getEvents();
for( int i=0; i< flightEvents.size(); i++ ) {
if ( eventsSelected.get(i) ) {
FlightEvent event = flightEvents.get(i);
eventsToShow.put( event.getTime(), event.getType().toString());
}
}
}
chart.setEvents(eventsToShow);
chart.setSeries1((FlightDataType)series1Spinner.getSelectedItem());
chart.setSeries2((FlightDataType)series2Spinner.getSelectedItem());
@ -103,10 +119,42 @@ public class SimulationSeriesDialog extends DialogFragment {
};
series1Spinner.setAdapter(serieses);
series1Spinner.setSelection(0);
series2Spinner.setAdapter(serieses);
series2Spinner.setSelection(1);
eventList = (ListView) v.findViewById(R.id.simulationEventsList);
FlightDataBranch data = chart.getFlightDataBranch(CurrentRocketHolder.getCurrentRocket().getRocketDocument());
// Initialize the eventList
ArrayAdapter<FlightEvent> events = new ArrayAdapter<FlightEvent>(getActivity(),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 = inflater;
v = li.inflate(android.R.layout.simple_list_item_multiple_choice,null);
}
FlightEvent event = this.getItem(position);
((TextView)v.findViewById(android.R.id.text1)).setText( event.getType().toString() + " " + event.getTime() + " (s)" );
return v;
}
};
eventList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
eventList.setAdapter(events);
return builder.create();
}
@Override
public void onSaveInstanceState(Bundle arg0) {
super.onSaveInstanceState(arg0);
arg0.putSerializable("chart", chart);
}
}