Skip to content

Commit

Permalink
Keyboard polishing (MozillaReality#2425)
Browse files Browse the repository at this point in the history
* Update keyboard domains

* Force capitalize initial keyboard letter

* Remove hardcoded languages
  • Loading branch information
keianhzo authored and Alexandre Lissy committed Jan 21, 2020
1 parent 7b25b5a commit 1ef4d18
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 189 deletions.
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

0 comments on commit 1ef4d18

Please sign in to comment.