1 package net.sf.openrocket.android;
\r
4 import java.io.IOException;
\r
5 import java.util.Locale;
\r
7 import net.sf.openrocket.aerodynamics.WarningSet;
\r
8 import net.sf.openrocket.android.util.AndroidLogWrapper;
\r
9 import net.sf.openrocket.database.ComponentPresetDatabase;
\r
10 import net.sf.openrocket.document.OpenRocketDocument;
\r
11 import net.sf.openrocket.document.Simulation;
\r
12 import net.sf.openrocket.file.openrocket.OpenRocketSaver;
\r
13 import net.sf.openrocket.l10n.DebugTranslator;
\r
14 import net.sf.openrocket.l10n.ResourceBundleTranslator;
\r
15 import net.sf.openrocket.l10n.Translator;
\r
16 import net.sf.openrocket.rocketcomponent.Rocket;
\r
17 import android.content.pm.ApplicationInfo;
\r
18 import android.net.Uri;
\r
19 import android.preference.PreferenceManager;
\r
21 public class Application extends android.app.Application {
\r
23 private OpenRocketDocument rocketDocument;
\r
24 private Uri fileUri;
\r
26 private WarningSet warnings;
\r
28 // Big B boolean so I can synchronize on it.
\r
29 private static Boolean initialized = false;
\r
31 public void initialize() {
\r
32 synchronized (initialized) {
\r
33 if ( initialized == true ) {
\r
37 // Android does not have a default sax parser set. This needs to be defined first.
\r
38 System.setProperty("org.xml.sax.driver","org.xmlpull.v1.sax2.Driver");
\r
40 net.sf.openrocket.startup.Application.setLogger( new AndroidLogWrapper.LogHelper() );
\r
42 net.sf.openrocket.startup.Application.setPreferences( new PreferencesAdapter() );
\r
44 net.sf.openrocket.startup.Application.setComponentPresetDao( new ComponentPresetDatabase() );
\r
46 MotorDatabaseAdapter db = new MotorDatabaseAdapter(this);
\r
48 net.sf.openrocket.startup.Application.setMotorSetDatabase(db);
\r
51 t = new ResourceBundleTranslator("l10n.messages");
\r
52 if (Locale.getDefault().getLanguage().equals("xx")) {
\r
53 t = new DebugTranslator(t);
\r
56 net.sf.openrocket.startup.Application.setBaseTranslator(t);
\r
62 public Application() {
\r
66 * @see android.app.Application#onCreate()
\r
69 public void onCreate() {
\r
72 boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
\r
73 AndroidLogWrapper.setLogEnabled(isDebuggable);
\r
74 PreferencesActivity.initializePreferences(this, PreferenceManager.getDefaultSharedPreferences(this));
\r
77 private RocketChangedEventHandler handler;
\r
79 public void setHandler( RocketChangedEventHandler handler ) {
\r
80 this.handler = handler;
\r
84 * @return the rocketDocument
\r
86 public OpenRocketDocument getRocketDocument() {
\r
87 return rocketDocument;
\r
90 public void addNewSimulation() {
\r
91 Rocket rocket = rocketDocument.getRocket();
\r
92 Simulation newSim = new Simulation(rocket);
\r
93 newSim.setName(rocketDocument.getNextSimulationName());
\r
94 rocketDocument.addSimulation(newSim);
\r
95 if ( handler != null ) {
\r
96 handler.simsChangedMessage();
\r
100 public void deleteSimulation( int simulationPos ) {
\r
101 rocketDocument.removeSimulation( simulationPos );
\r
102 if ( handler != null ) {
\r
103 handler.simsChangedMessage();
\r
107 public String addNewMotorConfig() {
\r
108 String configId = rocketDocument.getRocket().newMotorConfigurationID();
\r
109 if ( handler != null ) {
\r
110 handler.configsChangedMessage();
\r
115 * @param rocketDocument the rocketDocument to set
\r
117 public void setRocketDocument(OpenRocketDocument rocketDocument) {
\r
118 this.rocketDocument = rocketDocument;
\r
121 public WarningSet getWarnings() {
\r
125 public void setWarnings(WarningSet warnings) {
\r
126 this.warnings = warnings;
\r
129 public Uri getFileUri() {
\r
133 public void setFileUri(Uri fileUri) {
\r
134 this.fileUri = fileUri;
\r
137 public void saveOpenRocketDocument() throws IOException {
\r
138 OpenRocketSaver saver = new OpenRocketSaver();
\r
139 saver.save(new File(fileUri.getPath()),rocketDocument);
\r