mirror of
https://github.com/jamessanford/kegs.git
synced 2025-01-08 13:29:49 +00:00
Show a dialog until the internal images are ready to be used.
This commit is contained in:
parent
029a485d0d
commit
d1934cb53d
@ -21,7 +21,8 @@
|
||||
<item>Unlimited</item>
|
||||
</string-array>
|
||||
|
||||
<string name="diskimage_title">Insert disk</string>
|
||||
<string name="diskimage_title">Choose a disk</string>
|
||||
<string name="asset_loading">Preparing disk image...</string>
|
||||
|
||||
<!-- R.menu.actions -->
|
||||
<string name="input_joystick">Use Joystick</string>
|
||||
|
@ -5,13 +5,18 @@ import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.ProgressDialog;
|
||||
import android.util.Log;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
class AssetImages extends AsyncTask<Void, Void, Boolean> {
|
||||
interface AssetsReady {
|
||||
void onAssetsReady(boolean success);
|
||||
}
|
||||
|
||||
private KegsMain mContext;
|
||||
private ConfigFile mConfigFile;
|
||||
|
||||
AssetImages(ConfigFile config) {
|
||||
AssetImages(KegsMain context, ConfigFile config) {
|
||||
mContext = context;
|
||||
mConfigFile = config;
|
||||
}
|
||||
|
||||
@ -23,14 +28,22 @@ class AssetImages extends AsyncTask<Void, Void, Boolean> {
|
||||
mConfigFile.ensureAssetCopied("System 6 Shareware.zip",
|
||||
"System 6 and Free Games.hdv");
|
||||
// TODO: could check to make sure they actually exist now.
|
||||
|
||||
// For testing:
|
||||
// try { Thread.sleep(20000); } catch (InterruptedException e) {}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onCancelled(Boolean success) {
|
||||
// post message, runnable, ...tell it about failure
|
||||
protected void onCancelled(final Boolean success) {
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
public void run() { mContext.onAssetsReady(false); }
|
||||
});
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean success) {
|
||||
// post message, runnable, ...tell it to continue (or fail)
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
mContext.runOnUiThread(new Runnable() {
|
||||
public void run() { mContext.onAssetsReady(success); }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -23,12 +23,13 @@ import android.view.View.OnTouchListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
public class KegsMain extends Activity implements KegsKeyboard.StickyReset, AssetImages.AssetsReady {
|
||||
private static final String FRAGMENT_ROM = "rom";
|
||||
private static final String FRAGMENT_DOWNLOAD = "download";
|
||||
private static final String FRAGMENT_ERROR = "error";
|
||||
private static final String FRAGMENT_SPEED = "speed";
|
||||
private static final String FRAGMENT_DISKIMAGE = "diskimage";
|
||||
private static final String FRAGMENT_ASSET = "asset";
|
||||
|
||||
private ConfigFile mConfigFile;
|
||||
private KegsThread mKegsThread;
|
||||
@ -40,6 +41,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
private KegsKeyboard mKegsKeyboard;
|
||||
private TouchJoystick mJoystick;
|
||||
|
||||
private boolean mAssetsReady = false;
|
||||
private boolean mModeMouse = true;
|
||||
private int mLastActionBar = 0; // window height at last ActionBar change.
|
||||
|
||||
@ -94,14 +96,35 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
((ToggleButton)findViewById(R.id.key_closed_apple)).setChecked(false);
|
||||
}
|
||||
|
||||
public void onAssetsReady(boolean success) {
|
||||
mAssetsReady = success;
|
||||
}
|
||||
|
||||
private void loadConfigWhenReady(final String configfile) {
|
||||
final AssetFragment frag = (AssetFragment)getFragmentManager().findFragmentByTag(FRAGMENT_ASSET);
|
||||
|
||||
if (!getThread().nowWaitingForPowerOn() || !mAssetsReady) {
|
||||
if (frag == null && !mAssetsReady) {
|
||||
// Only the asset part will take time, so only show the dialog
|
||||
// when waiting for the asset.
|
||||
final DialogFragment assetProgress = new AssetFragment();
|
||||
assetProgress.show(getFragmentManager(), FRAGMENT_ASSET);
|
||||
}
|
||||
mKegsView.postDelayed(new Runnable() {
|
||||
public void run() { loadConfigWhenReady(configfile); }
|
||||
}, 100);
|
||||
} else {
|
||||
if (frag != null) {
|
||||
frag.dismiss();
|
||||
}
|
||||
mConfigFile.internalConfig(configfile);
|
||||
getThread().allowPowerOn();
|
||||
}
|
||||
}
|
||||
|
||||
protected void loadConfig(String configfile) {
|
||||
getThread().doPowerOff();
|
||||
while(!getThread().nowWaitingForPowerOn()) {
|
||||
// FIXME: should not do this in the UI thread...should use a probe or handler
|
||||
try { Thread.sleep(50); } catch (InterruptedException e) {}
|
||||
}
|
||||
mConfigFile.internalConfig(configfile);
|
||||
getThread().allowPowerOn();
|
||||
loadConfigWhenReady(configfile);
|
||||
}
|
||||
|
||||
protected void getRomFile(String romfile) {
|
||||
@ -164,6 +187,24 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
}
|
||||
}
|
||||
|
||||
class AssetFragment extends DialogFragment {
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
ProgressDialog dialog = new ProgressDialog(getActivity());
|
||||
// TODO: should probably use an XML layout for this.
|
||||
dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
|
||||
dialog.setMessage(getResources().getText(R.string.asset_loading));
|
||||
dialog.setProgressNumberFormat(null);
|
||||
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||
dialog.setProgressPercentFormat(null);
|
||||
}
|
||||
dialog.setIndeterminate(true);
|
||||
dialog.setCancelable(false);
|
||||
dialog.setCanceledOnTouchOutside(false);
|
||||
return dialog;
|
||||
}
|
||||
}
|
||||
|
||||
public KegsThread getThread() {
|
||||
return mKegsThread;
|
||||
}
|
||||
@ -351,7 +392,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
findViewById(R.id.key_down).setOnClickListener(mButtonClick);
|
||||
|
||||
// Make sure local copy of internal disk images exist.
|
||||
new AssetImages(mConfigFile).execute();
|
||||
new AssetImages(this, mConfigFile).execute();
|
||||
|
||||
final String romfile = mConfigFile.whichRomFile();
|
||||
if (romfile == null) {
|
||||
|
Loading…
Reference in New Issue
Block a user