forked from extern/Unexpected-Keyboard
Key to switch to numeric pane
This commit is contained in:
parent
549c753450
commit
03cc0a5429
@ -3,6 +3,5 @@
|
|||||||
<string-array name="pref_layout_values">
|
<string-array name="pref_layout_values">
|
||||||
<item>azerty</item>
|
<item>azerty</item>
|
||||||
<item>qwerty</item>
|
<item>qwerty</item>
|
||||||
<item>numeric</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
<string-array name="pref_layout_entries">
|
<string-array name="pref_layout_entries">
|
||||||
<item>Azerty</item>
|
<item>Azerty</item>
|
||||||
<item>Qwerty</item>
|
<item>Qwerty</item>
|
||||||
<item>Numeric</item>
|
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
<string name="pref_category_typing">Typing</string>
|
<string name="pref_category_typing">Typing</string>
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<key width="2.0" key0="backspace" key1="insert" key2="delete" />
|
<key width="2.0" key0="backspace" key1="insert" key2="delete" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key width="1.8" key0="ctrl" />
|
<key width="1.8" key0="ctrl" key3="switch_numeric" />
|
||||||
<key width="1.0" key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
|
<key width="1.0" key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
|
||||||
<key width="4.4" key0="space" />
|
<key width="4.4" key0="space" />
|
||||||
<key key1="up" key2="right" key3="left" key4="down" />
|
<key key1="up" key2="right" key3="left" key4="down" />
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
<key width="1.0" key0="enter" key1="config" />
|
<key width="1.0" key0="enter" key1="config" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key width="1.0" key0="ctrl" />
|
<key width="1.0" key0="ctrl" key3="switch_text" />
|
||||||
<key width="1.0" key0="space" />
|
<key width="1.0" key0="space" />
|
||||||
<key width="1.0" key0="space" />
|
<key width="1.0" key0="space" />
|
||||||
<key width="3.0" key0="0" />
|
<key width="3.0" key0="0" />
|
||||||
|
@ -35,7 +35,7 @@
|
|||||||
<key width="1.5" key0="backspace" key2="delete" />
|
<key width="1.5" key0="backspace" key2="delete" />
|
||||||
</row>
|
</row>
|
||||||
<row>
|
<row>
|
||||||
<key width="1.8" key0="ctrl" />
|
<key width="1.8" key0="ctrl" key3="switch_numeric" />
|
||||||
<key key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
|
<key key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
|
||||||
<key width="4.4" key0="space" />
|
<key width="4.4" key0="space" />
|
||||||
<key key1="up" key2="right" key3="left" key4="down" />
|
<key key1="up" key2="right" key3="left" key4="down" />
|
||||||
|
@ -8,6 +8,8 @@ class KeyValue
|
|||||||
{
|
{
|
||||||
public static final int EVENT_NONE = -1;
|
public static final int EVENT_NONE = -1;
|
||||||
public static final int EVENT_CONFIG = -2;
|
public static final int EVENT_CONFIG = -2;
|
||||||
|
public static final int EVENT_SWITCH_TEXT = -3;
|
||||||
|
public static final int EVENT_SWITCH_NUMERIC = -4;
|
||||||
public static final char CHAR_NONE = '\0';
|
public static final char CHAR_NONE = '\0';
|
||||||
|
|
||||||
public static final int FLAG_KEEP_ON = 1;
|
public static final int FLAG_KEEP_ON = 1;
|
||||||
@ -165,6 +167,9 @@ class KeyValue
|
|||||||
new KeyValue("9", null, '9', KeyEvent.KEYCODE_9, 0);
|
new KeyValue("9", null, '9', KeyEvent.KEYCODE_9, 0);
|
||||||
|
|
||||||
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, 0);
|
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, 0);
|
||||||
|
new KeyValue("switch_text", "ABC", CHAR_NONE, EVENT_SWITCH_TEXT, 0);
|
||||||
|
new KeyValue("switch_numeric", "123+", CHAR_NONE, EVENT_SWITCH_NUMERIC, 0);
|
||||||
|
|
||||||
new KeyValue("enter", "↵", CHAR_NONE, KeyEvent.KEYCODE_ENTER, 0);
|
new KeyValue("enter", "↵", CHAR_NONE, KeyEvent.KEYCODE_ENTER, 0);
|
||||||
new KeyValue("up", "↑", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, 0);
|
new KeyValue("up", "↑", CHAR_NONE, KeyEvent.KEYCODE_DPAD_UP, 0);
|
||||||
new KeyValue("right", "→", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, 0);
|
new KeyValue("right", "→", CHAR_NONE, KeyEvent.KEYCODE_DPAD_RIGHT, 0);
|
||||||
|
@ -5,7 +5,9 @@ import android.content.Intent;
|
|||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.inputmethodservice.InputMethodService;
|
import android.inputmethodservice.InputMethodService;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.text.InputType;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -14,6 +16,8 @@ public class Keyboard2 extends InputMethodService
|
|||||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
{
|
{
|
||||||
private Keyboard2View _inputView = null;
|
private Keyboard2View _inputView = null;
|
||||||
|
private KeyboardData _textKeyboard = null;
|
||||||
|
private KeyboardData _numericKeyboard = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
@ -21,6 +25,7 @@ public class Keyboard2 extends InputMethodService
|
|||||||
super.onCreate();
|
super.onCreate();
|
||||||
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
|
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
|
||||||
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
|
||||||
|
updateConfig();
|
||||||
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
|
_inputView = (Keyboard2View)getLayoutInflater().inflate(R.layout.input, null);
|
||||||
_inputView.reset_prefs(this);
|
_inputView.reset_prefs(this);
|
||||||
}
|
}
|
||||||
@ -32,13 +37,22 @@ public class Keyboard2 extends InputMethodService
|
|||||||
|
|
||||||
if (parent != null)
|
if (parent != null)
|
||||||
parent.removeView(_inputView);
|
parent.removeView(_inputView);
|
||||||
_inputView.reset();
|
|
||||||
return (_inputView);
|
return (_inputView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStartInputView(EditorInfo info, boolean restarting)
|
||||||
|
{
|
||||||
|
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
|
||||||
|
_inputView.setKeyboard(_numericKeyboard);
|
||||||
|
else
|
||||||
|
_inputView.setKeyboard(_textKeyboard);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||||
{
|
{
|
||||||
|
updateConfig();
|
||||||
_inputView.reset_prefs(this);
|
_inputView.reset_prefs(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,6 +67,20 @@ public class Keyboard2 extends InputMethodService
|
|||||||
_inputView.reset();
|
_inputView.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateConfig()
|
||||||
|
{
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
String keyboardLayout = prefs.getString("keyboard_layout", null);
|
||||||
|
int xmlRes = 0;
|
||||||
|
|
||||||
|
if (keyboardLayout != null)
|
||||||
|
xmlRes = getResources().getIdentifier(keyboardLayout, "xml", getPackageName());
|
||||||
|
if (xmlRes == 0)
|
||||||
|
xmlRes = R.xml.azerty;
|
||||||
|
_textKeyboard = new KeyboardData(getResources().getXml(xmlRes));
|
||||||
|
_numericKeyboard = new KeyboardData(getResources().getXml(R.xml.numeric));
|
||||||
|
}
|
||||||
|
|
||||||
public void handleKeyUp(KeyValue key, int flags)
|
public void handleKeyUp(KeyValue key, int flags)
|
||||||
{
|
{
|
||||||
if (getCurrentInputConnection() == null)
|
if (getCurrentInputConnection() == null)
|
||||||
@ -63,6 +91,10 @@ public class Keyboard2 extends InputMethodService
|
|||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
else if (key.getEventCode() == KeyValue.EVENT_SWITCH_TEXT)
|
||||||
|
_inputView.setKeyboard(_textKeyboard);
|
||||||
|
else if (key.getEventCode() == KeyValue.EVENT_SWITCH_NUMERIC)
|
||||||
|
_inputView.setKeyboard(_numericKeyboard);
|
||||||
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
|
else if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0)
|
||||||
handleMetaKeyUp(key, flags);
|
handleMetaKeyUp(key, flags);
|
||||||
else if (key.getEventCode() == KeyEvent.KEYCODE_DEL)
|
else if (key.getEventCode() == KeyEvent.KEYCODE_DEL)
|
||||||
|
@ -102,15 +102,12 @@ public class Keyboard2View extends View
|
|||||||
_marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("margin_bottom", (int)_marginBottom), getResources().getDisplayMetrics());
|
_marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("margin_bottom", (int)_marginBottom), getResources().getDisplayMetrics());
|
||||||
_keyHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("key_height", (int)_keyHeight), getResources().getDisplayMetrics());
|
_keyHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("key_height", (int)_keyHeight), getResources().getDisplayMetrics());
|
||||||
_horizontalMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("horizontal_margin", (int)_horizontalMargin), getResources().getDisplayMetrics());
|
_horizontalMargin = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, prefs.getInt("horizontal_margin", (int)_horizontalMargin), getResources().getDisplayMetrics());
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
String keyboardLayout = prefs.getString("keyboard_layout", null);
|
public void setKeyboard(KeyboardData keyboard)
|
||||||
int xmlRes = 0;
|
{
|
||||||
|
_keyboard = keyboard;
|
||||||
if (keyboardLayout != null)
|
|
||||||
xmlRes = ime.getResources().getIdentifier(keyboardLayout, "xml", ime.getPackageName());
|
|
||||||
if (xmlRes == 0)
|
|
||||||
xmlRes = R.xml.azerty;
|
|
||||||
_keyboard = new KeyboardData(ime.getResources().getXml(xmlRes));
|
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user