mirror of
https://github.com/Julow/Unexpected-Keyboard.git
synced 2025-06-24 11:41:32 +02:00
Add the "layout" option again
Some versions of android don't allow to configure several languages.
This commit is contained in:
parent
c86a119448
commit
d00576ac2d
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="pref_layout_values">
|
||||
<item>azerty</item>
|
||||
<item>qwerty</item>
|
||||
</string-array>
|
||||
<string-array name="pref_layout_values">
|
||||
<item>system</item>
|
||||
<item>azerty</item>
|
||||
<item>qwerty</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
@ -5,10 +5,17 @@
|
||||
|
||||
<string name="settings_activity_label">Unexpected Keyboard Settings</string>
|
||||
|
||||
<string name="subtype_label_azerty">%s AZERTY</string>
|
||||
<string name="subtype_label_qwerty">%s QWERTY</string>
|
||||
<string name="subtype_label_azerty">%s</string>
|
||||
<string name="subtype_label_qwerty">%s</string>
|
||||
|
||||
<string name="pref_category_layout">Layout</string>
|
||||
<string name="pref_layout_title">Change keyboard layout</string>
|
||||
<string name="pref_layout_summary">%s</string>
|
||||
<string-array name="pref_layout_entries">
|
||||
<item>System settings</item>
|
||||
<item>Azerty</item>
|
||||
<item>Qwerty</item>
|
||||
</string-array>
|
||||
<string name="pref_disable_accent_keys_title">Toggle accent keys</string>
|
||||
<string name="pref_disable_accent_keys_summary">Whether to remove the accent keys from the keyboard</string>
|
||||
|
||||
|
@ -7,11 +7,13 @@
|
||||
android:imeSubtypeLocale="en_US"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=qwerty"
|
||||
/>
|
||||
<subtype android:label="@string/subtype_label_azerty"
|
||||
android:languageTag="fr"
|
||||
android:imeSubtypeLocale="fr_FR"
|
||||
android:imeSubtypeMode="keyboard"
|
||||
android:isAsciiCapable="true"
|
||||
android:imeSubtypeExtraValue="default_layout=azerty"
|
||||
/>
|
||||
</input-method>
|
||||
|
@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<PreferenceCategory android:title="@string/pref_category_layout">
|
||||
<ListPreference
|
||||
android:key="layout"
|
||||
android:title="@string/pref_layout_title"
|
||||
android:summary="@string/pref_layout_summary"
|
||||
android:defaultValue="system"
|
||||
android:entries="@array/pref_layout_entries"
|
||||
android:entryValues="@array/pref_layout_values" />
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="disable_accent_keys"
|
||||
android:title="@string/pref_disable_accent_keys_title"
|
||||
|
@ -15,6 +15,7 @@ class Config
|
||||
public final float keyHorizontalInterval;
|
||||
public final float keyRound;
|
||||
|
||||
public int layout; // Or '-1' for the system defaults
|
||||
public float subValueDist;
|
||||
public boolean vibrateEnabled;
|
||||
public long vibrateDuration;
|
||||
@ -41,6 +42,7 @@ class Config
|
||||
keyHorizontalInterval = res.getDimension(R.dimen.key_horizontal_interval);
|
||||
keyRound = res.getDimension(R.dimen.key_round);
|
||||
// default values
|
||||
layout = -1;
|
||||
subValueDist = 10f;
|
||||
vibrateEnabled = true;
|
||||
vibrateDuration = 20;
|
||||
@ -65,6 +67,7 @@ class Config
|
||||
{
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(_context);
|
||||
|
||||
layout = layoutId_of_string(prefs.getString("layout", "system"));
|
||||
subValueDist = prefs.getFloat("sub_value_dist", subValueDist);
|
||||
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
|
||||
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);
|
||||
@ -87,4 +90,16 @@ class Config
|
||||
return (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value,
|
||||
_context.getResources().getDisplayMetrics()));
|
||||
}
|
||||
|
||||
public static int layoutId_of_string(String name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "azerty": return R.xml.azerty;
|
||||
case "qwerty": return R.xml.qwerty;
|
||||
case "system": return -1;
|
||||
default: throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,19 +33,6 @@ public class Keyboard2 extends InputMethodService
|
||||
|
||||
private Map<Integer, KeyboardData> _layoutCache = new HashMap<Integer, KeyboardData>();
|
||||
|
||||
private static final int DEFAULT_LAYOUT = R.xml.qwerty;
|
||||
private static final Map<String, Integer> LAYOUTS = new HashMap<String, Integer>();
|
||||
|
||||
private static void add_layout(String lang, int resId)
|
||||
{
|
||||
LAYOUTS.put(new Locale(lang).getLanguage(), resId);
|
||||
}
|
||||
|
||||
static
|
||||
{
|
||||
add_layout("fr", R.xml.azerty);
|
||||
}
|
||||
|
||||
private KeyboardData getLayout(int resId)
|
||||
{
|
||||
KeyboardData l = _layoutCache.get(resId);
|
||||
@ -81,10 +68,23 @@ public class Keyboard2 extends InputMethodService
|
||||
|
||||
private void refreshSubtype(InputMethodSubtype subtype)
|
||||
{
|
||||
Integer l = LAYOUTS.get(subtype.getLanguageTag());
|
||||
if (l == null)
|
||||
l = DEFAULT_LAYOUT;
|
||||
_currentTextLayout = l;
|
||||
int l;
|
||||
if (_config.layout == -1)
|
||||
l = Config.layoutId_of_string(subtype.getExtraValueOf("default_layout"));
|
||||
else
|
||||
l = _config.layout;
|
||||
if (_currentTextLayout != l)
|
||||
{
|
||||
_currentTextLayout = l;
|
||||
_keyboardView.setKeyboard(getLayout(l));
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshSubtypeImm()
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
|
||||
refreshSubtype(imm.getCurrentInputMethodSubtype());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,27 +100,23 @@ public class Keyboard2 extends InputMethodService
|
||||
@Override
|
||||
public void onStartInputView(EditorInfo info, boolean restarting)
|
||||
{
|
||||
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
_config.shouldOfferSwitchingToNextInputMethod = imm.shouldOfferSwitchingToNextInputMethod(getConnectionToken());
|
||||
refreshSubtype(imm.getCurrentInputMethodSubtype());
|
||||
refreshSubtypeImm();
|
||||
if ((info.inputType & InputType.TYPE_CLASS_NUMBER) != 0)
|
||||
_keyboardView.setKeyboard(getLayout(R.xml.numeric));
|
||||
else
|
||||
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCurrentInputMethodSubtypeChanged(InputMethodSubtype subtype)
|
||||
{
|
||||
refreshSubtype(subtype);
|
||||
_keyboardView.setKeyboard(getLayout(_currentTextLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key)
|
||||
{
|
||||
_config.refresh();
|
||||
_keyboardView.refreshConfig(_config);
|
||||
refreshSubtypeImm();
|
||||
_keyboardView.refreshConfig(_config, getLayout(_currentTextLayout));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,11 +56,12 @@ public class Keyboard2View extends View
|
||||
super(context, attrs);
|
||||
_vibratorService = (Vibrator)context.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
_handler = new Handler(this);
|
||||
refreshConfig(((Keyboard2)context).getConfig());
|
||||
refreshConfig(((Keyboard2)context).getConfig(), null);
|
||||
setOnTouchListener(this);
|
||||
}
|
||||
|
||||
public void refreshConfig(Config config)
|
||||
/* Internally calls [reset()]. */
|
||||
public void refreshConfig(Config config, KeyboardData kw)
|
||||
{
|
||||
Resources res = getResources();
|
||||
_config = config;
|
||||
@ -76,6 +77,8 @@ public class Keyboard2View extends View
|
||||
Typeface specialKeysFont = ((Keyboard2)getContext()).getSpecialKeyFont();
|
||||
_specialKeyLabelPaint = initLabelPaint(Paint.Align.CENTER, specialKeysFont);
|
||||
_specialKeySubLabelPaint = initLabelPaint(Paint.Align.LEFT, specialKeysFont);
|
||||
if (kw != null)
|
||||
setKeyboard(kw); // handle layout options then calls reset().
|
||||
}
|
||||
|
||||
private Paint initLabelPaint(Paint.Align align, Typeface font)
|
||||
|
Loading…
x
Reference in New Issue
Block a user