Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Commit

Permalink
Keyboard updates: Polish, Danish UIS-6 and bug fixing (#1890)
Browse files Browse the repository at this point in the history
* Keyboard updated

Added Danish and Polish and updated the Spec to UIS-6_Keyboard_021

* Added Danish and Polish to display and voice languages

* Fixed spacebar strings for polish and Danish

* Updated Polski language string
  • Loading branch information
keianhzo authored and bluemarvin committed Oct 16, 2019
1 parent 1bb6b98 commit e8a2dad
Show file tree
Hide file tree
Showing 33 changed files with 603 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.content.res.XmlResourceParser;
import android.inputmethodservice.Keyboard;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;

import java.lang.reflect.Field;
import java.util.ArrayList;
Expand All @@ -22,6 +21,7 @@ public class CustomKeyboard extends Keyboard {
private Key mSpaceKey;
private Key mModeChangeKey;
private int mMaxColums;
private int[] mDisabledKeysIndexes;

public static final int KEYCODE_SYMBOLS_CHANGE = -10;
public static final int KEYCODE_VOICE_INPUT = -11;
Expand Down Expand Up @@ -235,7 +235,23 @@ public int[] getShiftKeyIndices() {
}
}

public int getMaxColums() {
public int getMaxColumns() {
return mMaxColums;
}

public void disableKeys(int[] disabledKeyIndexes) {
mDisabledKeysIndexes = disabledKeyIndexes;
}

public boolean isKeyEnabled(int keyIndex) {
if (mDisabledKeysIndexes != null) {
for (int key : mDisabledKeysIndexes) {
if (key == keyIndex) {
return false;
}
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Locale getLocale() {
@Override
public String getSpaceKeyText(String aComposingText) {
if (aComposingText == null || aComposingText.trim().isEmpty()) {
return mContext.getString(R.string.pinyin_spacebar_space);
return StringUtils.getStringByLocale(mContext, R.string.settings_language_simplified_chinese, getLocale());
} else {
return mContext.getString(R.string.pinyin_spacebar_selection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public Locale getLocale() {
@Override
public String getSpaceKeyText(String aComposingText) {
if (aComposingText == null || aComposingText.trim().isEmpty()) {
return mContext.getString(R.string.zhuyin_spacebar_space);
return StringUtils.getStringByLocale(mContext, R.string.settings_language_traditional_chinese, getLocale());
} else {
return mContext.getString(R.string.zhuyin_spacebar_selection);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.mozilla.vrbrowser.ui.keyboards;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.input.CustomKeyboard;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.StringUtils;

import java.util.Locale;

public class DanishKeyboard extends BaseKeyboard {
private CustomKeyboard mKeyboard;
private CustomKeyboard mSymbolsKeyboard;
private Locale mLocale;

public DanishKeyboard(Context aContext) {
super(aContext);
mLocale = new Locale("da", "DK");
}

@NonNull
@Override
public CustomKeyboard getAlphabeticKeyboard() {
if (mKeyboard == null) {
mKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_danish);
}
return mKeyboard;
}

@Nullable
@Override
public CustomKeyboard getSymbolsKeyboard() {
if (mSymbolsKeyboard == null) {
mSymbolsKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_symbols_danish);
}
return mSymbolsKeyboard;
}

@Override
public float getAlphabeticKeyboardWidth() {
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_alphabetic_width_danish);
}

@Nullable
@Override
public CandidatesResult getCandidates(String aText) {
return null;
}

@Override
public String getKeyboardTitle() {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_danish, getLocale());
}

@Override
public Locale getLocale() {
return mLocale;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_danish, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return Locale.ENGLISH;
}
@Override
public String getSpaceKeyText(String aComposingText) {

return StringUtils.getStringByLocale(mContext, R.string.settings_language_english, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return Locale.FRENCH;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_french, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return Locale.GERMAN;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_german, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return Locale.ITALIAN;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_italian, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Locale getLocale() {
@Override
public String getSpaceKeyText(String aComposingText) {
if (aComposingText == null || aComposingText.trim().isEmpty()) {
return mContext.getString(R.string.japanese_spacebar_space);
return StringUtils.getStringByLocale(mContext, R.string.settings_language_japanese, getLocale());
} else {
return mContext.getString(R.string.japanese_spacebar_selection);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return Locale.KOREAN;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_korean, getLocale());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package org.mozilla.vrbrowser.ui.keyboards;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.input.CustomKeyboard;
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
import org.mozilla.vrbrowser.utils.StringUtils;

import java.util.Locale;

public class PolishKeyboard extends BaseKeyboard {
private CustomKeyboard mKeyboard;
private CustomKeyboard mSymbolsKeyboard;
private Locale mLocale;

public PolishKeyboard(Context aContext) {
super(aContext);
mLocale = new Locale("pl", "PL");
}

@NonNull
@Override
public CustomKeyboard getAlphabeticKeyboard() {
if (mKeyboard == null) {
mKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_polish);
}
return mKeyboard;
}

@Nullable
@Override
public CustomKeyboard getSymbolsKeyboard() {
if (mSymbolsKeyboard == null) {
mSymbolsKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_symbols_polish);
}
return mSymbolsKeyboard;
}

@Override
public float getAlphabeticKeyboardWidth() {
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_alphabetic_width);
}

@Nullable
@Override
public CandidatesResult getCandidates(String aText) {
return null;
}

@Override
public String getKeyboardTitle() {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_polish, getLocale());
}

@Override
public Locale getLocale() {
return mLocale;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_polish, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return mLocale;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_russian, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,9 @@ public String getKeyboardTitle() {
public Locale getLocale() {
return mSpanishLocale;
}

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_spanish, getLocale());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.graphics.Paint.Align;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.Region.Op;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.inputmethodservice.Keyboard;
Expand All @@ -32,7 +31,6 @@
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.GestureDetector;
import android.view.Gravity;
Expand Down Expand Up @@ -184,6 +182,9 @@ public interface OnKeyboardActionListener {
android.R.attr.state_checked
};

private final static int[] KEY_STATE_NORMAL = {
};

private int mVerticalCorrection;
private int mProximityThreshold;

Expand Down Expand Up @@ -738,23 +739,31 @@ private void onBufferDraw() {
if (drawSingleKey && invalidKey != key) {
continue;
}
int[] drawableState = key.getCurrentDrawableState();
if (mHoveredKey == i && !key.pressed) {
// Fork: implement hovered key
drawableState = KEY_STATE_HOVERED;
}

boolean stateHovered = false;
boolean statePressed = false;
for (int state : drawableState) {
if (state == android.R.attr.state_hovered) {
stateHovered = true;
} else if (state == android.R.attr.state_pressed) {
statePressed = true;
int[] drawableState = key.getCurrentDrawableState();

if (((CustomKeyboard)mKeyboard).isKeyEnabled(i)) {
if (mHoveredKey == i && !key.pressed) {
// Fork: implement hovered key
drawableState = KEY_STATE_HOVERED;
}

for (int state : drawableState) {
if (state == android.R.attr.state_hovered) {
stateHovered = true;
} else if (state == android.R.attr.state_pressed) {
statePressed = true;
}
}

} else {
drawableState = KEY_STATE_NORMAL;
}

Drawable keyBackground = mKeyBackground;
int columns = ((CustomKeyboard)mKeyboard).getMaxColums();
int columns = ((CustomKeyboard)mKeyboard).getMaxColumns();
if (mFeaturedKeyBackground != null && mFeaturedKeyCodes.contains(key.codes[0])) {
keyBackground = mFeaturedKeyBackground;
} else if ((i == columns && i == keyCount - 1) && mKeySingleBackground != null) {
Expand Down Expand Up @@ -912,7 +921,7 @@ private int getKeyIndices(int x, int y, int[] allKeys) {
private void detectAndSendKey(int index, int x, int y, long eventTime) {
if (index != NOT_A_KEY && index < mKeys.length) {
final Key key = mKeys[index];
if (key.text != null) {
if (key.text != null && (key.popupCharacters == null || key.popupCharacters.length() == 0)) {
if (mKeyboardActionListener != null) {
mKeyboardActionListener.onText(key.text);
mKeyboardActionListener.onRelease(NOT_A_KEY);
Expand Down Expand Up @@ -1252,6 +1261,10 @@ private boolean onModifiedTouchEvent(MotionEvent me, boolean possiblePoly) {
int keyIndex = getKeyIndices(touchX, touchY, null);
mPossiblePoly = possiblePoly;

if (keyIndex != NOT_A_KEY && !((CustomKeyboard)mKeyboard).isKeyEnabled(keyIndex)) {
return true;
}

// Track the last few movements to look for spurious swipes.
if (action == MotionEvent.ACTION_DOWN) mSwipeTracker.clear();
mSwipeTracker.addMovement(me);
Expand Down
Loading

0 comments on commit e8a2dad

Please sign in to comment.