* Added "Space on Zero" option to address #5 * Implemented quick and simple fix for #11 * Expanded remapping feature. Can remap just IME keys or OSwide.
This commit is contained in:
parent
1b15cd0928
commit
e08c4a4fde
9 changed files with 253 additions and 169 deletions
|
|
@ -2,34 +2,26 @@ package org.nyanya.android.traditionalt9;
|
|||
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KeyMap {
|
||||
public static final String keymapfname = "keymap.txt";
|
||||
public static Map<Integer, Integer> keyMapping = new HashMap<Integer, Integer>();
|
||||
|
||||
public static int DPAD_CENTER = KeyEvent.KEYCODE_DPAD_CENTER;
|
||||
public static int DPAD_DOWN = KeyEvent.KEYCODE_DPAD_DOWN;
|
||||
public static int DPAD_UP = KeyEvent.KEYCODE_DPAD_UP;
|
||||
public static int DPAD_LEFT = KeyEvent.KEYCODE_DPAD_LEFT;
|
||||
public static int DPAD_RIGHT = KeyEvent.KEYCODE_DPAD_RIGHT;
|
||||
public static int SOFT_RIGHT = KeyEvent.KEYCODE_SOFT_RIGHT;
|
||||
public static int SOFT_LEFT = KeyEvent.KEYCODE_SOFT_LEFT;
|
||||
public static int DEL = KeyEvent.KEYCODE_DEL;
|
||||
public static int BACK = KeyEvent.KEYCODE_BACK;
|
||||
public static int ENTER = KeyEvent.KEYCODE_ENTER;
|
||||
public static int STAR = KeyEvent.KEYCODE_STAR;
|
||||
public static int POUND = KeyEvent.KEYCODE_POUND;
|
||||
static {
|
||||
setKeys();
|
||||
}
|
||||
|
||||
public static void setKeys() {
|
||||
public static int setKeys() {
|
||||
int msg = 0;
|
||||
keyMapping = new HashMap<Integer, Integer>();
|
||||
// check storage
|
||||
if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(Environment.getExternalStorageState())
|
||||
|| Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
|
||||
|
|
@ -37,7 +29,7 @@ public class KeyMap {
|
|||
if ((new File(new File(Environment.getExternalStorageDirectory(), TraditionalT9Settings.sddir),
|
||||
keymapfname)).exists()) {
|
||||
BufferedReader br = null;
|
||||
Log.d("KeyMap", "Attemping to load keys");
|
||||
Log.d("T9.KeyMap", "Attemping to load keys");
|
||||
try {
|
||||
br = new BufferedReader(new FileReader(new File(
|
||||
new File(Environment.getExternalStorageDirectory(), TraditionalT9Settings.sddir), keymapfname)));
|
||||
|
|
@ -48,43 +40,21 @@ public class KeyMap {
|
|||
if (ws.length != 2) {continue;}
|
||||
else if (line.startsWith("#")) {continue;}
|
||||
try {
|
||||
if (ws[0].equals("DPAD_CENTER")) {
|
||||
DPAD_CENTER = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("DPAD_DOWN")) {
|
||||
DPAD_DOWN = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("DPAD_UP")) {
|
||||
DPAD_UP = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("DPAD_LEFT")) {
|
||||
DPAD_LEFT = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("DPAD_RIGHT")) {
|
||||
DPAD_RIGHT = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("SOFT_RIGHT")) {
|
||||
SOFT_RIGHT = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("SOFT_LEFT")) {
|
||||
SOFT_LEFT = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("DEL")) {
|
||||
DEL = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("BACK")) {
|
||||
BACK = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("ENTER")) {
|
||||
ENTER = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("STAR")) {
|
||||
STAR = Integer.parseInt(ws[1]);
|
||||
} else if (ws[0].equals("POUND")) {
|
||||
POUND = Integer.parseInt(ws[1]);
|
||||
}
|
||||
keyMapping.put(Integer.parseInt(ws[0]), Integer.parseInt(ws[1]));
|
||||
} catch (NumberFormatException _ignore) {
|
||||
Log.w("T9.KeyMap", "Invalid number found");
|
||||
msg = R.string.pref_reloadKeysDoneWE;
|
||||
}
|
||||
}
|
||||
Log.d("KeyMap", "Done.");
|
||||
Log.d("T9.KeyMap", "Done.");
|
||||
} catch (IOException _ignore) {
|
||||
Log.e("T9.KeyMap", "Error while reading line.");
|
||||
try { br.close(); }
|
||||
catch (IOException ignored) {}
|
||||
}
|
||||
} catch (FileNotFoundException ignored) { }
|
||||
}
|
||||
}
|
||||
} catch (FileNotFoundException ignored) { msg = R.string.pref_reloadKeysDone; }
|
||||
} else { msg = R.string.pref_reloadKeysNoFile; }
|
||||
} else { msg = R.string.pref_reloadKeysNoFile; }
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue