diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 896c515..c6e2139 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1,7 +1,8 @@ - - azerty - qwerty - + + system + azerty + qwerty + diff --git a/res/values/strings.xml b/res/values/strings.xml index 9637b57..04c3b57 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -5,10 +5,17 @@ Unexpected Keyboard Settings - %s AZERTY - %s QWERTY + %s + %s Layout + Change keyboard layout + %s + + System settings + Azerty + Qwerty + Toggle accent keys Whether to remove the accent keys from the keyboard diff --git a/res/xml/method.xml b/res/xml/method.xml index 92c02ff..5a515cd 100644 --- a/res/xml/method.xml +++ b/res/xml/method.xml @@ -7,11 +7,13 @@ android:imeSubtypeLocale="en_US" android:imeSubtypeMode="keyboard" android:isAsciiCapable="true" + android:imeSubtypeExtraValue="default_layout=qwerty" /> diff --git a/res/xml/settings.xml b/res/xml/settings.xml index d56f029..f943557 100644 --- a/res/xml/settings.xml +++ b/res/xml/settings.xml @@ -1,6 +1,14 @@ + + /> _layoutCache = new HashMap(); - private static final int DEFAULT_LAYOUT = R.xml.qwerty; - private static final Map LAYOUTS = new HashMap(); - - 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 diff --git a/srcs/juloo.keyboard2/Keyboard2View.java b/srcs/juloo.keyboard2/Keyboard2View.java index 0dc76ea..37a210f 100644 --- a/srcs/juloo.keyboard2/Keyboard2View.java +++ b/srcs/juloo.keyboard2/Keyboard2View.java @@ -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)