25
25
#include <stdlib.h>
26
26
#include <config.h>
27
27
28
- #include <android_native_app_glue.h>
29
28
#include <android/input.h>
30
29
#include <android/window.h>
31
30
42
41
#include "clutter-android-application-private.h"
43
42
#include "clutter-stage-android.h"
44
43
44
+ #include "android_native_app_glue.h"
45
+ #include "android_jni_utils.h"
46
+
45
47
G_DEFINE_TYPE (ClutterAndroidApplication ,
46
48
clutter_android_application ,
47
49
G_TYPE_OBJECT )
@@ -155,10 +157,6 @@ clutter_android_handle_cmd (struct android_app *app,
155
157
//test_fini (data);
156
158
break ;
157
159
158
- case APP_CMD_GAINED_FOCUS :
159
- g_message ("command: GAINED_FOCUS" );
160
- break ;
161
-
162
160
case APP_CMD_WINDOW_RESIZED :
163
161
g_message ("command: window resized!" );
164
162
if (app -> window != NULL )
@@ -200,6 +198,10 @@ clutter_android_handle_cmd (struct android_app *app,
200
198
g_message ("command: CONTENT_RECT_CHANGED" );
201
199
break ;
202
200
201
+ case APP_CMD_GAINED_FOCUS :
202
+ g_message ("command: GAINED_FOCUS" );
203
+ break ;
204
+
203
205
case APP_CMD_LOST_FOCUS :
204
206
/* When our app loses focus, we stop monitoring the accelerometer.
205
207
* This is to avoid consuming battery while not being used. */
@@ -225,24 +227,24 @@ clutter_android_handle_cmd (struct android_app *app,
225
227
}
226
228
227
229
static gboolean
228
- translate_motion_event (ClutterEvent * event , AInputEvent * a_event )
230
+ translate_motion_event (AInputEvent * a_event )
229
231
{
230
232
int32_t action ;
233
+ ClutterEvent * event ;
231
234
ClutterDeviceManager * manager ;
232
235
ClutterInputDevice * pointer_device ;
233
236
234
237
manager = clutter_device_manager_get_default ();
235
238
pointer_device =
236
239
clutter_device_manager_get_core_device (manager ,
237
240
CLUTTER_POINTER_DEVICE );
238
- _clutter_input_device_set_stage (pointer_device , event -> any .stage );
239
241
240
242
action = AMotionEvent_getAction (a_event );
241
243
242
244
switch (action & AMOTION_EVENT_ACTION_MASK )
243
245
{
244
246
case AMOTION_EVENT_ACTION_DOWN :
245
- event -> button . type = event -> type = CLUTTER_BUTTON_PRESS ;
247
+ event = clutter_event_new ( CLUTTER_BUTTON_PRESS ) ;
246
248
event -> button .button = 1 ;
247
249
event -> button .click_count = 1 ;
248
250
event -> button .device = pointer_device ;
@@ -252,7 +254,7 @@ translate_motion_event (ClutterEvent *event, AInputEvent *a_event)
252
254
break ;
253
255
254
256
case AMOTION_EVENT_ACTION_UP :
255
- event -> button . type = event -> type = CLUTTER_BUTTON_RELEASE ;
257
+ event = clutter_event_new ( CLUTTER_BUTTON_RELEASE ) ;
256
258
event -> button .button = 1 ;
257
259
event -> button .click_count = 1 ;
258
260
event -> button .device = pointer_device ;
@@ -262,7 +264,7 @@ translate_motion_event (ClutterEvent *event, AInputEvent *a_event)
262
264
break ;
263
265
264
266
case AMOTION_EVENT_ACTION_MOVE :
265
- event -> motion . type = event -> type = CLUTTER_MOTION ;
267
+ event = clutter_event_new ( CLUTTER_MOTION ) ;
266
268
event -> motion .device = pointer_device ;
267
269
/* TODO: Following line is a massive hack for touch screen */
268
270
event -> motion .modifier_state = CLUTTER_BUTTON1_MASK ;
@@ -276,40 +278,64 @@ translate_motion_event (ClutterEvent *event, AInputEvent *a_event)
276
278
return FALSE;
277
279
}
278
280
281
+ event -> any .stage =
282
+ clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
283
+ _clutter_input_device_set_stage (pointer_device , event -> any .stage );
284
+
285
+ _clutter_event_push (event , FALSE);
286
+
279
287
return TRUE;
280
288
}
281
289
282
290
static gboolean
283
- translate_key_event (ClutterEvent * event , AInputEvent * a_event )
291
+ translate_key_event (AInputEvent * a_event )
284
292
{
285
293
int32_t state ;
294
+ ClutterEvent * event ;
295
+ ClutterDeviceManager * manager ;
296
+ ClutterInputDevice * keyboard_device ;
286
297
287
- /* g_message ("\tbutton/motion event: (%.02lf,%0.2lf)", */
288
- /* AMotionEvent_getX (a_event, 0), */
289
- /* AMotionEvent_getY (a_event, 0)); */
298
+ g_message ("key event" );
290
299
291
300
state = AMotionEvent_getMetaState (a_event );
292
301
293
- event -> key .unicode_value = AKeyEvent_getKeyCode (a_event );
302
+ manager = clutter_device_manager_get_default ();
303
+ keyboard_device =
304
+ clutter_device_manager_get_core_device (manager ,
305
+ CLUTTER_KEYBOARD_DEVICE );
306
+
307
+ g_message ("\tflags = %x keycode = %i" ,
308
+ AKeyEvent_getFlags (a_event ),
309
+ AKeyEvent_getKeyCode (a_event ));
294
310
295
311
switch (state )
296
312
{
297
313
case AKEY_STATE_UP :
298
- /* g_message ("\tkey release"); */
299
- event -> type = event -> key . type = CLUTTER_KEY_RELEASE ;
314
+ g_message ("\tkey release" );
315
+ event = clutter_event_new ( CLUTTER_KEY_RELEASE ) ;
300
316
break ;
301
317
302
318
case AKEY_STATE_DOWN :
303
319
case AKEY_STATE_VIRTUAL : /* TODO: Should we synthetize release? */
304
- /* g_message ("\tkey press"); */
305
- event -> type = event -> key . type = CLUTTER_KEY_PRESS ;
320
+ g_message ("\tkey press" );
321
+ event = clutter_event_new ( CLUTTER_KEY_PRESS ) ;
306
322
break ;
307
323
308
324
default :
309
- /* g_message ("\tmeh? %i", state); */
325
+ g_message ("\tmeh? %i" , state );
310
326
return FALSE;
311
327
}
312
328
329
+ event -> key .unicode_value = AKeyEvent_getKeyCode (a_event );
330
+ g_message ("\tunicode value = %i" , AKeyEvent_getKeyCode (a_event ));
331
+ event -> key .device = keyboard_device ;
332
+
333
+ event -> any .stage =
334
+ clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
335
+ _clutter_input_device_set_stage (keyboard_device , event -> any .stage );
336
+
337
+ _clutter_event_push (event , FALSE);
338
+
313
339
return TRUE;
314
340
}
315
341
@@ -320,30 +346,19 @@ static int32_t
320
346
clutter_android_handle_input (struct android_app * app ,
321
347
AInputEvent * a_event )
322
348
{
323
- ClutterEvent * event ;
324
349
gboolean process = FALSE;
325
350
326
351
g_message ("input!" );
327
352
328
- event = clutter_event_new (CLUTTER_NOTHING );
329
- event -> any .stage =
330
- clutter_stage_manager_get_default_stage (clutter_stage_manager_get_default ());
331
-
332
- g_message ("plop!" );
333
353
if (AInputEvent_getType (a_event ) == AINPUT_EVENT_TYPE_KEY )
334
354
{
335
- process = translate_key_event (event , a_event );
355
+ process = translate_key_event (a_event );
336
356
}
337
357
else if (AInputEvent_getType (a_event ) == AINPUT_EVENT_TYPE_MOTION )
338
358
{
339
- process = translate_motion_event (event , a_event );
359
+ process = translate_motion_event (a_event );
340
360
}
341
361
342
- if (process )
343
- _clutter_event_push (event , FALSE);
344
- else
345
- clutter_event_free (event );
346
-
347
362
return (int32_t ) process ;
348
363
}
349
364
@@ -375,6 +390,43 @@ clutter_android_application_get_asset_manager (ClutterAndroidApplication *applic
375
390
return application -> android_application -> activity -> assetManager ;
376
391
}
377
392
393
+ void
394
+ clutter_android_application_show_keyboard (ClutterAndroidApplication * application ,
395
+ gboolean show_keyboard ,
396
+ gboolean implicit )
397
+ {
398
+ jint ret ;
399
+
400
+ g_return_if_fail (CLUTTER_IS_ANDROID_APPLICATION (application ));
401
+
402
+ if (show_keyboard )
403
+ {
404
+ g_message ("showing keyboard" );
405
+ if (implicit )
406
+ ret = _android_show_keyboard (application -> android_application ,
407
+ JNI_TRUE ,
408
+ ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT );
409
+ else
410
+ ret = _android_show_keyboard (application -> android_application ,
411
+ JNI_TRUE ,
412
+ ANATIVEACTIVITY_SHOW_SOFT_INPUT_IMPLICIT );
413
+ }
414
+ else
415
+ {
416
+ g_message ("hiding keyboard" );
417
+ if (implicit )
418
+ ret = _android_show_keyboard (application -> android_application ,
419
+ JNI_FALSE ,
420
+ ANATIVEACTIVITY_HIDE_SOFT_INPUT_IMPLICIT_ONLY );
421
+ else
422
+ ret = _android_show_keyboard (application -> android_application ,
423
+ JNI_FALSE ,
424
+ ANATIVEACTIVITY_HIDE_SOFT_INPUT_NOT_ALWAYS );
425
+ }
426
+
427
+ g_message ("THE FucK %i" , ret );
428
+ }
429
+
378
430
/*
379
431
* This is the main entry point of a native application that is using
380
432
* android_native_app_glue. It runs in its own thread, with its own
0 commit comments