NativeActivity and navigational stability improvements
Improve shutdown when errors occur to prevent inability to restart Reduce the context for launching activities to local application Error checking when launching the native touchpad interface
This commit is contained in:
parent
014daafa2a
commit
ea80157d2e
|
@ -1 +1 @@
|
|||
f2622f07bb50c5126c7a722070fe30dd64cd86f8
|
||||
014daafa2ab7a821beaf6041c68c50f8baf60b83
|
|
@ -40,6 +40,12 @@
|
|||
|
||||
#define EXPORT_XPLAY __attribute__ ((visibility("default")))
|
||||
|
||||
#define TAG "reidc"
|
||||
#define LOGW(...) ((void)__android_log_print( ANDROID_LOG_WARN, TAG, __VA_ARGS__ ))
|
||||
|
||||
#undef NUM_METHODS
|
||||
#define NUM_METHODS(x) (sizeof(x)/sizeof(*(x)))
|
||||
|
||||
static JavaVM *jVM;
|
||||
|
||||
typedef unsigned char BOOL;
|
||||
|
@ -50,7 +56,6 @@ static jobject g_pActivity = 0;
|
|||
static jmethodID javaOnNDKTouch = 0;
|
||||
static jmethodID javaOnNDKKey = 0;
|
||||
|
||||
//int target;
|
||||
static bool isXperiaPlay;
|
||||
|
||||
/**
|
||||
|
@ -147,13 +152,14 @@ engine_handle_input( struct android_app* app, AInputEvent* event )
|
|||
touchstate[nPointerId].x = AMotionEvent_getX( event, n );
|
||||
touchstate[nPointerId].y = AMotionEvent_getY( event, n );
|
||||
}
|
||||
//if( jni && g_pActivity && device == target ) {
|
||||
|
||||
if( jni && g_pActivity && isXperiaPlay) {
|
||||
(*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y, newTouch);
|
||||
// (*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y, newTouch);
|
||||
(*jni)->CallVoidMethod( jni, g_pActivity, javaOnNDKTouch, device, nSourceId, nRawAction, touchstate[nPointerId].x, touchstate[nPointerId].y);
|
||||
}
|
||||
newTouch = JNI_FALSE;
|
||||
}
|
||||
// if( device == target ) {
|
||||
|
||||
if( isXperiaPlay ) {
|
||||
return 1;
|
||||
} else {
|
||||
|
@ -197,14 +203,6 @@ engine_handle_cmd( struct android_app* app, int32_t cmd )
|
|||
}
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
IsXperiaPlay() {
|
||||
char mod[PROP_VALUE_MAX + 1];
|
||||
int lmod = __system_property_get("ro.product.model", mod);
|
||||
return mod == "R800a" || mod == "R800i" || mod == "R800x" || mod == "R800at" || mod == "SO-01D" || mod == "zeus";
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the main entry point of a native application that is using
|
||||
* android_native_app_glue. It runs in its own thread, with its own
|
||||
|
@ -228,8 +226,6 @@ android_main( struct android_app* state )
|
|||
//JNIEnv *env;
|
||||
//(*jVM)->AttachCurrentThread(jVM, &env, NULL);
|
||||
|
||||
isXperiaPlay = IsXperiaPlay();
|
||||
|
||||
if( state->savedState != NULL )
|
||||
{
|
||||
// We are starting with a previous saved state; restore from it.
|
||||
|
@ -263,25 +259,55 @@ android_main( struct android_app* state )
|
|||
}
|
||||
}
|
||||
|
||||
void EXPORT_XPLAY JNICALL Java_com_reicast_emulator_GL2JNINative_registerNative(JNIEnv *env, jobject clazz)
|
||||
static
|
||||
int
|
||||
RegisterNative( JNIEnv* env, jobject clazz, jboolean touchpad )
|
||||
{
|
||||
g_pActivity = (jobject)(*env)->NewGlobalRef(env, clazz);
|
||||
g_pActivity = (jobject)(*env)->NewGlobalRef( env, clazz );
|
||||
isXperiaPlay = (bool) touchpad;
|
||||
return 0;
|
||||
}
|
||||
//void EXPORT_XPLAY JNICALL Java_com_reicast_emulator_GL2JNINative_registerXperia(JNIEnv *env, jobject clazz, jint xperia)
|
||||
//{
|
||||
// target = xperia;
|
||||
//}
|
||||
|
||||
static const JNINativeMethod activity_methods[] =
|
||||
{
|
||||
{ "RegisterNative", "(Z)I", (void*)RegisterNative },
|
||||
};
|
||||
|
||||
jint EXPORT_XPLAY JNICALL JNI_OnLoad(JavaVM * vm, void * reserved)
|
||||
{
|
||||
JNIEnv *env;
|
||||
jVM = vm;
|
||||
if((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_4) != JNI_OK)
|
||||
{
|
||||
LOGW("%s - Failed to get the environment using GetEnv()", __FUNCTION__);
|
||||
return -1;
|
||||
}
|
||||
const char* interface_path = "com/reicast/emulator/GL2JNINative";
|
||||
jclass java_activity_class = (*env)->FindClass( env, interface_path );
|
||||
javaOnNDKTouch = (*env)->GetMethodID( env, java_activity_class, "OnNativeMotion", "(IIIIIZ)Z");
|
||||
|
||||
if( !java_activity_class )
|
||||
{
|
||||
LOGW( "%s - Failed to get %s class reference", __FUNCTION__, interface_path );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if( (*env)->RegisterNatives( env, java_activity_class, activity_methods, NUM_METHODS(activity_methods) ) != JNI_OK )
|
||||
{
|
||||
LOGW( "%s - Failed to register native activity methods", __FUNCTION__ );
|
||||
return -1;
|
||||
}
|
||||
|
||||
char device_type[PROP_VALUE_MAX];
|
||||
__system_property_get("ro.product.model", device_type);
|
||||
if( isXperiaPlay ) {
|
||||
LOGW( "%s touchpad enabled", device_type );
|
||||
} else {
|
||||
LOGW( "%s touchpad ignored", device_type );
|
||||
}
|
||||
|
||||
// javaOnNDKTouch = (*env)->GetMethodID( env, java_activity_class, "OnNativeMotion", "(IIIIIZ)Z");
|
||||
javaOnNDKTouch = (*env)->GetMethodID( env, java_activity_class, "OnNativeMotion", "(IIIII)Z");
|
||||
javaOnNDKKey = (*env)->GetMethodID( env, java_activity_class, "OnNativeKeyPress", "(IIII)Z");
|
||||
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,7 @@ public class GL2JNINative extends NativeActivity {
|
|||
System.loadLibrary("sexplay");
|
||||
}
|
||||
|
||||
public native void registerNative();
|
||||
// public native void registerXperia(int xperia);
|
||||
native int RegisterNative(boolean touchpad);
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
|
||||
@Override
|
||||
|
@ -69,16 +68,17 @@ public class GL2JNINative extends NativeActivity {
|
|||
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
|
||||
}
|
||||
getWindow().takeSurface(null);
|
||||
registerNative();
|
||||
|
||||
pad.isXperiaPlay = pad.IsXperiaPlay();
|
||||
pad.isOuyaOrTV = pad.IsOuyaOrTV(GL2JNINative.this);
|
||||
// isNvidiaShield = Gamepad.IsNvidiaShield();
|
||||
|
||||
RegisterNative(pad.isXperiaPlay);
|
||||
|
||||
config = new Config(GL2JNINative.this);
|
||||
config.getConfigurationPrefs();
|
||||
menu = new OnScreenMenu(GL2JNINative.this, prefs);
|
||||
|
||||
pad.isXperiaPlay = pad.IsXperiaPlay();
|
||||
pad.isOuyaOrTV = pad.IsOuyaOrTV(GL2JNINative.this);
|
||||
// isNvidiaShield = Gamepad.IsNvidiaShield();
|
||||
|
||||
String fileName = null;
|
||||
|
||||
// Call parent onCreate()
|
||||
|
@ -515,12 +515,15 @@ public class GL2JNINative extends NativeActivity {
|
|||
return false;
|
||||
}
|
||||
|
||||
// public boolean OnNativeMotion(int device, int source, int action, int x,
|
||||
// int y, boolean newEvent) {
|
||||
public boolean OnNativeMotion(int device, int source, int action, int x,
|
||||
int y, boolean newEvent) {
|
||||
int y) {
|
||||
Integer playerNum = pad.playerNumX.get(device);
|
||||
if (playerNum != null && playerNum != -1) {
|
||||
Log.d("reidc", playerNum + " - " + device + ": " + source);
|
||||
if (newEvent && source == Gamepad.Xperia_Touchpad) {
|
||||
// if (newEvent && source == Gamepad.Xperia_Touchpad) {
|
||||
if (source == Gamepad.Xperia_Touchpad) {
|
||||
if (action == MotionEvent.ACTION_UP) {
|
||||
x = 0;
|
||||
y = 0;
|
||||
|
|
|
@ -90,7 +90,8 @@ public class MainActivity extends SlidingFragmentActivity implements
|
|||
String log = output.toString();
|
||||
mPrefs.edit().putString("prior_error", log).commit();
|
||||
error.printStackTrace();
|
||||
MainActivity.this.finish();
|
||||
android.os.Process.killProcess(android.os.Process.myPid());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -417,11 +418,12 @@ public class MainActivity extends SlidingFragmentActivity implements
|
|||
// show it
|
||||
alertDialog.show();
|
||||
} else {
|
||||
Config.nativeact = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean(Config.pref_nativeact, Config.nativeact);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD && Config.nativeact) {
|
||||
startActivity(new Intent("com.reciast.LAUNCH_ROM", uri, getBaseContext(),
|
||||
startActivity(new Intent("com.reciast.LAUNCH_ROM", uri, getApplicationContext(),
|
||||
GL2JNINative.class));
|
||||
} else {
|
||||
startActivity(new Intent("com.reciast.LAUNCH_ROM", uri, getBaseContext(),
|
||||
startActivity(new Intent("com.reciast.LAUNCH_ROM", uri, getApplicationContext(),
|
||||
GL2JNIActivity.class));
|
||||
}
|
||||
}
|
||||
|
@ -525,10 +527,9 @@ public class MainActivity extends SlidingFragmentActivity implements
|
|||
args.putString("browse_entry", null);
|
||||
args.putBoolean("games_entry", false);
|
||||
fragment.setArguments(args);
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, fragment,
|
||||
"MAIN_BROWSER").commit();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragment_container, fragment, "MAIN_BROWSER")
|
||||
.addToBackStack(null).commit();
|
||||
setTitle(R.string.browser);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue