widget/gonk/libui/InputListener.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/widget/gonk/libui/InputListener.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,182 @@
     1.4 +/*
     1.5 + * Copyright (C) 2011 The Android Open Source Project
     1.6 + *
     1.7 + * Licensed under the Apache License, Version 2.0 (the "License");
     1.8 + * you may not use this file except in compliance with the License.
     1.9 + * You may obtain a copy of the License at
    1.10 + *
    1.11 + *      http://www.apache.org/licenses/LICENSE-2.0
    1.12 + *
    1.13 + * Unless required by applicable law or agreed to in writing, software
    1.14 + * distributed under the License is distributed on an "AS IS" BASIS,
    1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    1.16 + * See the License for the specific language governing permissions and
    1.17 + * limitations under the License.
    1.18 + */
    1.19 +
    1.20 +#define LOG_TAG "InputListener"
    1.21 +
    1.22 +//#define LOG_NDEBUG 0
    1.23 +
    1.24 +#include "InputListener.h"
    1.25 +
    1.26 +#include "cutils_log.h"
    1.27 +
    1.28 +namespace android {
    1.29 +
    1.30 +// --- NotifyConfigurationChangedArgs ---
    1.31 +
    1.32 +NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(nsecs_t eventTime) :
    1.33 +        eventTime(eventTime) {
    1.34 +}
    1.35 +
    1.36 +NotifyConfigurationChangedArgs::NotifyConfigurationChangedArgs(
    1.37 +        const NotifyConfigurationChangedArgs& other) :
    1.38 +        eventTime(other.eventTime) {
    1.39 +}
    1.40 +
    1.41 +void NotifyConfigurationChangedArgs::notify(const sp<InputListenerInterface>& listener) const {
    1.42 +    listener->notifyConfigurationChanged(this);
    1.43 +}
    1.44 +
    1.45 +
    1.46 +// --- NotifyKeyArgs ---
    1.47 +
    1.48 +NotifyKeyArgs::NotifyKeyArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
    1.49 +        uint32_t policyFlags,
    1.50 +        int32_t action, int32_t flags, int32_t keyCode, int32_t scanCode,
    1.51 +        int32_t metaState, nsecs_t downTime) :
    1.52 +        eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags),
    1.53 +        action(action), flags(flags), keyCode(keyCode), scanCode(scanCode),
    1.54 +        metaState(metaState), downTime(downTime) {
    1.55 +}
    1.56 +
    1.57 +NotifyKeyArgs::NotifyKeyArgs(const NotifyKeyArgs& other) :
    1.58 +        eventTime(other.eventTime), deviceId(other.deviceId), source(other.source),
    1.59 +        policyFlags(other.policyFlags),
    1.60 +        action(other.action), flags(other.flags),
    1.61 +        keyCode(other.keyCode), scanCode(other.scanCode),
    1.62 +        metaState(other.metaState), downTime(other.downTime) {
    1.63 +}
    1.64 +
    1.65 +void NotifyKeyArgs::notify(const sp<InputListenerInterface>& listener) const {
    1.66 +    listener->notifyKey(this);
    1.67 +}
    1.68 +
    1.69 +
    1.70 +// --- NotifyMotionArgs ---
    1.71 +
    1.72 +NotifyMotionArgs::NotifyMotionArgs(nsecs_t eventTime, int32_t deviceId, uint32_t source,
    1.73 +        uint32_t policyFlags,
    1.74 +        int32_t action, int32_t flags, int32_t metaState, int32_t buttonState,
    1.75 +        int32_t edgeFlags, int32_t displayId, uint32_t pointerCount,
    1.76 +        const PointerProperties* pointerProperties, const PointerCoords* pointerCoords,
    1.77 +        float xPrecision, float yPrecision, nsecs_t downTime) :
    1.78 +        eventTime(eventTime), deviceId(deviceId), source(source), policyFlags(policyFlags),
    1.79 +        action(action), flags(flags), metaState(metaState), buttonState(buttonState),
    1.80 +        edgeFlags(edgeFlags), displayId(displayId), pointerCount(pointerCount),
    1.81 +        xPrecision(xPrecision), yPrecision(yPrecision), downTime(downTime) {
    1.82 +    for (uint32_t i = 0; i < pointerCount; i++) {
    1.83 +        this->pointerProperties[i].copyFrom(pointerProperties[i]);
    1.84 +        this->pointerCoords[i].copyFrom(pointerCoords[i]);
    1.85 +    }
    1.86 +}
    1.87 +
    1.88 +NotifyMotionArgs::NotifyMotionArgs(const NotifyMotionArgs& other) :
    1.89 +        eventTime(other.eventTime), deviceId(other.deviceId), source(other.source),
    1.90 +        policyFlags(other.policyFlags),
    1.91 +        action(other.action), flags(other.flags),
    1.92 +        metaState(other.metaState), buttonState(other.buttonState),
    1.93 +        edgeFlags(other.edgeFlags), displayId(other.displayId),
    1.94 +        pointerCount(other.pointerCount),
    1.95 +        xPrecision(other.xPrecision), yPrecision(other.yPrecision), downTime(other.downTime) {
    1.96 +    for (uint32_t i = 0; i < pointerCount; i++) {
    1.97 +        pointerProperties[i].copyFrom(other.pointerProperties[i]);
    1.98 +        pointerCoords[i].copyFrom(other.pointerCoords[i]);
    1.99 +    }
   1.100 +}
   1.101 +
   1.102 +void NotifyMotionArgs::notify(const sp<InputListenerInterface>& listener) const {
   1.103 +    listener->notifyMotion(this);
   1.104 +}
   1.105 +
   1.106 +
   1.107 +// --- NotifySwitchArgs ---
   1.108 +
   1.109 +NotifySwitchArgs::NotifySwitchArgs(nsecs_t eventTime, uint32_t policyFlags,
   1.110 +        uint32_t switchValues, uint32_t switchMask) :
   1.111 +        eventTime(eventTime), policyFlags(policyFlags),
   1.112 +        switchValues(switchValues), switchMask(switchMask) {
   1.113 +}
   1.114 +
   1.115 +NotifySwitchArgs::NotifySwitchArgs(const NotifySwitchArgs& other) :
   1.116 +        eventTime(other.eventTime), policyFlags(other.policyFlags),
   1.117 +        switchValues(other.switchValues), switchMask(other.switchMask) {
   1.118 +}
   1.119 +
   1.120 +void NotifySwitchArgs::notify(const sp<InputListenerInterface>& listener) const {
   1.121 +    listener->notifySwitch(this);
   1.122 +}
   1.123 +
   1.124 +
   1.125 +// --- NotifyDeviceResetArgs ---
   1.126 +
   1.127 +NotifyDeviceResetArgs::NotifyDeviceResetArgs(nsecs_t eventTime, int32_t deviceId) :
   1.128 +        eventTime(eventTime), deviceId(deviceId) {
   1.129 +}
   1.130 +
   1.131 +NotifyDeviceResetArgs::NotifyDeviceResetArgs(const NotifyDeviceResetArgs& other) :
   1.132 +        eventTime(other.eventTime), deviceId(other.deviceId) {
   1.133 +}
   1.134 +
   1.135 +void NotifyDeviceResetArgs::notify(const sp<InputListenerInterface>& listener) const {
   1.136 +    listener->notifyDeviceReset(this);
   1.137 +}
   1.138 +
   1.139 +
   1.140 +// --- QueuedInputListener ---
   1.141 +
   1.142 +QueuedInputListener::QueuedInputListener(const sp<InputListenerInterface>& innerListener) :
   1.143 +        mInnerListener(innerListener) {
   1.144 +}
   1.145 +
   1.146 +QueuedInputListener::~QueuedInputListener() {
   1.147 +    size_t count = mArgsQueue.size();
   1.148 +    for (size_t i = 0; i < count; i++) {
   1.149 +        delete mArgsQueue[i];
   1.150 +    }
   1.151 +}
   1.152 +
   1.153 +void QueuedInputListener::notifyConfigurationChanged(
   1.154 +        const NotifyConfigurationChangedArgs* args) {
   1.155 +    mArgsQueue.push(new NotifyConfigurationChangedArgs(*args));
   1.156 +}
   1.157 +
   1.158 +void QueuedInputListener::notifyKey(const NotifyKeyArgs* args) {
   1.159 +    mArgsQueue.push(new NotifyKeyArgs(*args));
   1.160 +}
   1.161 +
   1.162 +void QueuedInputListener::notifyMotion(const NotifyMotionArgs* args) {
   1.163 +    mArgsQueue.push(new NotifyMotionArgs(*args));
   1.164 +}
   1.165 +
   1.166 +void QueuedInputListener::notifySwitch(const NotifySwitchArgs* args) {
   1.167 +    mArgsQueue.push(new NotifySwitchArgs(*args));
   1.168 +}
   1.169 +
   1.170 +void QueuedInputListener::notifyDeviceReset(const NotifyDeviceResetArgs* args) {
   1.171 +    mArgsQueue.push(new NotifyDeviceResetArgs(*args));
   1.172 +}
   1.173 +
   1.174 +void QueuedInputListener::flush() {
   1.175 +    size_t count = mArgsQueue.size();
   1.176 +    for (size_t i = 0; i < count; i++) {
   1.177 +        NotifyArgs* args = mArgsQueue[i];
   1.178 +        args->notify(mInnerListener);
   1.179 +        delete args;
   1.180 +    }
   1.181 +    mArgsQueue.clear();
   1.182 +}
   1.183 +
   1.184 +
   1.185 +} // namespace android

mercurial