(Android) Rename handle_hotplug_get_device_name into android_input_get_id_name

This commit is contained in:
twinaphex 2014-06-21 06:17:10 +02:00
parent 5deb9a31e6
commit f65950521e

View File

@ -293,7 +293,20 @@ static inline void android_input_poll_event_type_key(android_input_t *android, s
*handled = 0;
}
static void handle_hotplug_get_device_name(char *buf, size_t size, int id)
static int android_input_get_id_port(android_input_t *android, int id, int source)
{
unsigned i;
if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD))
return 0; // touch overlay is always player 1
for (i = 0; i < android->pads_connected; i++)
if (android->state_device_ids[i] == id)
return i;
return -1;
}
static bool android_input_get_id_name(char *buf, size_t size, int id)
{
jclass class;
jmethodID method, getName;
@ -301,47 +314,50 @@ static void handle_hotplug_get_device_name(char *buf, size_t size, int id)
JNIEnv *env = (JNIEnv*)jni_thread_getenv();
if (!env)
return;
buf[0] = '\0';
goto error;
class = NULL;
FIND_CLASS(env, class, "android/view/InputDevice");
if (!class)
return;
goto error;
method = NULL;
GET_STATIC_METHOD_ID(env, method, class, "getDevice", "(I)Landroid/view/InputDevice;");
if (!method)
return;
goto error;
device = NULL;
CALL_OBJ_STATIC_METHOD_PARAM(env, device, class, method, (jint)id);
if (!device)
{
RARCH_ERR("Failed to find device for ID: %d\n", id);
return;
goto error;
}
getName = NULL;
GET_METHOD_ID(env, getName, class, "getName", "()Ljava/lang/String;");
if (!getName)
return;
goto error;
name = NULL;
CALL_OBJ_METHOD(env, name, device, getName);
if (!name)
{
RARCH_ERR("Failed to find name for device ID: %d\n", id);
return;
goto error;
}
buf[0] = '\0';
const char *str = (*env)->GetStringUTFChars(env, name, 0);
if (str)
strlcpy(buf, str, size);
(*env)->ReleaseStringUTFChars(env, name, str);
RARCH_LOG("device name: %s\n", buf);
return true;
error:
return false;
}
static void handle_hotplug(struct android_app *android_app, unsigned *port, unsigned id,
@ -360,7 +376,7 @@ static void handle_hotplug(struct android_app *android_app, unsigned *port, unsi
return;
}
handle_hotplug_get_device_name(device_name, sizeof(device_name), id);
android_input_get_id_name(device_name, sizeof(device_name), id);
//FIXME: Ugly hack, see other FIXME note below.
if (strstr(device_name, "keypad-game-zeus") || strstr(device_name, "keypad-zeus"))
@ -554,18 +570,6 @@ static void handle_hotplug(struct android_app *android_app, unsigned *port, unsi
}
}
static int android_input_get_id_port(android_input_t *android, int id, int source)
{
unsigned i;
if (source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD))
return 0; // touch overlay is always player 1
for (i = 0; i < android->pads_connected; i++)
if (android->state_device_ids[i] == id)
return i;
return -1;
}
// Handle all events. If our activity is in pause state, block until we're unpaused.
static void android_input_poll(void *data)