add azerty layouts

This commit is contained in:
Yuriy Liskov
2020-02-11 22:58:05 +02:00
parent 34719a47e0
commit 1fdbcc6de9
10 changed files with 111 additions and 41 deletions

View File

@@ -1,10 +1,12 @@
package com.liskovsoft.leankeyboard.addons;
public interface KeyboardInfo {
boolean isEnabled();
String getLangCode();
void setLangCode(String langCode);
String getLangName();
void setLangName(String langName);
void setLangCode(String langCode);
boolean isEnabled();
void setEnabled(boolean enabled);
boolean isAzerty();
void setIsAzerty(boolean enabled);
}

View File

@@ -1,4 +0,0 @@
package com.liskovsoft.leankeyboard.addons.kbdsize;
public class KeyboardSizeWatcher {
}

View File

@@ -1,13 +0,0 @@
package com.liskovsoft.leankeyboard.addons.reskbdfactory;
import android.inputmethodservice.Keyboard;
import androidx.annotation.Nullable;
import com.liskovsoft.leankeyboard.addons.KeyboardBuilder;
class ResKeyboardBuilder implements KeyboardBuilder {
@Nullable
@Override
public Keyboard createKeyboard() {
return null;
}
}

View File

@@ -2,7 +2,6 @@ package com.liskovsoft.leankeyboard.addons.reskbdfactory;
import android.content.Context;
import android.inputmethodservice.Keyboard;
import androidx.annotation.Nullable;
import com.liskovsoft.leankeyboard.addons.KeyboardBuilder;
import com.liskovsoft.leankeyboard.addons.KeyboardFactory;
import com.liskovsoft.leankeyboard.addons.KeyboardInfo;
@@ -23,17 +22,15 @@ public class ResKeyboardFactory implements KeyboardFactory {
List<KeyboardInfo> infos = ResKeyboardInfo.getAllKeyboardInfos(context);
for (final KeyboardInfo info : infos) {
if (!info.isEnabled()) {
continue;
if (info.isEnabled()) {
result.add(createKeyboard(info));
}
result.add(createKeyboard(info.getLangCode()));
}
// at least one kbd should be enabled
if (result.isEmpty()) {
KeyboardInfo firstKbd = infos.get(0);
result.add(createKeyboard(firstKbd.getLangCode()));
result.add(createKeyboard(firstKbd));
firstKbd.setEnabled(true);
ResKeyboardInfo.updateAllKeyboardInfos(mContext, infos);
}
@@ -41,8 +38,15 @@ public class ResKeyboardFactory implements KeyboardFactory {
return result;
}
private KeyboardBuilder createKeyboard(final String langCode) {
return () -> new Keyboard(mContext, mContext.getResources().getIdentifier("qwerty_" + langCode, "xml", mContext.getPackageName()));
/**
* NOTE: create keyboard from xml data
*/
private KeyboardBuilder createKeyboard(final KeyboardInfo info) {
return () -> {
String prefix = info.isAzerty() ? "azerty_" : "qwerty_";
int kbResId = mContext.getResources().getIdentifier(prefix + info.getLangCode(), "xml", mContext.getPackageName());
return new Keyboard(mContext, kbResId);
};
}
@Override

View File

@@ -3,6 +3,7 @@ package com.liskovsoft.leankeyboard.addons.reskbdfactory;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import com.liskovsoft.leankeyboard.addons.KeyboardInfo;
import com.liskovsoft.leankeykeyboard.R;
@@ -14,6 +15,7 @@ public class ResKeyboardInfo implements KeyboardInfo {
private boolean mEnabled;
private String mLangCode;
private String mLangName;
private boolean mIsAzerty;
public static List<KeyboardInfo> getAllKeyboardInfos(Context ctx) {
List<KeyboardInfo> result = new ArrayList<>();
@@ -22,9 +24,11 @@ public class ResKeyboardInfo implements KeyboardInfo {
String[] pairs = langPair.split("\\|");
final String langName = pairs[0];
final String langCode = pairs[1];
final boolean isAzerty = pairs.length >= 3 && "azerty".equals(pairs[2]);
KeyboardInfo info = new ResKeyboardInfo();
info.setLangName(langName);
info.setLangCode(langCode);
info.setIsAzerty(isAzerty);
// sync with prefs
syncWithPrefs(ctx, info);
result.add(info);
@@ -43,7 +47,7 @@ public class ResKeyboardInfo implements KeyboardInfo {
private static void syncWithPrefs(Context ctx, KeyboardInfo info) {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
final boolean kbdEnabled = sharedPreferences.getBoolean(info.getLangCode(), false);
final boolean kbdEnabled = sharedPreferences.getBoolean(info.toString(), false);
info.setEnabled(kbdEnabled);
}
@@ -51,7 +55,7 @@ public class ResKeyboardInfo implements KeyboardInfo {
final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(ctx);
final SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(info.getLangCode(), info.isEnabled());
editor.putBoolean(info.toString(), info.isEnabled());
editor.apply();
}
@@ -89,4 +93,19 @@ public class ResKeyboardInfo implements KeyboardInfo {
mEnabled = enabled;
}
@Override
public boolean isAzerty() {
return mIsAzerty;
}
@Override
public void setIsAzerty(boolean isAzerty) {
mIsAzerty = isAzerty;
}
@NonNull
@Override
public String toString() {
return String.format("{Name: %s, Code: %s, IsAzerty: %b}", mLangName, mLangCode, mIsAzerty);
}
}

View File

@@ -1,11 +0,0 @@
package com.liskovsoft.leankeyboard.addons.reskbdfactory;
import com.liskovsoft.leankeyboard.addons.KeyboardInfo;
import java.util.List;
class ResKeyboardManager {
public List<KeyboardInfo> getAllKeyboardInfos() {
return null;
}
}

View File

@@ -2,12 +2,14 @@
<resources>
<string-array name="additional_languages">
<item>English|en_us</item>
<item>English (azerty)|en_us|azerty</item>
<item>German|de</item>
<item>Russian|ru</item>
<item>Ukrainian|uk</item>
<item>Bulgarian|bg</item>
<item>Dutch|nl</item>
<item>French|fr</item>
<item>French (azerty)|fr|azerty</item>
<item>Greek|el</item>
<item>Icelandic|is</item>
<item>Italian|it</item>

View File

@@ -56,7 +56,9 @@
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-2" android:keyEdgeFlags="left" android:keyLabel="@string/keyboardview_keycode_mode_change" android:keyIcon="@drawable/ic_ime_symbols" />
<Key android:codes="-1" android:keyLabel="@string/keyboardview_keycode_shift" android:keyIcon="@drawable/ic_ime_shift_off" />
<Key android:keyWidth="@dimen/space_key_width" android:codes="32" android:keyLabel="@string/keyboardview_keycode_space" android:keyIcon="@drawable/ic_ime_space" />
<Key android:codes="-9" android:keyLabel="@string/keyboardview_keycode_lang" android:keyIcon="@drawable/ic_ime_world" />
<Key android:codes="32" android:keyLabel="@string/keyboardview_keycode_space" android:keyIcon="@drawable/ic_ime_space_en" android:keyWidth="@dimen/space_key_width" />
<Key android:codes="-7" android:keyLabel="@string/keyboardview_keycode_voice" android:keyIcon="@drawable/ic_ime_voice" android:popupKeyboard="@xml/accent_voice" />
<Key android:codes="-3" android:keyLabel="@string/keyboardview_keycode_left" android:keyIcon="@drawable/ic_ime_left_arrow" />
<Key android:codes="-4" android:keyEdgeFlags="right" android:keyLabel="@string/keyboardview_keycode_right" android:keyIcon="@drawable/ic_ime_right_arrow" />
</Row>

View File

@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<Keyboard android:keyWidth="@dimen/key_width" android:keyHeight="@dimen/key_height" android:horizontalGap="@dimen/keyboard_horizontal_gap" android:verticalGap="@dimen/keyboard_vertical_gap"
xmlns:android="http://schemas.android.com/apk/res/android">
<!-- All letters needed for German and Danish are in the C0 Controls and Basic Latin and C1 Controls and Latin-1 Supplement blocks. (See Wikipedia's list of languages supported by those blocks.)
For Czech/Slovak, you also need Latin Extended-A.
You should also include General Punctuation, as well as any other symbols you may use (e.g. Arrows).
See http://en.wikipedia.org/wiki/Latin_characters_in_Unicode. -->
<Row android:rowEdgeFlags="top">
<Key android:codes="49" android:popupKeyboard="@xml/shift_1" android:keyEdgeFlags="left" android:keyLabel="1" />
<Key android:codes="50" android:popupKeyboard="@xml/shift_2" android:keyLabel="2" />
<Key android:codes="51" android:popupKeyboard="@xml/shift_3" android:keyLabel="3" />
<Key android:codes="52" android:popupKeyboard="@xml/shift_4" android:keyLabel="4" />
<Key android:codes="53" android:popupKeyboard="@xml/shift_5" android:keyLabel="5" />
<Key android:codes="54" android:popupKeyboard="@xml/shift_6" android:keyLabel="6" />
<Key android:codes="55" android:popupKeyboard="@xml/shift_7" android:keyLabel="7" />
<Key android:codes="56" android:popupKeyboard="@xml/shift_8" android:keyLabel="8" />
<Key android:codes="57" android:popupKeyboard="@xml/shift_9" android:keyLabel="9" />
<Key android:codes="48" android:popupKeyboard="@xml/shift_0" android:keyLabel="0" />
<Key android:codes="-5" android:keyEdgeFlags="right" android:keyLabel="@string/keyboardview_keycode_delete" android:keyIcon="@drawable/ic_ime_delete" />
</Row>
<Row>
<Key android:codes="97" android:popupKeyboard="@xml/accent_a" android:keyEdgeFlags="left" android:keyLabel="a" />
<Key android:codes="122" android:popupKeyboard="@xml/accent_z" android:keyLabel="z" />
<Key android:codes="101" android:popupKeyboard="@xml/accent_e" android:keyLabel="e" />
<Key android:codes="114" android:popupKeyboard="@xml/shift_r" android:keyLabel="r" />
<Key android:codes="116" android:popupKeyboard="@xml/accent_t" android:keyLabel="t" />
<Key android:codes="121" android:popupKeyboard="@xml/shift_y" android:keyLabel="y" />
<Key android:codes="117" android:popupKeyboard="@xml/accent_u" android:keyLabel="u" />
<Key android:codes="105" android:popupKeyboard="@xml/accent_i" android:keyLabel="i" />
<Key android:codes="111" android:popupKeyboard="@xml/accent_o" android:keyLabel="o" />
<Key android:codes="112" android:popupKeyboard="@xml/shift_p" android:keyLabel="p" />
<Key android:codes="64" android:keyEdgeFlags="right" android:keyLabel="\@" />
</Row>
<Row>
<Key android:codes="113" android:popupKeyboard="@xml/shift_q" android:keyEdgeFlags="left" android:keyLabel="q" />
<Key android:codes="115" android:popupKeyboard="@xml/accent_s" android:keyLabel="s" />
<Key android:codes="100" android:popupKeyboard="@xml/accent_d" android:keyLabel="d" />
<Key android:codes="102" android:popupKeyboard="@xml/shift_f" android:keyLabel="f" />
<Key android:codes="103" android:popupKeyboard="@xml/accent_g" android:keyLabel="g" />
<Key android:codes="104" android:popupKeyboard="@xml/shift_h" android:keyLabel="h" />
<Key android:codes="106" android:popupKeyboard="@xml/shift_j" android:keyLabel="j" />
<Key android:codes="107" android:popupKeyboard="@xml/accent_k" android:keyLabel="k" />
<Key android:codes="108" android:popupKeyboard="@xml/accent_l" android:keyLabel="l" />
<Key android:codes="109" android:popupKeyboard="@xml/shift_m" android:keyLabel="m" />
<Key android:codes="38" android:keyEdgeFlags="right" android:keyLabel="&amp;" />
</Row>
<Row>
<Key android:codes="119" android:popupKeyboard="@xml/shift_w" android:keyEdgeFlags="left" android:keyLabel="w" />
<Key android:codes="120" android:popupKeyboard="@xml/shift_x" android:keyLabel="x" />
<Key android:codes="99" android:popupKeyboard="@xml/accent_c" android:keyLabel="c" />
<Key android:codes="118" android:popupKeyboard="@xml/shift_v" android:keyLabel="v" />
<Key android:codes="98" android:popupKeyboard="@xml/shift_b" android:keyLabel="b" />
<Key android:codes="110" android:popupKeyboard="@xml/accent_n" android:keyLabel="n" />
<Key android:codes="39" android:keyLabel="'" />
<Key android:codes="44" android:keyLabel="," />
<Key android:codes="46" android:keyLabel="." />
<Key android:codes="45" android:keyLabel="-" />
<Key android:codes="63" android:keyEdgeFlags="right" android:keyLabel="\?" />
</Row>
<Row android:rowEdgeFlags="bottom">
<Key android:codes="-2" android:keyEdgeFlags="left" android:keyLabel="@string/keyboardview_keycode_mode_change" android:keyIcon="@drawable/ic_ime_symbols" />
<Key android:codes="-1" android:keyLabel="@string/keyboardview_keycode_shift" android:keyIcon="@drawable/ic_ime_shift_off" />
<Key android:codes="-9" android:keyLabel="@string/keyboardview_keycode_lang" android:keyIcon="@drawable/ic_ime_world" />
<Key android:codes="32" android:keyLabel="@string/keyboardview_keycode_space" android:keyIcon="@drawable/ic_ime_space_fr" android:keyWidth="@dimen/space_key_width" />
<Key android:codes="-7" android:keyLabel="@string/keyboardview_keycode_voice" android:keyIcon="@drawable/ic_ime_voice" android:popupKeyboard="@xml/accent_voice" />
<Key android:codes="-3" android:keyLabel="@string/keyboardview_keycode_left" android:keyIcon="@drawable/ic_ime_left_arrow" />
<Key android:codes="-4" android:keyEdgeFlags="right" android:keyLabel="@string/keyboardview_keycode_right" android:keyIcon="@drawable/ic_ime_right_arrow" />
</Row>
</Keyboard>