/services/input/InputListener.h

https://github.com/aizuzi/platform_frameworks_base · C Header · 196 lines · 114 code · 53 blank · 29 comment · 0 complexity · f8137cb02ca671db82db9c2e8a8c8ff5 MD5 · raw file

  1. /*
  2. * Copyright (C) 2011 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _UI_INPUT_LISTENER_H
  17. #define _UI_INPUT_LISTENER_H
  18. #include <input/Input.h>
  19. #include <utils/RefBase.h>
  20. #include <utils/Vector.h>
  21. namespace android {
  22. class InputListenerInterface;
  23. /* Superclass of all input event argument objects */
  24. struct NotifyArgs {
  25. virtual ~NotifyArgs() { }
  26. virtual void notify(const sp<InputListenerInterface>& listener) const = 0;
  27. };
  28. /* Describes a configuration change event. */
  29. struct NotifyConfigurationChangedArgs : public NotifyArgs {
  30. nsecs_t eventTime;
  31. inline NotifyConfigurationChangedArgs() { }
  32. NotifyConfigurationChangedArgs(nsecs_t eventTime);
  33. NotifyConfigurationChangedArgs(const NotifyConfigurationChangedArgs& other);
  34. virtual ~NotifyConfigurationChangedArgs() { }
  35. virtual void notify(const sp<InputListenerInterface>& listener) const;
  36. };
  37. /* Describes a key event. */
  38. struct NotifyKeyArgs : public NotifyArgs {
  39. nsecs_t eventTime;
  40. int32_t deviceId;
  41. uint32_t source;
  42. uint32_t policyFlags;
  43. int32_t action;
  44. int32_t flags;
  45. int32_t keyCode;
  46. int32_t scanCode;
  47. int32_t metaState;
  48. nsecs_t downTime;
  49. inline NotifyKeyArgs() { }
  50. NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
  51. int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
  52. int32_t metaState, nsecs_t downTime);
  53. NotifyKeyArgs(const NotifyKeyArgs& other);
  54. virtual ~NotifyKeyArgs() { }
  55. virtual void notify(const sp<InputListenerInterface>& listener) const;
  56. };
  57. /* Describes a motion event. */
  58. struct NotifyMotionArgs : public NotifyArgs {
  59. nsecs_t eventTime;
  60. int32_t deviceId;
  61. uint32_t source;
  62. uint32_t policyFlags;
  63. int32_t action;
  64. int32_t flags;
  65. int32_t metaState;
  66. int32_t buttonState;
  67. int32_t edgeFlags;
  68. int32_t displayId;
  69. uint32_t pointerCount;
  70. PointerProperties pointerProperties[MAX_POINTERS];
  71. PointerCoords pointerCoords[MAX_POINTERS];
  72. float xPrecision;
  73. float yPrecision;
  74. nsecs_t downTime;
  75. inline NotifyMotionArgs() { }
  76. NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source, uint32_t policyFlags,
  77. int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
  78. int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
  79. const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
  80. float xPrecision, float yPrecision, nsecs_t downTime);
  81. NotifyMotionArgs(const NotifyMotionArgs& other);
  82. virtual ~NotifyMotionArgs() { }
  83. virtual void notify(const sp<InputListenerInterface>& listener) const;
  84. };
  85. /* Describes a switch event. */
  86. struct NotifySwitchArgs : public NotifyArgs {
  87. nsecs_t eventTime;
  88. uint32_t policyFlags;
  89. uint32_t switchValues;
  90. uint32_t switchMask;
  91. inline NotifySwitchArgs() { }
  92. NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
  93. uint32_t switchValues, uint32_t switchMask);
  94. NotifySwitchArgs(const NotifySwitchArgs& other);
  95. virtual ~NotifySwitchArgs() { }
  96. virtual void notify(const sp<InputListenerInterface>& listener) const;
  97. };
  98. /* Describes a device reset event, such as when a device is added,
  99. * reconfigured, or removed. */
  100. struct NotifyDeviceResetArgs : public NotifyArgs {
  101. nsecs_t eventTime;
  102. int32_t deviceId;
  103. inline NotifyDeviceResetArgs() { }
  104. NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId);
  105. NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other);
  106. virtual ~NotifyDeviceResetArgs() { }
  107. virtual void notify(const sp<InputListenerInterface>& listener) const;
  108. };
  109. /*
  110. * The interface used by the InputReader to notify the InputListener about input events.
  111. */
  112. class InputListenerInterface : public virtual RefBase {
  113. protected:
  114. InputListenerInterface() { }
  115. virtual ~InputListenerInterface() { }
  116. public:
  117. virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args) = 0;
  118. virtual void notifyKey(const NotifyKeyArgs* args) = 0;
  119. virtual void notifyMotion(const NotifyMotionArgs* args) = 0;
  120. virtual void notifySwitch(const NotifySwitchArgs* args) = 0;
  121. virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args) = 0;
  122. };
  123. /*
  124. * An implementation of the listener interface that queues up and defers dispatch
  125. * of decoded events until flushed.
  126. */
  127. class QueuedInputListener : public InputListenerInterface {
  128. protected:
  129. virtual ~QueuedInputListener();
  130. public:
  131. QueuedInputListener(const sp<InputListenerInterface>& innerListener);
  132. virtual void notifyConfigurationChanged(const NotifyConfigurationChangedArgs* args);
  133. virtual void notifyKey(const NotifyKeyArgs* args);
  134. virtual void notifyMotion(const NotifyMotionArgs* args);
  135. virtual void notifySwitch(const NotifySwitchArgs* args);
  136. virtual void notifyDeviceReset(const NotifyDeviceResetArgs* args);
  137. void flush();
  138. private:
  139. sp<InputListenerInterface> mInnerListener;
  140. Vector<NotifyArgs*> mArgsQueue;
  141. };
  142. } // namespace android
  143. #endif // _UI_INPUT_LISTENER_H