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

Commit 451ce73

Browse files
authored
Add support for display/voice/content languages (#1474)
* Add support for display/voice/content languages * Fixed crash when running using an applicationId suffix
1 parent c03ef4b commit 451ce73

56 files changed

Lines changed: 2034 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
6464
import org.mozilla.vrbrowser.ui.widgets.dialogs.CrashDialogWidget;
6565
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
66+
import org.mozilla.vrbrowser.utils.LocaleUtils;
6667
import org.mozilla.vrbrowser.utils.ServoUtils;
6768

6869
import java.io.IOException;
@@ -173,6 +174,11 @@ public void onGlobalFocusChanged(View oldFocus, View newFocus) {
173174
}
174175
};
175176

177+
@Override
178+
protected void attachBaseContext(Context base) {
179+
super.attachBaseContext(LocaleUtils.setLocale(base));
180+
}
181+
176182
@Override
177183
protected void onCreate(Bundle savedInstanceState) {
178184
// Fix for infinite restart on startup crashes.
@@ -189,6 +195,8 @@ protected void onCreate(Bundle savedInstanceState) {
189195
// Set a global exception handler as soon as possible
190196
GlobalExceptionHandler.register(this.getApplicationContext());
191197

198+
LocaleUtils.init(this);
199+
192200
if (DeviceType.isOculusBuild()) {
193201
workaroundGeckoSigAction();
194202
}

app/src/common/shared/org/mozilla/vrbrowser/VRBrowserApplication.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
package org.mozilla.vrbrowser;
77

88
import android.app.Application;
9+
import android.content.Context;
10+
import android.content.res.Configuration;
911

1012
import org.mozilla.vrbrowser.browser.Places;
1113
import org.mozilla.vrbrowser.db.AppDatabase;
1214
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
15+
import org.mozilla.vrbrowser.utils.LocaleUtils;
1316

1417
public class VRBrowserApplication extends Application {
1518

@@ -26,6 +29,18 @@ public void onCreate() {
2629
TelemetryWrapper.init(this);
2730
}
2831

32+
@Override
33+
protected void attachBaseContext(Context base) {
34+
LocaleUtils.saveSystemLocale();
35+
super.attachBaseContext(LocaleUtils.setLocale(base));
36+
}
37+
38+
@Override
39+
public void onConfigurationChanged(Configuration newConfig) {
40+
super.onConfigurationChanged(newConfig);
41+
LocaleUtils.setLocale(this);
42+
}
43+
2944
public AppDatabase getDatabase() {
3045
return AppDatabase.getInstance(this, mAppExecutors);
3146
}

app/src/common/shared/org/mozilla/vrbrowser/browser/SessionStore.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,12 @@ public boolean getAutoplayEnabled() {
10001000
return false;
10011001
}
10021002

1003+
public void setLocales(List<String> locales) {
1004+
if (mRuntime != null) {
1005+
mRuntime.getSettings().setLocales(locales.stream().toArray(String[]::new));
1006+
}
1007+
}
1008+
10031009
// NavigationDelegate
10041010

10051011
@Override

app/src/common/shared/org/mozilla/vrbrowser/browser/SettingsStore.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import android.os.StrictMode;
77
import android.preference.PreferenceManager;
88

9+
import org.json.JSONArray;
10+
import org.json.JSONException;
911
import org.mozilla.geckoview.GeckoSessionSettings;
1012
import org.mozilla.telemetry.TelemetryHolder;
1113
import org.mozilla.vrbrowser.R;
@@ -16,6 +18,8 @@
1618

1719
import androidx.annotation.NonNull;
1820

21+
import java.util.ArrayList;
22+
import java.util.List;
1923
import java.util.Locale;
2024

2125
import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;
@@ -408,21 +412,63 @@ public void setAudioEnabled(boolean isEnabled) {
408412
editor.commit();
409413
}
410414

411-
public String getVoiceSearchLanguage() {
415+
public String getVoiceSearchLocale() {
412416
String language = mPrefs.getString(
413417
mContext.getString(R.string.settings_key_voice_search_language), null);
414418
if (language == null) {
415-
return LocaleUtils.getDefaultVoiceSearchLanguage(mContext);
419+
return LocaleUtils.getDefaultVoiceSearchLocale(mContext);
416420
}
417421
return language;
418422
}
419423

420-
public void setVoiceSearchLanguage(String language) {
424+
public void setVoiceSearchLocale(String language) {
421425
SharedPreferences.Editor editor = mPrefs.edit();
422426
editor.putString(mContext.getString(R.string.settings_key_voice_search_language), language);
423427
editor.commit();
424428
}
425429

430+
public String getDisplayLocale() {
431+
String language = mPrefs.getString(
432+
mContext.getString(R.string.settings_key_display_language), null);
433+
if (language == null) {
434+
return LocaleUtils.getDefaultDisplayLocale(mContext);
435+
}
436+
return language;
437+
}
438+
439+
public void setDisplayLocale(String language) {
440+
SharedPreferences.Editor editor = mPrefs.edit();
441+
editor.putString(mContext.getString(R.string.settings_key_display_language), language);
442+
editor.commit();
443+
}
444+
445+
public ArrayList<String> getContentLocales() {
446+
ArrayList<String> result = new ArrayList<>();
447+
448+
String json = mPrefs.getString(
449+
mContext.getString(R.string.settings_key_content_languages),
450+
new JSONArray().toString());
451+
452+
try {
453+
JSONArray jsonArray = new JSONArray(json);
454+
for (int i=0; i<jsonArray.length(); i++) {
455+
result.add(jsonArray.getString(i));
456+
}
457+
458+
} catch (JSONException e) {
459+
e.printStackTrace();
460+
}
461+
462+
return result;
463+
}
464+
465+
public void setContentLocales(List<String> languages) {
466+
JSONArray json = new JSONArray(languages);
467+
SharedPreferences.Editor editor = mPrefs.edit();
468+
editor.putString(mContext.getString(R.string.settings_key_content_languages), json.toString());
469+
editor.commit();
470+
}
471+
426472
public float getCylinderDensity() {
427473
return mPrefs.getFloat(mContext.getString(R.string.settings_key_cylinder_density), 0);
428474
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
package org.mozilla.vrbrowser.ui.adapters;
22

3+
import android.graphics.Typeface;
34
import android.view.View;
5+
import android.widget.TextView;
46

57
import androidx.databinding.BindingAdapter;
68

79

810
public class BindingAdapters {
11+
912
@BindingAdapter("visibleGone")
1013
public static void showHide(View view, boolean show) {
1114
view.setVisibility(show ? View.VISIBLE : View.GONE);
1215
}
16+
17+
@BindingAdapter("visibleInvisible")
18+
public static void showInvisible(View view, boolean show) {
19+
view.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
20+
}
21+
22+
@BindingAdapter("typeface")
23+
public static void setTypeface(TextView v, String style) {
24+
switch (style) {
25+
case "bold":
26+
v.setTypeface(null, Typeface.BOLD);
27+
break;
28+
default:
29+
v.setTypeface(null, Typeface.NORMAL);
30+
break;
31+
}
32+
}
1333
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.mozilla.vrbrowser.ui.adapters;
2+
3+
public class Language {
4+
5+
public Language(String id, String name) {
6+
this.id = id;
7+
this.name = name;
8+
}
9+
10+
private String name;
11+
private String id;
12+
13+
public String getId() {
14+
return this.id;
15+
}
16+
17+
public String getName() {
18+
return this.name;
19+
}
20+
21+
@Override
22+
public int hashCode() {
23+
return id.hashCode();
24+
}
25+
}

0 commit comments

Comments
 (0)