2015-02-15 17:52:27 +00:00
|
|
|
/*
|
2015-02-23 19:19:41 +00:00
|
|
|
* Apple // emulator for *nix
|
2015-02-15 17:52:27 +00:00
|
|
|
*
|
|
|
|
* This software package is subject to the GNU General Public License
|
|
|
|
* version 2 or later (your choice) as published by the Free Software
|
|
|
|
* Foundation.
|
|
|
|
*
|
|
|
|
* THERE ARE NO WARRANTIES WHATSOEVER.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.deadc0de.apple2;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
2015-02-23 19:19:41 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.SharedPreferences;
|
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
|
import android.content.pm.PackageInfo;
|
|
|
|
import android.content.pm.PackageManager;
|
2015-02-15 17:52:27 +00:00
|
|
|
import android.os.Bundle;
|
2015-02-23 19:19:41 +00:00
|
|
|
import android.util.Log;
|
2015-02-15 17:52:27 +00:00
|
|
|
|
2015-02-23 19:19:41 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
2015-02-15 17:52:27 +00:00
|
|
|
public class Apple2Activity extends Activity {
|
|
|
|
|
2015-02-23 19:19:41 +00:00
|
|
|
private final static String TAG = "Apple2Activity";
|
|
|
|
|
|
|
|
private final static int BUF_SZ = 4096;
|
|
|
|
|
|
|
|
private final static String PREFS_CONFIGURED = "prefs_configured";
|
|
|
|
|
2015-02-25 00:03:21 +00:00
|
|
|
private Apple2View mView = null;
|
|
|
|
|
2015-02-15 17:52:27 +00:00
|
|
|
static {
|
|
|
|
System.loadLibrary("apple2ix");
|
2015-02-23 19:19:41 +00:00
|
|
|
}
|
2015-02-15 17:52:27 +00:00
|
|
|
|
2015-02-23 19:19:41 +00:00
|
|
|
private native void nativeOnCreate(String dataDir);
|
2015-02-15 17:52:27 +00:00
|
|
|
private native void nativeOnResume();
|
|
|
|
private native void nativeOnPause();
|
2015-02-25 00:03:21 +00:00
|
|
|
public native void nativeGraphicsInitialized(int width, int height);
|
|
|
|
public native void nativeRender();
|
2015-02-15 17:52:27 +00:00
|
|
|
|
2015-02-23 19:19:41 +00:00
|
|
|
// HACK NOTE 2015/02/22 : Apparently native code cannot easily access stuff in the APK ... so copy various resources
|
|
|
|
// out of the APK and into the /data/data/... for ease of access. Because this is FOSS software we don't care about
|
|
|
|
// these assets
|
|
|
|
private String firstTimeInitialization() {
|
|
|
|
|
|
|
|
String dataDir = null;
|
|
|
|
try {
|
|
|
|
PackageManager pm = getPackageManager();
|
|
|
|
PackageInfo pi = pm.getPackageInfo(getPackageName(), 0);
|
|
|
|
dataDir = pi.applicationInfo.dataDir;
|
|
|
|
} catch (PackageManager.NameNotFoundException e) {
|
|
|
|
Log.e(TAG, ""+e);
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
SharedPreferences settings = getPreferences(Context.MODE_PRIVATE);
|
|
|
|
if (settings.getBoolean(PREFS_CONFIGURED, false)) {
|
|
|
|
return dataDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(TAG, "First time copying stuff-n-things out of APK for ease-of-NDK access...");
|
|
|
|
|
|
|
|
try {
|
2015-02-25 04:53:19 +00:00
|
|
|
String[] shaders = getAssets().list("shaders");
|
|
|
|
for (String shader : shaders) {
|
|
|
|
_copyFile(dataDir, "shaders", shader);
|
|
|
|
}
|
|
|
|
String[] disks = getAssets().list("disks");
|
|
|
|
for (String disk : disks) {
|
|
|
|
_copyFile(dataDir, "disks", disk);
|
|
|
|
}
|
2015-02-23 19:19:41 +00:00
|
|
|
} catch (IOException e) {
|
|
|
|
Log.e(TAG, "problem copying resources : "+e);
|
|
|
|
System.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Log.d(TAG, "Saving default preferences");
|
|
|
|
SharedPreferences.Editor editor = settings.edit();
|
|
|
|
editor.putBoolean(PREFS_CONFIGURED, true);
|
|
|
|
editor.commit();
|
|
|
|
|
|
|
|
return dataDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void _copyFile(String dataDir, String subdir, String assetName)
|
|
|
|
throws IOException
|
|
|
|
{
|
|
|
|
String outputPath = dataDir+File.separator+subdir;
|
|
|
|
Log.d(TAG, "Copying "+subdir+File.separator+assetName+" to "+outputPath+File.separator+assetName+" ...");
|
|
|
|
new File(outputPath).mkdirs();
|
|
|
|
|
|
|
|
InputStream is = getAssets().open(subdir+File.separator+assetName);
|
|
|
|
if (is == null) {
|
|
|
|
Log.e(TAG, "inputstream is null");
|
|
|
|
}
|
|
|
|
File file = new File(outputPath+File.separator+assetName);
|
|
|
|
file.setWritable(true);
|
|
|
|
|
|
|
|
FileOutputStream os = new FileOutputStream(file);
|
|
|
|
if (os == null) {
|
|
|
|
Log.e(TAG, "outputstream is null");
|
|
|
|
}
|
|
|
|
|
|
|
|
byte[] buf = new byte[BUF_SZ];
|
|
|
|
while (true) {
|
|
|
|
int len = is.read(buf, 0, BUF_SZ);
|
|
|
|
if (len < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
os.write(buf, 0, len);
|
|
|
|
}
|
|
|
|
os.flush();
|
|
|
|
os.close();
|
|
|
|
}
|
|
|
|
|
2015-02-15 17:52:27 +00:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
|
|
|
super.onCreate(savedInstanceState);
|
2015-02-23 19:19:41 +00:00
|
|
|
Log.e(TAG, "onCreate()");
|
|
|
|
|
|
|
|
String dataDir = firstTimeInitialization();
|
|
|
|
nativeOnCreate(dataDir);
|
|
|
|
|
2015-02-25 00:03:21 +00:00
|
|
|
mView = new Apple2View(this);
|
|
|
|
setContentView(mView);
|
2015-02-15 17:52:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onResume() {
|
|
|
|
super.onResume();
|
2015-02-25 00:03:21 +00:00
|
|
|
mView.onResume();
|
2015-02-15 17:52:27 +00:00
|
|
|
nativeOnResume();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onPause() {
|
|
|
|
super.onPause();
|
2015-02-25 00:03:21 +00:00
|
|
|
mView.onPause();
|
2015-02-15 17:52:27 +00:00
|
|
|
nativeOnPause();
|
|
|
|
}
|
|
|
|
}
|