summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/button-android.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-07-18 21:02:47 +0000
committerThomas Martitz <kugel@rockbox.org>2011-07-18 21:02:47 +0000
commit33de9cdaefd8684e3411486612e68c0c2bd6be3d (patch)
treef1219711bfc0c1333ad8ec611a45f7ab0c416216 /firmware/target/hosted/android/button-android.c
parent788e246c996c9ac6e8efae87d13b14af001fd354 (diff)
downloadrockbox-33de9cdaefd8684e3411486612e68c0c2bd6be3d.tar.gz
rockbox-33de9cdaefd8684e3411486612e68c0c2bd6be3d.zip
Android: Refactor some of the glue code.
* Cleanup RockboxService.java by moving the battery and headphone monitors to separate classes and detaching their instances * Move those monitors and RockboxTelephony.java into a new monitors subdirectory * Call those monitors all the same from native code by creating the objects there git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30160 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/hosted/android/button-android.c')
-rw-r--r--firmware/target/hosted/android/button-android.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/firmware/target/hosted/android/button-android.c b/firmware/target/hosted/android/button-android.c
index dfc5bd0fb3..c913a3d7f7 100644
--- a/firmware/target/hosted/android/button-android.c
+++ b/firmware/target/hosted/android/button-android.c
@@ -34,7 +34,8 @@ extern JNIEnv *env_ptr;
34extern jclass RockboxService_class; 34extern jclass RockboxService_class;
35extern jobject RockboxService_instance; 35extern jobject RockboxService_instance;
36 36
37static jfieldID _headphone_state; 37static jobject HeadphoneMonitor_instance;
38static jfieldID headphone_state;
38static int last_y, last_x; 39static int last_y, last_x;
39static int last_btns; 40static int last_btns;
40 41
@@ -114,20 +115,18 @@ Java_org_rockbox_RockboxFramebuffer_buttonHandler(JNIEnv*env, jclass class,
114 115
115void button_init_device(void) 116void button_init_device(void)
116{ 117{
117 jmethodID initHeadphoneMonitor = (*env_ptr)->GetMethodID(env_ptr, 118 JNIEnv e = *env_ptr;
118 RockboxService_class, 119 jclass class = e->FindClass(env_ptr, "org/rockbox/monitors/HeadphoneMonitor");
119 "initHeadphoneMonitor", 120 jmethodID constructor = e->GetMethodID(env_ptr, class,
120 "()V"); 121 "<init>",
121 /* start the monitor */ 122 "(Landroid/content/Context;)V");
122 (*env_ptr)->CallVoidMethod(env_ptr, 123 HeadphoneMonitor_instance = e->NewObject(env_ptr, class,
123 RockboxService_instance, 124 constructor,
124 initHeadphoneMonitor); 125 RockboxService_instance);
125 126 /* cache the battery level field id */
126 /* cache the headphone state field id */ 127 headphone_state = (*env_ptr)->GetFieldID(env_ptr,
127 _headphone_state = (*env_ptr)->GetFieldID(env_ptr, 128 class,
128 RockboxService_class, 129 "mHpState", "I");
129 "headphone_state",
130 "I");
131} 130}
132 131
133int button_read_device(int *data) 132int button_read_device(int *data)
@@ -150,7 +149,8 @@ int button_read_device(int *data)
150/* Tell if anything is in the jack. */ 149/* Tell if anything is in the jack. */
151bool headphones_inserted(void) 150bool headphones_inserted(void)
152{ 151{
153 int state = (*env_ptr)->GetIntField(env_ptr, RockboxService_instance, _headphone_state); 152 int state = (*env_ptr)->GetIntField(env_ptr, HeadphoneMonitor_instance,
153 headphone_state);
154 /* 0 is disconnected, 1 and 2 are connected */ 154 /* 0 is disconnected, 1 and 2 are connected */
155 return (state == 0) ? false : true; 155 return (state == 0) ? false : true;
156} 156}