Wire in save for OpenRocketDocument.

This commit is contained in:
Kevin Ruland 2012-05-15 23:01:39 +00:00
parent 00519d820a
commit 00696ce7a3
5 changed files with 49 additions and 16 deletions

View File

@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_save"
android:title="@string/save"/>
<item
android:id="@+id/motor_list_menu_option"
android:icon="@drawable/ic_motorbrowser"

View File

@ -0,0 +1,2 @@
build.version=12.03-droid-DEV
build.source=source

View File

@ -1,24 +1,30 @@
package net.sf.openrocket.android;
import java.io.File;
import java.io.IOException;
import java.util.Locale;
import net.sf.openrocket.aerodynamics.WarningSet;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.database.ComponentPresetDatabase;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.file.openrocket.OpenRocketSaver;
import net.sf.openrocket.l10n.DebugTranslator;
import net.sf.openrocket.l10n.ResourceBundleTranslator;
import net.sf.openrocket.l10n.Translator;
import android.net.Uri;
import android.preference.PreferenceManager;
public class Application extends android.app.Application {
private OpenRocketDocument rocketDocument;
private Uri fileUri;
private WarningSet warnings;
// Big B boolean so I can synchronize on it.
private static Boolean initialized = false;
public void initialize() {
synchronized (initialized) {
if ( initialized == true ) {
@ -29,21 +35,21 @@ public class Application extends android.app.Application {
System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
net.sf.openrocket.startup.Application.setLogger( new AndroidLogWrapper.LogHelper() );
net.sf.openrocket.startup.Application.setPreferences( new PreferencesAdapter() );
net.sf.openrocket.startup.Application.setComponentPresetDao( new ComponentPresetDatabase() );
MotorDatabaseAdapter db = new MotorDatabaseAdapter(this);
net.sf.openrocket.startup.Application.setMotorSetDatabase(db);
Translator t;
t = new ResourceBundleTranslator("l10n.messages");
if (Locale.getDefault().getLanguage().equals("xx")) {
t = new DebugTranslator(t);
}
net.sf.openrocket.startup.Application.setBaseTranslator(t);
initialized = true;
@ -84,7 +90,18 @@ public class Application extends android.app.Application {
public void setWarnings(WarningSet warnings) {
this.warnings = warnings;
}
public Uri getFileUri() {
return fileUri;
}
public void setFileUri(Uri fileUri) {
this.fileUri = fileUri;
}
public void saveOpenRocketDocument() throws IOException {
OpenRocketSaver saver = new OpenRocketSaver();
saver.save(new File(fileUri.getPath()),rocketDocument);
}
}

View File

@ -46,6 +46,7 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
}
private void loadOrkFile( Uri file ) {
((Application)getApplication()).setFileUri( file );
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
String path = file.getPath();
File orkFile = new File(path);

View File

@ -1,6 +1,8 @@
package net.sf.openrocket.android.rocket;
import java.io.IOException;
import net.sf.openrocket.R;
import net.sf.openrocket.android.ActivityHelpers;
import net.sf.openrocket.android.Application;
@ -37,13 +39,13 @@ implements Simulations.OnSimulationSelectedListener
setContentView(R.layout.openrocketviewer);
ViewPager viewPager = (ViewPager)findViewById(R.id.pager);
viewPager.setAdapter( new OpenRocketViewerPager( this.getSupportFragmentManager()));
setTitle(app.getRocketDocument().getRocket().getName());
getActionBarHelper().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
@ -55,6 +57,14 @@ implements Simulations.OnSimulationSelectedListener
public boolean onMenuItemSelected(int featureId, MenuItem item) {
AndroidLogWrapper.d(OpenRocketViewer.class,"onMenuItemSelected" + item.getItemId());
switch(item.getItemId()) {
case R.id.menu_save:
// FIXME - Probably want to open a dialog here.
try {
((Application)getApplication()).saveOpenRocketDocument();
} catch ( IOException iex ) {
AndroidLogWrapper.d(OpenRocketViewer.class, iex.getMessage());
}
return true;
case android.R.id.home:
ActivityHelpers.goHome(this);
return true;
@ -73,7 +83,7 @@ implements Simulations.OnSimulationSelectedListener
@Override
public void onSimulationSelected(int simulationId) {
Simulation sim = app.getRocketDocument().getSimulation(simulationId);
// Check if there is data for this simulation.
if ( sim.getSimulatedData().getBranchCount() == 0 ) {
@ -83,7 +93,7 @@ implements Simulations.OnSimulationSelectedListener
builder.show();
return;
}
View sidepane = findViewById(R.id.sidepane);
if ( /* if multi pane */ sidepane != null ) {
SimulationChart chart = new SimulationChart(simulationId);