mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-04-22 23:29:10 +00:00
display "<language> (<layout>)" also for custom layouts
This commit is contained in:
parent
9bd2136ebe
commit
3754b2be82
6 changed files with 21 additions and 7 deletions
|
@ -24,6 +24,7 @@ import helium314.keyboard.latin.common.LocaleUtils
|
||||||
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
import helium314.keyboard.latin.utils.DeviceProtectedUtils
|
||||||
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
|
||||||
import helium314.keyboard.latin.utils.addEnabledSubtype
|
import helium314.keyboard.latin.utils.addEnabledSubtype
|
||||||
|
import helium314.keyboard.latin.utils.displayName
|
||||||
import helium314.keyboard.latin.utils.isAdditionalSubtype
|
import helium314.keyboard.latin.utils.isAdditionalSubtype
|
||||||
import helium314.keyboard.latin.utils.locale
|
import helium314.keyboard.latin.utils.locale
|
||||||
import helium314.keyboard.latin.utils.removeEnabledSubtype
|
import helium314.keyboard.latin.utils.removeEnabledSubtype
|
||||||
|
@ -89,7 +90,7 @@ private class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), c
|
||||||
var start = true
|
var start = true
|
||||||
infos.forEach {
|
infos.forEach {
|
||||||
val string = SpannableString(SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(it.subtype)
|
val string = SpannableString(SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(it.subtype)
|
||||||
?: SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(it.subtype))
|
?: it.subtype.displayName(context))
|
||||||
if (it.isEnabled)
|
if (it.isEnabled)
|
||||||
string.setSpan(StyleSpan(Typeface.BOLD), 0, string.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
string.setSpan(StyleSpan(Typeface.BOLD), 0, string.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
||||||
if (!start) {
|
if (!start) {
|
||||||
|
|
|
@ -141,7 +141,7 @@ class LanguageSettingsDialog(
|
||||||
if (layoutSetName?.startsWith(CUSTOM_LAYOUT_PREFIX) == false // don't allow copying custom layout (at least for now)
|
if (layoutSetName?.startsWith(CUSTOM_LAYOUT_PREFIX) == false // don't allow copying custom layout (at least for now)
|
||||||
&& !layoutSetName.endsWith("+")) { // don't allow copying layouts only defined via extra keys
|
&& !layoutSetName.endsWith("+")) { // don't allow copying layouts only defined via extra keys
|
||||||
layouts.add(layoutSetName)
|
layouts.add(layoutSetName)
|
||||||
displayNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(it.subtype))
|
displayNames.add(it.subtype.displayName(context).toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (infos.first().subtype.isAsciiCapable) {
|
if (infos.first().subtype.isAsciiCapable) {
|
||||||
|
@ -171,7 +171,7 @@ class LanguageSettingsDialog(
|
||||||
val layoutSetName = subtype.subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET) ?: "qwerty"
|
val layoutSetName = subtype.subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET) ?: "qwerty"
|
||||||
row.findViewById<TextView>(R.id.language_name).text =
|
row.findViewById<TextView>(R.id.language_name).text =
|
||||||
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype.subtype)
|
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype.subtype)
|
||||||
?: SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype.subtype)
|
?: subtype.subtype.displayName(context)
|
||||||
if (layoutSetName.startsWith(CUSTOM_LAYOUT_PREFIX)) {
|
if (layoutSetName.startsWith(CUSTOM_LAYOUT_PREFIX)) {
|
||||||
row.findViewById<TextView>(R.id.language_details).setText(R.string.edit_layout)
|
row.findViewById<TextView>(R.id.language_details).setText(R.string.edit_layout)
|
||||||
row.findViewById<View>(R.id.language_text).setOnClickListener { editCustomLayout(layoutSetName, context) }
|
row.findViewById<View>(R.id.language_text).setOnClickListener { editCustomLayout(layoutSetName, context) }
|
||||||
|
|
|
@ -30,6 +30,7 @@ import helium314.keyboard.latin.utils.DictionaryUtilsKt;
|
||||||
import helium314.keyboard.latin.utils.ExecutorUtils;
|
import helium314.keyboard.latin.utils.ExecutorUtils;
|
||||||
import helium314.keyboard.latin.utils.JniUtils;
|
import helium314.keyboard.latin.utils.JniUtils;
|
||||||
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
|
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
|
||||||
|
import helium314.keyboard.latin.utils.SubtypeUtilsKt;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
@ -89,7 +90,7 @@ public final class SettingsFragment extends PreferenceFragmentCompat {
|
||||||
for (final InputMethodSubtype subtype : subtypes) {
|
for (final InputMethodSubtype subtype : subtypes) {
|
||||||
if (sb.length() > 0)
|
if (sb.length() > 0)
|
||||||
sb.append(", ");
|
sb.append(", ");
|
||||||
sb.append(subtype.getDisplayName(getActivity(), requireContext().getPackageName(), requireContext().getApplicationInfo()));
|
sb.append(SubtypeUtilsKt.displayName(subtype, requireContext()));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,9 @@ fun createInputMethodPickerDialog(latinIme: LatinIME, richImm: RichInputMethodMa
|
||||||
for (imiAndSubtype in enabledSubtypes) {
|
for (imiAndSubtype in enabledSubtypes) {
|
||||||
val (imi, subtype) = imiAndSubtype
|
val (imi, subtype) = imiAndSubtype
|
||||||
|
|
||||||
val title = SpannableString(subtype?.getDisplayName(latinIme, imi.packageName, imi.serviceInfo.applicationInfo)
|
val subtypeName = if (imi == thisImi) subtype?.displayName(latinIme)
|
||||||
?.ifBlank { imi.loadLabel(pm) }
|
else subtype?.getDisplayName(latinIme, imi.packageName, imi.serviceInfo.applicationInfo)
|
||||||
?: imi.loadLabel(pm))
|
val title = SpannableString(subtypeName?.ifBlank { imi.loadLabel(pm) } ?: imi.loadLabel(pm))
|
||||||
val subtitle = SpannableString(if (subtype == null) "" else "\n${imi.loadLabel(pm)}")
|
val subtitle = SpannableString(if (subtype == null) "" else "\n${imi.loadLabel(pm)}")
|
||||||
title.setSpan(
|
title.setSpan(
|
||||||
RelativeSizeSpan(0.9f), 0, title.length,
|
RelativeSizeSpan(0.9f), 0, title.length,
|
||||||
|
|
|
@ -29,6 +29,7 @@ import androidx.annotation.Nullable;
|
||||||
* A helper class to deal with subtype locales.
|
* A helper class to deal with subtype locales.
|
||||||
*/
|
*/
|
||||||
// TODO: consolidate this into RichInputMethodSubtype
|
// TODO: consolidate this into RichInputMethodSubtype
|
||||||
|
// todo (later): see whether this complicated mess can be simplified
|
||||||
public final class SubtypeLocaleUtils {
|
public final class SubtypeLocaleUtils {
|
||||||
static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
|
static final String TAG = SubtypeLocaleUtils.class.getSimpleName();
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package helium314.keyboard.latin.utils
|
package helium314.keyboard.latin.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.view.inputmethod.InputMethodSubtype
|
import android.view.inputmethod.InputMethodSubtype
|
||||||
|
import helium314.keyboard.latin.common.LocaleUtils
|
||||||
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
|
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
|
@ -12,3 +14,12 @@ fun InputMethodSubtype.locale(): Locale {
|
||||||
}
|
}
|
||||||
@Suppress("deprecation") return locale.constructLocale()
|
@Suppress("deprecation") return locale.constructLocale()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Workaround for SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale ignoring custom layout names */
|
||||||
|
// todo (later): this should be done properly and in SubtypeLocaleUtils
|
||||||
|
fun InputMethodSubtype.displayName(context: Context): CharSequence {
|
||||||
|
val layoutName = SubtypeLocaleUtils.getKeyboardLayoutSetName(this)
|
||||||
|
if (layoutName.startsWith(CUSTOM_LAYOUT_PREFIX))
|
||||||
|
return "${LocaleUtils.getLocaleDisplayNameInSystemLocale(locale(), context)} (${getLayoutDisplayName(layoutName)})"
|
||||||
|
return SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(this)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue