mirror of
https://github.com/jamessanford/kegs.git
synced 2025-01-22 15:31:15 +00:00
User can choose between some built in disk images.
This commit is contained in:
parent
4d11d473d6
commit
029a485d0d
@ -5,7 +5,6 @@
|
||||
|
||||
<uses-sdk android:minSdkVersion="9" android:targetSdkVersion="16" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
|
||||
|
||||
<uses-feature android:name="android.hardware.touchscreen.multitouch.distinct" android:required="false"/>
|
||||
|
@ -1,7 +1,7 @@
|
||||
|
||||
g_limit_speed = 2
|
||||
g_limit_speed = 3
|
||||
|
||||
s7d1 = System 6.hdv
|
||||
s7d1 = System 6 and Free Games.hdv
|
||||
|
||||
bram1[00] = 00 00 00 01 00 00 0d 06 02 01 01 00 01 00 00 00
|
||||
bram1[10] = 00 00 07 06 02 01 01 00 00 00 0f 06 06 00 05 06
|
||||
|
@ -287,9 +287,21 @@ insert_disk(int slot, int drive, const char *name, int ejected, int force_size,
|
||||
free(dsk->name_ptr);
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
int use_cwd = (name[0] == '/') ? 0 : 1;
|
||||
extern char g_cfg_cwd_str[];
|
||||
name_len = strlen(name) + (use_cwd ? strlen(g_cfg_cwd_str) : 0);
|
||||
name_ptr = (char *)malloc(name_len + 1);
|
||||
name_ptr[0] = 0;
|
||||
if (use_cwd) {
|
||||
strncat(name_ptr, g_cfg_cwd_str, name_len);
|
||||
}
|
||||
strncat(name_ptr, name, name_len - strlen(name_ptr));
|
||||
#else
|
||||
name_len = strlen(name);
|
||||
name_ptr = (char *)malloc(name_len + 1);
|
||||
strncpy(name_ptr, name, name_len + 1);
|
||||
#endif
|
||||
dsk->name_ptr = name_ptr;
|
||||
|
||||
dsk->partition_name = 0;
|
||||
|
@ -14,6 +14,7 @@
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="64dip"
|
||||
android:layout_height="64dip"
|
||||
android:visibility="gone"
|
||||
android:scaleType="fitCenter" />
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
36
src/com/froop/app/kegs/AssetImages.java
Normal file
36
src/com/froop/app/kegs/AssetImages.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.froop.app.kegs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
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> {
|
||||
private ConfigFile mConfigFile;
|
||||
|
||||
AssetImages(ConfigFile config) {
|
||||
mConfigFile = config;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
}
|
||||
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
mConfigFile.ensureAssetCopied("XMAS_DEMO.2MG");
|
||||
mConfigFile.ensureAssetCopied("System 6 Shareware.zip",
|
||||
"System 6 and Free Games.hdv");
|
||||
// TODO: could check to make sure they actually exist now.
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onCancelled(Boolean success) {
|
||||
// post message, runnable, ...tell it about failure
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean success) {
|
||||
// post message, runnable, ...tell it to continue (or fail)
|
||||
}
|
||||
}
|
@ -2,8 +2,11 @@ package com.froop.app.kegs;
|
||||
|
||||
import android.content.Context;
|
||||
import java.io.File;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
class ConfigFile {
|
||||
public static final String ROM03 = "ROM.03";
|
||||
@ -28,6 +31,28 @@ class ConfigFile {
|
||||
return mConfigPath;
|
||||
}
|
||||
|
||||
public void ensureAssetCopied(String zipfile, String exampleFile) {
|
||||
// We only check for a local copy of a single file before unzipping...
|
||||
final File local_copy = new File(mConfigPath, exampleFile);
|
||||
if (local_copy != null && local_copy.exists()) {
|
||||
// Assume that whatever is there will work.
|
||||
return;
|
||||
}
|
||||
|
||||
// NOTE: There's no sanity checking here, so it's best for builtin assets.
|
||||
try {
|
||||
ZipInputStream zipStream = new ZipInputStream(new BufferedInputStream(mContext.getAssets().open(zipfile)));
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = zipStream.getNextEntry()) != null) {
|
||||
new CopyHelper(zipStream, false,
|
||||
mConfigPath, zipEntry.getName()).copy();
|
||||
}
|
||||
} catch (java.io.IOException e) {
|
||||
// KEGS will just fail.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void ensureAssetCopied(String assetName) {
|
||||
// Make sure there's a user-readable copy of whatever from assets.
|
||||
final File local_copy = new File(mConfigPath, assetName);
|
||||
|
@ -7,16 +7,22 @@ import java.io.FileOutputStream;
|
||||
|
||||
public class CopyHelper {
|
||||
private InputStream mInput;
|
||||
private boolean mClose;
|
||||
private String mDir;
|
||||
private String mFile;
|
||||
private static final String mTmp = "tmp_";
|
||||
|
||||
CopyHelper(InputStream input, String dir, String filename) {
|
||||
CopyHelper(InputStream input, boolean close, String dir, String filename) {
|
||||
mInput = input;
|
||||
mClose = close;
|
||||
mDir = dir;
|
||||
mFile = filename;
|
||||
}
|
||||
|
||||
CopyHelper(InputStream input, String dir, String filename) {
|
||||
this(input, true, dir, filename);
|
||||
}
|
||||
|
||||
// This leaves a partial temporary file on error and doesn't let you know
|
||||
// whether it was successful. If your disk is full you will be unhappy.
|
||||
//
|
||||
@ -47,6 +53,8 @@ public class CopyHelper {
|
||||
} while (true);
|
||||
out.close();
|
||||
output_file.renameTo(final_file);
|
||||
if (mClose) {
|
||||
mInput.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,6 +94,16 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
((ToggleButton)findViewById(R.id.key_closed_apple)).setChecked(false);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
protected void getRomFile(String romfile) {
|
||||
final DialogFragment download = new DownloadDialogFragment();
|
||||
download.show(getFragmentManager(), FRAGMENT_DOWNLOAD);
|
||||
@ -283,8 +293,7 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
invalidateOptionsMenu(); // update icon
|
||||
return true;
|
||||
} else if (item_id == R.id.action_diskimage) {
|
||||
// FIXME
|
||||
// new DiskImageFragment().show(getFragmentManager(), FRAGMENT_DISKIMAGE);
|
||||
new DiskImageFragment().show(getFragmentManager(), FRAGMENT_DISKIMAGE);
|
||||
return true;
|
||||
} else if (item_id == R.id.action_more_keys) {
|
||||
final int vis = areControlsVisible() ? View.GONE : View.VISIBLE;
|
||||
@ -341,8 +350,8 @@ public class KegsMain extends Activity implements KegsKeyboard.StickyReset {
|
||||
findViewById(R.id.key_up).setOnClickListener(mButtonClick);
|
||||
findViewById(R.id.key_down).setOnClickListener(mButtonClick);
|
||||
|
||||
// TODO: Kick this off in the background for built in images.
|
||||
// mConfigFile.ensureAssetCopied("XMAS_DEMO.2MG");
|
||||
// Make sure local copy of internal disk images exist.
|
||||
new AssetImages(mConfigFile).execute();
|
||||
|
||||
final String romfile = mConfigFile.whichRomFile();
|
||||
if (romfile == null) {
|
||||
|
82
src/com/froop/app/kegs/diskimage/DiskImageFragment.java
Normal file
82
src/com/froop/app/kegs/diskimage/DiskImageFragment.java
Normal file
@ -0,0 +1,82 @@
|
||||
package com.froop.app.kegs;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
|
||||
public class DiskImageFragment extends DialogFragment {
|
||||
private String[] mImages = {
|
||||
"System 6", "X-MAS Demo (FTA)"};
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
DiskImageAdapter items = new DiskImageAdapter(getActivity());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
builder.setTitle(R.string.diskimage_title);
|
||||
builder.setSingleChoiceItems(items, -1,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int item) {
|
||||
dismiss();
|
||||
if (item == 0) {
|
||||
((KegsMain)getActivity()).loadConfig("boot_slot_7");
|
||||
} else if (item == 1) {
|
||||
((KegsMain)getActivity()).loadConfig("boot_slot_5");
|
||||
}
|
||||
}
|
||||
});
|
||||
final AlertDialog dialog = builder.create();
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public class DiskImageAdapter extends BaseAdapter {
|
||||
private LayoutInflater mInflater;
|
||||
private Bitmap mBitmap;
|
||||
private Bitmap mBitmap2;
|
||||
|
||||
public DiskImageAdapter(Context context) {
|
||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
mBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon);
|
||||
mBitmap2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.jog_tab_target_green);
|
||||
}
|
||||
|
||||
public Object getItem(int pos) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public long getItemId(int pos) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return mImages.length;
|
||||
}
|
||||
|
||||
public View getView(int pos, View convertView, ViewGroup parent) {
|
||||
if (convertView == null) {
|
||||
convertView = mInflater.inflate(
|
||||
R.layout.disk_image_list_item, parent, false);
|
||||
}
|
||||
|
||||
int item = pos; // BUG: this should be getItem(pos)
|
||||
// ((ImageView)convertView.findViewById(R.id.icon)).setImageBitmap(mBitmap);
|
||||
((TextView)convertView.findViewById(android.R.id.text1)).setText(mImages[item]);
|
||||
// If cached, this puts a nice green dot next to the name:
|
||||
// ((ImageView)convertView.findViewById(R.id.cached)).setImageBitmap(mBitmap2);
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user