OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.res.Configuration; | 9 import android.content.res.Configuration; |
10 import android.os.Build; | 10 import android.os.Build; |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return super.onOptionsItemSelected(item); | 176 return super.onOptionsItemSelected(item); |
177 } | 177 } |
178 | 178 |
179 /** | 179 /** |
180 * Called once when a keyboard key is pressed, then again when that same key
is released. This | 180 * Called once when a keyboard key is pressed, then again when that same key
is released. This |
181 * is not guaranteed to be notified of all soft keyboard events: certian key
boards might not | 181 * is not guaranteed to be notified of all soft keyboard events: certian key
boards might not |
182 * call it at all, while others might skip it in certain situations (e.g. sw
ipe input). | 182 * call it at all, while others might skip it in certain situations (e.g. sw
ipe input). |
183 */ | 183 */ |
184 @Override | 184 @Override |
185 public boolean dispatchKeyEvent(KeyEvent event) { | 185 public boolean dispatchKeyEvent(KeyEvent event) { |
| 186 int keyCode = event.getKeyCode(); |
| 187 |
| 188 // Dispatch the back button to the system to handle navigation |
| 189 if (keyCode == KeyEvent.KEYCODE_BACK) { |
| 190 return super.dispatchKeyEvent(event); |
| 191 } |
| 192 |
186 // Send TextEvent in two cases: | 193 // Send TextEvent in two cases: |
187 // 1. This is an ACTION_MULTIPLE event. | 194 // 1. This is an ACTION_MULTIPLE event. |
188 // 2. The event was generated by on-screen keyboard and Ctrl, Alt and | 195 // 2. The event was generated by on-screen keyboard and Ctrl, Alt and |
189 // Meta are not pressed. | 196 // Meta are not pressed. |
190 // This ensures that on-screen keyboard always injects input that | 197 // This ensures that on-screen keyboard always injects input that |
191 // correspond to what user sees on the screen, while physical keyboard | 198 // correspond to what user sees on the screen, while physical keyboard |
192 // acts as if it is connected to the remote host. | 199 // acts as if it is connected to the remote host. |
193 if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { | 200 if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { |
194 JniInterface.sendTextEvent(event.getCharacters()); | 201 JniInterface.sendTextEvent(event.getCharacters()); |
195 return super.dispatchKeyEvent(event); | 202 return true; |
196 } | 203 } |
197 | 204 |
198 int keyCode = event.getKeyCode(); | |
199 boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; | 205 boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN; |
200 | 206 |
201 // For Enter getUnicodeChar() returns 10 (line feed), but we still | 207 // For Enter getUnicodeChar() returns 10 (line feed), but we still |
202 // want to send it as KeyEvent. | 208 // want to send it as KeyEvent. |
203 int unicode = keyCode != KeyEvent.KEYCODE_ENTER ? event.getUnicodeChar()
: 0; | 209 int unicode = keyCode != KeyEvent.KEYCODE_ENTER ? event.getUnicodeChar()
: 0; |
204 | 210 |
205 boolean no_modifiers = !event.isAltPressed() && | 211 boolean no_modifiers = !event.isAltPressed() && |
206 !event.isCtrlPressed() && !event.isMetaPressed(); | 212 !event.isCtrlPressed() && !event.isMetaPressed(); |
207 | 213 |
208 if (event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD && | 214 if (event.getDeviceId() == KeyCharacterMap.VIRTUAL_KEYBOARD && |
(...skipping 29 matching lines...) Expand all Loading... |
238 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); | 244 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, pressed); |
239 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed); | 245 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, pressed); |
240 return true; | 246 return true; |
241 | 247 |
242 default: | 248 default: |
243 // We try to send all other key codes to the host directly. | 249 // We try to send all other key codes to the host directly. |
244 return JniInterface.sendKeyEvent(keyCode, pressed); | 250 return JniInterface.sendKeyEvent(keyCode, pressed); |
245 } | 251 } |
246 } | 252 } |
247 } | 253 } |
OLD | NEW |