140 {
141 int pointerCount = event.getPointerCount();
142
143
144
145
146 ByteBuffer packet =
147 ByteBuffer.allocateDirect(pointerCount * POINTER_DATA_FIELD_COUNT *
BYTES_PER_FIELD);
148 packet.order(ByteOrder.LITTLE_ENDIAN);
149
150 int maskedAction = event.getActionMasked();
151 int pointerChange = getPointerChangeForAction(
event.getActionMasked());
152 boolean updateForSinglePointer =
153 maskedAction == MotionEvent.ACTION_DOWN || maskedAction == MotionEvent.ACTION_POINTER_DOWN;
154 boolean updateForMultiplePointers =
155 !updateForSinglePointer
156 && (maskedAction == MotionEvent.ACTION_UP
157 || maskedAction == MotionEvent.ACTION_POINTER_UP);
158 if (updateForSinglePointer) {
159
160 addPointerForIndex(
event,
event.getActionIndex(), pointerChange, 0, transformMatrix, packet);
161 } else if (updateForMultiplePointers) {
162
163
164
165
166 for (
int p = 0;
p < pointerCount;
p++) {
167 if (
p !=
event.getActionIndex() &&
event.getToolType(
p) == MotionEvent.TOOL_TYPE_FINGER) {
168 addPointerForIndex(
169 event,
p, PointerChange.MOVE, POINTER_DATA_FLAG_BATCHED, transformMatrix, packet);
170 }
171 }
172
173
174 addPointerForIndex(
event,
event.getActionIndex(), pointerChange, 0, transformMatrix, packet);
175 } else {
176
177
178
179 for (
int p = 0;
p < pointerCount;
p++) {
180 addPointerForIndex(
event,
p, pointerChange, 0, transformMatrix, packet);
181 }
182 }
183
184
185 if (packet.position() % (POINTER_DATA_FIELD_COUNT *
BYTES_PER_FIELD) != 0) {
186 throw new AssertionError("Packet position is not on field boundary");
187 }
188
189
191
192 return true;
193 }