diff options
Diffstat (limited to 'java')
-rw-r--r-- | java/res/xml-hi/keyboard_set.xml | 42 | ||||
-rw-r--r-- | java/res/xml-sw600dp/rows_hindi.xml | 61 | ||||
-rw-r--r-- | java/res/xml-sw768dp/rows_hindi.xml | 65 | ||||
-rw-r--r-- | java/res/xml/kbd_hindi.xml | 26 | ||||
-rw-r--r-- | java/res/xml/method.xml | 7 | ||||
-rw-r--r-- | java/res/xml/rowkeys_hindi1.xml | 197 | ||||
-rw-r--r-- | java/res/xml/rowkeys_hindi2.xml | 142 | ||||
-rw-r--r-- | java/res/xml/rowkeys_hindi3.xml | 113 | ||||
-rw-r--r-- | java/res/xml/rows_hindi.xml | 52 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/LatinIME.java | 13 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/UserBigramDictionary.java | 62 | ||||
-rw-r--r-- | java/src/com/android/inputmethod/latin/UserUnigramDictionary.java | 276 |
12 files changed, 761 insertions, 295 deletions
diff --git a/java/res/xml-hi/keyboard_set.xml b/java/res/xml-hi/keyboard_set.xml new file mode 100644 index 000000000..804323a31 --- /dev/null +++ b/java/res/xml-hi/keyboard_set.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<KeyboardSet + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" + latin:keyboardLocale="hi"> + <Element + latin:elementName="alphabet" + latin:elementKeyboard="@xml/kbd_hindi" /> + <Element + latin:elementName="symbols" + latin:elementKeyboard="@xml/kbd_symbols" /> + <Element + latin:elementName="symbolsShifted" + latin:elementKeyboard="@xml/kbd_symbols_shift" /> + <Element + latin:elementName="phone" + latin:elementKeyboard="@xml/kbd_phone" /> + <Element + latin:elementName="phoneSymbols" + latin:elementKeyboard="@xml/kbd_phone_symbols" /> + <Element + latin:elementName="number" + latin:elementKeyboard="@xml/kbd_number" /> +</KeyboardSet> diff --git a/java/res/xml-sw600dp/rows_hindi.xml b/java/res/xml-sw600dp/rows_hindi.xml new file mode 100644 index 000000000..6bec7f0b5 --- /dev/null +++ b/java/res/xml-sw600dp/rows_hindi.xml @@ -0,0 +1,61 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <include + latin:keyboardLayout="@xml/key_styles_common" /> + <Row + latin:keyWidth="7.6%p" + > + <include + latin:keyboardLayout="@xml/rowkeys_hindi1" + latin:keyLabelFlags="disableAdditionalMoreKeys|disableKeyHintLabel" /> + <Key + latin:keyStyle="deleteKeyStyle" + latin:keyWidth="fillBoth" /> + </Row> + <Row + latin:keyWidth="7.6%p" + > + <include + latin:keyboardLayout="@xml/rowkeys_hindi2" + latin:keyXPos="4.500%p" /> + <Key + latin:keyStyle="enterKeyStyle" + latin:keyWidth="fillBoth" /> + </Row> + <Row + latin:keyWidth="6.923%p" + > + <Key + latin:keyStyle="shiftKeyStyle" + latin:keyWidth="10.0%p" /> + <include + latin:keyboardLayout="@xml/rowkeys_hindi3" /> + <include + latin:keyboardLayout="@xml/keys_comma_period" /> + <include + latin:keyboardLayout="@xml/key_smiley" /> + </Row> + <include + latin:keyboardLayout="@xml/row_qwerty4" /> +</merge> diff --git a/java/res/xml-sw768dp/rows_hindi.xml b/java/res/xml-sw768dp/rows_hindi.xml new file mode 100644 index 000000000..bb1884227 --- /dev/null +++ b/java/res/xml-sw768dp/rows_hindi.xml @@ -0,0 +1,65 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <include + latin:keyboardLayout="@xml/key_styles_common" /> + <Row + latin:keyWidth="7.333%p" + > + <Key + latin:keyStyle="tabKeyStyle" + latin:keyLabelFlags="alignLeft" /> + <include + latin:keyboardLayout="@xml/rowkeys_hindi1" + latin:keyLabelFlags="disableAdditionalMoreKeys|disableKeyHintLabel" /> + <Key + latin:keyStyle="deleteKeyStyle" + latin:keyWidth="fillBoth" /> + </Row> + <Row + latin:keyWidth="7.194%p" + > + <Key + latin:keyStyle="toSymbolKeyStyle" + latin:keyLabelFlags="alignLeft" + latin:keyWidth="9.375%p" /> + <include + latin:keyboardLayout="@xml/rowkeys_hindi2" /> + <Key + latin:keyStyle="enterKeyStyle" + latin:keyWidth="fillBoth" /> + </Row> + <Row + latin:keyWidth="7.135%p" + > + <Key + latin:keyStyle="shiftKeyStyle" + latin:keyWidth="14.375%p" /> + <include + latin:keyboardLayout="@xml/rowkeys_hindi3" /> + <include + latin:keyboardLayout="@xml/keys_comma_period" /> + </Row> + <include + latin:keyboardLayout="@xml/row_qwerty4" /> +</merge> diff --git a/java/res/xml/kbd_hindi.xml b/java/res/xml/kbd_hindi.xml new file mode 100644 index 000000000..0e69e3ae2 --- /dev/null +++ b/java/res/xml/kbd_hindi.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<Keyboard + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <include + latin:keyboardLayout="@xml/rows_hindi" /> +</Keyboard> diff --git a/java/res/xml/method.xml b/java/res/xml/method.xml index cdcea0ed0..077574f34 100644 --- a/java/res/xml/method.xml +++ b/java/res/xml/method.xml @@ -38,6 +38,7 @@ fr: French/azerty fr_CA: French Canada/qwerty fr_CH: French Switzerland/qwertz + hi: Hindi/hindi hr: Croatian/qwertz hu: Hungarian/qwertz it: Italian/qwerty @@ -171,6 +172,12 @@ /> <subtype android:icon="@drawable/ic_subtype_keyboard" android:label="@string/subtype_generic" + android:imeSubtypeLocale="hi" + android:imeSubtypeMode="keyboard" + android:imeSubtypeExtraValue="SupportTouchPositionCorrection" + /> + <subtype android:icon="@drawable/ic_subtype_keyboard" + android:label="@string/subtype_generic" android:imeSubtypeLocale="hr" android:imeSubtypeMode="keyboard" android:imeSubtypeExtraValue="AsciiCapable,SupportTouchPositionCorrection" diff --git a/java/res/xml/rowkeys_hindi1.xml b/java/res/xml/rowkeys_hindi1.xml new file mode 100644 index 000000000..4f7a4148c --- /dev/null +++ b/java/res/xml/rowkeys_hindi1.xml @@ -0,0 +1,197 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <switch> + <case + latin:keyboardSetElement="alphabetManualShifted|alphabetShiftLockShifted" + > + <!-- U+0914: "औ" DEVANAGARI LETTER AU + U+0912/U+0902: "ऒं" DEVANAGARI LETTER SHORT O//DEVANAGARI SIGN ANUSVARA + U+0967: "१" DEVANAGARI DIGIT ONE --> + <Key + latin:keyLabel="औ" + latin:moreKeys="ऒं,%" + latin:keyHintLabel="1" + latin:additionalMoreKeys="१,1" /> + <!-- U+0910: "ऐ" DEVANAGARI LETTER AI + U+0910/U+0902: "ऐं" DEVANAGARI LETTER AI/DEVANAGARI SIGN ANUSVARA + U+0968: "२" DEVANAGARI DIGIT TWO --> + <Key + latin:keyLabel="ऐ" + latin:moreKeys="ऐं,%" + latin:keyHintLabel="2" + latin:additionalMoreKeys="२,2" /> + <!-- U+0906: "आ" DEVANAGARI LETTER AA + U+0906/U+0902: "आं" DEVANAGARI LETTER AA/DEVANAGARI SIGN ANUSVARA + U+0906/U+0901: "आँ" DEVANAGARI LETTER AA/DEVANAGARI SIGN CANDRABINDU + U+0969: "३" DEVANAGARI DIGIT THREE --> + <Key + latin:keyLabel="आ" + latin:moreKeys="आं,आँ,%" + latin:keyHintLabel="3" + latin:additionalMoreKeys="३,3" /> + <!-- U+0908: "ई" DEVANAGARI LETTER II + U+0908/U+0902: "ईं" DEVANAGARI LETTER II/DEVANAGARI SIGN ANUSVARA + U+096A: "४" DEVANAGARI DIGIT FOUR --> + <Key + latin:keyLabel="ई" + latin:moreKeys="ईं,%" + latin:keyHintLabel="4" + latin:additionalMoreKeys="४,4" /> + <!-- U+090A: "ऊ" DEVANAGARI LETTER UU + U+090A/U+0902: "ऊं" DEVANAGARI LETTER UU/DEVANAGARI SIGN ANUSVARA + U+090A/U+0901: "ऊँ" DEVANAGARI LETTER UU/DEVANAGARI SIGN CANDRABINDU + U+096B: "५" DEVANAGARI DIGIT FIVE --> + <Key + latin:keyLabel="ऊ" + latin:moreKeys="ऊं,ऊँ,%" + latin:keyHintLabel="5" + latin:additionalMoreKeys="५,5" /> + <!-- U+092D: "भ" DEVANAGARI LETTER BHA + U+096C: "६" DEVANAGARI DIGIT SIX --> + <Key + latin:keyLabel="भ" + latin:keyHintLabel="6" + latin:additionalMoreKeys="६,6" /> + <!-- U+0903: "ः" DEVANAGARI SIGN VISARGA + U+096D: "७" DEVANAGARI DIGIT SEVEN --> + <Key + latin:keyLabel="ः" + latin:keyHintLabel="7" + latin:additionalMoreKeys="७,7" /> + <!-- U+0918: "घ" DEVANAGARI LETTER GHA + U+096E: "८" DEVANAGARI DIGIT EIGHT --> + <Key + latin:keyLabel="घ" + latin:keyHintLabel="8" + latin:additionalMoreKeys="८,8" /> + <!-- U+0927: "ध" DEVANAGARI LETTER DHA + U+0915/U+094D/U+0937: "क्ष" DEVANAGARI LETTER KA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER SSA + U+0936/U+094D/U+0930: "श्र" DEVANAGARI LETTER SHA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + U+096F: "९" DEVANAGARI DIGIT NINE --> + <Key + latin:keyLabel="ध" + latin:moreKeys="क्ष,श्र,%" + latin:keyHintLabel="9" + latin:additionalMoreKeys="9" /> + <!-- U+091D: "झ" DEVANAGARI LETTER JHA + U+0966: "०" DEVANAGARI DIGIT ZERO --> + <Key + latin:keyLabel="झ" + latin:keyHintLabel="0" + latin:additionalMoreKeys="०,0" /> + <!-- U+0922: "ढ" DEVANAGARI LETTER DDHA --> + <Key + latin:keyLabel="ढ" /> + </case> + <default> + <!-- U+094C: "ौ" DEVANAGARI VOWEL SIGN AU + U+094C/U+0902: "ौं" DEVANAGARI VOWEL SIGN AU/DEVANAGARI SIGN ANUSVARA + U+0967: "१" DEVANAGARI DIGIT ONE --> + <Key + latin:keyLabel="ौ" + latin:moreKeys="ौं,%" + latin:keyHintLabel="1" + latin:additionalMoreKeys="१,1" /> + <!-- U+0948: "ै" DEVANAGARI VOWEL SIGN AI + U+0948/U+0902: "ैं" DEVANAGARI VOWEL SIGN AI/DEVANAGARI SIGN ANUSVARA + U+0968: "२" DEVANAGARI DIGIT TWO --> + <Key + latin:keyLabel="ै" + latin:moreKeys="ैं,%" + latin:keyHintLabel="2" + latin:additionalMoreKeys="२,2" /> + <!-- U+093E: "ा" DEVANAGARI VOWEL SIGN AA + U+093E/U+0902: "ां" DEVANAGARI VOWEL SIGN AA/DEVANAGARI SIGN ANUSVARA + U+093E/U+0901: "ाँ" DEVANAGARI VOWEL SIGN AA/DEVANAGARI SIGN CANDRABINDU + U+0969: "३" DEVANAGARI DIGIT THREE --> + <Key + latin:keyLabel="ा" + latin:moreKeys="ां,ाँ,%" + latin:keyHintLabel="3" + latin:additionalMoreKeys="३,3" /> + <!-- U+0940: "ी" DEVANAGARI VOWEL SIGN II + U+0940/U+0902: "ीं" DEVANAGARI VOWEL SIGN II/DEVANAGARI SIGN ANUSVARA + U+096A: "४" DEVANAGARI DIGIT FOUR --> + <Key + latin:keyLabel="ी" + latin:moreKeys="ीं,%" + latin:keyHintLabel="4" + latin:additionalMoreKeys="४,4" /> + <!-- U+0942: "ू" DEVANAGARI VOWEL SIGN UU + U+0942/U+0902: "ूं" DEVANAGARI VOWEL SIGN UU/DEVANAGARI SIGN ANUSVARA + U+0942/U+0901: "ूँ" DEVANAGARI VOWEL SIGN UU/DEVANAGARI SIGN CANDRABINDU + U+096B: "५" DEVANAGARI DIGIT FIVE --> + <Key + latin:keyLabel="ू" + latin:moreKeys="ूं,ूँ,%" + latin:keyHintLabel="5" + latin:additionalMoreKeys="५,5" /> + <!-- U+092C: "ब" DEVANAGARI LETTER BA + U+092C/U+0952: "ब॒" DEVANAGARI LETTER BA/DEVANAGARI STRESS SIGN ANUDATTA --> + <Key + latin:keyLabel="ब" + latin:moreKeys="ब॒,%" + latin:keyHintLabel="6" + latin:additionalMoreKeys="६,6" /> + <!-- U+0939: "ह" DEVANAGARI LETTER HA + U+096D: "७" DEVANAGARI DIGIT SEVEN --> + <Key + latin:keyLabel="ह" + latin:keyHintLabel="7" + latin:additionalMoreKeys="७,7" /> + <!-- U+0917: "ग" DEVANAGARI LETTER GA + U+091C/U+094D/U+091E: "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + U+0917/U+093C: "ग़" DEVANAGARI LETTER GA/DEVANAGARI SIGN NUKTA + U+0917/U+0952: "ग॒" DEVANAGARI LETTER GA/DEVANAGARI STRESS SIGN ANUDATTA + U+096E: "८" DEVANAGARI DIGIT EIGHT --> + <Key + latin:keyLabel="ग" + latin:moreKeys="ज्ञ,ग़,ग॒,%" + latin:keyHintLabel="8" + latin:additionalMoreKeys="८,8" /> + <!-- U+0926: "द" DEVANAGARI LETTER DA + U+096F: "९" DEVANAGARI DIGIT NINE --> + <Key + latin:keyLabel="द" + latin:keyHintLabel="9" + latin:additionalMoreKeys="9" /> + <!-- U+091C: "ज" DEVANAGARI LETTER JA + U+091C/U+0952: "ज॒" DEVANAGARI LETTER JA/DEVANAGARI STRESS SIGN ANUDATTA + U+091C/U+094D/U+091E: "ज्ञ" DEVANAGARI LETTER JA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER NYA + U+091C/U+093C: "ज़" DEVANAGARI LETTER JA/DEVANAGARI SIGN NUKTA + U+0966: "०" DEVANAGARI DIGIT ZERO --> + <Key + latin:keyLabel="ज" + latin:moreKeys="ज॒,ज्ञ,ज़,%" + latin:keyHintLabel="0" + latin:additionalMoreKeys="०,0" /> + <!-- U+0921: "ड" DEVANAGARI LETTER DDA + U+0921/U+0952: "ड॒" DEVANAGARI LETTER DDA/DEVANAGARI STRESS SIGN ANUDATTA + U+0921/U+093C: "ड़" DEVANAGARI LETTER DDA/DEVANAGARI SIGN NUKTA --> + <Key + latin:keyLabel="ड" + latin:moreKeys="ड॒,ड़" /> + </default> + </switch> +</merge> diff --git a/java/res/xml/rowkeys_hindi2.xml b/java/res/xml/rowkeys_hindi2.xml new file mode 100644 index 000000000..1bf6fd4df --- /dev/null +++ b/java/res/xml/rowkeys_hindi2.xml @@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <switch> + <case + latin:keyboardSetElement="alphabetManualShifted|alphabetShiftLockShifted" + > + <!-- U+0913: "ओ" DEVANAGARI LETTER O + U+0913/U+0902: "ओं" DEVANAGARI LETTER O/DEVANAGARI SIGN ANUSVARA + U+0911: "ऑ" DEVANAGARI LETTER CANDRA O + U+0912: "ऒ" DEVANAGARI LETTER SHORT O --> + <Key + latin:keyLabel="ओ" + latin:moreKeys="ओं,ऑ,ऒ" /> + <!-- U+090F: "ए" DEVANAGARI LETTER E + U+090F/U+0902: "एं" DEVANAGARI LETTER E/DEVANAGARI SIGN ANUSVARA + U+090F/U+0901: "एँ" DEVANAGARI LETTER E/DEVANAGARI SIGN CANDRABINDU + U+090D: "ऍ" DEVANAGARI LETTER CANDRA E + U+090E: "ऎ" DEVANAGARI LETTER SHORT E --> + <Key + latin:keyLabel="ए" + latin:moreKeys="एं,एँ,ऍ,ऎ" /> + <!-- U+0905: "अ" DEVANAGARI LETTER A + U+0905/U+0902: "अं" DEVANAGARI LETTER A/DEVANAGARI SIGN ANUSVARA + U+0905/U+0901: "अँ" DEVANAGARI LETTER A/DEVANAGARI SIGN CANDRABINDU --> + <Key + latin:keyLabel="अ" + latin:moreKeys="अं,अँ" /> + <!-- U+0907: "इ" DEVANAGARI LETTER I + U+0907/U+0902: "इं" DEVANAGARI LETTER I/DEVANAGARI SIGN ANUSVARA + U+0907/U+0901: "इं" DEVANAGARI LETTER I/DEVANAGARI SIGN CANDRABINDU --> + <Key + latin:keyLabel="इ" + latin:moreKeys="इं,इँ" /> + <!-- U+0909: "उ" DEVANAGARI LETTER U + U+0909/U+0902: "उं" DEVANAGARI LETTER U/DEVANAGARI SIGN ANUSVARA + U+0909/U+0901: "उँ" DEVANAGARI LETTER U/DEVANAGARI SIGN CANDRABINDU --> + <Key + latin:keyLabel="उ" + latin:moreKeys="उं,उँ" /> + <!-- U+092B: "फ" DEVANAGARI LETTER PHA + U+092B/U+093C: "फ़" DEVANAGARI LETTER PHA/DEVANAGARI SIGN NUKTA --> + <Key + latin:keyLabel="फ" + latin:moreKeys="फ़" /> + <!-- U+0931: "ऱ" DEVANAGARI LETTER RRA + U+094D/U+0930: "्र" DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA + U+0930/U+094D: "र्" DEVANAGARI LETTER RA/DEVANAGARI SIGN VIRAMA --> + <Key + latin:keyLabel="ऱ" + latin:moreKeys="्र,र्" /> + <!-- U+0916: "ख" DEVANAGARI LETTER KHA + U+0916/U+093C: "ख़" DEVANAGARI LETTER KHA/DEVANAGARI SIGN NUKTA --> + <Key + latin:keyLabel="ख" + latin:moreKeys="ख़" /> + <!-- U+0925: "थ" DEVANAGARI LETTER THA --> + <Key + latin:keyLabel="थ" /> + <!-- U+091B: "छ" DEVANAGARI LETTER CHA --> + <Key + latin:keyLabel="छ" /> + <!-- U+0920: "ठ" DEVANAGARI LETTER TTHA --> + <Key + latin:keyLabel="ठ" /> + </case> + <default> + <!-- U+094B: "ो" DEVANAGARI VOWEL SIGN O + U+094B/U+0902: "қं" DEVANAGARI VOWEL SIGN O/DEVANAGARI SIGN ANUSVARA + U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O + U+094A: "ॊ" DEVANAGARI VOWEL SIGN SHORT O --> + <Key + latin:keyLabel="ो" + latin:moreKeys="ों,ॉ,ॊ" /> + <!-- U+0947: "े" DEVANAGARI VOWEL SIGN E + U+0947/U+0902: "ें" DEVANAGARI VOWEL SIGN E/DEVANAGARI SIGN ANUSVARA --> + <Key + latin:keyLabel="े" + latin:moreKeys="ें" /> + <!-- U+094D: "्" DEVANAGARI SIGN VIRAMA --> + <Key + latin:keyLabel="्" /> + <!-- U+093F: "ि" DEVANAGARI VOWEL SIGN I + U+093F/U+0902: "िं" DEVANAGARI VOWEL SIGN I/DEVANAGARI SIGN ANUSVARA --> + <Key + latin:keyLabel="ि" + latin:moreKeys="िं" /> + <!-- U+0941: "ु" DEVANAGARI VOWEL SIGN U + U+0941/U+0902: "ुं" DEVANAGARI VOWEL SIGN U/DEVANAGARI SIGN ANUSVARA + U+0941/U+0901: "ुँ" DEVANAGARI VOWEL SIGN U/DEVANAGARI SIGN CANDRABINDU --> + <Key + latin:keyLabel="ु" + latin:moreKeys="ुं,ुँ" /> + <!-- U+092A: "प" DEVANAGARI LETTER PA --> + <Key + latin:keyLabel="प" /> + <!-- U+0930: "र" DEVANAGARI LETTER RA + U+090B: "ऋ" DEVANAGARI LETTER VOCALIC R + U+0930/U+093C: "ऱ" DEVANAGARI LETTER RA/DEVANAGARI SIGN NUKTA + U+0960: "ॠ" DEVANAGARI LETTER VOCALIC RR --> + <Key + latin:keyLabel="र" + latin:moreKeys="ऋ,ऱ,ॠ" /> + <!-- U+0915: "क" DEVANAGARI LETTER KA + U+0915/U+093C: "क़" DEVANAGARI LETTER KA/DEVANAGARI SIGN NUKTA --> + <Key + latin:keyLabel="क" + latin:moreKeys="क़" /> + <!-- U+0924: "त" DEVANAGARI LETTER TA + U+0924/U+094D/U+0930: "त्र" DEVANAGARI LETTER TA/DEVANAGARI SIGN VIRAMA/DEVANAGARI LETTER RA --> + <Key + latin:keyLabel="त" + latin:moreKeys="त्र" /> + <!-- U+091A: "च" DEVANAGARI LETTER CA --> + <Key + latin:keyLabel="च" /> + <!-- U+091F: "ट" DEVANAGARI LETTER TTA --> + <Key + latin:keyLabel="ट" /> + </default> + </switch> +</merge> diff --git a/java/res/xml/rowkeys_hindi3.xml b/java/res/xml/rowkeys_hindi3.xml new file mode 100644 index 000000000..e6b430f1b --- /dev/null +++ b/java/res/xml/rowkeys_hindi3.xml @@ -0,0 +1,113 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <switch> + <case + latin:keyboardSetElement="alphabetManualShifted|alphabetShiftLockShifted" + > + <!-- U+0911: "ऑ" DEVANAGARI LETTER CANDRA O --> + <Key + latin:keyLabel="ऑ" /> + <!-- U+090E: "ऎ" DEVANAGARI LETTER SHORT E --> + <Key + latin:keyLabel="ऎ" /> + <!-- U+0901: "ँ" DEVANAGARI SIGN CANDRABINDU + U+0945: "ॅ" DEVANAGARI VOWEL SIGN CANDRA E--> + <Key + latin:keyLabel="ँ" + latin:moreKeys="ॅ" /> + <!-- U+0923: "ण" DEVANAGARI LETTER NNA --> + <Key + latin:keyLabel="ण" /> + <!-- U+0929: "ऩ" DEVANAGARI LETTER NNNA --> + <Key + latin:keyLabel="ऩ" /> + <!-- U+0933: "ळ" DEVANAGARI LETTER LLA + U+0934: "ऴ" DEVANAGARI LETTER LLLA --> + <Key + latin:keyLabel="ळ" + latin:moreKeys="ऴ" /> + <!-- U+0936: "श" DEVANAGARI LETTER SHA --> + <Key + latin:keyLabel="श" /> + <!-- U+0937: "ष" DEVANAGARI LETTER SSA --> + <Key + latin:keyLabel="ष" /> + <!-- U+0943: "ृ" DEVANAGARI VOWEL SIGN VOCALIC R + U+0944: "ॄ" DEVANAGARI VOWEL SIGN VOCALIC RR --> + <Key + latin:keyLabel="ृ" + latin:moreKeys="ॄ" /> + <!-- U+091E: "ञ" DEVANAGARI LETTER NYA --> + <Key + latin:keyLabel="ञ" /> + </case> + <default> + <!-- U+0949: "ॉ" DEVANAGARI VOWEL SIGN CANDRA O --> + <Key + latin:keyLabel="ॉ" /> + <!-- U+0946: "ॆ" DEVANAGARI VOWEL SIGN SHORT E --> + <Key + latin:keyLabel="ॆ" /> + <!-- U+0902: "ं" DEVANAGARI SIGN ANUSVARA --> + <Key + latin:keyLabel="ं" /> + <!-- U+092E: "म" DEVANAGARI LETTER MA + U+0950: "ॐ" DEVANAGARI OM --> + <Key + latin:keyLabel="म" + latin:moreKeys="ॐ" /> + <!-- U+0928: "न" DEVANAGARI LETTER NA + U+091E: "ञ" DEVANAGARI LETTER NYA + U+0919: "ङ" DEVANAGARI LETTER NGA + U+0928/U+093C: "ऩ" DEVANAGARI LETTER NA/DEVANAGARI SIGN NUKTA --> + <Key + latin:keyLabel="न" + latin:moreKeys="ञ,ङ,ऩ" /> + <!-- U+0935: "व" DEVANAGARI LETTER VA --> + <Key + latin:keyLabel="व" /> + <!-- U+0932: "ल" DEVANAGARI LETTER LA + U+090C: "ऌ" DEVANAGARI LETTER VOCALIC L + U+0961: "ॡ" DEVANAGARI LETTER VOCALIC LL --> + <Key + latin:keyLabel="ल" + latin:moreKeys="ऌ,ॡ" /> + <!-- U+0938: "स" DEVANAGARI LETTER SA --> + <Key + latin:keyLabel="स" /> + <!-- U+092F: "य" DEVANAGARI LETTER YA + U+095F: "य़" DEVANAGARI LETTER YYA --> + <Key + latin:keyLabel="य" + latin:moreKeys="य़" /> + <!-- U+093C: "़" DEVANAGARI SIGN NUKTA + U+097D: "ॽ" DEVANAGARI LETTER GLOTTAL STOP + U+0970: "॰" DEVANAGARI ABBREVIATION SIGN + U+093D: "ऽ" DEVANAGARI SIGN AVAGRAHA --> + <Key + latin:keyLabel="़" + latin:moreKeys="ॽ,॰,ऽ" /> + </default> + </switch> +</merge> diff --git a/java/res/xml/rows_hindi.xml b/java/res/xml/rows_hindi.xml new file mode 100644 index 000000000..42d89b546 --- /dev/null +++ b/java/res/xml/rows_hindi.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/* +** +** Copyright 2012, The Android Open Source Project +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ +--> + +<merge + xmlns:latin="http://schemas.android.com/apk/res/com.android.inputmethod.latin" +> + <include + latin:keyboardLayout="@xml/key_styles_common" /> + <Row + latin:keyWidth="9.091%p" + > + <include + latin:keyboardLayout="@xml/rowkeys_hindi1" /> + </Row> + <Row + latin:keyWidth="9.091%p" + > + <include + latin:keyboardLayout="@xml/rowkeys_hindi2" /> + </Row> + <Row + latin:keyWidth="7.65%p" + > + <Key + latin:keyStyle="shiftKeyStyle" + latin:keyWidth="11.75%p" /> + <include + latin:keyboardLayout="@xml/rowkeys_hindi3" /> + <Key + latin:keyStyle="deleteKeyStyle" + latin:keyWidth="fillRight" /> + </Row> + <include + latin:keyboardLayout="@xml/row_qwerty4" /> +</merge> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 7c08377be..234a501de 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -204,7 +204,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private UserDictionary mUserDictionary; private UserBigramDictionary mUserBigramDictionary; - private UserUnigramDictionary mUserUnigramDictionary; private boolean mIsUserDictionaryAvailable; private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; @@ -528,12 +527,10 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar resetContactsDictionary(oldContactsDictionary); - mUserUnigramDictionary - = new UserUnigramDictionary(this, this, localeStr, Suggest.DIC_USER_UNIGRAM); - mSuggest.setUserUnigramDictionary(mUserUnigramDictionary); - + // TODO: rename UserBigramDictionary into UserHistoryDictionary mUserBigramDictionary = new UserBigramDictionary(this, this, localeStr, Suggest.DIC_USER_BIGRAM); + mSuggest.setUserUnigramDictionary(mUserBigramDictionary); mSuggest.setUserBigramDictionary(mUserBigramDictionary); LocaleUtils.setSystemLocale(res, savedLocale); @@ -776,7 +773,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.closing(); - if (mUserUnigramDictionary != null) mUserUnigramDictionary.flushPendingWrites(); if (mUserBigramDictionary != null) mUserBigramDictionary.flushPendingWrites(); } @@ -2009,11 +2005,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar return; } - if (null != mUserUnigramDictionary) { - mUserUnigramDictionary.addUnigram(suggestion.toString()); - } - if (mUserBigramDictionary != null) { + mUserBigramDictionary.addUnigram(suggestion.toString()); final InputConnection ic = getCurrentInputConnection(); if (null != ic) { final CharSequence prevWord = diff --git a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java index 52a31f2e6..42d3a70cd 100644 --- a/java/src/com/android/inputmethod/latin/UserBigramDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserBigramDictionary.java @@ -24,6 +24,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.database.sqlite.SQLiteQueryBuilder; import android.os.AsyncTask; import android.provider.BaseColumns; +import android.text.TextUtils; import android.util.Log; import java.util.HashMap; @@ -155,19 +156,49 @@ public class UserBigramDictionary extends ExpandableDictionary { } /** - * Pair will be added to the userbigram database. + * Return whether the passed charsequence is in the dictionary. */ - public int addBigramPair(String word1, String word2) { + @Override + public boolean isValidWord(final CharSequence word) { + // TODO: figure out what is the correct thing to do here. + return false; + } + + /** + * Add a single word without context. + * + * This is a temporary method to match the interface to UserUnigramDictionary. In the end + * this should be merged with addBigramPair. + */ + public void addUnigram(final String newWord) { + addBigramPair(null, newWord); + } + + /** + * Pair will be added to the user history dictionary. + * + * The first word may be null. That means we don't know the context, in other words, + * it's only a unigram. The first word may also be an empty string : this means start + * context, as in beginning of a sentence for example. + * The second word may not be null (a NullPointerException would be thrown). + */ + public int addBigramPair(final String word1, String word2) { // remove caps if second word is autocapitalized if (mIme != null && mIme.isAutoCapitalized()) { word2 = Character.toLowerCase(word2.charAt(0)) + word2.substring(1); } // Do not insert a word as a bigram of itself - if (word1.equals(word2)) { + if (word2.equals(word1)) { return 0; } - int freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED); + int freq; + if (null == word1) { + freq = FREQUENCY_FOR_TYPED; + super.addWord(word2, FREQUENCY_FOR_TYPED); + } else { + freq = super.addBigram(word1, word2, FREQUENCY_FOR_TYPED); + } if (freq > FREQUENCY_MAX) freq = FREQUENCY_MAX; synchronized (mPendingWritesLock) { if (freq == FREQUENCY_FOR_TYPED || mPendingWrites.isEmpty()) { @@ -225,7 +256,10 @@ public class UserBigramDictionary extends ExpandableDictionary { int frequency = cursor.getInt(frequencyIndex); // Safeguard against adding really long words. Stack may overflow due // to recursive lookup - if (word1.length() < MAX_WORD_LENGTH && word2.length() < MAX_WORD_LENGTH) { + if (null == word1) { + super.addWord(word2, frequency); + } else if (word1.length() < MAX_WORD_LENGTH + && word2.length() < MAX_WORD_LENGTH) { super.setBigram(word1, word2, frequency); } cursor.moveToNext(); @@ -367,13 +401,23 @@ public class UserBigramDictionary extends ExpandableDictionary { // Write all the entries to the db Iterator<Bigram> iterator = mMap.iterator(); while (iterator.hasNext()) { + // TODO: this process of making a text search for each pair each time + // is terribly inefficient. Optimize this. Bigram bi = iterator.next(); // find pair id - Cursor c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, - MAIN_COLUMN_WORD1 + "=? AND " + MAIN_COLUMN_WORD2 + "=? AND " - + MAIN_COLUMN_LOCALE + "=?", - new String[] { bi.mWord1, bi.mWord2, mLocale }, null, null, null); + final Cursor c; + if (null != bi.mWord1) { + c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, + MAIN_COLUMN_WORD1 + "=? AND " + MAIN_COLUMN_WORD2 + "=? AND " + + MAIN_COLUMN_LOCALE + "=?", + new String[] { bi.mWord1, bi.mWord2, mLocale }, null, null, null); + } else { + c = db.query(MAIN_TABLE_NAME, new String[] { MAIN_COLUMN_ID }, + MAIN_COLUMN_WORD1 + " IS NULL AND " + MAIN_COLUMN_WORD2 + "=? AND " + + MAIN_COLUMN_LOCALE + "=?", + new String[] { bi.mWord2, mLocale }, null, null, null); + } int pairId; if (c.moveToFirst()) { diff --git a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java b/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java deleted file mode 100644 index 2fc395c3e..000000000 --- a/java/src/com/android/inputmethod/latin/UserUnigramDictionary.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package com.android.inputmethod.latin; - -import android.content.ContentValues; -import android.content.Context; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; -import android.database.sqlite.SQLiteOpenHelper; -import android.database.sqlite.SQLiteQueryBuilder; -import android.os.AsyncTask; -import android.provider.BaseColumns; -import android.util.Log; - -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Set; - -/** - * This class (inherited from the old AutoDictionary) is used for user history - * based dictionary. It stores words that the user typed to supply a provision - * for suggesting and re-ordering of candidates. - */ -public class UserUnigramDictionary extends ExpandableDictionary { - static final boolean ENABLE_USER_UNIGRAM_DICTIONARY = false; - - // Weight added to a user picking a new word from the suggestion strip - static final int FREQUENCY_FOR_PICKED = 3; - // Weight added to a user typing a new word that doesn't get corrected (or is reverted) - static final int FREQUENCY_FOR_TYPED = 1; - // If the user touches a typed word 2 times or more, it will become valid. - private static final int VALIDITY_THRESHOLD = 2 * FREQUENCY_FOR_PICKED; - - private LatinIME mIme; - // Locale for which this user unigram dictionary is storing words - private String mLocale; - - private HashMap<String,Integer> mPendingWrites = new HashMap<String,Integer>(); - private final Object mPendingWritesLock = new Object(); - - // TODO: we should probably change the database name - private static final String DATABASE_NAME = "auto_dict.db"; - private static final int DATABASE_VERSION = 1; - - // These are the columns in the dictionary - // TODO: Consume less space by using a unique id for locale instead of the whole - // 2-5 character string. - private static final String COLUMN_ID = BaseColumns._ID; - private static final String COLUMN_WORD = "word"; - private static final String COLUMN_FREQUENCY = "freq"; - private static final String COLUMN_LOCALE = "locale"; - - /** Sort by descending order of frequency. */ - public static final String DEFAULT_SORT_ORDER = COLUMN_FREQUENCY + " DESC"; - - /** Name of the words table in the database */ - private static final String USER_UNIGRAM_DICT_TABLE_NAME = "words"; - - private static HashMap<String, String> sDictProjectionMap; - - static { - if (ENABLE_USER_UNIGRAM_DICTIONARY) { - sDictProjectionMap = new HashMap<String, String>(); - sDictProjectionMap.put(COLUMN_ID, COLUMN_ID); - sDictProjectionMap.put(COLUMN_WORD, COLUMN_WORD); - sDictProjectionMap.put(COLUMN_FREQUENCY, COLUMN_FREQUENCY); - sDictProjectionMap.put(COLUMN_LOCALE, COLUMN_LOCALE); - } - } - - private static DatabaseHelper sOpenHelper = null; - - public UserUnigramDictionary(Context context, LatinIME ime, String locale, int dicTypeId) { - super(context, dicTypeId); - // Super must be first statement of the constructor... I'd like not to do it if the - // user unigram dictionary is not enabled, but Java won't let me. - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return; - mIme = ime; - mLocale = locale; - if (sOpenHelper == null) { - sOpenHelper = new DatabaseHelper(getContext()); - } - if (mLocale != null && mLocale.length() > 1) { - loadDictionary(); - } - } - - @Override - public synchronized boolean isValidWord(CharSequence word) { - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return false; - final int frequency = getWordFrequency(word); - return frequency >= VALIDITY_THRESHOLD; - } - - @Override - public void close() { - super.close(); - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return; - flushPendingWrites(); - // Don't close the database as locale changes will require it to be reopened anyway - // Also, the database is written to somewhat frequently, so it needs to be kept alive - // throughout the life of the process. - // mOpenHelper.close(); - } - - @Override - public void loadDictionaryAsync() { - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return; - // Load the words that correspond to the current input locale - final Cursor cursor = query(COLUMN_LOCALE + "=?", new String[] { mLocale }); - if (null == cursor) return; - try { - if (cursor.moveToFirst()) { - int wordIndex = cursor.getColumnIndex(COLUMN_WORD); - int frequencyIndex = cursor.getColumnIndex(COLUMN_FREQUENCY); - while (!cursor.isAfterLast()) { - String word = cursor.getString(wordIndex); - int frequency = cursor.getInt(frequencyIndex); - // Safeguard against adding really long words. Stack may overflow due - // to recursive lookup - if (word.length() < getMaxWordLength()) { - super.addWord(word, frequency); - } - cursor.moveToNext(); - } - } - } finally { - cursor.close(); - } - } - - public void addUnigram(String newWord) { - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return; - final int addFrequency = FREQUENCY_FOR_TYPED; - String word = newWord; - final int length = word.length(); - // Don't add very short or very long words. - if (length < 2 || length > getMaxWordLength()) return; - if (mIme.isAutoCapitalized()) { - // Remove caps before adding - word = Character.toLowerCase(word.charAt(0)) + word.substring(1); - } - int freq = getWordFrequency(word); - freq = freq < 0 ? addFrequency : freq + addFrequency; - super.addWord(word, freq); - - synchronized (mPendingWritesLock) { - // Write a null frequency if it is to be deleted from the db - mPendingWrites.put(word, freq == 0 ? null : new Integer(freq)); - } - } - - /** - * Schedules a background thread to write any pending words to the database. - */ - public void flushPendingWrites() { - if (!ENABLE_USER_UNIGRAM_DICTIONARY) return; - synchronized (mPendingWritesLock) { - // Nothing pending? Return - if (mPendingWrites.isEmpty()) return; - // Create a background thread to write the pending entries - new UpdateDbTask(sOpenHelper, mPendingWrites, mLocale).execute(); - // Create a new map for writing new entries into while the old one is written to db - mPendingWrites = new HashMap<String, Integer>(); - } - } - - /** - * This class helps open, create, and upgrade the database file. - */ - private static class DatabaseHelper extends SQLiteOpenHelper { - - DatabaseHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - } - - @Override - public void onCreate(SQLiteDatabase db) { - db.execSQL("CREATE TABLE " + USER_UNIGRAM_DICT_TABLE_NAME + " (" - + COLUMN_ID + " INTEGER PRIMARY KEY," - + COLUMN_WORD + " TEXT," - + COLUMN_FREQUENCY + " INTEGER," - + COLUMN_LOCALE + " TEXT" - + ");"); - } - - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - Log.w("UserUnigramDictionary", "Upgrading database from version " + oldVersion + " to " - + newVersion + ", which will destroy all old data"); - db.execSQL("DROP TABLE IF EXISTS " + USER_UNIGRAM_DICT_TABLE_NAME); - onCreate(db); - } - } - - private static Cursor query(String selection, String[] selectionArgs) { - SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); - qb.setTables(USER_UNIGRAM_DICT_TABLE_NAME); - qb.setProjectionMap(sDictProjectionMap); - - // Get the database and run the query - try { - SQLiteDatabase db = sOpenHelper.getReadableDatabase(); - Cursor c = qb.query(db, null, selection, selectionArgs, null, null, - DEFAULT_SORT_ORDER); - return c; - } catch (android.database.sqlite.SQLiteCantOpenDatabaseException e) { - // Can't open the database : presumably we can't access storage. That may happen - // when the device is wedged; do a best effort to still start the keyboard. - return null; - } - } - - /** - * Async task to write pending words to the database so that it stays in sync with - * the in-memory trie. - */ - private static class UpdateDbTask extends AsyncTask<Void, Void, Void> { - private final HashMap<String, Integer> mMap; - private final DatabaseHelper mDbHelper; - private final String mLocale; - - public UpdateDbTask(DatabaseHelper openHelper, HashMap<String, Integer> pendingWrites, - String locale) { - mMap = pendingWrites; - mLocale = locale; - mDbHelper = openHelper; - } - - @Override - protected Void doInBackground(Void... v) { - SQLiteDatabase db = null; - try { - db = mDbHelper.getWritableDatabase(); - } catch (android.database.sqlite.SQLiteCantOpenDatabaseException e) { - // With no access to the DB, this is moot. Do nothing: we'll exit through the - // test for null == db. - } - if (null == db) return null; - // Write all the entries to the db - Set<Entry<String,Integer>> mEntries = mMap.entrySet(); - for (Entry<String,Integer> entry : mEntries) { - Integer freq = entry.getValue(); - db.delete(USER_UNIGRAM_DICT_TABLE_NAME, COLUMN_WORD + "=? AND " + COLUMN_LOCALE - + "=?", new String[] { entry.getKey(), mLocale }); - if (freq != null) { - db.insert(USER_UNIGRAM_DICT_TABLE_NAME, null, - getContentValues(entry.getKey(), freq, mLocale)); - } - } - return null; - } - - private static ContentValues getContentValues(String word, int frequency, String locale) { - ContentValues values = new ContentValues(4); - values.put(COLUMN_WORD, word); - values.put(COLUMN_FREQUENCY, frequency); - values.put(COLUMN_LOCALE, locale); - return values; - } - } -} |