| 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.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
| 9 import android.os.Bundle; | 9 import android.os.Bundle; |
| 10 import android.view.KeyEvent; | 10 import android.view.KeyEvent; |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 return true; | 96 return true; |
| 97 | 97 |
| 98 case R.id.actionbar_send_ctrl_alt_del: | 98 case R.id.actionbar_send_ctrl_alt_del: |
| 99 { | 99 { |
| 100 int[] keys = { | 100 int[] keys = { |
| 101 KeyEvent.KEYCODE_CTRL_LEFT, | 101 KeyEvent.KEYCODE_CTRL_LEFT, |
| 102 KeyEvent.KEYCODE_ALT_LEFT, | 102 KeyEvent.KEYCODE_ALT_LEFT, |
| 103 KeyEvent.KEYCODE_FORWARD_DEL, | 103 KeyEvent.KEYCODE_FORWARD_DEL, |
| 104 }; | 104 }; |
| 105 for (int key : keys) { | 105 for (int key : keys) { |
| 106 JniInterface.keyboardAction(key, true); | 106 JniInterface.sendKeyEvent(key, true); |
| 107 } | 107 } |
| 108 for (int key : keys) { | 108 for (int key : keys) { |
| 109 JniInterface.keyboardAction(key, false); | 109 JniInterface.sendKeyEvent(key, false); |
| 110 } | 110 } |
| 111 } | 111 } |
| 112 return true; | 112 return true; |
| 113 | 113 |
| 114 case R.id.actionbar_help: | 114 case R.id.actionbar_help: |
| 115 HelpActivity.launch(this, HELP_URL); | 115 HelpActivity.launch(this, HELP_URL); |
| 116 return true; | 116 return true; |
| 117 | 117 |
| 118 default: | 118 default: |
| 119 return super.onOptionsItemSelected(item); | 119 return super.onOptionsItemSelected(item); |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Called once when a keyboard key is pressed, then again when that same key
is released. This | 124 * Called once when a keyboard key is pressed, then again when that same key
is released. This |
| 125 * is not guaranteed to be notified of all soft keyboard events: certian key
boards might not | 125 * is not guaranteed to be notified of all soft keyboard events: certian key
boards might not |
| 126 * call it at all, while others might skip it in certain situations (e.g. sw
ipe input). | 126 * call it at all, while others might skip it in certain situations (e.g. sw
ipe input). |
| 127 */ | 127 */ |
| 128 @Override | 128 @Override |
| 129 public boolean dispatchKeyEvent(KeyEvent event) { | 129 public boolean dispatchKeyEvent(KeyEvent event) { |
| 130 // Send ACTION_MULTIPLE event as TextEvent. |
| 131 // |
| 132 // TODO(sergeyu): For all keys on English keyboard Android generates |
| 133 // ACTION_DOWN/ACTION_UP events, so they are sent as KeyEvent instead of |
| 134 // TextEvent. As result the host may handle them as non-English chars |
| 135 // when it has non-English layout selected, which might be confusing for |
| 136 // the user. This code should be fixed to send all text input events as |
| 137 // TextEvent, but it cannot be done now because not all hosts support |
| 138 // TextEvent. Also, to handle keyboard shortcuts properly this code will |
| 139 // need to track the state of modifier keys (such as Ctrl or Alt) and |
| 140 // send KeyEvents in the case any of the modifier keys are pressed. |
| 141 if (event.getAction() == KeyEvent.ACTION_MULTIPLE) { |
| 142 JniInterface.sendTextEvent(event.getCharacters()); |
| 143 return super.dispatchKeyEvent(event); |
| 144 } |
| 145 |
| 130 boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN; | 146 boolean depressed = event.getAction() == KeyEvent.ACTION_DOWN; |
| 131 | 147 |
| 132 switch (event.getKeyCode()) { | 148 switch (event.getKeyCode()) { |
| 133 case KeyEvent.KEYCODE_AT: | 149 case KeyEvent.KEYCODE_AT: |
| 134 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depress
ed); | 150 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed
); |
| 135 JniInterface.keyboardAction(KeyEvent.KEYCODE_2, depressed); | 151 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_2, depressed); |
| 136 break; | 152 break; |
| 137 | 153 |
| 138 case KeyEvent.KEYCODE_POUND: | 154 case KeyEvent.KEYCODE_POUND: |
| 139 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depress
ed); | 155 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed
); |
| 140 JniInterface.keyboardAction(KeyEvent.KEYCODE_3, depressed); | 156 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_3, depressed); |
| 141 break; | 157 break; |
| 142 | 158 |
| 143 case KeyEvent.KEYCODE_STAR: | 159 case KeyEvent.KEYCODE_STAR: |
| 144 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depress
ed); | 160 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed
); |
| 145 JniInterface.keyboardAction(KeyEvent.KEYCODE_8, depressed); | 161 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_8, depressed); |
| 146 break; | 162 break; |
| 147 | 163 |
| 148 case KeyEvent.KEYCODE_PLUS: | 164 case KeyEvent.KEYCODE_PLUS: |
| 149 JniInterface.keyboardAction(KeyEvent.KEYCODE_SHIFT_LEFT, depress
ed); | 165 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_SHIFT_LEFT, depressed
); |
| 150 JniInterface.keyboardAction(KeyEvent.KEYCODE_EQUALS, depressed); | 166 JniInterface.sendKeyEvent(KeyEvent.KEYCODE_EQUALS, depressed); |
| 151 break; | 167 break; |
| 152 | 168 |
| 153 default: | 169 default: |
| 154 // We try to send all other key codes to the host directly. | 170 // We try to send all other key codes to the host directly. |
| 155 JniInterface.keyboardAction(event.getKeyCode(), depressed); | 171 JniInterface.sendKeyEvent(event.getKeyCode(), depressed); |
| 156 } | 172 } |
| 157 | 173 |
| 158 return super.dispatchKeyEvent(event); | 174 return super.dispatchKeyEvent(event); |
| 159 } | 175 } |
| 160 } | 176 } |
| OLD | NEW |