Use a different approach to prevent ForceClose after the application has been put to sleep for a long period of time. Each of the fragments in the Viewer will do their setup in onResume instead of in onCreateView. Further, the ProgressDialogFragment used in the OpenRocketLoaderFragment now exposes a dismissAllowStateLoss method so the dialog can be dismissed if the application is put in the background while loading.

This commit is contained in:
Kevin Ruland 2012-06-21 19:10:06 +00:00
parent f6e841ef94
commit 077147d5d1
8 changed files with 49 additions and 21 deletions

View File

@ -56,9 +56,8 @@
android:scheme="file" />
</intent-filter>
</activity>
<activity
android:name=".android.rocket.OpenRocketViewer"
android:finishOnTaskLaunch="true" />
<activity android:name=".android.rocket.OpenRocketViewer"
android:windowSoftInputMode="adjustPan" />
<activity android:name=".android.PreferencesActivity" >
<intent-filter>
<action android:name="net.sf.openrocket.android.PreferencesActivity" />

View File

@ -31,13 +31,12 @@ public class Component extends Fragment {
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
public void onResume() {
super.onResume();
final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
componentTree.setAdapter( buildAdapter( rocketDocument.getRocket() ) );
}
private ListAdapter buildAdapter( Rocket rocket ) {
TreeStateManager<RocketComponentWithId> manager = new InMemoryTreeStateManager<RocketComponentWithId>();

View File

@ -42,6 +42,12 @@ public class Configurations extends ExpandableListFragment {
return v;
}
@Override
public void onResume() {
setup();
super.onResume();
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.rocket_viewer_configurations_option_menu, menu);
@ -59,14 +65,6 @@ public class Configurations extends ExpandableListFragment {
}
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
setup();
}
public void refreshConfigsList() {
setup();
}

View File

@ -105,7 +105,7 @@ public class OpenRocketLoaderFragment extends Fragment {
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Finished loading " + OpenRocketLoaderTask.this);
Fragment progress = getActivity().getSupportFragmentManager().findFragmentByTag(PROGRESS_DIALOG_TAG);
if ( progress != null ) {
((DialogFragment)progress).dismiss();
((ProgressDialogFragment)progress).dismissAllowingStateLoss();
}
if ( listener != null ) {
listener.onOpenRocketFileLoaded(result);

View File

@ -10,6 +10,7 @@ import net.sf.openrocket.android.simulation.SimulationChart;
import net.sf.openrocket.android.simulation.SimulationViewActivity;
import net.sf.openrocket.android.simulation.SimulationViewFragment;
import net.sf.openrocket.android.util.AndroidLogWrapper;
import net.sf.openrocket.document.OpenRocketDocument;
import net.sf.openrocket.document.Simulation;
import android.app.AlertDialog;
import android.content.Intent;
@ -41,7 +42,17 @@ implements Simulations.OnSimulationSelectedListener
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(CurrentRocketHolder.getCurrentRocket().getRocketDocument().getRocket().getName());
// If the application sleeps for a long time, the CurrentRocketHolder might get cleaned
// up. When this happens, we cannot restore this state, so instead we just
// go home.
OpenRocketDocument rocDoc = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
if ( rocDoc == null ) {
AndroidLogWrapper.d(OpenRocketViewer.class, "No document - go home");
ActivityHelpers.goHome(this);
finish();
return;
}
setTitle(rocDoc.getRocket().getName());
getSupportActionBar().setHomeButtonEnabled(true);
setContentView(R.layout.openrocketviewer);
@ -59,10 +70,7 @@ implements Simulations.OnSimulationSelectedListener
@Override
protected void onResume() {
RocketChangedEventHandler handler = new RocketChangedEventHandler();
// Fire change notices so the displayed lists get updated.
// This is primarily because simulations run in the background
handler.doSimsChanged();
CurrentRocketHolder.getCurrentRocket().setHandler( handler );
CurrentRocketHolder.getCurrentRocket().setHandler(handler);
super.onResume();
}

View File

@ -55,6 +55,11 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onResume() {
super.onResume();
setup();
}

View File

@ -87,6 +87,11 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
prefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onResume() {
super.onResume();
setup();
}

View File

@ -1,5 +1,7 @@
package net.sf.openrocket.android.util;
import java.lang.reflect.Method;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
@ -18,6 +20,18 @@ public class ProgressDialogFragment extends DialogFragment {
return fragment;
}
/**
* Expose the private method to allow dismissing a dialog after saveInstanceState.
*/
public void dismissAllowingStateLoss() {
try {
Method dismissInternalMethod = ProgressDialogFragment.class.getMethod("dismissInternal", Boolean.class);
dismissInternalMethod.setAccessible(true);
dismissInternalMethod.invoke(this, true);
} catch (Exception ex ) {
AndroidLogWrapper.d(ProgressDialogFragment.class, "Exception calling dismissAllowingStateInteral");
}
}
@Override
public void onCreate(Bundle savedInstanceState) {