aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
Diffstat (limited to 'java')
-rwxr-xr-xjava/res/xml-iw/kbd_qwerty.xml164
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java39
2 files changed, 197 insertions, 6 deletions
diff --git a/java/res/xml-iw/kbd_qwerty.xml b/java/res/xml-iw/kbd_qwerty.xml
new file mode 100755
index 000000000..3cec7cda4
--- /dev/null
+++ b/java/res/xml-iw/kbd_qwerty.xml
@@ -0,0 +1,164 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+**
+** Copyright 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.
+*/
+-->
+
+<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:keyLabel="ק"
+ android:horizontalGap="5%p"
+ android:keyEdgeFlags="left"/>
+ <Key android:keyLabel="ר"/>
+ <Key android:keyLabel="א"/>
+ <Key android:keyLabel="ט"/>
+ <Key android:keyLabel="ו"/>
+ <Key android:keyLabel="ן"/>
+ <Key android:keyLabel="ם"/>
+ <Key android:keyLabel="פ"/>
+ <Key android:codes="-5"
+ android:horizontalGap="1.25%p"
+ android:keyIcon="@drawable/sym_keyboard_delete"
+ android:keyWidth="13.75%p" android:keyEdgeFlags="right"
+ android:iconPreview="@drawable/sym_keyboard_feedback_delete"
+ android:isRepeatable="true"/>
+ </Row>
+
+ <Row>
+ <Key android:keyLabel="ש" android:keyEdgeFlags="left"/>
+ <Key android:keyLabel="ד"/>
+ <Key android:keyLabel="ג"/>
+ <Key android:keyLabel="כ"/>
+ <Key android:keyLabel="ע"/>
+ <Key android:keyLabel="י"/>
+ <Key android:keyLabel="ח"/>
+ <Key android:keyLabel="ל"/>
+ <Key android:keyLabel="ך"/>
+ <Key android:keyLabel="ף" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row>
+ <Key android:keyLabel="ז" android:horizontalGap="5%p" android:keyEdgeFlags="left"/>
+ <Key android:keyLabel="ס"/>
+ <Key android:keyLabel="ב"/>
+ <Key android:keyLabel="ה"/>
+ <Key android:keyLabel="נ"/>
+ <Key android:keyLabel="מ"/>
+ <Key android:keyLabel="צ"/>
+ <Key android:keyLabel="ת"/>
+ <Key android:keyLabel="ץ" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row android:keyboardMode="@+id/mode_normal" android:rowEdgeFlags="bottom">
+ <Key android:codes="-2" android:keyLabel="@string/label_symbol_key"
+ android:popupKeyboard="@xml/kbd_popup_template"
+ android:popupCharacters="_"
+ android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ <Key android:codes="@integer/key_f1" android:keyIcon="@drawable/sym_keyboard_globe"
+ android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:iconPreview="@drawable/sym_keyboard_feedback_space"
+ android:keyWidth="40%p" android:isRepeatable="true"/>
+ <Key android:codes="46" android:keyLabel="." android:popupKeyboard="@xml/popup_punctuation"
+ android:keyWidth="10%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:iconPreview="@drawable/sym_keyboard_feedback_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row android:keyboardMode="@+id/mode_url" android:rowEdgeFlags="bottom">
+ <Key android:codes="-2" android:keyLabel="@string/label_symbol_key"
+ android:popupKeyboard="@xml/kbd_popup_template"
+ android:popupCharacters="_"
+ android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ <Key android:keyLabel="/" android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:iconPreview="@drawable/sym_keyboard_feedback_space"
+ android:keyWidth="20%p" android:isRepeatable="true"/>
+ <Key android:keyLabel="@string/popular_domain_0"
+ android:keyOutputText="@string/popular_domain_0"
+ android:popupKeyboard="@xml/popup_domains"
+ android:keyWidth="20%p"/>
+ <Key android:keyLabel="." android:popupKeyboard="@xml/popup_punctuation"
+ android:keyWidth="10%p"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:iconPreview="@drawable/sym_keyboard_feedback_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row android:keyboardMode="@+id/mode_email" android:rowEdgeFlags="bottom">
+ <Key android:codes="-2" android:keyLabel="@string/label_symbol_key"
+ android:popupKeyboard="@xml/kbd_popup_template"
+ android:popupCharacters="_"
+ android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ <Key android:keyLabel="\@" android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:iconPreview="@drawable/sym_keyboard_feedback_space"
+ android:keyWidth="20%p" android:isRepeatable="true"/>
+ <Key android:keyLabel="@string/popular_domain_0"
+ android:keyOutputText="@string/popular_domain_0"
+ android:popupKeyboard="@xml/popup_domains"
+ android:keyWidth="20%p"/>
+ <Key android:keyLabel="." android:popupKeyboard="@xml/popup_punctuation"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:iconPreview="@drawable/sym_keyboard_feedback_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row android:keyboardMode="@+id/mode_im" android:rowEdgeFlags="bottom">
+ <Key android:codes="-2" android:keyLabel="@string/label_symbol_key"
+ android:popupKeyboard="@xml/kbd_popup_template"
+ android:popupCharacters="_"
+ android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ <Key android:codes="@integer/key_f1" android:keyIcon="@drawable/sym_keyboard_globe"
+ android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:iconPreview="@drawable/sym_keyboard_feedback_space"
+ android:keyWidth="40%p" android:isRepeatable="true"/>
+ <Key android:codes="46" android:keyLabel="." android:popupKeyboard="@xml/popup_punctuation"
+ android:keyWidth="10%p"/>
+ <Key android:keyLabel=":-)" android:keyOutputText=":-) "
+ android:popupKeyboard="@xml/popup_smileys"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+
+ <Row android:keyboardMode="@+id/mode_webentry" android:rowEdgeFlags="bottom">
+ <Key android:codes="-2" android:keyLabel="@string/label_symbol_key"
+ android:popupKeyboard="@xml/kbd_popup_template"
+ android:popupCharacters="_"
+ android:keyWidth="20%p" android:keyEdgeFlags="left"/>
+ <Key android:codes="@integer/key_f1" android:keyIcon="@drawable/sym_keyboard_globe"
+ android:keyWidth="10%p"/>
+ <Key android:codes="32" android:keyIcon="@drawable/sym_keyboard_space"
+ android:iconPreview="@drawable/sym_keyboard_feedback_space"
+ android:keyWidth="20%p" android:isRepeatable="true"/>
+ <Key android:codes="9" android:keyIcon="@drawable/sym_keyboard_tab"
+ android:iconPreview="@drawable/sym_keyboard_feedback_tab"
+ android:keyWidth="20%p"/>
+ <Key android:keyLabel="." android:popupKeyboard="@xml/popup_punctuation"/>
+ <Key android:codes="10" android:keyIcon="@drawable/sym_keyboard_return"
+ android:iconPreview="@drawable/sym_keyboard_feedback_return"
+ android:keyWidth="20%p" android:keyEdgeFlags="right"/>
+ </Row>
+</Keyboard>
+
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 87de94b76..4901b210b 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -16,6 +16,11 @@
package com.android.inputmethod.latin;
+import java.io.InputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.Channels;
import java.util.Arrays;
import android.content.Context;
@@ -27,6 +32,7 @@ import android.util.Log;
*/
public class BinaryDictionary extends Dictionary {
+ private static final String TAG = "BinaryDictionary";
public static final int MAX_WORD_LENGTH = 48;
private static final int MAX_ALTERNATIVES = 16;
private static final int MAX_WORDS = 16;
@@ -35,10 +41,13 @@ public class BinaryDictionary extends Dictionary {
private static final boolean ENABLE_MISSED_CHARACTERS = true;
private int mNativeDict;
- private int mDictLength; // This value is set from native code, don't change the name!!!!
+ private int mDictLength;
private int[] mInputCodes = new int[MAX_WORD_LENGTH * MAX_ALTERNATIVES];
private char[] mOutputChars = new char[MAX_WORD_LENGTH * MAX_WORDS];
private int[] mFrequencies = new int[MAX_WORDS];
+ // Keep a reference to the native dict direct buffer in Java to avoid
+ // unexpected deallocation of the direct buffer.
+ private ByteBuffer mNativeDictDirectBuffer;
static {
try {
@@ -59,8 +68,7 @@ public class BinaryDictionary extends Dictionary {
}
}
- private native int openNative(AssetManager am, String resourcePath, int typedLetterMultiplier,
- int fullWordMultiplier);
+ private native int openNative(ByteBuffer bb, int typedLetterMultiplier, int fullWordMultiplier);
private native void closeNative(int dict);
private native boolean isValidWordNative(int nativeData, char[] word, int wordLength);
private native int getSuggestionsNative(int dict, int[] inputCodes, int codesSize,
@@ -69,9 +77,28 @@ public class BinaryDictionary extends Dictionary {
int[] nextLettersFrequencies, int nextLettersSize);
private final void loadDictionary(Context context, int resId) {
- AssetManager am = context.getResources().getAssets();
- String assetName = context.getResources().getString(resId);
- mNativeDict = openNative(am, assetName, TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER);
+ InputStream is = context.getResources().openRawResource(resId);
+ try {
+ int avail = is.available();
+ mNativeDictDirectBuffer =
+ ByteBuffer.allocateDirect(avail).order(ByteOrder.nativeOrder());
+ int got = Channels.newChannel(is).read(mNativeDictDirectBuffer);
+ if (got != avail) {
+ Log.e(TAG, "Read " + got + " bytes, expected " + avail);
+ } else {
+ mNativeDict = openNative(mNativeDictDirectBuffer,
+ TYPED_LETTER_MULTIPLIER, FULL_WORD_FREQ_MULTIPLIER);
+ mDictLength = avail;
+ }
+ } catch (IOException e) {
+ Log.w(TAG, "No available size for binary dictionary");
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ Log.w(TAG, "Failed to close input stream");
+ }
+ }
}
@Override