Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: samples/android_sample/jni/input_service.cc

Issue 11467028: Migrate files to embedder. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review fixes Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samples/android_sample/jni/input_service.h ('k') | samples/android_sample/jni/log.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #include <android_native_app_glue.h>
6 #include <cmath>
7
8 #include "jni/input_service.h"
9 #include "jni/log.h"
10
11 InputService::InputService(android_app* application,
12 VMGlue* vm_glue,
13 const int32_t& width,
14 const int32_t& height) :
15 application_(application),
16 vm_glue_(vm_glue),
17 width_(width),
18 height_(height) {
19 }
20
21 int32_t InputService::Start() {
22 if ((width_ == 0) || (height_ == 0)) {
23 return -1;
24 }
25 return 0;
26 }
27
28 bool InputService::OnTouchEvent(AInputEvent* event) {
29 int32_t type = AMotionEvent_getAction(event);
30 const char *function = NULL;
31 switch (type) {
32 case AMOTION_EVENT_ACTION_DOWN:
33 function = "onMotionDown";
34 break;
35 case AMOTION_EVENT_ACTION_UP:
36 function = "onMotionUp";
37 break;
38 case AMOTION_EVENT_ACTION_MOVE:
39 function = "onMotionMove";
40 break;
41 case AMOTION_EVENT_ACTION_CANCEL:
42 function = "onMotionCancel";
43 break;
44 case AMOTION_EVENT_ACTION_OUTSIDE:
45 function = "onMotionOutside";
46 break;
47 case AMOTION_EVENT_ACTION_POINTER_DOWN:
48 function = "onMotionPointerDown";
49 break;
50 case AMOTION_EVENT_ACTION_POINTER_UP:
51 function = "onMotionPointerUp";
52 break;
53 default:
54 break;
55 }
56 if (function != NULL) {
57 // For now we just get the last coords.
58 float move_x = AMotionEvent_getX(event, 0);
59 float move_y = AMotionEvent_getY(event, 0);
60 int64_t when = AMotionEvent_getEventTime(event);
61 LOGI("Got motion event %d at %f, %f", type, move_x, move_y);
62
63 if (vm_glue_->OnMotionEvent(function, when, move_x, move_y) != 0) {
64 return false;
65 }
66 } else {
67 return false;
68 }
69 return true;
70 }
71
72 bool InputService::OnKeyEvent(AInputEvent* event) {
73 int32_t type = AKeyEvent_getAction(event);
74 const char *function = NULL;
75 switch (type) {
76 case AKEY_EVENT_ACTION_DOWN:
77 function = "onKeyDown";
78 break;
79 case AKEY_EVENT_ACTION_UP:
80 function = "onKeyUp";
81 break;
82 case AKEY_EVENT_ACTION_MULTIPLE:
83 function = "onKeyMultiple";
84 break;
85 }
86 if (function != NULL) {
87 int32_t flags = AKeyEvent_getFlags(event);
88 /* Get the key code of the key event.
89 * This is the physical key that was pressed, not the Unicode character. */
90 int32_t key_code = AKeyEvent_getKeyCode(event);
91 /* Get the meta key state. */
92 int32_t meta_state = AKeyEvent_getMetaState(event);
93 /* Get the repeat count of the event.
94 * For both key up an key down events, this is the number of times the key
95 * has repeated with the first down starting at 0 and counting up from
96 * there. For multiple key events, this is the number of down/up pairs
97 * that have occurred. */
98 int32_t repeat = AKeyEvent_getRepeatCount(event);
99
100 /* Get the time of the most recent key down event, in the
101 * java.lang.System.nanoTime() time base. If this is a down event,
102 * this will be the same as eventTime.
103 * Note that when chording keys, this value is the down time of the most
104 * recently pressed key, which may not be the same physical key of this
105 * event. */
106 int64_t key_down_time = AKeyEvent_getDownTime(event);
107
108 /* Get the time this event occurred, in the
109 * java.lang.System.nanoTime() time base. */
110 int64_t when = AKeyEvent_getEventTime(event);
111
112 LOGI("Got key event %d %d", type, key_code);
113 if (vm_glue_->OnKeyEvent(function, when, flags, key_code,
114 meta_state, repeat) != 0) {
115 return false;
116 }
117 } else {
118 return false;
119 }
120 return true;
121 }
OLDNEW
« no previous file with comments | « samples/android_sample/jni/input_service.h ('k') | samples/android_sample/jni/log.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698