Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard polishing #2425

Merged
merged 3 commits into from
Dec 9, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected void onCreate(Bundle savedInstanceState) {
// Set a global exception handler as soon as possible
GlobalExceptionHandler.register(this.getApplicationContext());

LocaleUtils.init(this);
LocaleUtils.init();

if (DeviceType.isOculusBuild()) {
workaroundGeckoSigAction();
Expand All @@ -225,6 +225,7 @@ protected void onCreate(Bundle savedInstanceState) {
SessionStore.get().setContext(this, extras);
SessionStore.get().initializeServices();
SessionStore.get().initializeStores(this);
SessionStore.get().setLocales(LocaleUtils.getPreferredLocales(this));

// Create broadcast receiver for getting crash messages from crash process
IntentFilter intentFilter = new IntentFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public String getVoiceSearchLocale() {
String language = mPrefs.getString(
mContext.getString(R.string.settings_key_voice_search_language), null);
if (language == null) {
return LocaleUtils.getDefaultVoiceSearchLocale(mContext);
return LocaleUtils.getDefaultSupportedLocale();
}
return language;
}
Expand All @@ -436,7 +436,7 @@ public String getDisplayLocale() {
String language = mPrefs.getString(
mContext.getString(R.string.settings_key_display_language), null);
if (language == null) {
return LocaleUtils.getDefaultDisplayLocale(mContext);
return LocaleUtils.getDefaultSupportedLocale();
}
return language;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ public String getSpaceKeyText(String aComposingText) {

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".de");
return super.getDomains(".de", ".at", ".ch");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,4 @@ public Locale getLocale() {
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_russian, getLocale());
}

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".ru");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,4 @@ public Locale getLocale() {
public String getSpaceKeyText(String aComposingText) {
return StringUtils.getStringByLocale(mContext, R.string.settings_language_spanish, getLocale());
}

@Override
public String[] getDomains(String... domains) {
return super.getDomains(".es");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,17 @@ private void initialize(Context aContext) {

mKeyboards = new ArrayList<>();
mKeyboards.add(new EnglishKeyboard(aContext));
mKeyboards.add(new ItalianKeyboard(aContext));
mKeyboards.add(new ChinesePinyinKeyboard(aContext));
mKeyboards.add(new ChineseZhuyinKeyboard(aContext));
mKeyboards.add(new JapaneseKeyboard(aContext));
mKeyboards.add(new FrenchKeyboard(aContext));
mKeyboards.add(new GermanKeyboard(aContext));
mKeyboards.add(new SpanishKeyboard(aContext));
mKeyboards.add(new RussianKeyboard(aContext));
mKeyboards.add(new ChinesePinyinKeyboard(aContext));
mKeyboards.add(new ChineseZhuyinKeyboard(aContext));
mKeyboards.add(new KoreanKeyboard(aContext));
mKeyboards.add(new JapaneseKeyboard(aContext));
mKeyboards.add(new PolishKeyboard(aContext));
mKeyboards.add(new ItalianKeyboard(aContext));
mKeyboards.add(new DanishKeyboard(aContext));
mKeyboards.add(new PolishKeyboard(aContext));
mKeyboards.add(new NorwegianKeyboard(aContext));
mKeyboards.add(new SwedishKeyboard(aContext));
mKeyboards.add(new FinnishKeyboard(aContext));
Expand Down Expand Up @@ -686,7 +686,7 @@ private void handleGlobeClick() {
if (mLanguageSelectorView.getItems() == null || mLanguageSelectorView.getItems().size() == 0) {
ArrayList<KeyboardSelectorView.Item> items = new ArrayList<>();
for (KeyboardInterface keyboard: mKeyboards) {
items.add(new KeyboardSelectorView.Item(keyboard.getKeyboardTitle(), keyboard));
items.add(new KeyboardSelectorView.Item(StringUtils.capitalize(keyboard.getKeyboardTitle()), keyboard));
}
mLanguageSelectorView.setItems(items);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.mozilla.vrbrowser.utils.LocaleUtils;

import java.util.Arrays;
import java.util.Collections;

public class ContentLanguageOptionsView extends SettingsView {

Expand Down Expand Up @@ -115,9 +116,9 @@ public void onMoveDown(View view, Language language) {

private void saveCurrentLanguages() {
SettingsStore.getInstance(getContext()).setContentLocales(
LocaleUtils.getLanguageIdsFromList(mPreferredAdapter.getItems()));
LocaleUtils.getLocalesFromLanguages(mPreferredAdapter.getItems()));
SessionStore.get().setLocales(
LocaleUtils.getLanguageIdsFromList(mPreferredAdapter.getItems()));
LocaleUtils.getLocalesFromLanguages(mPreferredAdapter.getItems()));
}

private void refreshLanguages() {
Expand All @@ -129,8 +130,8 @@ private void refreshLanguages() {

@Override
protected boolean reset() {
SettingsStore.getInstance(getContext()).setContentLocales(Arrays.asList(LocaleUtils.getSystemLocale()));
SessionStore.get().setLocales(Arrays.asList(LocaleUtils.getSystemLocale()));
SettingsStore.getInstance(getContext()).setContentLocales(Collections.singletonList(LocaleUtils.getSystemLocale()));
SessionStore.get().setLocales(Collections.singletonList(LocaleUtils.getSystemLocale()));
LocaleUtils.resetLanguages();
refreshLanguages();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,30 @@ private void initialize(Context aContext) {
// Footer
mBinding.footerLayout.setFooterButtonClickListener(mResetListener);

String language = LocaleUtils.getDisplayLocale(getContext());
mBinding.languageRadio.setOptions(LocaleUtils.getSupportedLocalizedLanguages(getContext()));

String locale = LocaleUtils.getDisplayLocale(getContext());
mBinding.languageRadio.setOnCheckedChangeListener(mLanguageListener);
setLanguage(mBinding.languageRadio.getIdForValue(language), false);
setLanguage(LocaleUtils.getIndexForSupportedLocale(locale), false);
}

@Override
protected boolean reset() {
String systemLocale = LocaleUtils.getSystemLocale();
String currentLocale = LocaleUtils.getCurrentLocale();
if (!currentLocale.equalsIgnoreCase(systemLocale)) {
setLanguage(mBinding.languageRadio.getIdForValue(systemLocale), true);
setLanguage(LocaleUtils.getIndexForSupportedLocale(systemLocale), true);
return true;

} else {
setLanguage(mBinding.languageRadio.getIdForValue(systemLocale), false);
setLanguage(LocaleUtils.getIndexForSupportedLocale(systemLocale), false);
return false;
}
}

private RadioGroupSetting.OnCheckedChangeListener mLanguageListener = (radioGroup, checkedId, doApply) -> {
String currentLocale = LocaleUtils.getCurrentLocale();
String locale = mBinding.languageRadio.getValueForId(mBinding.languageRadio.getCheckedRadioButtonId()).toString();
String locale = LocaleUtils.getSupportedLocaleForIndex(mBinding.languageRadio.getCheckedRadioButtonId());

if (!locale.equalsIgnoreCase(currentLocale)) {
setLanguage(checkedId, true);
Expand All @@ -86,8 +88,8 @@ private void setLanguage(int checkedId, boolean doApply) {
mBinding.languageRadio.setOnCheckedChangeListener(mLanguageListener);

if (doApply) {
String language = mBinding.languageRadio.getValueForId(checkedId).toString();
LocaleUtils.setDisplayLocale(getContext(), language);
String locale = LocaleUtils.getSupportedLocaleForIndex(checkedId);
LocaleUtils.setDisplayLocale(getContext(), locale);

if (mDelegate != null) {
mDelegate.showRestartDialog();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected void onDismiss() {
};

private void setVoiceLanguage() {
mBinding.voiceSearchLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getVoiceSearchLanguageString(getContext())), TextView.BufferType.SPANNABLE);
mBinding.voiceSearchLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getVoiceSearchLanguage(getContext())), TextView.BufferType.SPANNABLE);
}

private void setContentLanguage() {
Expand All @@ -105,7 +105,7 @@ private void setContentLanguage() {
}

private void setDisplayLanguage() {
mBinding.displayLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getDisplayCurrentLanguageString()));
mBinding.displayLanguageDescription.setText(getSpannedLanguageText(LocaleUtils.getDisplayLanguage()));
}

private int getLanguageIndex(@NonNull String text) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ private void initialize(Context aContext) {
// Footer
mBinding.footerLayout.setFooterButtonClickListener(mResetListener);

String language = LocaleUtils.getVoiceSearchLocale(getContext());
mBinding.languageRadio.setOptions(LocaleUtils.getSupportedLocalizedLanguages(getContext()));

String locale = LocaleUtils.getVoiceSearchLocale(getContext());
mBinding.languageRadio.setOnCheckedChangeListener(mLanguageListener);
setLanguage(mBinding.languageRadio.getIdForValue(language), false);
setLanguage(LocaleUtils.getIndexForSupportedLocale(locale), false);
}

@Override
protected boolean reset() {
String value = mBinding.languageRadio.getValueForId(mBinding.languageRadio.getCheckedRadioButtonId()).toString();
String value = LocaleUtils.getSupportedLocaleForIndex(mBinding.languageRadio.getCheckedRadioButtonId());
if (!value.equals(LocaleUtils.getSystemLocale())) {
setLanguage(mBinding.languageRadio.getIdForValue(LocaleUtils.getSystemLocale()), true);
setLanguage(LocaleUtils.getIndexForSupportedLocale(LocaleUtils.getSystemLocale()), true);
}

return false;
Expand All @@ -76,7 +78,7 @@ private void setLanguage(int checkedId, boolean doApply) {
mBinding.languageRadio.setChecked(checkedId, doApply);
mBinding.languageRadio.setOnCheckedChangeListener(mLanguageListener);

LocaleUtils.setVoiceSearchLocale(getContext(), mBinding.languageRadio.getValueForId(checkedId).toString());
LocaleUtils.setVoiceSearchLocale(getContext(), LocaleUtils.getSupportedLocaleForIndex(checkedId));
}

@Override
Expand Down