Skip to content

Commit

Permalink
Fixes #2561 Support uppercase for text keys (#2679)
Browse files Browse the repository at this point in the history
* Handle uppercase for text keys

* Removed unnecessary intermediate variable
  • Loading branch information
keianhzo authored and MortimerGoro committed Jan 22, 2020
1 parent 2db96c1 commit ef63182
Showing 1 changed file with 22 additions and 18 deletions.
Expand Up @@ -31,42 +31,42 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

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

import org.mozilla.geckoview.GeckoSession;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.browser.SettingsStore;
import org.mozilla.vrbrowser.browser.engine.Session;
import org.mozilla.vrbrowser.input.CustomKeyboard;
import org.mozilla.vrbrowser.telemetry.GleanMetricsService;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.ui.keyboards.ChinesePinyinKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.ChineseZhuyinKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.DanishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.FinnishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.DutchKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.ItalianKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.EnglishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.FinnishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.FrenchKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.GermanKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.ChineseZhuyinKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.ItalianKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.JapaneseKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.KeyboardInterface;
import org.mozilla.vrbrowser.ui.keyboards.KoreanKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.NorwegianKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.PolishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.RussianKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.KoreanKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.SpanishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.SwedishKeyboard;
import org.mozilla.vrbrowser.ui.views.AutoCompletionView;
import org.mozilla.vrbrowser.ui.views.CustomKeyboardView;
import org.mozilla.vrbrowser.ui.views.KeyboardSelectorView;
import org.mozilla.vrbrowser.ui.widgets.dialogs.VoiceSearchWidget;
import org.mozilla.vrbrowser.ui.keyboards.ChinesePinyinKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.EnglishKeyboard;
import org.mozilla.vrbrowser.utils.StringUtils;

import java.util.ArrayList;
import java.util.Locale;

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


public class KeyboardWidget extends UIWidget implements CustomKeyboardView.OnKeyboardActionListener, AutoCompletionView.Delegate,
GeckoSession.TextInputDelegate, WidgetManagerDelegate.FocusChangeListener, VoiceSearchWidget.VoiceSearchDelegate, TextWatcher, WindowWidget.WindowListener {
Expand Down Expand Up @@ -619,7 +619,6 @@ private void cleanComposingText() {

private void handleShift(boolean isShifted) {
CustomKeyboard keyboard = (CustomKeyboard) mKeyboardView.getKeyboard();
boolean shifted = isShifted;
int[] shiftIndices = keyboard.getShiftKeyIndices();
for (int shiftIndex: shiftIndices) {
if (shiftIndex >= 0) {
Expand All @@ -635,13 +634,13 @@ private void handleShift(boolean isShifted) {
key.pressed = true;

} else {
key.icon = shifted ? mShiftOnIcon : mShiftOffIcon;
key.icon = isShifted ? mShiftOnIcon : mShiftOffIcon;
key.pressed = false;
}
}
}
}
mKeyboardView.setShifted(shifted || mIsCapsLock);
mKeyboardView.setShifted(isShifted || mIsCapsLock);
}

private void handleBackspace() {
Expand Down Expand Up @@ -822,35 +821,40 @@ private void handleKey(int primaryCode, int[] keyCodes) {
handleText(str);
}

private void handleText(final String aText) {
private void handleText(String aText) {
if (mFocusedView == null || mInputConnection == null) {
return;
}

if (mKeyboardView.isShifted()) {
aText = aText.toUpperCase();
}

final String text = aText;
if (mCurrentKeyboard.usesComposingText()) {
CharSequence seq = mInputConnection.getSelectedText(0);
String selected = seq != null ? seq.toString() : "";
if (selected.length() > 0 && StringUtils.removeSpaces(selected).contains(mComposingText)) {
// Clean composing text if the text is selected.
mComposingText = "";
}
mComposingText += aText;
mComposingText += text;
} else if (mCurrentKeyboard.usesTextOverride()) {
String beforeText = getTextBeforeCursor(mInputConnection);
final String newBeforeText = mCurrentKeyboard.overrideAddText(beforeText, aText);
final String newBeforeText = mCurrentKeyboard.overrideAddText(beforeText, text);
final InputConnection connection = mInputConnection;
postInputCommand(() -> {
if (newBeforeText != null) {
connection.deleteSurroundingText(beforeText.length(), 0);
connection.commitText(newBeforeText, 1);
} else {
connection.commitText(aText, 1);
connection.commitText(text, 1);
}
});

} else {
final InputConnection connection = mInputConnection;
postInputCommand(() -> connection.commitText(aText, 1));
postInputCommand(() -> connection.commitText(text, 1));
}
updateCandidates();
}
Expand Down

0 comments on commit ef63182

Please sign in to comment.