Skip to content

Commit

Permalink
display "<language> (<layout>)" also for custom layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Helium314 committed Apr 11, 2024
1 parent 9bd2136 commit 3754b2b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.utils.DeviceProtectedUtils
import helium314.keyboard.latin.utils.SubtypeLocaleUtils
import helium314.keyboard.latin.utils.addEnabledSubtype
import helium314.keyboard.latin.utils.displayName
import helium314.keyboard.latin.utils.isAdditionalSubtype
import helium314.keyboard.latin.utils.locale
import helium314.keyboard.latin.utils.removeEnabledSubtype
Expand Down Expand Up @@ -89,7 +90,7 @@ private class LanguageAdapter(list: List<MutableList<SubtypeInfo>> = listOf(), c
var start = true
infos.forEach {
val string = SpannableString(SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(it.subtype)
?: SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(it.subtype))
?: it.subtype.displayName(context))
if (it.isEnabled)
string.setSpan(StyleSpan(Typeface.BOLD), 0, string.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
if (!start) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class LanguageSettingsDialog(
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
layouts.add(layoutSetName)
displayNames.add(SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(it.subtype))
displayNames.add(it.subtype.displayName(context).toString())
}
}
if (infos.first().subtype.isAsciiCapable) {
Expand Down Expand Up @@ -171,7 +171,7 @@ class LanguageSettingsDialog(
val layoutSetName = subtype.subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET) ?: "qwerty"
row.findViewById<TextView>(R.id.language_name).text =
SubtypeLocaleUtils.getKeyboardLayoutSetDisplayName(subtype.subtype)
?: SubtypeLocaleUtils.getSubtypeDisplayNameInSystemLocale(subtype.subtype)
?: subtype.subtype.displayName(context)
if (layoutSetName.startsWith(CUSTOM_LAYOUT_PREFIX)) {
row.findViewById<TextView>(R.id.language_details).setText(R.string.edit_layout)
row.findViewById<View>(R.id.language_text).setOnClickListener { editCustomLayout(layoutSetName, context) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import helium314.keyboard.latin.utils.ExecutorUtils;
import helium314.keyboard.latin.utils.JniUtils;
import helium314.keyboard.latin.utils.SubtypeSettingsKt;
import helium314.keyboard.latin.utils.SubtypeUtilsKt;

import java.util.List;
import java.io.BufferedOutputStream;
Expand Down Expand Up @@ -89,7 +90,7 @@ private String getEnabledSubtypesLabel() {
for (final InputMethodSubtype subtype : subtypes) {
if (sb.length() > 0)
sb.append(", ");
sb.append(subtype.getDisplayName(getActivity(), requireContext().getPackageName(), requireContext().getApplicationInfo()));
sb.append(SubtypeUtilsKt.displayName(subtype, requireContext()));
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ fun createInputMethodPickerDialog(latinIme: LatinIME, richImm: RichInputMethodMa
for (imiAndSubtype in enabledSubtypes) {
val (imi, subtype) = imiAndSubtype

val title = SpannableString(subtype?.getDisplayName(latinIme, imi.packageName, imi.serviceInfo.applicationInfo)
?.ifBlank { imi.loadLabel(pm) }
?: imi.loadLabel(pm))
val subtypeName = if (imi == thisImi) subtype?.displayName(latinIme)
else subtype?.getDisplayName(latinIme, imi.packageName, imi.serviceInfo.applicationInfo)
val title = SpannableString(subtypeName?.ifBlank { imi.loadLabel(pm) } ?: imi.loadLabel(pm))
val subtitle = SpannableString(if (subtype == null) "" else "\n${imi.loadLabel(pm)}")
title.setSpan(
RelativeSizeSpan(0.9f), 0, title.length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* A helper class to deal with subtype locales.
*/
// TODO: consolidate this into RichInputMethodSubtype
// todo (later): see whether this complicated mess can be simplified
public final class SubtypeLocaleUtils {
static final String TAG = SubtypeLocaleUtils.class.getSimpleName();

Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/helium314/keyboard/latin/utils/SubtypeUtils.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package helium314.keyboard.latin.utils

import android.content.Context
import android.os.Build
import android.view.inputmethod.InputMethodSubtype
import helium314.keyboard.latin.common.LocaleUtils
import helium314.keyboard.latin.common.LocaleUtils.constructLocale
import java.util.Locale

Expand All @@ -12,3 +14,12 @@ fun InputMethodSubtype.locale(): Locale {
}
@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)
}

0 comments on commit 3754b2b

Please sign in to comment.