|
|
@@ -5,6 +5,8 @@ import android.inputmethodservice.Keyboard;
|
|
|
import android.inputmethodservice.KeyboardView;
|
|
|
import android.util.Xml;
|
|
|
|
|
|
+import java.util.Locale;
|
|
|
+
|
|
|
import info.knacki.pass.R;
|
|
|
|
|
|
public class KeyboardWidget extends KeyboardView implements KeyboardView.OnKeyboardActionListener {
|
|
|
@@ -15,7 +17,6 @@ public class KeyboardWidget extends KeyboardView implements KeyboardView.OnKeybo
|
|
|
private final Context fContext;
|
|
|
private boolean fIsDisplayingLetters;
|
|
|
|
|
|
-
|
|
|
public KeyboardWidget(Context c) {
|
|
|
super(c, Xml.asAttributeSet(c.getResources().getXml(R.xml.keyboard_attributes)));
|
|
|
fContext = c;
|
|
|
@@ -39,34 +40,40 @@ public class KeyboardWidget extends KeyboardView implements KeyboardView.OnKeybo
|
|
|
public void onRelease(int primaryCode) {
|
|
|
}
|
|
|
|
|
|
+ private Keyboard SetActiveLayout(Keyboard loadedKeyboard, int layout) {
|
|
|
+ Keyboard k = loadedKeyboard == null ? new Keyboard(fContext, layout) : loadedKeyboard;
|
|
|
+ setKeyboard(k);
|
|
|
+ return k;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public void onKey(int primaryCode, int[] keyCodes) {
|
|
|
if (primaryCode == fContext.getResources().getInteger(R.integer.id_keyboard_numbers)) {
|
|
|
- if (fIsDisplayingLetters) {
|
|
|
- if (fNumberKeyboard == null)
|
|
|
- fNumberKeyboard = new Keyboard(fContext, R.xml.qwerty_symbols);
|
|
|
- setKeyboard(fNumberKeyboard);
|
|
|
- setShifted(false);
|
|
|
- fIsDisplayingLetters = false;
|
|
|
- } else {
|
|
|
+ if (fIsDisplayingLetters)
|
|
|
+ fNumberKeyboard = SetActiveLayout(fNumberKeyboard, R.xml.qwerty_symbols);
|
|
|
+ else
|
|
|
setKeyboard(fKeyboard);
|
|
|
- fIsDisplayingLetters = true;
|
|
|
- }
|
|
|
+ fIsDisplayingLetters = !fIsDisplayingLetters;
|
|
|
+ setShifted(false);
|
|
|
} else if (primaryCode == fContext.getResources().getInteger(R.integer.id_keyboard_shift)) {
|
|
|
if (!fIsDisplayingLetters) {
|
|
|
if (isShifted()) {
|
|
|
setKeyboard(fNumberKeyboard);
|
|
|
+ setShifted(false);
|
|
|
} else {
|
|
|
- if (fSymbolsKeyboard == null)
|
|
|
- fSymbolsKeyboard = new Keyboard(fContext, R.xml.qwerty_symbol_shift);
|
|
|
- setKeyboard(fSymbolsKeyboard);
|
|
|
+ fSymbolsKeyboard = SetActiveLayout(fSymbolsKeyboard, R.xml.qwerty_symbol_shift);
|
|
|
+ setShifted(true);
|
|
|
}
|
|
|
}
|
|
|
- setShifted(!isShifted());
|
|
|
+ else
|
|
|
+ setShifted(!isShifted());
|
|
|
} else if (primaryCode == fContext.getResources().getInteger(R.integer.id_keyboard_delete)) {
|
|
|
fListener.OnBackspace();
|
|
|
} else {
|
|
|
- final String text = new String(Character.toChars(primaryCode));
|
|
|
+ String text = new String(Character.toChars(primaryCode));
|
|
|
+
|
|
|
+ if (isShifted() && fIsDisplayingLetters)
|
|
|
+ text = text.toUpperCase(Locale.getDefault());
|
|
|
if (text.length() > 0)
|
|
|
fListener.OnKeyReceived(text);
|
|
|
}
|