Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.mozilla.vrbrowser.ui.widgets.WindowWidget;
import org.mozilla.vrbrowser.ui.widgets.dialogs.CrashDialogWidget;
import org.mozilla.vrbrowser.utils.ConnectivityReceiver;
import org.mozilla.vrbrowser.utils.LocaleUtils;
Comment thread
keianhzo marked this conversation as resolved.
import org.mozilla.vrbrowser.utils.ServoUtils;

import java.io.IOException;
Expand Down Expand Up @@ -173,6 +174,11 @@ public void onGlobalFocusChanged(View oldFocus, View newFocus) {
}
};

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(LocaleUtils.setLocale(base));
}

@Override
protected void onCreate(Bundle savedInstanceState) {
// Fix for infinite restart on startup crashes.
Expand All @@ -189,6 +195,8 @@ protected void onCreate(Bundle savedInstanceState) {
// Set a global exception handler as soon as possible
GlobalExceptionHandler.register(this.getApplicationContext());

LocaleUtils.init(this);

if (DeviceType.isOculusBuild()) {
workaroundGeckoSigAction();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
package org.mozilla.vrbrowser;

import android.app.Application;
import android.content.Context;
import android.content.res.Configuration;

import org.mozilla.vrbrowser.browser.Places;
import org.mozilla.vrbrowser.db.AppDatabase;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.LocaleUtils;

public class VRBrowserApplication extends Application {

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

@Override
protected void attachBaseContext(Context base) {
LocaleUtils.saveSystemLocale();
super.attachBaseContext(LocaleUtils.setLocale(base));
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
LocaleUtils.setLocale(this);
}

public AppDatabase getDatabase() {
return AppDatabase.getInstance(this, mAppExecutors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,12 @@ public boolean getAutoplayEnabled() {
return false;
}

public void setLocales(List<String> locales) {
if (mRuntime != null) {
mRuntime.getSettings().setLocales(locales.stream().toArray(String[]::new));
}
}

// NavigationDelegate

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
import android.os.StrictMode;
import android.preference.PreferenceManager;

import org.json.JSONArray;
import org.json.JSONException;
import org.mozilla.geckoview.GeckoSessionSettings;
import org.mozilla.telemetry.TelemetryHolder;
import org.mozilla.vrbrowser.BuildConfig;
import org.mozilla.vrbrowser.R;
import org.mozilla.vrbrowser.telemetry.TelemetryWrapper;
import org.mozilla.vrbrowser.utils.DeviceType;
Expand All @@ -17,6 +18,8 @@

import androidx.annotation.NonNull;

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

import static org.mozilla.vrbrowser.utils.ServoUtils.isServoAvailable;
Expand Down Expand Up @@ -409,21 +412,63 @@ public void setAudioEnabled(boolean isEnabled) {
editor.commit();
}

public String getVoiceSearchLanguage() {
public String getVoiceSearchLocale() {
String language = mPrefs.getString(
mContext.getString(R.string.settings_key_voice_search_language), null);
if (language == null) {
return LocaleUtils.getDefaultVoiceSearchLanguage(mContext);
return LocaleUtils.getDefaultVoiceSearchLocale(mContext);
}
return language;
}

public void setVoiceSearchLanguage(String language) {
public void setVoiceSearchLocale(String language) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_voice_search_language), language);
editor.commit();
}

public String getDisplayLocale() {
String language = mPrefs.getString(
mContext.getString(R.string.settings_key_display_language), null);
if (language == null) {
return LocaleUtils.getDefaultDisplayLocale(mContext);
}
return language;
}

public void setDisplayLocale(String language) {
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_display_language), language);
editor.commit();
}

public ArrayList<String> getContentLocales() {
ArrayList<String> result = new ArrayList<>();

String json = mPrefs.getString(
mContext.getString(R.string.settings_key_content_languages),
new JSONArray().toString());

try {
JSONArray jsonArray = new JSONArray(json);
for (int i=0; i<jsonArray.length(); i++) {
result.add(jsonArray.getString(i));
}

} catch (JSONException e) {
e.printStackTrace();
}

return result;
}

public void setContentLocales(List<String> languages) {
JSONArray json = new JSONArray(languages);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString(mContext.getString(R.string.settings_key_content_languages), json.toString());
editor.commit();
}

public float getCylinderDensity() {
return mPrefs.getFloat(mContext.getString(R.string.settings_key_cylinder_density), 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,33 @@
package org.mozilla.vrbrowser.ui.adapters;

import android.graphics.Typeface;
import android.view.View;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;


public class BindingAdapters {

@BindingAdapter("visibleGone")
public static void showHide(View view, boolean show) {
view.setVisibility(show ? View.VISIBLE : View.GONE);
}

@BindingAdapter("visibleInvisible")
public static void showInvisible(View view, boolean show) {
view.setVisibility(show ? View.VISIBLE : View.INVISIBLE);
}

@BindingAdapter("typeface")
public static void setTypeface(TextView v, String style) {
switch (style) {
case "bold":
v.setTypeface(null, Typeface.BOLD);
break;
default:
v.setTypeface(null, Typeface.NORMAL);
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.mozilla.vrbrowser.ui.adapters;

public class Language {

public Language(String id, String name) {
this.id = id;
this.name = name;
}

private String name;
private String id;

public String getId() {
return this.id;
}

public String getName() {
return this.name;
}

@Override
public int hashCode() {
return id.hashCode();
}
}
Loading