Loading packages/SystemUI/src/com/android/systemui/statusbar/gesture/GenericGestureDetector.kt +22 −16 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ package com.android.systemui.statusbar.gesture import android.annotation.CallSuper Loading Loading @@ -55,20 +54,24 @@ abstract class GenericGestureDetector( * The callback receive the last motion event in the gesture. */ fun addOnGestureDetectedCallback(tag: String, callback: (MotionEvent) -> Unit) { synchronized(callbacks) { val callbacksWasEmpty = callbacks.isEmpty() callbacks[tag] = callback if (callbacksWasEmpty) { startGestureListening() } } } /** Removes the callback. */ fun removeOnGestureDetectedCallback(tag: String) { synchronized(callbacks) { callbacks.remove(tag) if (callbacks.isEmpty()) { stopGestureListening() } } } /** Triggered each time a touch event occurs (and at least one callback is registered). */ abstract fun onInputEvent(ev: InputEvent) Loading @@ -78,7 +81,8 @@ abstract class GenericGestureDetector( * event in the gesture. */ internal fun onGestureDetected(e: MotionEvent) { callbacks.values.forEach { it.invoke(e) } val callbackValues = synchronized(callbacks) { ArrayList(callbacks.values) } callbackValues.forEach { it.invoke(e) } } /** Start listening to touch events. */ Loading @@ -86,11 +90,13 @@ abstract class GenericGestureDetector( internal open fun startGestureListening() { stopGestureListening() inputMonitor = InputMonitorCompat(tag, displayId).also { inputReceiver = it.getInputReceiver( inputMonitor = InputMonitorCompat(tag, displayId).also { inputReceiver = it.getInputReceiver( Looper.getMainLooper(), Choreographer.getInstance(), this::onInputEvent this::onInputEvent, ) } } Loading Loading
packages/SystemUI/src/com/android/systemui/statusbar/gesture/GenericGestureDetector.kt +22 −16 Original line number Diff line number Diff line Loading @@ -14,7 +14,6 @@ * limitations under the License. */ package com.android.systemui.statusbar.gesture import android.annotation.CallSuper Loading Loading @@ -55,20 +54,24 @@ abstract class GenericGestureDetector( * The callback receive the last motion event in the gesture. */ fun addOnGestureDetectedCallback(tag: String, callback: (MotionEvent) -> Unit) { synchronized(callbacks) { val callbacksWasEmpty = callbacks.isEmpty() callbacks[tag] = callback if (callbacksWasEmpty) { startGestureListening() } } } /** Removes the callback. */ fun removeOnGestureDetectedCallback(tag: String) { synchronized(callbacks) { callbacks.remove(tag) if (callbacks.isEmpty()) { stopGestureListening() } } } /** Triggered each time a touch event occurs (and at least one callback is registered). */ abstract fun onInputEvent(ev: InputEvent) Loading @@ -78,7 +81,8 @@ abstract class GenericGestureDetector( * event in the gesture. */ internal fun onGestureDetected(e: MotionEvent) { callbacks.values.forEach { it.invoke(e) } val callbackValues = synchronized(callbacks) { ArrayList(callbacks.values) } callbackValues.forEach { it.invoke(e) } } /** Start listening to touch events. */ Loading @@ -86,11 +90,13 @@ abstract class GenericGestureDetector( internal open fun startGestureListening() { stopGestureListening() inputMonitor = InputMonitorCompat(tag, displayId).also { inputReceiver = it.getInputReceiver( inputMonitor = InputMonitorCompat(tag, displayId).also { inputReceiver = it.getInputReceiver( Looper.getMainLooper(), Choreographer.getInstance(), this::onInputEvent this::onInputEvent, ) } } Loading