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

Commit

Permalink
Support Thai keyboard. (#3544)
Browse files Browse the repository at this point in the history
* Support Thai keyboard.

* Adding domain names for Chinese keyboard.

* Correct Swedish dot symbol.
  • Loading branch information
daoshengmu committed Jun 29, 2020
1 parent 3481381 commit 93be5bc
Show file tree
Hide file tree
Showing 15 changed files with 418 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,24 @@ public String getModeChangeKeyText() {
return mContext.getString(R.string.keyboard_mode_change);
}

@Override
public float getKeyboardTranslateYInWorld() {
return WidgetPlacement.unitFromMeters(mContext, R.dimen.keyboard_y);
}

@Override
public float getKeyboardWorldWidth() {
return WidgetPlacement.floatDimension(mContext, R.dimen.keyboard_world_width);
}

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

public float getAlphabeticKeyboardHeight() {
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height);
}

@Override
public String[] getDomains(String... domains) {
return Stream.of(new String[]{".com", ".net", ".org", ".co"}, domains).flatMap(Stream::of)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,4 +484,9 @@ public DBHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".cn");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,9 @@ public DBPhraseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
}

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".tw");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public enum Action {
}
@NonNull CustomKeyboard getAlphabeticKeyboard();
float getAlphabeticKeyboardWidth();
float getAlphabeticKeyboardHeight();
float getKeyboardTranslateYInWorld();
float getKeyboardWorldWidth();
default @Nullable CustomKeyboard getAlphabeticCapKeyboard() { return null; }
default @Nullable CustomKeyboard getSymbolsKeyboard() { return null; }
default @Nullable CandidatesResult getCandidates(String aComposingText) { return null; }
default @Nullable String overrideAddText(String aTextBeforeCursor, String aNextText) { return null; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

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 ThaiKeyboard extends BaseKeyboard {
private Locale mLocale;
private CustomKeyboard mKeyboard;
private CustomKeyboard mCapKeyboard;
private CustomKeyboard mSymbolsKeyboard;

public ThaiKeyboard(Context aContext) {
super(aContext);
mLocale = new Locale("th", "TH");
}

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

@NonNull
@Override
public CustomKeyboard getAlphabeticCapKeyboard() {
if (mCapKeyboard == null) {
mCapKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_thai_cap);
mCapKeyboard.setShifted(true);
}
return mCapKeyboard;
}

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

@Override
public float getKeyboardTranslateYInWorld() {
return WidgetPlacement.unitFromMeters(mContext, R.dimen.keyboard_y_extra_row);
}

@Override
public float getKeyboardWorldWidth() {
return WidgetPlacement.floatDimension(mContext, R.dimen.keyboard_world_extra_row_width);
}

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

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

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

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

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

@Override
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_thai, getLocale());
}

@Override
public String getModeChangeKeyText() {
return mContext.getString(R.string.thai_keyboard_mode_change);
}

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".th");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.mozilla.vrbrowser.ui.keyboards.RussianKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.SpanishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.SwedishKeyboard;
import org.mozilla.vrbrowser.ui.keyboards.ThaiKeyboard;
import org.mozilla.vrbrowser.ui.views.AutoCompletionView;
import org.mozilla.vrbrowser.ui.views.CustomKeyboardView;
import org.mozilla.vrbrowser.ui.views.KeyboardSelectorView;
Expand Down Expand Up @@ -294,6 +295,7 @@ private void initialize(Context aContext) {
mKeyboards.add(new SwedishKeyboard(aContext));
mKeyboards.add(new FinnishKeyboard(aContext));
mKeyboards.add(new DutchKeyboard(aContext));
mKeyboards.add(new ThaiKeyboard(aContext));

mDefaultKeyboardSymbols = new CustomKeyboard(aContext.getApplicationContext(), R.xml.keyboard_symbols);
mKeyboardNumeric = new CustomKeyboard(aContext.getApplicationContext(), R.xml.keyboard_numeric);
Expand Down Expand Up @@ -377,9 +379,7 @@ public void releaseWidget() {
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
Context context = getContext();
aPlacement.width = getKeyboardWidth(WidgetPlacement.dpDimension(context, R.dimen.keyboard_alphabetic_width));
aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.keyboard_height);
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.autocompletion_widget_line_height);
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.keyboard_layout_padding);
aPlacement.height = getKeyboardHeight(WidgetPlacement.dpDimension(context, R.dimen.keyboard_height));
aPlacement.anchorX = 0.5f;
aPlacement.anchorY = 0.0f;
aPlacement.parentAnchorY = 0.0f;
Expand Down Expand Up @@ -429,6 +429,13 @@ private int getKeyboardWidth(float aAlphabeticWidth) {
return (int) width;
}

private int getKeyboardHeight(float aAlphabeticHeight) {
float height = aAlphabeticHeight;
height += WidgetPlacement.dpDimension(getContext(), R.dimen.autocompletion_widget_line_height);
height += WidgetPlacement.dpDimension(getContext(), R.dimen.keyboard_layout_padding);
return (int) height;
}

private void resetKeyboardLayout() {
if ((mEditorInfo.inputType & EditorInfo.TYPE_CLASS_NUMBER) == EditorInfo.TYPE_CLASS_NUMBER) {
mKeyboardView.setKeyboard(getSymbolsKeyboard());
Expand Down Expand Up @@ -735,6 +742,16 @@ private void cleanComposingText() {
}

private void handleShift(boolean isShifted) {
final boolean statusChanged = mKeyboardView.isShifted() != isShifted;

if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) {
if (isShifted || mIsCapsLock) {
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticCapKeyboard());
} else {
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticKeyboard());
}
}

CustomKeyboard keyboard = (CustomKeyboard) mKeyboardView.getKeyboard();
int[] shiftIndices = keyboard.getShiftKeyIndices();
for (int shiftIndex: shiftIndices) {
Expand All @@ -760,7 +777,7 @@ private void handleShift(boolean isShifted) {

// setShifted trigger a full keyboard redraw.
// To avoid this we only call setShifted if it's state has changed.
if (mKeyboardView.isShifted() != isShifted) {
if (statusChanged) {
mKeyboardView.setShifted(isShifted || mIsCapsLock);
}
}
Expand Down Expand Up @@ -859,18 +876,29 @@ private void handleLanguageChange(KeyboardInterface aKeyboard) {

mCurrentKeyboard = aKeyboard;
final int width = getKeyboardWidth(mCurrentKeyboard.getAlphabeticKeyboardWidth());
if (width != mWidgetPlacement.width) {
final int height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight());
if (width != mWidgetPlacement.width || height != mWidgetPlacement.height) {
mWidgetPlacement.width = width;
float defaultWorldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.keyboard_world_width);
mWidgetPlacement.height = height;
mWidgetPlacement.translationY = mCurrentKeyboard.getKeyboardTranslateYInWorld() -
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
float defaultWorldWidth = mCurrentKeyboard.getKeyboardWorldWidth();
int defaultKeyboardWidth = getKeyboardWidth(mKeyboards.get(0).getAlphabeticKeyboardWidth());
mWidgetPlacement.worldWidth = defaultWorldWidth * ((float) width / (float) defaultKeyboardWidth);
mWidgetManager.updateWidget(this);
ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams();
params.width = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight());
mKeyboardContainer.setLayoutParams(params);
}

final int pixelHeight = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight());
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)mKeyboardLayout.getLayoutParams();
if (pixelHeight != params.height) {
// We can consider to make mKeyboardLayout height is the maximum of height value in the future
// then we can avoid resize.
params.height = pixelHeight;
}
params.topMargin = mCurrentKeyboard.supportsAutoCompletion() ? WidgetPlacement.pixelDimension(getContext(), R.dimen.keyboard_margin_top_without_autocompletion) : 0;
mKeyboardLayout.setLayoutParams(params);

Expand Down Expand Up @@ -933,7 +961,6 @@ private void handleDone() {
}
}


private void handleModeChange() {
Keyboard current = mKeyboardView.getKeyboard();
Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard();
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/keyboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
android:padding="15dp"
android:layout_gravity="center"
android:background="@drawable/dialog_background"
android:alpha="0.5"
android:alpha="0.0"
android:visibility="gone"/>
</FrameLayout>

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/navigation_url.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
android:id="@+id/urlEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:paddingEnd="10dp"
android:layout_toStartOf="@id/endButtonsLayout"
android:layout_toEndOf="@id/icons"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/values/dimen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@

<!-- Keyboard -->
<item name="keyboard_world_width" format="float" type="dimen">3.25</item>
<item name="keyboard_world_extra_row_width" format="float" type="dimen">3.43</item>
<item name="keyboard_x" format="float" type="dimen">-0.15</item>
<item name="keyboard_y" format="float" type="dimen">-0.45</item>
<item name="zhuyin_keyboard_y" format="float" type="dimen">-0.63</item>
<item name="keyboard_y_extra_row" format="float" type="dimen">-0.72</item>
<item name="keyboard_z" format="float" type="dimen">-2.5</item>
<item name="keyboard_world_rotation" format="float" type="dimen">-35.0</item>
<dimen name="keyboard_height">188dp</dimen>
<dimen name="keyboard_height">186dp</dimen>
<dimen name="keyboard_alphabetic_width">526dp</dimen>
<dimen name="keyboard_alphabetic_width_danish">540dp</dimen>
<dimen name="keyboard_alphabetic_width_norwegian">540dp</dimen>
<dimen name="keyboard_alphabetic_width_swedish">540dp</dimen>
<dimen name="keyboard_alphabetic_width_finnish">540dp</dimen>
<dimen name="keyboard_alphabetic_width_zhuyin">470dp</dimen>
<dimen name="keyboard_alphabetic_width_extra_column">564dp</dimen>
<dimen name="keyboard_alphabetic_height_thai">226dp</dimen>
<dimen name="keyboard_numeric_width">144dp</dimen>
<dimen name="keyboard_zhuyin_height">228dp</dimen>
<dimen name="keyboard_horizontal_gap">4dp</dimen>
<dimen name="keyboard_vertical_gap">4dp</dimen>
<dimen name="keyboard_key_width">36dp</dimen>
Expand All @@ -49,6 +49,8 @@
<dimen name="keyboard_key_zhuyin_space_width">50dp</dimen>
<dimen name="keyboard_key_zhuyin_space_height">70dp</dimen>
<dimen name="keyboard_key_zhuyin_enter_width">74dp</dimen>
<dimen name="keyboard_key_thai_enter_width">50dp</dimen>
<dimen name="keyboard_key_thai_enter_height">72dp</dimen>
<dimen name="keyboard_key_backspace_width">50dp</dimen>
<dimen name="keyboard_key_enter_width">72dp</dimen>
<dimen name="keyboard_key_enter_width_small">62dp</dimen>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/non_L10n.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
<string name="japanese_enter_completion" translatable="false">確定</string>
<string name="japanese_keyboard_mode_change" translatable="false">かな</string>

<string name="thai_keyboard_mode_change" translatable="false">กขค</string>

<!-- Keyboard -->
<string name="keyboard_popup_a" translatable="false">aáàäãåâąæā</string>
<string name="keyboard_popup_b" translatable="false">bƀḃḅḇ</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@
changes the app and the language of the speech-recognition-based search to 'Dutch'. -->
<string name="settings_language_dutch">Dutch</string>

<!-- This string is used to label a radio button in the settings language dialog that, when pressed,
changes the app and the language of the speech-recognition-based search to 'Thai'. -->
<string name="settings_language_thai">Thai</string>

<!-- This string is used to label a button in the 'Settings' dialog window that, when pressed,
opens a dialog box that contains display-related settings: window size, pixel density, etc. -->
<string name="settings_display">Display</string>
Expand Down
Loading

0 comments on commit 93be5bc

Please sign in to comment.