mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Amazfit Active 2: Add missing languages
This commit is contained in:
+32
@@ -28,6 +28,8 @@ import androidx.preference.Preference;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
@@ -188,6 +190,36 @@ public final class DeviceSettingsUtils {
|
||||
});
|
||||
}
|
||||
|
||||
public static void sortListPreference(final ListPreference listPreference) {
|
||||
final CharSequence[] entries = listPreference.getEntries();
|
||||
final CharSequence[] entryValues = listPreference.getEntryValues();
|
||||
|
||||
if (entries == null || entryValues == null || entries.length != entryValues.length) {
|
||||
LOG.warn("Invalid entries or values to sort");
|
||||
return;
|
||||
}
|
||||
|
||||
final int length = entries.length;
|
||||
final String[][] combined = new String[length][2];
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
combined[i][0] = entries[i].toString();
|
||||
combined[i][1] = entryValues[i].toString();
|
||||
}
|
||||
|
||||
// Sort, keeping "auto" at the top
|
||||
Arrays.sort(combined, 1, length, Comparator.comparing(o -> o[0]));
|
||||
|
||||
// Reassign sorted values
|
||||
for (int i = 0; i < length; i++) {
|
||||
entries[i] = combined[i][0];
|
||||
entryValues[i] = combined[i][1];
|
||||
}
|
||||
|
||||
listPreference.setEntries(entries);
|
||||
listPreference.setEntryValues(entryValues);
|
||||
}
|
||||
|
||||
public static final class MinMaxInputFilter implements InputFilter {
|
||||
private final int min;
|
||||
private final int max;
|
||||
|
||||
+5
@@ -244,6 +244,11 @@ public class ZeppOsSettingsCustomizer extends HuamiSettingsCustomizer {
|
||||
|
||||
setupGpsPreference(handler, prefs);
|
||||
setupButtonClickPreferences(handler);
|
||||
|
||||
final Preference languagePref = handler.findPreference("language");
|
||||
if (languagePref != null) {
|
||||
DeviceSettingsUtils.sortListPreference((ListPreference) languagePref);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+12
@@ -40,13 +40,25 @@ public class HuamiLanguageType {
|
||||
put("it_IT", 0x0a);
|
||||
put("ja_JP", 0x0b);
|
||||
put("th_TH", 0x0c);
|
||||
put("ar_SA", 0x0d);
|
||||
put("vi_VN", 0x0e);
|
||||
put("pt_PT", 0x0f);
|
||||
put("nl_NL", 0x10);
|
||||
put("tr_TR", 0x11);
|
||||
put("uk_UA", 0x12);
|
||||
put("he_IL", 0x13);
|
||||
put("pt_BR", 0x14);
|
||||
put("ro_RO", 0x15);
|
||||
put("cs_CZ", 0x16);
|
||||
put("el_GR", 0x17);
|
||||
put("sh_SP", 0x18);
|
||||
put("ca_ES", 0x19);
|
||||
put("fi_FI", 0x1a);
|
||||
put("nb_NO", 0x1b);
|
||||
put("da_DK", 0x1c);
|
||||
put("sv_SE", 0x1d);
|
||||
put("hu_HU", 0x1e);
|
||||
put("ms_MY", 0x1f);
|
||||
// FIXME put("pt_BR", 0x22);
|
||||
}};
|
||||
}
|
||||
|
||||
+13
-1
@@ -1204,7 +1204,13 @@ public class ZeppOsConfigService extends AbstractZeppOsService {
|
||||
final List<String> possibleLanguages = new ArrayList<>();
|
||||
possibleLanguages.add("auto");
|
||||
for (final byte possibleValue : value.getPossibleValues()) {
|
||||
possibleLanguages.add(languageByteToLocale(possibleValue));
|
||||
final String languageCode = languageByteToLocale(possibleValue);
|
||||
if (languageCode == null) {
|
||||
LOG.warn("Unknown language byte {}", String.format("0x%02x", possibleValue));
|
||||
possibleLanguages.add(String.format("0x%x", possibleValue));
|
||||
} else {
|
||||
possibleLanguages.add(languageCode);
|
||||
}
|
||||
}
|
||||
possibleLanguages.removeAll(Collections.singleton(null));
|
||||
prefs.put(DeviceSettingsUtils.getPrefPossibleValuesKey(configArg.getPrefKey()), TextUtils.join(",", possibleLanguages));
|
||||
@@ -1693,6 +1699,12 @@ public class ZeppOsConfigService extends AbstractZeppOsService {
|
||||
return (byte) (int) HuamiLanguageType.idLookup.get(locale);
|
||||
}
|
||||
|
||||
// value doesn't match a known language, attempt to parse it as hex
|
||||
final Matcher matcher = Pattern.compile("^0[xX]([0-9a-fA-F]{1,2})$").matcher(locale);
|
||||
if (matcher.find()) {
|
||||
return (byte) Integer.parseInt(matcher.group(1), 16);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2569,6 +2569,11 @@
|
||||
<item name="nb_NO">@string/norwegian_bokmal</item>
|
||||
<item name="ro_RO">@string/romanian</item>
|
||||
<item name="sv_SE">@string/swedish</item>
|
||||
<item name="sh_SP">@string/serbian_latin</item>
|
||||
<item name="ca_ES">@string/catalan</item>
|
||||
<item name="fi_FI">@string/finnish</item>
|
||||
<item name="hu_HU">@string/hungarian</item>
|
||||
<item name="ms_MY">@string/bahasa_melayu</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_language_all_values">
|
||||
@@ -2607,6 +2612,11 @@
|
||||
<item>nb_NO</item>
|
||||
<item>ro_RO</item>
|
||||
<item>sv_SE</item>
|
||||
<item>sh_SP</item>
|
||||
<item>ca_ES</item>
|
||||
<item>fi_FI</item>
|
||||
<item>hu_HU</item>
|
||||
<item>ms_MY</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_amazfitbip_language">
|
||||
|
||||
@@ -1199,6 +1199,10 @@
|
||||
<string name="swedish">Swedish</string>
|
||||
<string name="czesh">Czech</string>
|
||||
<string name="danish">Danish</string>
|
||||
<string name="serbian_latin">Serbian (Latin)</string>
|
||||
<string name="catalan">Catalan</string>
|
||||
<string name="finnish">Finnish</string>
|
||||
<string name="bahasa_melayu">Bahasa Melayu</string>
|
||||
<string name="FetchActivityOperation_about_to_transfer_since">About to transfer data since %1$s</string>
|
||||
<string name="waiting_for_reconnect">Waiting for reconnect</string>
|
||||
<string name="activity_prefs_about_you">About you</string>
|
||||
|
||||
Reference in New Issue
Block a user