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:
parent
f6e841ef94
commit
077147d5d1
@ -56,9 +56,8 @@
|
|||||||
android:scheme="file" />
|
android:scheme="file" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
<activity android:name=".android.rocket.OpenRocketViewer"
|
||||||
android:name=".android.rocket.OpenRocketViewer"
|
android:windowSoftInputMode="adjustPan" />
|
||||||
android:finishOnTaskLaunch="true" />
|
|
||||||
<activity android:name=".android.PreferencesActivity" >
|
<activity android:name=".android.PreferencesActivity" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="net.sf.openrocket.android.PreferencesActivity" />
|
<action android:name="net.sf.openrocket.android.PreferencesActivity" />
|
||||||
|
@ -31,9 +31,8 @@ public class Component extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityCreated(Bundle savedInstanceState) {
|
public void onResume() {
|
||||||
super.onActivityCreated(savedInstanceState);
|
super.onResume();
|
||||||
|
|
||||||
final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
|
final OpenRocketDocument rocketDocument = CurrentRocketHolder.getCurrentRocket().getRocketDocument();
|
||||||
componentTree.setAdapter( buildAdapter( rocketDocument.getRocket() ) );
|
componentTree.setAdapter( buildAdapter( rocketDocument.getRocket() ) );
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,12 @@ public class Configurations extends ExpandableListFragment {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
setup();
|
||||||
|
super.onResume();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||||
inflater.inflate(R.menu.rocket_viewer_configurations_option_menu, menu);
|
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() {
|
public void refreshConfigsList() {
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
@ -105,7 +105,7 @@ public class OpenRocketLoaderFragment extends Fragment {
|
|||||||
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Finished loading " + OpenRocketLoaderTask.this);
|
AndroidLogWrapper.d(OpenRocketLoaderActivity.class,"Finished loading " + OpenRocketLoaderTask.this);
|
||||||
Fragment progress = getActivity().getSupportFragmentManager().findFragmentByTag(PROGRESS_DIALOG_TAG);
|
Fragment progress = getActivity().getSupportFragmentManager().findFragmentByTag(PROGRESS_DIALOG_TAG);
|
||||||
if ( progress != null ) {
|
if ( progress != null ) {
|
||||||
((DialogFragment)progress).dismiss();
|
((ProgressDialogFragment)progress).dismissAllowingStateLoss();
|
||||||
}
|
}
|
||||||
if ( listener != null ) {
|
if ( listener != null ) {
|
||||||
listener.onOpenRocketFileLoaded(result);
|
listener.onOpenRocketFileLoaded(result);
|
||||||
|
@ -10,6 +10,7 @@ import net.sf.openrocket.android.simulation.SimulationChart;
|
|||||||
import net.sf.openrocket.android.simulation.SimulationViewActivity;
|
import net.sf.openrocket.android.simulation.SimulationViewActivity;
|
||||||
import net.sf.openrocket.android.simulation.SimulationViewFragment;
|
import net.sf.openrocket.android.simulation.SimulationViewFragment;
|
||||||
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
import net.sf.openrocket.android.util.AndroidLogWrapper;
|
||||||
|
import net.sf.openrocket.document.OpenRocketDocument;
|
||||||
import net.sf.openrocket.document.Simulation;
|
import net.sf.openrocket.document.Simulation;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -41,7 +42,17 @@ implements Simulations.OnSimulationSelectedListener
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
|
|
||||||
setContentView(R.layout.openrocketviewer);
|
setContentView(R.layout.openrocketviewer);
|
||||||
@ -59,10 +70,7 @@ implements Simulations.OnSimulationSelectedListener
|
|||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
RocketChangedEventHandler handler = new RocketChangedEventHandler();
|
RocketChangedEventHandler handler = new RocketChangedEventHandler();
|
||||||
// Fire change notices so the displayed lists get updated.
|
CurrentRocketHolder.getCurrentRocket().setHandler(handler);
|
||||||
// This is primarily because simulations run in the background
|
|
||||||
handler.doSimsChanged();
|
|
||||||
CurrentRocketHolder.getCurrentRocket().setHandler( handler );
|
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,11 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
|||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,11 @@ implements SharedPreferences.OnSharedPreferenceChangeListener
|
|||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package net.sf.openrocket.android.util;
|
package net.sf.openrocket.android.util;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
@ -18,6 +20,18 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
return fragment;
|
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
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user