Add qwerty layout + popup to change layout

This commit is contained in:
juloo 2015-08-03 20:01:05 +02:00
parent b32f2ce3f3
commit 1be1ec7a4b
5 changed files with 88 additions and 9 deletions

View File

@ -25,20 +25,20 @@
<key key0="m" key2="µ" key4="*" /> <key key0="m" key2="µ" key4="*" />
</row> </row>
<row> <row>
<key width="1.4" key0="shift" /> <key width="2.0" key0="shift" />
<key key0="w" key1="&gt;" key3="&lt;" /> <key key0="w" key1="&gt;" key3="&lt;" />
<key key0="x" /> <key key0="x" />
<key key0="c" key2="\?" key4="," /> <key key0="c" key2="\?" key4="," />
<key key0="v" key2="." key4=";" /> <key key0="v" key2="." key4=";" />
<key key0="b" key2="/" key4=":" /> <key key0="b" key2="/" key4=":" />
<key key0="n" key2="§" key4="!" /> <key key0="n" key2="§" key4="!" />
<key key1="up" key2="right" key3="left" key4="down" /> <key width="2.0" key0="backspace" key1="insert" key2="delete" />
<key width="1.6" key0="backspace" key1="insert" key2="delete" />
</row> </row>
<row> <row>
<key width="1.6" key0="ctrl" /> <key width="1.8" key0="ctrl" />
<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.8" key0="space" /> <key width="4.4" key0="space" />
<key width="2.6" key0="enter" /> <key key1="up" key2="right" key3="left" key4="down" />
<key width="1.8" key0="enter" key1="config" />
</row> </row>
</keyboard> </keyboard>

44
res/xml/qwerty.xml Normal file
View File

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<keyboard>
<row>
<key key0="q" key1="~" key2="1" key3="!" key4="`" />
<key key0="w" key2="2" key3="\@" />
<key key0="e" key2="3" key3="\#" />
<key key0="r" key2="4" key3="$" />
<key key0="t" key2="5" key3="%" />
<key key0="y" key2="6" key3="^" />
<key key0="u" key2="7" key3="&amp;" />
<key key0="i" key2="8" key3="*" />
<key key0="o" key2="9" key3="(" />
<key key0="p" key2="0" key3=")" />
</row>
<row>
<key key0="a" key1="tab" />
<key key0="s" />
<key key0="d" />
<key key0="f" />
<key key0="g" key2="_" key3="-" />
<key key0="h" key2="+" key3="=" />
<key key0="j" key2="{" key3="[" />
<key key0="k" key2="}" key3="]" />
<key key0="l" key2="|" key3="\" />
</row>
<row>
<key width="1.5" key0="shift" />
<key key0="z" />
<key key0="x" />
<key key0="c" key2="&lt;" key3="." />
<key key0="v" key2="&gt;" key3="," />
<key key0="b" key2="\?" key3="/" />
<key key0="n" key2=":" key3=";" />
<key key0="m" key2="&quot;" key3="'" />
<key width="1.5" key0="backspace" key1="insert" key2="delete" />
</row>
<row>
<key width="1.8" key0="ctrl" />
<key key0="alt" key1="page_up" key2="end" key3="home" key4="page_down" />
<key width="4.4" key0="space" />
<key key1="up" key2="right" key3="left" key4="down" />
<key width="1.8" key0="enter" key1="config" />
</row>
</keyboard>

View File

@ -6,6 +6,7 @@ import java.util.HashMap;
class KeyValue 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 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;
@ -121,6 +122,7 @@ class KeyValue
new KeyValue("8", "8", '8', KeyEvent.KEYCODE_8, 0); new KeyValue("8", "8", '8', KeyEvent.KEYCODE_8, 0);
new KeyValue("9", "9", '9', KeyEvent.KEYCODE_9, 0); new KeyValue("9", "9", '9', KeyEvent.KEYCODE_9, 0);
new KeyValue("config", "Conf", CHAR_NONE, EVENT_CONFIG, 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);

View File

@ -10,13 +10,13 @@ public class Keyboard2 extends InputMethodService
public static final String TAG = "Keyboard_2.0"; public static final String TAG = "Keyboard_2.0";
private KeyboardData _keyboardData; private KeyboardData _keyboardData;
private Keyboard2View _inputView; private Keyboard2View _inputView = null;
@Override @Override
public void onCreate() public void onCreate()
{ {
super.onCreate(); super.onCreate();
_keyboardData = new KeyboardData(getResources().getXml(R.xml.azerty)); setKeyboard(R.xml.azerty);
} }
@Override @Override
@ -27,11 +27,42 @@ public class Keyboard2 extends InputMethodService
return (_inputView); return (_inputView);
} }
private void setKeyboard(int res)
{
_keyboardData = new KeyboardData(getResources().getXml(res));
if (_inputView != null)
_inputView.setKeyboard(this, _keyboardData);
}
public void handleKeyUp(KeyValue key, int flags) public void handleKeyUp(KeyValue key, int flags)
{ {
if (getCurrentInputConnection() == null) if (getCurrentInputConnection() == null)
return ; return ;
if ((flags & (KeyValue.FLAG_CTRL | KeyValue.FLAG_ALT)) != 0) if (key.getEventCode() == KeyValue.EVENT_CONFIG)
{
// TODO improve this shit
final CharSequence layouts[] = new CharSequence[]{"Azerty", "Qwerty"};
final int layout_res[] = new int[]{R.xml.azerty, R.xml.qwerty};
final Keyboard2 self = this;
android.app.AlertDialog dialog = new android.app.AlertDialog.Builder(this)
.setTitle("Change keyboard layout")
.setItems(layouts, new android.content.DialogInterface.OnClickListener()
{
@Override
public void onClick(android.content.DialogInterface dialog, int which)
{
self.setKeyboard(layout_res[which]);
}
})
.create();
android.view.WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
lp.token = _inputView.getWindowToken();
lp.type = android.view.WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
dialog.getWindow().setAttributes(lp);
dialog.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
dialog.show();
}
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)
handleDelKey(1, 0); handleDelKey(1, 0);

View File

@ -75,6 +75,8 @@ public class Keyboard2View extends View
{ {
_ime = ime; _ime = ime;
_keyboard = keyboardData; _keyboard = keyboardData;
requestLayout();
invalidate();
} }
@Override @Override