Change the initial screen handling and add file load to OpenRocketViewer activity. The OpenRocketLoaderActivity is now used as a base class for the OpenRocketViewer and Main activities. These activities now share the code used for loading ork files. The OpenRocketLoaderActivity no longer is registered in the manifest because it is not a real activity any more. The OpenRocketViewer activity now has a menu item for "load" to load a new model. The Main activity uses finish() when it transfers control to the OpenRocketViewer thus removing it from the back stack. Further, if the Main activity detects that the Application contains a rocket, it will automatically forward to the OpenRocketViewer.
This commit is contained in:
parent
72ce4f8468
commit
1f0bcf6730
@ -25,11 +25,6 @@
|
|||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
|
||||||
<activity
|
|
||||||
android:name=".android.rocket.OpenRocketLoaderActivity"
|
|
||||||
android:theme="@style/AppTheme.NoActionBar" >
|
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
I don't understand why I need to have two different intent filters.
|
I don't understand why I need to have two different intent filters.
|
||||||
Combining the <data> elements into a single field did not result in a working
|
Combining the <data> elements into a single field did not result in a working
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_load"
|
||||||
|
android:title="@string/load"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_save"
|
android:id="@+id/menu_save"
|
||||||
android:title="@string/save"/>
|
android:title="@string/save"/>
|
||||||
|
@ -2,7 +2,8 @@
|
|||||||
<resources>
|
<resources>
|
||||||
|
|
||||||
<string name="app_name">OpenRocket</string>
|
<string name="app_name">OpenRocket</string>
|
||||||
<string name="version">version 12.07-a1</string>
|
<string name="version">version 12.07-b2</string>
|
||||||
|
<string name="load">Load</string>
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="Add">Add</string>
|
<string name="Add">Add</string>
|
||||||
<string name="MotorListTitle">Motor List</string>
|
<string name="MotorListTitle">Motor List</string>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
android:title="@string/motorbrowsergrouptitle" />
|
android:title="@string/motorbrowsergrouptitle" />
|
||||||
|
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="true"
|
||||||
android:title="@string/useinternalfilebrowsertitle"
|
android:title="@string/useinternalfilebrowsertitle"
|
||||||
android:key="@string/PreferenceUseInternalFileBrowserOption"
|
android:key="@string/PreferenceUseInternalFileBrowserOption"
|
||||||
android:summary="@string/useinternalfilebrowsersummary"
|
android:summary="@string/useinternalfilebrowsersummary"
|
||||||
|
@ -1,30 +1,27 @@
|
|||||||
package net.sf.openrocket.android;
|
package net.sf.openrocket.android;
|
||||||
|
|
||||||
import net.sf.openrocket.R;
|
import net.sf.openrocket.R;
|
||||||
import net.sf.openrocket.android.filebrowser.SimpleFileBrowser;
|
import net.sf.openrocket.android.rocket.OpenRocketLoaderActivity;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class Main extends SherlockFragmentActivity {
|
public class Main extends OpenRocketLoaderActivity {
|
||||||
|
|
||||||
private static final int PICK_ORK_FILE_RESULT = 1;
|
|
||||||
|
|
||||||
/** Called when the activity is first created. */
|
/** Called when the activity is first created. */
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
// Rocket already loaded. go to viewer.
|
||||||
|
if ( CurrentRocketHolder.getCurrentRocket().getRocketDocument() != null ) {
|
||||||
|
moveOnToViewer();
|
||||||
|
finish();
|
||||||
|
}
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
((Button) findViewById(R.id.main_open)).setOnClickListener(
|
((Button) findViewById(R.id.main_open)).setOnClickListener(
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
@ -69,55 +66,4 @@ public class Main extends SherlockFragmentActivity {
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
switch ( requestCode ) {
|
|
||||||
case PICK_ORK_FILE_RESULT:
|
|
||||||
if(resultCode==RESULT_OK){
|
|
||||||
Uri file = data.getData();
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
intent.setData(file);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void pickOrkFiles( ) {
|
|
||||||
Resources resources = this.getResources();
|
|
||||||
String key = resources.getString(R.string.PreferenceUseInternalFileBrowserOption);
|
|
||||||
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
|
||||||
|
|
||||||
boolean useinternalbrowser = pref.getBoolean(key, false);
|
|
||||||
|
|
||||||
if ( useinternalbrowser ) {
|
|
||||||
Intent intent = new Intent(Main.this, SimpleFileBrowser.class);
|
|
||||||
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
|
||||||
intent.setType("file/*");
|
|
||||||
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
|
||||||
} catch ( ActivityNotFoundException ex ) {
|
|
||||||
// No activity for ACTION_GET_CONTENT use internal file browser
|
|
||||||
// update the preference value.
|
|
||||||
pref.edit().putBoolean(key, false).commit();
|
|
||||||
// fire our browser
|
|
||||||
Intent intent = new Intent(Main.this, SimpleFileBrowser.class);
|
|
||||||
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void pickOrkFiles( View v ) {
|
|
||||||
pickOrkFiles();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void browseMotors( View v ) {
|
|
||||||
ActivityHelpers.browseMotors(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -6,16 +6,21 @@ import java.util.Set;
|
|||||||
import net.sf.openrocket.R;
|
import net.sf.openrocket.R;
|
||||||
import net.sf.openrocket.aerodynamics.WarningSet;
|
import net.sf.openrocket.aerodynamics.WarningSet;
|
||||||
import net.sf.openrocket.android.CurrentRocketHolder;
|
import net.sf.openrocket.android.CurrentRocketHolder;
|
||||||
|
import net.sf.openrocket.android.filebrowser.SimpleFileBrowser;
|
||||||
import net.sf.openrocket.android.thrustcurve.TCMissingMotorDownloadAction;
|
import net.sf.openrocket.android.thrustcurve.TCMissingMotorDownloadAction;
|
||||||
import net.sf.openrocket.android.thrustcurve.TCQueryAction;
|
import net.sf.openrocket.android.thrustcurve.TCQueryAction;
|
||||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
|
import net.sf.openrocket.motor.ThrustCurveMotorPlaceholder;
|
||||||
import net.sf.openrocket.rocketcomponent.Rocket;
|
import net.sf.openrocket.rocketcomponent.Rocket;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||||
@ -24,15 +29,18 @@ public class OpenRocketLoaderActivity extends SherlockFragmentActivity
|
|||||||
implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnOpenRocketFileLoaded
|
implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnOpenRocketFileLoaded
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private static final int PICK_ORK_FILE_RESULT = 1;
|
||||||
|
|
||||||
private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";
|
private final static String MISSING_MOTOR_DIAG_FRAGMENT_TAG = "missingmotordialog";
|
||||||
private final static String MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG = "missingmotortask";
|
private final static String MISSING_MOTOR_DOWNLOAD_FRAGMENT_TAG = "missingmotortask";
|
||||||
|
|
||||||
|
private boolean isLoading = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
Intent i = getIntent();
|
||||||
if ( savedInstanceState == null || savedInstanceState.getBoolean("isLoading", false) == false ) {
|
if (Intent.ACTION_VIEW.equals(i.getAction()) && i.getData() != null ) {
|
||||||
Intent i = getIntent();
|
|
||||||
Uri file = i.getData();
|
Uri file = i.getData();
|
||||||
loadOrkFile(file);
|
loadOrkFile(file);
|
||||||
} else {
|
} else {
|
||||||
@ -42,10 +50,54 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putBoolean("isLoading", true);
|
outState.putBoolean("isLoading", isLoading);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
switch ( requestCode ) {
|
||||||
|
case PICK_ORK_FILE_RESULT:
|
||||||
|
if(resultCode==RESULT_OK){
|
||||||
|
Uri file = data.getData();
|
||||||
|
loadOrkFile(file);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void pickOrkFiles( ) {
|
||||||
|
Resources resources = this.getResources();
|
||||||
|
String key = resources.getString(R.string.PreferenceUseInternalFileBrowserOption);
|
||||||
|
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
|
boolean useinternalbrowser = pref.getBoolean(key, true);
|
||||||
|
|
||||||
|
if ( useinternalbrowser ) {
|
||||||
|
Intent intent = new Intent(OpenRocketLoaderActivity.this, SimpleFileBrowser.class);
|
||||||
|
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
|
intent.setType("file/*");
|
||||||
|
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
||||||
|
} catch ( ActivityNotFoundException ex ) {
|
||||||
|
// No activity for ACTION_GET_CONTENT use internal file browser
|
||||||
|
// update the preference value.
|
||||||
|
pref.edit().putBoolean(key, false).commit();
|
||||||
|
// fire our browser
|
||||||
|
Intent intent = new Intent(OpenRocketLoaderActivity.this, SimpleFileBrowser.class);
|
||||||
|
startActivityForResult(intent,PICK_ORK_FILE_RESULT);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadOrkFile( Uri file ) {
|
private void loadOrkFile( Uri file ) {
|
||||||
|
isLoading = true;
|
||||||
CurrentRocketHolder.getCurrentRocket().setFileUri( file );
|
CurrentRocketHolder.getCurrentRocket().setFileUri( file );
|
||||||
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
|
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Use ork file: " + file);
|
||||||
String path = file.getPath();
|
String path = file.getPath();
|
||||||
@ -62,6 +114,7 @@ implements TCQueryAction.OnTCQueryCompleteListener, OpenRocketLoaderFragment.OnO
|
|||||||
* @param result
|
* @param result
|
||||||
*/
|
*/
|
||||||
public void onOpenRocketFileLoaded(OpenRocketLoaderResult result) {
|
public void onOpenRocketFileLoaded(OpenRocketLoaderResult result) {
|
||||||
|
isLoading = false;
|
||||||
if ( result.loadingError != null ) {
|
if ( result.loadingError != null ) {
|
||||||
|
|
||||||
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
|
||||||
|
@ -21,12 +21,11 @@ import android.support.v4.app.FragmentTransaction;
|
|||||||
import android.support.v4.view.ViewPager;
|
import android.support.v4.view.ViewPager;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
|
||||||
import com.actionbarsherlock.view.Menu;
|
import com.actionbarsherlock.view.Menu;
|
||||||
import com.actionbarsherlock.view.MenuInflater;
|
import com.actionbarsherlock.view.MenuInflater;
|
||||||
import com.actionbarsherlock.view.MenuItem;
|
import com.actionbarsherlock.view.MenuItem;
|
||||||
|
|
||||||
public class OpenRocketViewer extends SherlockFragmentActivity
|
public class OpenRocketViewer extends OpenRocketLoaderActivity
|
||||||
implements Simulations.OnSimulationSelectedListener
|
implements Simulations.OnSimulationSelectedListener
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -70,6 +69,10 @@ implements Simulations.OnSimulationSelectedListener
|
|||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
AndroidLogWrapper.d(OpenRocketViewer.class,"onMenuItemSelected" + item.getItemId());
|
AndroidLogWrapper.d(OpenRocketViewer.class,"onMenuItemSelected" + item.getItemId());
|
||||||
switch(item.getItemId()) {
|
switch(item.getItemId()) {
|
||||||
|
case R.id.menu_load:
|
||||||
|
// FIXME - Might want to prompt for save here.
|
||||||
|
pickOrkFiles();
|
||||||
|
return true;
|
||||||
case R.id.menu_save:
|
case R.id.menu_save:
|
||||||
// FIXME - Probably want to open a dialog here.
|
// FIXME - Probably want to open a dialog here.
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user