mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-06-01 04:12:12 +00:00
show secondary language on space bar, small adjustmwents
This commit is contained in:
parent
26efc80981
commit
307af99dff
2 changed files with 37 additions and 6 deletions
|
@ -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.CoordinateUtils;
|
||||
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.LanguageOnSpacebarUtils;
|
||||
import org.dslul.openboard.inputmethod.latin.utils.TypefaceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
@ -838,6 +841,24 @@ public final class MainKeyboardView extends KeyboardView implements DrawingProxy
|
|||
private String layoutLanguageOnSpacebar(final Paint paint,
|
||||
final RichInputMethodSubtype subtype, final int 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) {
|
||||
final String fullText = subtype.getFullDisplayName();
|
||||
if (fitsTextIntoWidth(width, fullText, paint)) {
|
||||
|
|
|
@ -138,23 +138,33 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
|
|||
}
|
||||
|
||||
private void showSecondaryLocaleDialog() {
|
||||
// only latin for now
|
||||
final List<String> locales = new ArrayList<String>(getAvailableDictionaryLocalesForScript(ScriptUtils.SCRIPT_LATIN));
|
||||
// only allow same script of main locale for now
|
||||
// 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(
|
||||
DialogUtils.getPlatformDialogThemeContext(getActivity()))
|
||||
.setTitle(R.string.select_language)
|
||||
.setPositiveButton(android.R.string.ok, null);
|
||||
|
||||
if (locales.isEmpty()) {
|
||||
builder.setMessage(R.string.no_secondary_locales)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
// add "no secondary language" option
|
||||
locales.add(getResources().getString(R.string.secondary_locale_none));
|
||||
|
||||
final CharSequence[] titles = locales.toArray(new CharSequence[0]);
|
||||
for (int i = 0; i < titles.length -1 ; i++) {
|
||||
titles[i] = LocaleUtils.constructLocaleFromString(titles[i].toString()).getDisplayLanguage();
|
||||
for (int i = 0; i < titles.length - 1 ; i++) {
|
||||
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;
|
||||
if (currentSecondaryLocale == null)
|
||||
checkedItem = locales.size() - 1;
|
||||
|
@ -163,7 +173,7 @@ public final class AdvancedSettingsFragment extends SubScreenFragment {
|
|||
|
||||
builder.setSingleChoiceItems(titles, checkedItem, (dialogInterface, i) -> {
|
||||
String locale = locales.get(i);
|
||||
if (locale.equals(getResources().getString(R.string.secondary_locale_none)))
|
||||
if (i == locales.size() - 1)
|
||||
locale = "";
|
||||
getSharedPreferences().edit().putString(Settings.PREF_SECONDARY_LOCALE, locale).apply();
|
||||
final Intent newDictBroadcast = new Intent(DictionaryPackConstants.NEW_DICTIONARY_INTENT_ACTION);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue