1
0
forked from GitHub/gf-core

added Devanagari keyboard for Android

This commit is contained in:
kr.angelov
2014-03-07 13:42:13 +00:00
parent 5b799685d8
commit 71005bb163
8 changed files with 230 additions and 54 deletions

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="@dimen/key_height"
>
<Row>
<Key android:codes="2325" android:keyLabel="क" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="क़०" android:keyEdgeFlags="left"/>
<Key android:codes="2326" android:keyLabel="ख" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ख़१"/>
<Key android:codes="2327" android:keyLabel="ग" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ग़२"/>
<Key android:codes="2328" android:keyLabel="घ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="३"/>
<Key android:codes="2329" android:keyLabel="ङ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="४"/>
<Key android:codes="2330" android:keyLabel="च" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="५"/>
<Key android:codes="2331" android:keyLabel="छ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="६"/>
<Key android:codes="2332" android:keyLabel="ज" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ज़७"/>
<Key android:codes="2333" android:keyLabel="झ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="८"/>
<Key android:codes="2334" android:keyLabel="ञ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="९" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="2335" android:keyLabel="ट" android:keyEdgeFlags="left"/>
<Key android:codes="2336" android:keyLabel="ठ"/>
<Key android:codes="2337" android:keyLabel="ड" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ड़"/>
<Key android:codes="2338" android:keyLabel="ढ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ढ़"/>
<Key android:codes="2339" android:keyLabel="ण"/>
<Key android:codes="2340" android:keyLabel="त"/>
<Key android:codes="2341" android:keyLabel="थ"/>
<Key android:codes="2342" android:keyLabel="द"/>
<Key android:codes="2343" android:keyLabel="ध"/>
<Key android:codes="2344" android:keyLabel="न" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="-10" android:keyLabel="1/2" android:horizontalGap="3%p" android:keyEdgeFlags="left"/>
<Key android:codes="2309" android:keyLabel="अ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="आा"/>
<Key android:codes="2311" android:keyLabel="इ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ीईि"/>
<Key android:codes="2313" android:keyLabel="उ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ूऊु"/>
<Key android:codes="2319" android:keyLabel="ए" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॅऐैेऍ"/>
<Key android:codes="2323" android:keyLabel="ओ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॉौऔोऑ"/>
<Key android:codes="2315" android:keyLabel="ऋ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॄॠृ"/>
<Key android:codes="2305" android:keyLabel="ँ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ंः"/>
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete"
android:keyWidth="15%p" android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>
<Row android:rowEdgeFlags="bottom" android:keyboardMode="@string/normalKeyboardMode">
<Key android:codes="-100" android:keyLabel="Sr" android:keyWidth="13%p" android:horizontalGap="6%p" android:keyEdgeFlags="left"/>
<Key android:codes="-200" android:keyLabel="Tr" android:keyWidth="13%p"/>
<Key android:codes="-2" android:keyLabel="123" android:keyWidth="13%p"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
android:keyWidth="29%p" android:isRepeatable="true"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="19%p" android:keyEdgeFlags="right"/>
</Row>
<Row android:rowEdgeFlags="bottom" android:keyboardMode="@string/internalKeyboardMode">
<Key android:codes="-2" android:keyLabel="123" android:keyWidth="18%p" android:horizontalGap="15%p" android:keyEdgeFlags="left"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
android:keyWidth="30%p" android:isRepeatable="true"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="20%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
android:keyWidth="10%p"
android:horizontalGap="0px"
android:verticalGap="0px"
android:keyHeight="@dimen/key_height"
>
<Row>
<Key android:codes="2346" android:keyLabel="प" android:keyEdgeFlags="left"/>
<Key android:codes="2347" android:keyLabel="फ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="फ़"/>
<Key android:codes="2348" android:keyLabel="ब"/>
<Key android:codes="2349" android:keyLabel="भ"/>
<Key android:codes="2350" android:keyLabel="म"/>
<Key android:codes="2351" android:keyLabel="य" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="य़"/>
<Key android:codes="2352" android:keyLabel="र" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ऱ"/>
<Key android:codes="2354" android:keyLabel="ल"/>
<Key android:codes="2355" android:keyLabel="ळ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ऴ"/>
<Key android:codes="2357" android:keyLabel="व" android:keyEdgeFlags="right"/>
</Row>
<Row>
<Key android:codes="2358" android:keyLabel="श" android:keyEdgeFlags="left"/>
<Key android:codes="2359" android:keyLabel="ष"/>
<Key android:codes="2360" android:keyLabel="स"/>
<Key android:codes="2361" android:keyLabel="ह"/>
<Key android:codes="2325,2381,2359" android:keyLabel="क्ष"/>
<Key android:codes="2340,2381,2352" android:keyLabel="त्र"/>
<Key android:codes="2332,2381,2334" android:keyLabel="ज्ञ"/>
<Key android:codes="2358,2381,2352" android:keyLabel="श्र"/>
<Key android:codes="2364" android:keyLabel="़"/>
<Key android:codes="2381" android:keyLabel="्"/>"आ"
</Row>
<Row>
<Key android:codes="-10" android:keyLabel="2/2" android:horizontalGap="3%p" android:keyEdgeFlags="left"/>
<Key android:codes="2310" android:keyLabel="आ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="अा"/>
<Key android:codes="2312" android:keyLabel="ई" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ीइि"/>
<Key android:codes="2314" android:keyLabel="ऊ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ूउु"/>
<Key android:codes="2320" android:keyLabel="ऐ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॅैएेऍ"/>
<Key android:codes="2324" android:keyLabel="औ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॉौओोऑ"/>
<Key android:codes="2400" android:keyLabel="ॠ" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ॄऋृ"/>
<Key android:codes="2306" android:keyLabel="ं" android:popupKeyboard="@xml/popup_keyboard" android:popupCharacters="ँः"/>
<Key android:codes="-5" android:keyIcon="@drawable/sym_keyboard_delete"
android:keyWidth="15%p" android:keyEdgeFlags="right"
android:isRepeatable="true"/>
</Row>
<Row android:rowEdgeFlags="bottom" android:keyboardMode="@string/normalKeyboardMode">
<Key android:codes="-100" android:keyLabel="Sr" android:keyWidth="13%p" android:horizontalGap="6%p" android:keyEdgeFlags="left"/>
<Key android:codes="-200" android:keyLabel="Tr" android:keyWidth="13%p"/>
<Key android:codes="-2" android:keyLabel="123" android:keyWidth="13%p"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
android:keyWidth="29%p" android:isRepeatable="true"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="19%p" android:keyEdgeFlags="right"/>
</Row>
<Row android:rowEdgeFlags="bottom" android:keyboardMode="@string/internalKeyboardMode">
<Key android:codes="-2" android:keyLabel="123" android:keyWidth="18%p" android:horizontalGap="15%p" android:keyEdgeFlags="left"/>
<Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
android:keyWidth="30%p" android:isRepeatable="true"/>
<Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
android:keyWidth="20%p" android:keyEdgeFlags="right"/>
</Row>
</Keyboard>

View File

@@ -8,14 +8,25 @@ public class Language implements Serializable {
private final String mLangCode;
private final String mLangName;
private final String mConcrete;
private final int mKeyboardResource;
private final int mKeyboardPage1Resource;
private final int mKeyboardPage2Resource;
public Language(String langCode, String langName, String concrete,
int keyboardResource) {
mLangCode = langCode;
mLangName = langName;
mConcrete = concrete;
mKeyboardResource = keyboardResource;
mKeyboardPage1Resource = keyboardResource;
mKeyboardPage2Resource = keyboardResource;
}
public Language(String langCode, String langName, String concrete,
int keyboardPage1Resource, int keyboardPage2Resource) {
mLangCode = langCode;
mLangName = langName;
mConcrete = concrete;
mKeyboardPage1Resource = keyboardPage1Resource;
mKeyboardPage2Resource = keyboardPage2Resource;
}
public String getLangCode() {
@@ -26,8 +37,12 @@ public class Language implements Serializable {
return mLangName;
}
public int getKeyboardResource() {
return mKeyboardResource;
public int getKeyboardPage1Resource() {
return mKeyboardPage1Resource;
}
public int getKeyboardPage2Resource() {
return mKeyboardPage2Resource;
}
String getConcrete() {

View File

@@ -35,7 +35,7 @@ public class Translator {
new Language("cmn-Hans-CN", "Chinese", "ParseChi", R.xml.qwerty),
new Language("fr-FR", "French", "ParseFre", R.xml.qwerty),
new Language("de-DE", "German", "ParseGer", R.xml.qwerty),
new Language("hi-IN", "Hindi", "ParseHin", R.xml.qwerty), ///
new Language("hi-IN", "Hindi", "ParseHin", R.xml.devanagari_page1, R.xml.devanagari_page2),
new Language("sv-SE", "Swedish", "ParseSwe", R.xml.qwerty),
new Language("fi-FI", "Finnish", "ParseFin", R.xml.qwerty),
};

View File

@@ -29,9 +29,10 @@ public class TranslatorInputMethodService extends InputMethodService
private long mLastShiftTime;
private long mMetaState;
private TranslatorKeyboard mSymbolsKeyboard;
private TranslatorKeyboard mSymbolsShiftedKeyboard;
private TranslatorKeyboard mLanguageKeyboard;
private TranslatorKeyboard mSymbolsPage1Keyboard;
private TranslatorKeyboard mSymbolsPage2Keyboard;
private TranslatorKeyboard mLanguagePage1Keyboard;
private TranslatorKeyboard mLanguagePage2Keyboard;
private TranslatorKeyboard mCurKeyboard;
@@ -45,9 +46,10 @@ public class TranslatorInputMethodService extends InputMethodService
mTranslator = ((GFTranslator) getApplicationContext()).getTranslator();
mSymbolsKeyboard = null;
mSymbolsShiftedKeyboard = null;
mLanguageKeyboard = null;
mSymbolsPage1Keyboard = null;
mSymbolsPage2Keyboard = null;
mLanguagePage1Keyboard = null;
mLanguagePage2Keyboard = null;
}
@Override
@@ -92,17 +94,20 @@ public class TranslatorInputMethodService extends InputMethodService
mCompletionOn = false;
mCompletions = null;
int res =
mTranslator.getSourceLanguage().getKeyboardResource();
int res1 =
mTranslator.getSourceLanguage().getKeyboardPage1Resource();
int res2 =
mTranslator.getSourceLanguage().getKeyboardPage2Resource();
mModeId = R.string.normalKeyboardMode;
if (attribute.extras != null &&
!attribute.extras.getBoolean("show_language_toggle", true)) {
mModeId = R.string.internalKeyboardMode;
}
mAttribute = attribute;
mLanguageKeyboard = new TranslatorKeyboard(this, res, mModeId);
mSymbolsKeyboard = new TranslatorKeyboard(this, R.xml.symbols, mModeId);
mSymbolsShiftedKeyboard = new TranslatorKeyboard(this, R.xml.symbols_shift, mModeId);
mLanguagePage1Keyboard = new TranslatorKeyboard(this, res1, mModeId);
mLanguagePage2Keyboard = new TranslatorKeyboard(this, res2, mModeId);
mSymbolsPage1Keyboard = new TranslatorKeyboard(this, R.xml.symbols_page1, mModeId);
mSymbolsPage2Keyboard = new TranslatorKeyboard(this, R.xml.symbols_page2, mModeId);
// We are now going to initialize our state based on the type of
// text being edited.
@@ -111,13 +116,13 @@ public class TranslatorInputMethodService extends InputMethodService
case InputType.TYPE_CLASS_DATETIME:
// Numbers and dates default to the symbols keyboard, with
// no extra features.
mCurKeyboard = mSymbolsKeyboard;
mCurKeyboard = mSymbolsPage1Keyboard;
break;
case InputType.TYPE_CLASS_PHONE:
// Phones will also default to the symbols keyboard, though
// often you will want to have a dedicated phone keyboard.
mCurKeyboard = mSymbolsKeyboard;
mCurKeyboard = mSymbolsPage1Keyboard;
break;
case InputType.TYPE_CLASS_TEXT:
@@ -125,7 +130,7 @@ public class TranslatorInputMethodService extends InputMethodService
// normal alphabetic keyboard, and assume that we should
// be doing predictive text (showing candidates as the
// user types).
mCurKeyboard = mLanguageKeyboard;
mCurKeyboard = mLanguagePage1Keyboard;
mPredictionOn = true;
// We now look for a few special variations of text that will
@@ -165,12 +170,13 @@ public class TranslatorInputMethodService extends InputMethodService
default:
// For all unknown input types, default to the alphabetic
// keyboard with no special features.
mCurKeyboard = mLanguageKeyboard;
mCurKeyboard = mLanguagePage1Keyboard;
updateShiftKeyState(attribute);
}
mActionId = attribute.imeOptions & (EditorInfo.IME_MASK_ACTION | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
mCurKeyboard.setImeOptions(getResources(), attribute.imeOptions);
mLanguagePage1Keyboard.setImeOptions(getResources(), attribute.imeOptions);
mLanguagePage2Keyboard.setImeOptions(getResources(), attribute.imeOptions);
mInstance = this;
}
@@ -189,7 +195,7 @@ public class TranslatorInputMethodService extends InputMethodService
// its window.
setCandidatesViewShown(false);
mCurKeyboard = mLanguageKeyboard;
mCurKeyboard = mLanguagePage1Keyboard;
if (mInputView != null) {
mInputView.closing();
}
@@ -332,8 +338,9 @@ public class TranslatorInputMethodService extends InputMethodService
* editor state.
*/
private void updateShiftKeyState(EditorInfo attr) {
if (attr != null
&& mInputView != null && mLanguageKeyboard == mInputView.getKeyboard()) {
if (attr != null && mInputView != null &&
(mLanguagePage1Keyboard == mInputView.getKeyboard() ||
mLanguagePage2Keyboard == mInputView.getKeyboard())) {
int caps = 0;
EditorInfo ei = getCurrentInputEditorInfo();
if (ei != null && ei.inputType != InputType.TYPE_NULL) {
@@ -379,19 +386,28 @@ public class TranslatorInputMethodService extends InputMethodService
mTranslator.getAvailableLanguages().get(TranslatorKeyboard.KEYCODE_TARGET_LANGUAGE-primaryCode-1);
mTranslator.setTargetLanguage(newTarget);
handleChangeTargetLanguage(newTarget);
} else if (primaryCode == TranslatorKeyboard.KEYCODE_MODE_CHANGE
&& mInputView != null) {
} else if (primaryCode == TranslatorKeyboard.KEYCODE_MODE_CHANGE &&
mInputView != null) {
TranslatorKeyboard current = (TranslatorKeyboard) mInputView.getKeyboard();
if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) {
current = mLanguageKeyboard;
if (current == mSymbolsPage1Keyboard || current == mSymbolsPage2Keyboard) {
current = mLanguagePage1Keyboard;
} else {
current = mSymbolsKeyboard;
current = mSymbolsPage1Keyboard;
}
mInputView.setKeyboard(current);
if (current == mSymbolsKeyboard) {
if (current == mSymbolsPage1Keyboard) {
current.setShifted(false);
}
} else if (primaryCode == 10) {
} else if (primaryCode == TranslatorKeyboard.KEYCODE_PAGE_CHANGE &&
mInputView != null) {
TranslatorKeyboard current = (TranslatorKeyboard) mInputView.getKeyboard();
if (current == mLanguagePage1Keyboard) {
current = mLanguagePage2Keyboard;
} else {
current = mLanguagePage1Keyboard;
}
mInputView.setKeyboard(current);
} else if (primaryCode == 10) {
if ((mActionId & EditorInfo.IME_FLAG_NO_ENTER_ACTION) == 0)
getCurrentInputConnection().performEditorAction(mActionId & EditorInfo.IME_MASK_ACTION);
else
@@ -469,18 +485,19 @@ public class TranslatorInputMethodService extends InputMethodService
}
TranslatorKeyboard currentKeyboard = (TranslatorKeyboard) mInputView.getKeyboard();
if (mLanguageKeyboard == currentKeyboard) {
if (mLanguagePage1Keyboard == currentKeyboard ||
mLanguagePage2Keyboard == currentKeyboard) {
// Alphabet keyboard
checkToggleCapsLock();
mInputView.setShifted(mCapsLock || !mInputView.isShifted());
} else if (currentKeyboard == mSymbolsKeyboard) {
mSymbolsKeyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsShiftedKeyboard);
mSymbolsShiftedKeyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsShiftedKeyboard) {
mSymbolsShiftedKeyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsKeyboard);
mSymbolsKeyboard.setShifted(false);
} else if (currentKeyboard == mSymbolsPage1Keyboard) {
mSymbolsPage1Keyboard.setShifted(true);
mInputView.setKeyboard(mSymbolsPage2Keyboard);
mSymbolsPage2Keyboard.setShifted(true);
} else if (currentKeyboard == mSymbolsPage2Keyboard) {
mSymbolsPage2Keyboard.setShifted(false);
mInputView.setKeyboard(mSymbolsPage1Keyboard);
mSymbolsPage1Keyboard.setShifted(false);
}
}
@@ -491,7 +508,9 @@ public class TranslatorInputMethodService extends InputMethodService
}
}
mComposing.append((char) primaryCode);
for (int i = 0; i < keyCodes.length && keyCodes[i] > 0; i++)
mComposing.append((char) keyCodes[i]);
if (primaryCode == 10)
commitTyped(getCurrentInputConnection());
else
@@ -511,17 +530,18 @@ public class TranslatorInputMethodService extends InputMethodService
void handleChangeSourceLanguage(Language newSource) {
updateLanguageKeyboard(newSource);
mSymbolsKeyboard.updateLanguageKeyLabels();
mSymbolsShiftedKeyboard.updateLanguageKeyLabels();
mSymbolsPage1Keyboard.updateLanguageKeyLabels();
mSymbolsPage2Keyboard.updateLanguageKeyLabels();
if (mInputView != null) {
mInputView.setKeyboard(mCurKeyboard);
}
}
void handleChangeTargetLanguage(Language newTarget) {
mLanguageKeyboard.updateLanguageKeyLabels();
mSymbolsKeyboard.updateLanguageKeyLabels();
mSymbolsShiftedKeyboard.updateLanguageKeyLabels();
mLanguagePage1Keyboard.updateLanguageKeyLabels();
mLanguagePage2Keyboard.updateLanguageKeyLabels();
mSymbolsPage1Keyboard.updateLanguageKeyLabels();
mSymbolsPage2Keyboard.updateLanguageKeyLabels();
if (mInputView != null) {
mInputView.invalidateAllKeys();
}
@@ -530,20 +550,26 @@ public class TranslatorInputMethodService extends InputMethodService
void handleSwitchLanguages() {
Language newSource = mTranslator.getSourceLanguage();
updateLanguageKeyboard(newSource);
mSymbolsKeyboard.updateLanguageKeyLabels();
mSymbolsShiftedKeyboard.updateLanguageKeyLabels();
mSymbolsPage1Keyboard.updateLanguageKeyLabels();
mSymbolsPage2Keyboard.updateLanguageKeyLabels();
if (mInputView != null)
mInputView.setKeyboard(mCurKeyboard);
}
private void updateLanguageKeyboard(Language language) {
TranslatorKeyboard keyboard =
new TranslatorKeyboard(this, language.getKeyboardResource(), mModeId);
keyboard.setImeOptions(getResources(), mAttribute.imeOptions);
if (mCurKeyboard == mLanguageKeyboard) {
mCurKeyboard = keyboard;
TranslatorKeyboard keyboard1 =
new TranslatorKeyboard(this, language.getKeyboardPage1Resource(), mModeId);
TranslatorKeyboard keyboard2 =
new TranslatorKeyboard(this, language.getKeyboardPage2Resource(), mModeId);
keyboard1.setImeOptions(getResources(), mAttribute.imeOptions);
keyboard2.setImeOptions(getResources(), mAttribute.imeOptions);
if (mCurKeyboard == mLanguagePage1Keyboard) {
mCurKeyboard = keyboard1;
} else if (mCurKeyboard == mLanguagePage2Keyboard) {
mCurKeyboard = keyboard2;
}
mLanguageKeyboard = keyboard;
mLanguagePage1Keyboard = keyboard1;
mLanguagePage2Keyboard = keyboard2;
}
private void checkToggleCapsLock() {

View File

@@ -14,6 +14,7 @@ public class TranslatorKeyboard extends Keyboard {
private Key mSourceLanguageKey;
private Key mTargetLanguageKey;
static final int KEYCODE_PAGE_CHANGE = -10;
static final int KEYCODE_SOURCE_LANGUAGE = -100;
static final int KEYCODE_TARGET_LANGUAGE = -200;
static final int MAX_LANGUAGE_KEYCODES = 99;