show secondary language on space bar, small adjustmwents

This commit is contained in:
Helium 2022-03-20 08:46:57 +01:00
parent 26efc80981
commit 307af99dff
2 changed files with 37 additions and 6 deletions

View file

@ -55,10 +55,13 @@ import org.dslul.openboard.inputmethod.latin.SuggestedWords;
import org.dslul.openboard.inputmethod.latin.common.Constants; import org.dslul.openboard.inputmethod.latin.common.Constants;
import org.dslul.openboard.inputmethod.latin.common.CoordinateUtils; import org.dslul.openboard.inputmethod.latin.common.CoordinateUtils;
import org.dslul.openboard.inputmethod.latin.settings.DebugSettings; import org.dslul.openboard.inputmethod.latin.settings.DebugSettings;
import org.dslul.openboard.inputmethod.latin.settings.Settings;
import org.dslul.openboard.inputmethod.latin.settings.SettingsValues;
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils; import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
import org.dslul.openboard.inputmethod.latin.utils.LanguageOnSpacebarUtils; import org.dslul.openboard.inputmethod.latin.utils.LanguageOnSpacebarUtils;
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils; import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
import java.util.Locale;
import java.util.WeakHashMap; import java.util.WeakHashMap;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
@ -838,6 +841,24 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
private String layoutLanguageOnSpacebar(final Paint paint, private String layoutLanguageOnSpacebar(final Paint paint,
final RichInputMethodSubtype subtype, final int width) { final RichInputMethodSubtype subtype, final int width) {
// Choose appropriate language name to fit into the width. // Choose appropriate language name to fit into the width.
final Locale secondaryLocale = Settings.getInstance().getCurrent().mSecondaryLocale;
if (secondaryLocale != null
// avoid showing same language twice
&& !secondaryLocale.getLanguage().equals(subtype.getLocale().getLanguage())) {
final Locale displayLocale = getResources().getConfiguration().locale;
final String full = subtype.getMiddleDisplayName() + " - " +
secondaryLocale.getDisplayLanguage(displayLocale);
if (fitsTextIntoWidth(width, full, paint)) {
return full;
}
final String middle = subtype.getLocale().getLanguage().toUpperCase(displayLocale) +
" - " + secondaryLocale.getLanguage().toUpperCase(displayLocale);
if (fitsTextIntoWidth(width, middle, paint)) {
return middle;
}
}
if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarUtils.FORMAT_TYPE_FULL_LOCALE) { if (mLanguageOnSpacebarFormatType == LanguageOnSpacebarUtils.FORMAT_TYPE_FULL_LOCALE) {
final String fullText = subtype.getFullDisplayName(); final String fullText = subtype.getFullDisplayName();
if (fitsTextIntoWidth(width, fullText, paint)) { if (fitsTextIntoWidth(width, fullText, paint)) {

View file

@ -138,23 +138,33 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
} }
private void showSecondaryLocaleDialog() { private void showSecondaryLocaleDialog() {
// only latin for now // only allow same script of main locale for now
final List<String> locales = new ArrayList<String>(getAvailableDictionaryLocalesForScript(ScriptUtils.SCRIPT_LATIN)); // TODO: how to get enabled keyboard locales? then setting a secondary locale per
// main locale would be rather simple
final SettingsValues settingsValues = Settings.getInstance().getCurrent();
final int scriptOfCurrentLocale = ScriptUtils.getScriptFromSpellCheckerLocale(settingsValues.mLocale);
final List<String> locales = new ArrayList<String>(getAvailableDictionaryLocalesForScript(scriptOfCurrentLocale));
final AlertDialog.Builder builder = new AlertDialog.Builder( final AlertDialog.Builder builder = new AlertDialog.Builder(
DialogUtils.getPlatformDialogThemeContext(getActivity())) DialogUtils.getPlatformDialogThemeContext(getActivity()))
.setTitle(R.string.select_language) .setTitle(R.string.select_language)
.setPositiveButton(android.R.string.ok, null); .setPositiveButton(android.R.string.ok, null);
if (locales.isEmpty()) { if (locales.isEmpty()) {
builder.setMessage(R.string.no_secondary_locales) builder.setMessage(R.string.no_secondary_locales)
.show(); .show();
return; return;
} }
// add "no secondary language" option
locales.add(getResources().getString(R.string.secondary_locale_none)); locales.add(getResources().getString(R.string.secondary_locale_none));
final CharSequence[] titles = locales.toArray(new CharSequence[0]); final CharSequence[] titles = locales.toArray(new CharSequence[0]);
for (int i = 0; i < titles.length -1 ; i++) { for (int i = 0; i < titles.length - 1 ; i++) {
titles[i] = LocaleUtils.constructLocaleFromString(titles[i].toString()).getDisplayLanguage(); final Locale loc = LocaleUtils.constructLocaleFromString(titles[i].toString());
titles[i] = loc.getDisplayLanguage(settingsValues.mLocale);
} }
Locale currentSecondaryLocale = Settings.getInstance().getCurrent().mSecondaryLocale;
Locale currentSecondaryLocale = settingsValues.mSecondaryLocale;
int checkedItem; int checkedItem;
if (currentSecondaryLocale == null) if (currentSecondaryLocale == null)
checkedItem = locales.size() - 1; checkedItem = locales.size() - 1;
@ -163,7 +173,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
builder.setSingleChoiceItems(titles, checkedItem, (dialogInterface, i) -> { builder.setSingleChoiceItems(titles, checkedItem, (dialogInterface, i) -> {
String locale = locales.get(i); String locale = locales.get(i);
if (locale.equals(getResources().getString(R.string.secondary_locale_none))) if (i == locales.size() - 1)
locale = ""; locale = "";
getSharedPreferences().edit().putString(Settings.PREF_SECONDARY_LOCALE, locale).apply(); getSharedPreferences().edit().putString(Settings.PREF_SECONDARY_LOCALE, locale).apply();
final Intent newDictBroadcast = new Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION); final Intent newDictBroadcast = new Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);