Added local foreground service which runs simulations. Wired into the SimulationEditFragment.
This commit is contained in:
parent
63290b98e4
commit
0250f29f26
@ -77,8 +77,11 @@
|
||||
<activity
|
||||
android:name=".android.simulation.SimulationViewActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar" />
|
||||
<activity android:name=".android.filebrowser.SimpleFileBrowser"
|
||||
<activity
|
||||
android:name=".android.filebrowser.SimpleFileBrowser"
|
||||
android:theme="@style/Theme.Sherlock.Dialog" />
|
||||
|
||||
<service android:name=".android.simservice.SimulationService" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -44,7 +44,7 @@
|
||||
android:text="@string/simulationConditionsLaunchRodAngle" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simulation_condition_roddirection"
|
||||
android:id="@+id/simulation_condition_rodangle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
@ -59,7 +59,7 @@
|
||||
android:text="@string/simulationConditionsLaunchRodDirection" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/simulation_condition_rodangle"
|
||||
android:id="@+id/simulation_condition_roddirection"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
|
@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="SimulationServiceNotificationID"></string>
|
||||
<string name="PreferenceMotorBrowserGroupingOption">PreferenceMotorBrowserGroupingOption</string>
|
||||
<string name="PreferenceUseInternalFileBrowserOption">PreferenceUseInternalFileBrowserOpion</string>
|
||||
<string name="PreferenceFileBrowserBaseDirectory">PreferenceFileBrowserBaseDirectory</string>
|
||||
|
@ -3,6 +3,8 @@ package net.sf.openrocket.android.rocket;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.CurrentRocketHolder;
|
||||
import net.sf.openrocket.android.simservice.SimulationService;
|
||||
import net.sf.openrocket.android.simservice.SimulationTask;
|
||||
import net.sf.openrocket.document.OpenRocketDocument;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.simulation.SimulationOptions;
|
||||
@ -59,13 +61,20 @@ public class SimulationEditFragment extends SherlockDialogFragment {
|
||||
|
||||
Button deleteButton = (Button) v.findViewById(R.id.simulationConditionDelete);
|
||||
deleteButton.setOnClickListener( new OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onDelete();
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Button runButton = (Button) v.findViewById(R.id.simulationConditionRun);
|
||||
runButton.setOnClickListener( new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onRun();
|
||||
}
|
||||
});
|
||||
|
||||
windspeedField = (EditText) v.findViewById(R.id.simulation_condition_windspeed);
|
||||
rodlengthField = (EditText) v.findViewById(R.id.simulation_condition_rodlength);
|
||||
rodangleField = (EditText) v.findViewById(R.id.simulation_condition_rodangle);
|
||||
@ -83,8 +92,8 @@ public class SimulationEditFragment extends SherlockDialogFragment {
|
||||
if ( options != null ) {
|
||||
windspeedField.setText( UnitGroup.UNITS_VELOCITY.toString( options.getWindSpeedAverage() ));
|
||||
rodlengthField.setText( UnitGroup.UNITS_LENGTH.toString( options.getLaunchRodLength() ));
|
||||
rodangleField.setText( String.valueOf( options.getLaunchRodLength() ));
|
||||
roddirectionField.setText( String.valueOf( options.getLaunchRodDirection() ));
|
||||
rodangleField.setText( UnitGroup.UNITS_ANGLE.toString( options.getLaunchRodAngle() ));
|
||||
roddirectionField.setText( UnitGroup.UNITS_ANGLE.toString( options.getLaunchRodDirection() ));
|
||||
motorSpinner.setSelectedConfiguration(options.getMotorConfigurationID());
|
||||
}
|
||||
|
||||
@ -103,4 +112,20 @@ public class SimulationEditFragment extends SherlockDialogFragment {
|
||||
getDialog().dismiss();
|
||||
}
|
||||
|
||||
public void onRun() {
|
||||
|
||||
OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
|
||||
Simulation sim = rocketDocument.getSimulation(simulationId);
|
||||
SimulationOptions options = sim.getOptions();
|
||||
|
||||
options.setWindSpeedAverage( UnitGroup.UNITS_VELOCITY.fromUnit(Double.parseDouble( windspeedField.getText().toString() )));
|
||||
options.setLaunchRodLength( UnitGroup.UNITS_LENGTH.fromUnit(Double.parseDouble( rodlengthField.getText().toString() )));
|
||||
options.setLaunchRodAngle( UnitGroup.UNITS_ANGLE.fromUnit(Double.parseDouble( rodangleField.getText().toString() )));
|
||||
options.setLaunchRodDirection( UnitGroup.UNITS_ANGLE.fromUnit(Double.parseDouble( roddirectionField.getText().toString() )));
|
||||
options.setMotorConfigurationID( motorSpinner.getSelectedConfiguration() );
|
||||
|
||||
SimulationTask t = new SimulationTask(simulationId);
|
||||
SimulationService.executeSimulationTask(getActivity(), t);
|
||||
getDialog().dismiss();
|
||||
}
|
||||
}
|
@ -0,0 +1,85 @@
|
||||
package net.sf.openrocket.android.simservice;
|
||||
|
||||
import net.sf.openrocket.R;
|
||||
import net.sf.openrocket.android.CurrentRocketHolder;
|
||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||
import net.sf.openrocket.document.Simulation;
|
||||
import net.sf.openrocket.simulation.exception.SimulationException;
|
||||
import android.app.IntentService;
|
||||
import android.app.Notification;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class SimulationService extends IntentService {
|
||||
|
||||
// We use an id (from a dummy string) as the notificationID because it is unique.
|
||||
private final static int notificationID = R.string.SimulationServiceNotificationID;
|
||||
|
||||
private Notification notification;
|
||||
|
||||
public static void executeSimulationTask( Context c, SimulationTask t ) {
|
||||
AndroidLogWrapper.d(SimulationService.class, "Submitting simulation " + t.simulationId );
|
||||
|
||||
Intent intent = new Intent( c, SimulationService.class );
|
||||
intent.putExtra("net.sf.openrocket.simulationtask", t);
|
||||
c.startService(intent);
|
||||
}
|
||||
|
||||
public SimulationService() {
|
||||
super("OpenRocket Simulation Execution Service");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onHandleIntent(Intent intent) {
|
||||
SimulationTask t = (SimulationTask) intent.getSerializableExtra("net.sf.openrocket.simulationtask");
|
||||
try {
|
||||
Simulation sim = CurrentRocketHolder.getCurrentRocket().getRocketDocument().getSimulation(t.simulationId);
|
||||
AndroidLogWrapper.d(SimulationService.class, "simulating " + t.simulationId );
|
||||
sim.simulate();
|
||||
CurrentRocketHolder.getCurrentRocket().notifySimsChanged();
|
||||
}
|
||||
catch (SimulationException simex) {
|
||||
Toast.makeText(this, "Error in simulation:" + simex.getMessage(), Toast.LENGTH_LONG ).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
this.notification = buildNotification();
|
||||
startForeground(notificationID, notification);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
private Notification buildNotification( ) {
|
||||
String message = "OpenRocket Simulation Execution";
|
||||
Notification notification = new Notification(R.drawable.or_launcher, message, System.currentTimeMillis());
|
||||
|
||||
notification.flags = Notification.FLAG_NO_CLEAR;
|
||||
PendingIntent contentIntent = PendingIntent.getActivity( this, 0 , new Intent( ), PendingIntent.FLAG_UPDATE_CURRENT );
|
||||
notification.setLatestEventInfo(this, "OpenRocket", message, contentIntent);
|
||||
return notification;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package net.sf.openrocket.android.simservice;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class SimulationTask implements Serializable {
|
||||
|
||||
int simulationId;
|
||||
|
||||
public SimulationTask(int simulationId) {
|
||||
this.simulationId = simulationId;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user