Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/MousePadPlugin/KeyListenerView.java
Show All 27 Lines | |||||
28 | import android.view.View; | 28 | import android.view.View; | ||
29 | import android.view.inputmethod.EditorInfo; | 29 | import android.view.inputmethod.EditorInfo; | ||
30 | import android.view.inputmethod.InputConnection; | 30 | import android.view.inputmethod.InputConnection; | ||
31 | 31 | | |||
32 | import org.kde.kdeconnect.BackgroundService; | 32 | import org.kde.kdeconnect.BackgroundService; | ||
33 | import org.kde.kdeconnect.Device; | 33 | import org.kde.kdeconnect.Device; | ||
34 | import org.kde.kdeconnect.NetworkPackage; | 34 | import org.kde.kdeconnect.NetworkPackage; | ||
35 | 35 | | |||
36 | public class KeyListenerView extends View { | 36 | public class KeyListenerView extends View { | ||
37 | 37 | | |||
38 | private String deviceId; | 38 | private String deviceId; | ||
39 | 39 | | |||
40 | private static SparseIntArray SpecialKeysMap = new SparseIntArray(); | 40 | private static SparseIntArray SpecialKeysMap = new SparseIntArray(); | ||
41 | | ||||
41 | static { | 42 | static { | ||
42 | int i = 0; | 43 | int i = 0; | ||
43 | SpecialKeysMap.put(KeyEvent.KEYCODE_DEL, ++i); // 1 | 44 | SpecialKeysMap.put(KeyEvent.KEYCODE_DEL, ++i); // 1 | ||
44 | SpecialKeysMap.put(KeyEvent.KEYCODE_TAB, ++i); // 2 | 45 | SpecialKeysMap.put(KeyEvent.KEYCODE_TAB, ++i); // 2 | ||
45 | SpecialKeysMap.put(KeyEvent.KEYCODE_ENTER, 12); ++i; // 3 is not used, return is 12 instead | 46 | SpecialKeysMap.put(KeyEvent.KEYCODE_ENTER, 12); | ||
47 | ++i; // 3 is not used, return is 12 instead | ||||
46 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_LEFT, ++i); // 4 | 48 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_LEFT, ++i); // 4 | ||
47 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_UP, ++i); // 5 | 49 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_UP, ++i); // 5 | ||
48 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, ++i); // 6 | 50 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_RIGHT, ++i); // 6 | ||
49 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_DOWN, ++i); // 7 | 51 | SpecialKeysMap.put(KeyEvent.KEYCODE_DPAD_DOWN, ++i); // 7 | ||
50 | SpecialKeysMap.put(KeyEvent.KEYCODE_PAGE_UP, ++i); // 8 | 52 | SpecialKeysMap.put(KeyEvent.KEYCODE_PAGE_UP, ++i); // 8 | ||
51 | SpecialKeysMap.put(KeyEvent.KEYCODE_PAGE_DOWN, ++i); // 9 | 53 | SpecialKeysMap.put(KeyEvent.KEYCODE_PAGE_DOWN, ++i); // 9 | ||
52 | if (Build.VERSION.SDK_INT >= 11) { | 54 | if (Build.VERSION.SDK_INT >= 11) { | ||
53 | SpecialKeysMap.put(KeyEvent.KEYCODE_MOVE_HOME, ++i); // 10 | 55 | SpecialKeysMap.put(KeyEvent.KEYCODE_MOVE_HOME, ++i); // 10 | ||
▲ Show 20 Lines • Show All 106 Lines • ▼ Show 20 Line(s) | 161 | if (specialKey != -1) { | |||
160 | np.set("specialKey", specialKey); | 162 | np.set("specialKey", specialKey); | ||
161 | } else if (event.getDisplayLabel() != 0 && modifier) { | 163 | } else if (event.getDisplayLabel() != 0 && modifier) { | ||
162 | //Alt will change the utf symbol to non-ascii characters, we want the plain original letter | 164 | //Alt will change the utf symbol to non-ascii characters, we want the plain original letter | ||
163 | //Since getDisplayLabel will always have a value, we have to check for special keys before | 165 | //Since getDisplayLabel will always have a value, we have to check for special keys before | ||
164 | char keyCharacter = event.getDisplayLabel(); | 166 | char keyCharacter = event.getDisplayLabel(); | ||
165 | np.set("key", new String(new char[]{keyCharacter}).toLowerCase()); | 167 | np.set("key", new String(new char[]{keyCharacter}).toLowerCase()); | ||
166 | } else { | 168 | } else { | ||
167 | //A normal key, but still not handled by the KeyInputConnection (happens with numbers) | 169 | //A normal key, but still not handled by the KeyInputConnection (happens with numbers) | ||
168 | np.set("key", new String(new char[]{(char)event.getUnicodeChar()})); | 170 | np.set("key", new String(new char[]{(char) event.getUnicodeChar()})); | ||
169 | } | 171 | } | ||
170 | 172 | | |||
171 | sendKeyPressPackage(np); | 173 | sendKeyPressPackage(np); | ||
172 | return true; | 174 | return true; | ||
173 | 175 | | |||
174 | } | 176 | } | ||
175 | 177 | | |||
176 | } | 178 | } |