lightly refactor two-phase first-time launch

This commit is contained in:
Aaron Culliney 2015-11-03 22:38:29 -08:00
parent d0319bd2ff
commit a6ac111707
2 changed files with 23 additions and 17 deletions

View File

@ -43,6 +43,7 @@ public class Apple2Activity extends Activity {
private static volatile boolean DEBUG_STRICT = false;
private Apple2View mView = null;
private Runnable mGraphicsInitializedRunnable = null;
private Apple2SplashScreen mSplashScreen = null;
private Apple2MainMenu mMainMenu = null;
private Apple2SettingsMenu mSettingsMenu = null;
@ -149,9 +150,21 @@ public class Apple2Activity extends Activity {
showSplashScreen();
Apple2CrashHandler.getInstance().checkForCrashes(Apple2Activity.this);
final boolean firstTime = !Apple2Preferences.FIRST_TIME_CONFIGURED.booleanValue(this);
Apple2Preferences.FIRST_TIME_CONFIGURED.saveBoolean(this, true);
// first-time initializations #1
if (!Apple2Preferences.FIRST_TIME_CONFIGURED.booleanValue(this)) {
mGraphicsInitializedRunnable = new Runnable() {
@Override
public void run() {
if (firstTime) {
Apple2Preferences.KeypadPreset.IJKM_SPACE.apply(Apple2Activity.this);
}
Apple2Preferences.loadPreferences(Apple2Activity.this);
}
};
// first-time initializations
if (firstTime) {
Apple2DisksMenu.firstTime(this);
}
@ -428,7 +441,8 @@ public class Apple2Activity extends Activity {
boolean glViewFirstTime = false;
if (mView == null) {
glViewFirstTime = true;
mView = new Apple2View(this);
mView = new Apple2View(this, mGraphicsInitializedRunnable);
mGraphicsInitializedRunnable = null;
mMainMenu = new Apple2MainMenu(this, mView);
}

View File

@ -22,8 +22,6 @@ import android.opengl.GLSurfaceView;
import android.util.Log;
import android.view.ViewTreeObserver;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
@ -53,7 +51,7 @@ class Apple2View extends GLSurfaceView {
private final static boolean DEBUG = false;
private Apple2Activity mActivity = null;
private AtomicBoolean mInitialLaunch = new AtomicBoolean(true);
private Runnable mGraphicsInitializedRunnable = null;
private static native void nativeGraphicsInitialized(int width, int height);
@ -61,9 +59,10 @@ class Apple2View extends GLSurfaceView {
private static native void nativeRender();
public Apple2View(Apple2Activity activity) {
public Apple2View(Apple2Activity activity, Runnable graphicsInitializedRunnable) {
super(activity.getApplication());
mActivity = activity;
mGraphicsInitializedRunnable = graphicsInitializedRunnable;
/* By default, GLSurfaceView() creates a RGB_565 opaque surface.
* If we want a translucent one, we should change the surface's
@ -347,16 +346,9 @@ class Apple2View extends GLSurfaceView {
nativeGraphicsInitialized(width, height);
// first-time initializations #2
if (!Apple2Preferences.FIRST_TIME_CONFIGURED.booleanValue(Apple2View.this.mActivity)) {
Apple2Preferences.KeypadPreset.IJKM_SPACE.apply(Apple2View.this.mActivity);
Apple2Preferences.FIRST_TIME_CONFIGURED.saveBoolean(Apple2View.this.mActivity, true);
}
// load preferences on each new process creation
if (mInitialLaunch.get()) {
mInitialLaunch.set(false);
Apple2Preferences.loadPreferences(Apple2View.this.mActivity);
if (Apple2View.this.mGraphicsInitializedRunnable != null) {
Apple2View.this.mGraphicsInitializedRunnable.run();
Apple2View.this.mGraphicsInitializedRunnable = null;
}
Apple2View.this.mActivity.maybeResumeCPU();