lib/android: intro motion down_time
[nit.git] / lib / android / input_events.nit
index 9c434d0..5ee9d87 100644 (file)
@@ -17,8 +17,8 @@
 # Pointer and hardware key events
 module input_events
 
-import mnit_input
-import android
+import mnit::input
+import android::game
 
 in "C header" `{
        #include <android/log.h>
@@ -57,11 +57,6 @@ private extern class NativeAndroidMotionEvent `{AInputEvent *`}
                return AMotionEvent_getPointerCount(self);
        `}
 
-       # Did this motion event just started?
-       fun just_went_down: Bool `{
-               return (AMotionEvent_getAction(self) & AMOTION_EVENT_ACTION_MASK) == AMOTION_EVENT_ACTION_DOWN;
-       `}
-
        fun edge: Int `{
                return AMotionEvent_getEdgeFlags(self);
        `}
@@ -75,6 +70,8 @@ private extern class NativeAndroidMotionEvent `{AInputEvent *`}
        `}
 
        fun action: AMotionEventAction `{ return AMotionEvent_getAction(self); `}
+
+       fun native_down_time: Int `{ return AMotionEvent_getDownTime(self); `}
 end
 
 private extern class AMotionEventAction `{ int32_t `}
@@ -125,7 +122,7 @@ class AndroidMotionEvent
                return new AndroidPointerEvent(self, index)
        end
 
-       redef fun just_went_down do return native.just_went_down
+       redef fun just_went_down do return native.action.is_down or native.action.is_pointer_down
 
        # Was the top edge of the screen intersected by this event?
        fun touch_to_edge: Bool do return native.edge == 1
@@ -154,6 +151,11 @@ class AndroidMotionEvent
                        return null
                end
        end
+
+       # Time when the user originally pressed down to start a stream of position events
+       #
+       # The return value is in the `java.lang.System.nanoTime()` time base.
+       fun down_time: Int do return native.native_down_time
 end
 
 # A pointer event
@@ -190,13 +192,12 @@ class AndroidPointerEvent
                return action.is_down or action.is_move or action.is_pointer_down
        end
 
-       redef fun depressed do return not pressed
+       redef fun is_move do return motion_event.acting_pointer == self and
+               motion_event.native.action.is_move
 
        # Does this pointer just began touching the screen?
-       fun just_went_down: Bool
-       do
-               return motion_event.down_pointer == self
-       end
+       fun just_went_down: Bool do return motion_event.acting_pointer == self and
+               motion_event.just_went_down
 
        # Unique id of this pointer since the beginning of the gesture
        fun pointer_id: Int do return native_pointer_id(motion_event.native, pointer_index)
@@ -219,7 +220,14 @@ extern class AndroidKeyEvent `{AInputEvent *`}
        # Hardware code of the key raising this event
        fun key_code: Int `{ return AKeyEvent_getKeyCode(self); `}
 
-       redef fun to_c `{
+       redef fun to_c
+       do
+               var i = native_to_c
+               if i == 0 then return null
+               return i.code_point
+       end
+
+       private fun native_to_c: Int `{
                int code = AKeyEvent_getKeyCode(self);
                if (code >= AKEYCODE_0 && code <= AKEYCODE_9)
                        return '0'+code-AKEYCODE_0;