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

Commit 93be5bc

Browse files
authored
Support Thai keyboard. (#3544)
* Support Thai keyboard. * Adding domain names for Chinese keyboard. * Correct Swedish dot symbol.
1 parent 3481381 commit 93be5bc

15 files changed

+418
-13
lines changed

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/BaseKeyboard.java

+14
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,24 @@ public String getModeChangeKeyText() {
4949
return mContext.getString(R.string.keyboard_mode_change);
5050
}
5151

52+
@Override
53+
public float getKeyboardTranslateYInWorld() {
54+
return WidgetPlacement.unitFromMeters(mContext, R.dimen.keyboard_y);
55+
}
56+
57+
@Override
58+
public float getKeyboardWorldWidth() {
59+
return WidgetPlacement.floatDimension(mContext, R.dimen.keyboard_world_width);
60+
}
61+
5262
public float getAlphabeticKeyboardWidth() {
5363
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_alphabetic_width);
5464
}
5565

66+
public float getAlphabeticKeyboardHeight() {
67+
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_height);
68+
}
69+
5670
@Override
5771
public String[] getDomains(String... domains) {
5872
return Stream.of(new String[]{".com", ".net", ".org", ".co"}, domains).flatMap(Stream::of)

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChinesePinyinKeyboard.java

+5
Original file line numberDiff line numberDiff line change
@@ -484,4 +484,9 @@ public DBHelper(Context context) {
484484
super(context, DATABASE_NAME, null, DATABASE_VERSION);
485485
}
486486
}
487+
488+
@Override
489+
public String[] getDomains(String... domains) {
490+
return super.getDomains(".cn");
491+
}
487492
}

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/ChineseZhuyinKeyboard.java

+5
Original file line numberDiff line numberDiff line change
@@ -480,4 +480,9 @@ public DBPhraseHelper(Context context) {
480480
super(context, DATABASE_NAME, null, DATABASE_VERSION);
481481
}
482482
}
483+
484+
@Override
485+
public String[] getDomains(String... domains) {
486+
return super.getDomains(".tw");
487+
}
483488
}

app/src/common/shared/org/mozilla/vrbrowser/ui/keyboards/KeyboardInterface.java

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public enum Action {
3030
}
3131
@NonNull CustomKeyboard getAlphabeticKeyboard();
3232
float getAlphabeticKeyboardWidth();
33+
float getAlphabeticKeyboardHeight();
34+
float getKeyboardTranslateYInWorld();
35+
float getKeyboardWorldWidth();
36+
default @Nullable CustomKeyboard getAlphabeticCapKeyboard() { return null; }
3337
default @Nullable CustomKeyboard getSymbolsKeyboard() { return null; }
3438
default @Nullable CandidatesResult getCandidates(String aComposingText) { return null; }
3539
default @Nullable String overrideAddText(String aTextBeforeCursor, String aNextText) { return null; }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
2+
* This Source Code Form is subject to the terms of the Mozilla Public
3+
* License, v. 2.0. If a copy of the MPL was not distributed with this
4+
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5+
6+
package org.mozilla.vrbrowser.ui.keyboards;
7+
8+
import android.content.Context;
9+
10+
import androidx.annotation.NonNull;
11+
import androidx.annotation.Nullable;
12+
13+
import org.mozilla.vrbrowser.R;
14+
import org.mozilla.vrbrowser.input.CustomKeyboard;
15+
import org.mozilla.vrbrowser.ui.widgets.WidgetPlacement;
16+
import org.mozilla.vrbrowser.utils.StringUtils;
17+
18+
import java.util.Locale;
19+
20+
public class ThaiKeyboard extends BaseKeyboard {
21+
private Locale mLocale;
22+
private CustomKeyboard mKeyboard;
23+
private CustomKeyboard mCapKeyboard;
24+
private CustomKeyboard mSymbolsKeyboard;
25+
26+
public ThaiKeyboard(Context aContext) {
27+
super(aContext);
28+
mLocale = new Locale("th", "TH");
29+
}
30+
31+
@NonNull
32+
@Override
33+
public CustomKeyboard getAlphabeticKeyboard() {
34+
if (mKeyboard == null) {
35+
mKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_thai);
36+
mKeyboard.setShifted(false);
37+
}
38+
return mKeyboard;
39+
}
40+
41+
@NonNull
42+
@Override
43+
public CustomKeyboard getAlphabeticCapKeyboard() {
44+
if (mCapKeyboard == null) {
45+
mCapKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_qwerty_thai_cap);
46+
mCapKeyboard.setShifted(true);
47+
}
48+
return mCapKeyboard;
49+
}
50+
51+
@Nullable
52+
@Override
53+
public CustomKeyboard getSymbolsKeyboard() {
54+
if (mSymbolsKeyboard == null) {
55+
mSymbolsKeyboard = new CustomKeyboard(mContext.getApplicationContext(), R.xml.keyboard_symbols_thai);
56+
}
57+
return mSymbolsKeyboard;
58+
}
59+
60+
@Override
61+
public float getKeyboardTranslateYInWorld() {
62+
return WidgetPlacement.unitFromMeters(mContext, R.dimen.keyboard_y_extra_row);
63+
}
64+
65+
@Override
66+
public float getKeyboardWorldWidth() {
67+
return WidgetPlacement.floatDimension(mContext, R.dimen.keyboard_world_extra_row_width);
68+
}
69+
70+
@Override
71+
public float getAlphabeticKeyboardWidth() {
72+
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_alphabetic_width_extra_column);
73+
}
74+
75+
@Override
76+
public float getAlphabeticKeyboardHeight() {
77+
return WidgetPlacement.dpDimension(mContext, R.dimen.keyboard_alphabetic_height_thai);
78+
}
79+
80+
@Nullable
81+
@Override
82+
public CandidatesResult getCandidates(String aText) {
83+
return null;
84+
}
85+
86+
@Override
87+
public String getKeyboardTitle() {
88+
return StringUtils.getStringByLocale(mContext, R.string.settings_language_thai, getLocale());
89+
}
90+
91+
@Override
92+
public Locale getLocale() {
93+
return mLocale;
94+
}
95+
96+
@Override
97+
public String getSpaceKeyText(String aComposingText) {
98+
return StringUtils.getStringByLocale(mContext, R.string.settings_language_thai, getLocale());
99+
}
100+
101+
@Override
102+
public String getModeChangeKeyText() {
103+
return mContext.getString(R.string.thai_keyboard_mode_change);
104+
}
105+
106+
@Override
107+
public String[] getDomains(String... domains) {
108+
return super.getDomains(".th");
109+
}
110+
}

app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/KeyboardWidget.java

+34-7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import org.mozilla.vrbrowser.ui.keyboards.RussianKeyboard;
5959
import org.mozilla.vrbrowser.ui.keyboards.SpanishKeyboard;
6060
import org.mozilla.vrbrowser.ui.keyboards.SwedishKeyboard;
61+
import org.mozilla.vrbrowser.ui.keyboards.ThaiKeyboard;
6162
import org.mozilla.vrbrowser.ui.views.AutoCompletionView;
6263
import org.mozilla.vrbrowser.ui.views.CustomKeyboardView;
6364
import org.mozilla.vrbrowser.ui.views.KeyboardSelectorView;
@@ -294,6 +295,7 @@ private void initialize(Context aContext) {
294295
mKeyboards.add(new SwedishKeyboard(aContext));
295296
mKeyboards.add(new FinnishKeyboard(aContext));
296297
mKeyboards.add(new DutchKeyboard(aContext));
298+
mKeyboards.add(new ThaiKeyboard(aContext));
297299

298300
mDefaultKeyboardSymbols = new CustomKeyboard(aContext.getApplicationContext(), R.xml.keyboard_symbols);
299301
mKeyboardNumeric = new CustomKeyboard(aContext.getApplicationContext(), R.xml.keyboard_numeric);
@@ -377,9 +379,7 @@ public void releaseWidget() {
377379
protected void initializeWidgetPlacement(WidgetPlacement aPlacement) {
378380
Context context = getContext();
379381
aPlacement.width = getKeyboardWidth(WidgetPlacement.dpDimension(context, R.dimen.keyboard_alphabetic_width));
380-
aPlacement.height = WidgetPlacement.dpDimension(context, R.dimen.keyboard_height);
381-
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.autocompletion_widget_line_height);
382-
aPlacement.height += WidgetPlacement.dpDimension(context, R.dimen.keyboard_layout_padding);
382+
aPlacement.height = getKeyboardHeight(WidgetPlacement.dpDimension(context, R.dimen.keyboard_height));
383383
aPlacement.anchorX = 0.5f;
384384
aPlacement.anchorY = 0.0f;
385385
aPlacement.parentAnchorY = 0.0f;
@@ -429,6 +429,13 @@ private int getKeyboardWidth(float aAlphabeticWidth) {
429429
return (int) width;
430430
}
431431

432+
private int getKeyboardHeight(float aAlphabeticHeight) {
433+
float height = aAlphabeticHeight;
434+
height += WidgetPlacement.dpDimension(getContext(), R.dimen.autocompletion_widget_line_height);
435+
height += WidgetPlacement.dpDimension(getContext(), R.dimen.keyboard_layout_padding);
436+
return (int) height;
437+
}
438+
432439
private void resetKeyboardLayout() {
433440
if ((mEditorInfo.inputType & EditorInfo.TYPE_CLASS_NUMBER) == EditorInfo.TYPE_CLASS_NUMBER) {
434441
mKeyboardView.setKeyboard(getSymbolsKeyboard());
@@ -735,6 +742,16 @@ private void cleanComposingText() {
735742
}
736743

737744
private void handleShift(boolean isShifted) {
745+
final boolean statusChanged = mKeyboardView.isShifted() != isShifted;
746+
747+
if (mCurrentKeyboard.getAlphabeticCapKeyboard() != null) {
748+
if (isShifted || mIsCapsLock) {
749+
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticCapKeyboard());
750+
} else {
751+
mKeyboardView.setKeyboard(mCurrentKeyboard.getAlphabeticKeyboard());
752+
}
753+
}
754+
738755
CustomKeyboard keyboard = (CustomKeyboard) mKeyboardView.getKeyboard();
739756
int[] shiftIndices = keyboard.getShiftKeyIndices();
740757
for (int shiftIndex: shiftIndices) {
@@ -760,7 +777,7 @@ private void handleShift(boolean isShifted) {
760777

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

860877
mCurrentKeyboard = aKeyboard;
861878
final int width = getKeyboardWidth(mCurrentKeyboard.getAlphabeticKeyboardWidth());
862-
if (width != mWidgetPlacement.width) {
879+
final int height = getKeyboardHeight(mCurrentKeyboard.getAlphabeticKeyboardHeight());
880+
if (width != mWidgetPlacement.width || height != mWidgetPlacement.height) {
863881
mWidgetPlacement.width = width;
864-
float defaultWorldWidth = WidgetPlacement.floatDimension(getContext(), R.dimen.keyboard_world_width);
882+
mWidgetPlacement.height = height;
883+
mWidgetPlacement.translationY = mCurrentKeyboard.getKeyboardTranslateYInWorld() -
884+
WidgetPlacement.unitFromMeters(getContext(), R.dimen.window_world_y);
885+
float defaultWorldWidth = mCurrentKeyboard.getKeyboardWorldWidth();
865886
int defaultKeyboardWidth = getKeyboardWidth(mKeyboards.get(0).getAlphabeticKeyboardWidth());
866887
mWidgetPlacement.worldWidth = defaultWorldWidth * ((float) width / (float) defaultKeyboardWidth);
867888
mWidgetManager.updateWidget(this);
868889
ViewGroup.LayoutParams params = mKeyboardContainer.getLayoutParams();
869890
params.width = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardWidth());
891+
params.height = WidgetPlacement.convertDpToPixel(getContext(), mCurrentKeyboard.getAlphabeticKeyboardHeight());
870892
mKeyboardContainer.setLayoutParams(params);
871893
}
872894

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

@@ -933,7 +961,6 @@ private void handleDone() {
933961
}
934962
}
935963

936-
937964
private void handleModeChange() {
938965
Keyboard current = mKeyboardView.getKeyboard();
939966
Keyboard alphabetic = mCurrentKeyboard.getAlphabeticKeyboard();

app/src/main/res/layout/keyboard.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
android:padding="15dp"
126126
android:layout_gravity="center"
127127
android:background="@drawable/dialog_background"
128-
android:alpha="0.5"
128+
android:alpha="0.0"
129129
android:visibility="gone"/>
130130
</FrameLayout>
131131

app/src/main/res/layout/navigation_url.xml

+2
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@
186186
android:id="@+id/urlEditText"
187187
android:layout_width="match_parent"
188188
android:layout_height="match_parent"
189+
android:layout_marginTop="5dp"
190+
android:layout_marginBottom="5dp"
189191
android:paddingEnd="10dp"
190192
android:layout_toStartOf="@id/endButtonsLayout"
191193
android:layout_toEndOf="@id/icons"

app/src/main/res/values/dimen.xml

+6-4
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,21 @@
2323

2424
<!-- Keyboard -->
2525
<item name="keyboard_world_width" format="float" type="dimen">3.25</item>
26+
<item name="keyboard_world_extra_row_width" format="float" type="dimen">3.43</item>
2627
<item name="keyboard_x" format="float" type="dimen">-0.15</item>
2728
<item name="keyboard_y" format="float" type="dimen">-0.45</item>
28-
<item name="zhuyin_keyboard_y" format="float" type="dimen">-0.63</item>
29+
<item name="keyboard_y_extra_row" format="float" type="dimen">-0.72</item>
2930
<item name="keyboard_z" format="float" type="dimen">-2.5</item>
3031
<item name="keyboard_world_rotation" format="float" type="dimen">-35.0</item>
31-
<dimen name="keyboard_height">188dp</dimen>
32+
<dimen name="keyboard_height">186dp</dimen>
3233
<dimen name="keyboard_alphabetic_width">526dp</dimen>
3334
<dimen name="keyboard_alphabetic_width_danish">540dp</dimen>
3435
<dimen name="keyboard_alphabetic_width_norwegian">540dp</dimen>
3536
<dimen name="keyboard_alphabetic_width_swedish">540dp</dimen>
3637
<dimen name="keyboard_alphabetic_width_finnish">540dp</dimen>
37-
<dimen name="keyboard_alphabetic_width_zhuyin">470dp</dimen>
3838
<dimen name="keyboard_alphabetic_width_extra_column">564dp</dimen>
39+
<dimen name="keyboard_alphabetic_height_thai">226dp</dimen>
3940
<dimen name="keyboard_numeric_width">144dp</dimen>
40-
<dimen name="keyboard_zhuyin_height">228dp</dimen>
4141
<dimen name="keyboard_horizontal_gap">4dp</dimen>
4242
<dimen name="keyboard_vertical_gap">4dp</dimen>
4343
<dimen name="keyboard_key_width">36dp</dimen>
@@ -49,6 +49,8 @@
4949
<dimen name="keyboard_key_zhuyin_space_width">50dp</dimen>
5050
<dimen name="keyboard_key_zhuyin_space_height">70dp</dimen>
5151
<dimen name="keyboard_key_zhuyin_enter_width">74dp</dimen>
52+
<dimen name="keyboard_key_thai_enter_width">50dp</dimen>
53+
<dimen name="keyboard_key_thai_enter_height">72dp</dimen>
5254
<dimen name="keyboard_key_backspace_width">50dp</dimen>
5355
<dimen name="keyboard_key_enter_width">72dp</dimen>
5456
<dimen name="keyboard_key_enter_width_small">62dp</dimen>

app/src/main/res/values/non_L10n.xml

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
<string name="japanese_enter_completion" translatable="false">確定</string>
102102
<string name="japanese_keyboard_mode_change" translatable="false">かな</string>
103103

104+
<string name="thai_keyboard_mode_change" translatable="false">กขค</string>
105+
104106
<!-- Keyboard -->
105107
<string name="keyboard_popup_a" translatable="false">aáàäãåâąæā</string>
106108
<string name="keyboard_popup_b" translatable="false">bƀḃḅḇ</string>

app/src/main/res/values/strings.xml

+4
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@
300300
changes the app and the language of the speech-recognition-based search to 'Dutch'. -->
301301
<string name="settings_language_dutch">Dutch</string>
302302

303+
<!-- This string is used to label a radio button in the settings language dialog that, when pressed,
304+
changes the app and the language of the speech-recognition-based search to 'Thai'. -->
305+
<string name="settings_language_thai">Thai</string>
306+
303307
<!-- This string is used to label a button in the 'Settings' dialog window that, when pressed,
304308
opens a dialog box that contains display-related settings: window size, pixel density, etc. -->
305309
<string name="settings_display">Display</string>

0 commit comments

Comments
 (0)