30
30
import android .app .Activity ;
31
31
import android .content .Context ;
32
32
import android .content .Intent ;
33
- import android .content .pm .ActivityInfo ;
34
- import android .content .pm .PackageManager ;
35
- import android .content .pm .PackageManager .NameNotFoundException ;
36
33
import android .graphics .PixelFormat ;
37
34
import android .graphics .Rect ;
38
35
import android .os .Bundle ;
52
49
import android .view .Surface ;
53
50
import android .view .SurfaceHolder ;
54
51
import android .view .SurfaceView ;
52
+ import android .view .ViewConfiguration ;
55
53
import android .view .ViewGroup ;
56
54
import android .view .Window ;
57
55
import android .view .WindowManager ;
58
- import android .view .WindowManager .LayoutParams ;
59
56
import android .view .inputmethod .BaseInputConnection ;
60
57
import android .view .inputmethod .EditorInfo ;
61
- import android .view .inputmethod .InputConnection ;
62
58
import android .view .inputmethod .InputMethodManager ;
63
59
import android .widget .FrameLayout ;
64
60
@@ -85,7 +81,6 @@ protected void onCreate(Bundle savedInstanceState) {
85
81
super .onCreate (savedInstanceState );
86
82
Log .v (TAG , "onCreate start, using Android Logging v1" );
87
83
System .err .println ("onCreate called, writing this to System.err" );
88
- super .onCreate (savedInstanceState );
89
84
90
85
getWindow ().requestFeature (Window .FEATURE_NO_TITLE );
91
86
getWindow ().setSoftInputMode (
@@ -223,10 +218,10 @@ public void run() {
223
218
private native void nativeSetSurface (Surface surface );
224
219
private native void nativeSurfaceRedrawNeeded ();
225
220
private native void nativeGotTouchEvent (int pcount , int [] actions , int [] ids , int [] touchXs , int [] touchYs );
226
- private native void nativeGotKeyEvent (int action , int keycode );
227
- private native void nativedispatchKeyEvent (int type , int key , char [] chars , int charCount , int modifiers );
221
+ private native void nativeDispatchKeyEvent (int type , int key , char [] chars , int charCount , int modifiers );
228
222
private native void nativeDispatchLifecycleEvent (String event );
229
223
private native void nativeDispatchActivityResult (int requestCode , int resultCode , Intent intent );
224
+ private native void nativeNotifyMenu (int x , int y , int xAbs , int yAbs , boolean isKeyboardTrigger );
230
225
231
226
class InternalSurfaceView extends SurfaceView {
232
227
private static final int ACTION_POINTER_STILL = -1 ;
@@ -251,7 +246,6 @@ public boolean dispatchTouchEvent(MotionEvent event) {
251
246
final int [] ids = new int [pcount ];
252
247
final int [] touchXs = new int [pcount ];
253
248
final int [] touchYs = new int [pcount ];
254
- Log .v (TAG , "Activity, get touch event, pcount = " +pcount );
255
249
if (pcount > 1 ) {
256
250
//multitouch
257
251
if (actionCode == MotionEvent .ACTION_POINTER_DOWN
@@ -278,6 +272,16 @@ public boolean dispatchTouchEvent(MotionEvent event) {
278
272
ids [0 ] = event .getPointerId (0 );
279
273
touchXs [0 ] = (int ) (event .getX ()/density );
280
274
touchYs [0 ] = (int ) (event .getY ()/density );
275
+
276
+ if (action == MotionEvent .ACTION_DOWN ) {
277
+ longPress .setX (touchXs [0 ]);
278
+ longPress .setY (touchYs [0 ]);
279
+ handler .postDelayed (longPress , ViewConfiguration .getLongPressTimeout ());
280
+ }
281
+
282
+ if (action == MotionEvent .ACTION_UP ) {
283
+ handler .removeCallbacks (longPress );
284
+ }
281
285
}
282
286
if (!isFocused ()) {
283
287
Log .v (TAG , "View wasn't focused, requesting focus" );
@@ -375,9 +379,31 @@ private void resetText(int length) {
375
379
public boolean dispatchKeyEvent (final KeyEvent event ) {
376
380
Log .v (TAG , "Activity, process get key event, action = " +event );
377
381
processAndroidKeyEvent (event );
378
- // nativeGotKeyEvent(event.getAction(), event.getKeyCode());
379
382
return true ;
380
383
}
384
+
385
+ private final Handler handler = new Handler ();
386
+ private final LongPress longPress = new LongPress ();
387
+
388
+ private class LongPress implements Runnable {
389
+
390
+ int x , y ;
391
+
392
+ void setX (int x ) {
393
+ this .x = x ;
394
+ }
395
+
396
+ void setY (int y ) {
397
+ this .y = y ;
398
+ }
399
+
400
+ @ Override
401
+ public void run () {
402
+ Log .d (TAG , "Long press!" );
403
+ nativeNotifyMenu (x , y , x , y , false );
404
+ }
405
+ }
406
+
381
407
}
382
408
383
409
@ Override
@@ -438,18 +464,16 @@ private void notifyLifecycleEvent(String event) {
438
464
private int deadKey = 0 ;
439
465
440
466
void processAndroidKeyEvent (KeyEvent event ) {
441
- System .out .println ("KeyEvent: " + event +" with action = " +event .getAction ());
442
467
int jfxModifiers = mapAndroidModifierToJfx (event .getMetaState ());
443
468
switch (event .getAction ()) {
444
469
case KeyEvent .ACTION_DOWN :
445
470
KeyCode jfxKeyCode = mapAndroidKeyCodeToJfx (event .getKeyCode ());
446
- System .out .println ("[JVDBG] eventkeycode = " +event .getKeyCode ()+" and jfxkc = " +jfxKeyCode +" with code " + jfxKeyCode .impl_getCode ());
447
- nativedispatchKeyEvent (PRESS , jfxKeyCode .impl_getCode (), jfxKeyCode .impl_getChar ().toCharArray (), jfxKeyCode .impl_getChar ().toCharArray ().length , jfxModifiers );
471
+ nativeDispatchKeyEvent (PRESS , jfxKeyCode .impl_getCode (), jfxKeyCode .impl_getChar ().toCharArray (), jfxKeyCode .impl_getChar ().toCharArray ().length , jfxModifiers );
448
472
break ;
449
473
450
474
case KeyEvent .ACTION_UP :
451
475
jfxKeyCode = mapAndroidKeyCodeToJfx (event .getKeyCode ());
452
- nativedispatchKeyEvent (RELEASE , jfxKeyCode .impl_getCode (), jfxKeyCode .impl_getChar ().toCharArray (), jfxKeyCode .impl_getChar ().toCharArray ().length , jfxModifiers );
476
+ nativeDispatchKeyEvent (RELEASE , jfxKeyCode .impl_getCode (), jfxKeyCode .impl_getChar ().toCharArray (), jfxKeyCode .impl_getChar ().toCharArray ().length , jfxModifiers );
453
477
int unicodeChar = event .getUnicodeChar ();
454
478
if ((unicodeChar & KeyCharacterMap .COMBINING_ACCENT ) != 0 ) {
455
479
deadKey = unicodeChar & KeyCharacterMap .COMBINING_ACCENT_MASK ;
@@ -462,20 +486,20 @@ void processAndroidKeyEvent (KeyEvent event) {
462
486
}
463
487
464
488
if (unicodeChar != 0 ) {
465
- nativedispatchKeyEvent (TYPED , KeyCode .UNDEFINED .impl_getCode (), Character .toChars (unicodeChar ), 1 , jfxModifiers );
489
+ nativeDispatchKeyEvent (TYPED , KeyCode .UNDEFINED .impl_getCode (), Character .toChars (unicodeChar ), 1 , jfxModifiers );
466
490
}
467
491
468
492
break ;
469
493
470
494
case KeyEvent .ACTION_MULTIPLE :
471
495
if (event .getKeyCode () == KeyEvent .KEYCODE_UNKNOWN ) {
472
- nativedispatchKeyEvent (TYPED , KeyCode .UNDEFINED .impl_getCode (), event .getCharacters ().toCharArray (), event .getCharacters ().toCharArray ().length , jfxModifiers );
496
+ nativeDispatchKeyEvent (TYPED , KeyCode .UNDEFINED .impl_getCode (), event .getCharacters ().toCharArray (), event .getCharacters ().toCharArray ().length , jfxModifiers );
473
497
} else {
474
498
jfxKeyCode = mapAndroidKeyCodeToJfx (event .getKeyCode ());
475
499
for (int i = 0 ; i < event .getRepeatCount (); i ++) {
476
- nativedispatchKeyEvent (PRESS , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
477
- nativedispatchKeyEvent (RELEASE , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
478
- nativedispatchKeyEvent (TYPED , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
500
+ nativeDispatchKeyEvent (PRESS , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
501
+ nativeDispatchKeyEvent (RELEASE , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
502
+ nativeDispatchKeyEvent (TYPED , jfxKeyCode .impl_getCode (), null , 0 , jfxModifiers );
479
503
}
480
504
}
481
505
0 commit comments