Skip to content

Commit

Permalink
Implement Chinese Pinyin keyboard (#1116)
Browse files Browse the repository at this point in the history
* Implement Chinese Pinyin keyboard

* Fix composed text while selecting. Fix some nits.

* Clear composed text when the keyboard is dismissed

* Fix backspace when composing text is selected

* Remove spaces when finalizing text with enter key
  • Loading branch information
MortimerGoro committed May 3, 2019
1 parent cf09d39 commit a555d88
Show file tree
Hide file tree
Showing 20 changed files with 1,159 additions and 77 deletions.
3 changes: 3 additions & 0 deletions app/build.gradle
Expand Up @@ -298,6 +298,9 @@ dependencies {
implementation deps.android_components.browser_domains
implementation deps.android_components.ui_autocomplete

// SQLite helper to handle DBs from assets
implementation deps.sqlite.sqlite

// Testing
testImplementation deps.junit
androidTestImplementation deps.atsl.runner
Expand Down
Expand Up @@ -170,7 +170,7 @@ public static void setParentField(Object obj, String fieldName, Object value) {
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
Key key = super.createKeyFromXml(res, parent, x, y, parser);
if (key.codes[0] == KeyEvent.KEYCODE_ENTER) {
if (key.codes[0] == KeyEvent.KEYCODE_ENTER || key.codes[0] == Keyboard.KEYCODE_DONE) {
mEnterKey = key;
} else if (key.codes[0] == ' ') {
mSpaceKey = key;
Expand All @@ -193,28 +193,22 @@ public int[] getNearestKeys(int x, int y) {
return new int[0];
}

public void setImeOptions(int options) {
if (mEnterKey == null) {
return;
public boolean setEnterKeyLabel(String aText) {
if (mEnterKey != null) {
boolean changed = !aText.equalsIgnoreCase(mEnterKey.label.toString());
mEnterKey.label = aText;
return changed;
}
return false;
}

switch (options & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
case EditorInfo.IME_ACTION_GO:
mEnterKey.label = "GO";
break;
case EditorInfo.IME_ACTION_NEXT:
mEnterKey.label = "NEXT";
break;
case EditorInfo.IME_ACTION_SEARCH:
mEnterKey.label = "SEARCH";
break;
case EditorInfo.IME_ACTION_SEND:
mEnterKey.label = "SEND";
break;
default:
mEnterKey.label = "ENTER";
break;
public boolean setSpaceKeyLabel(String aText) {
if (mSpaceKey != null) {
boolean changed = !aText.equalsIgnoreCase(mSpaceKey.label.toString());
mSpaceKey.label = aText;
return changed;
}
return false;
}

public int[] getShiftKeyIndices() {
Expand Down
@@ -0,0 +1,33 @@
package org.mozilla.vrbrowser.ui.keyboards;

import android.content.Context;
import android.view.inputmethod.EditorInfo;

import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.utils.StringUtils;

import java.util.Locale;

public abstract class BaseKeyboard implements KeyboardInterface {
protected Context mContext;
BaseKeyboard(Context aContext) {
mContext = aContext;
}

@Override
public String getEnterKeyText(int aIMEOptions, String aComposingText) {
Locale locale = getLocale();
switch (aIMEOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION)) {
case EditorInfo.IME_ACTION_GO:
return StringUtils.getStringByLocale(mContext, R.string.keyboard_go_label, locale);
case EditorInfo.IME_ACTION_NEXT:
return StringUtils.getStringByLocale(mContext, R.string.keyboard_next_label, locale);
case EditorInfo.IME_ACTION_SEARCH:
return StringUtils.getStringByLocale(mContext, R.string.keyboard_search_label, locale);
case EditorInfo.IME_ACTION_SEND:
return StringUtils.getStringByLocale(mContext, R.string.keyboard_send_label, locale);
default:
return StringUtils.getStringByLocale(mContext, R.string.keyboard_enter_label, locale);
}
}
}

0 comments on commit a555d88

Please sign in to comment.