diff options
Diffstat (limited to 'java')
29 files changed, 180 insertions, 122 deletions
diff --git a/java/res/drawable/btn_keyboard_key_ics.xml b/java/res/drawable/btn_keyboard_key_ics.xml index 0bb098d23..bacd5d78f 100644 --- a/java/res/drawable/btn_keyboard_key_ics.xml +++ b/java/res/drawable/btn_keyboard_key_ics.xml @@ -32,6 +32,8 @@ android:drawable="@drawable/btn_keyboard_key_normal_off_holo_dark" /> <!-- Empty background keys. --> + <item android:state_empty="true" android:state_pressed="true" + android:drawable="@drawable/btn_keyboard_key_pressed_ics_light" /> <item android:state_empty="true" android:drawable="@android:color/transparent" /> diff --git a/java/res/drawable/btn_keyboard_key_klp.xml b/java/res/drawable/btn_keyboard_key_klp.xml index 2a202a179..e2f208585 100644 --- a/java/res/drawable/btn_keyboard_key_klp.xml +++ b/java/res/drawable/btn_keyboard_key_klp.xml @@ -32,6 +32,8 @@ android:drawable="@drawable/btn_keyboard_key_normal_off_holo_dark" /> <!-- Empty background keys. --> + <item android:state_empty="true" android:state_pressed="true" + android:drawable="@drawable/btn_keyboard_key_pressed_klp_light" /> <item android:state_empty="true" android:drawable="@android:color/transparent" /> diff --git a/java/res/drawable/btn_keyboard_key_lxx_dark.xml b/java/res/drawable/btn_keyboard_key_lxx_dark.xml index bb1789ae3..161592d3d 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_dark.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_dark.xml @@ -32,8 +32,10 @@ android:drawable="@drawable/btn_keyboard_key_normal_off_lxx_dark" /> <!-- Empty background keys. --> + <item android:state_empty="true" android:state_pressed="true" + android:drawable="@color/key_background_pressed_lxx_dark" /> <item android:state_empty="true" - android:drawable="@color/key_background_lxx_dark" /> + android:drawable="@android:color/transparent" /> <!-- Normal keys. --> <item android:state_pressed="true" diff --git a/java/res/drawable/btn_keyboard_key_lxx_light.xml b/java/res/drawable/btn_keyboard_key_lxx_light.xml index 60fe02dd2..0154d75b4 100644 --- a/java/res/drawable/btn_keyboard_key_lxx_light.xml +++ b/java/res/drawable/btn_keyboard_key_lxx_light.xml @@ -32,8 +32,10 @@ android:drawable="@drawable/btn_keyboard_key_normal_off_lxx_light" /> <!-- Empty background keys. --> + <item android:state_empty="true" android:state_pressed="true" + android:drawable="@color/key_background_pressed_lxx_light" /> <item android:state_empty="true" - android:drawable="@color/key_background_lxx_light" /> + android:drawable="@android:color/transparent" /> <!-- Normal keys. --> <item android:state_pressed="true" diff --git a/java/res/values-eu-rES/strings-emoji-descriptions.xml b/java/res/values-eu-rES/strings-emoji-descriptions.xml index 2faec968a..c774ae1b8 100644 --- a/java/res/values-eu-rES/strings-emoji-descriptions.xml +++ b/java/res/values-eu-rES/strings-emoji-descriptions.xml @@ -846,6 +846,6 @@ <string name="spoken_emoji_1F6C1" msgid="2845056048320031158">"Bainuontzia"</string> <string name="spoken_emoji_1F6C2" msgid="8117262514698011877">"Pasaporte-kontrola"</string> <string name="spoken_emoji_1F6C3" msgid="1176342001834630675">"Aduana"</string> - <string name="spoken_emoji_1F6C4" msgid="1477622834179978886">"Maleta-erreklamazioa"</string> + <string name="spoken_emoji_1F6C4" msgid="1477622834179978886">"Ekipaje-erreklamazioa"</string> <string name="spoken_emoji_1F6C5" msgid="2495834050856617451">"Ahaztutako maletak"</string> </resources> diff --git a/java/res/values-km-rKH/strings-emoji-descriptions.xml b/java/res/values-km-rKH/strings-emoji-descriptions.xml index 757df50e7..e9b8780a5 100644 --- a/java/res/values-km-rKH/strings-emoji-descriptions.xml +++ b/java/res/values-km-rKH/strings-emoji-descriptions.xml @@ -267,7 +267,7 @@ <string name="spoken_emoji_1F36A" msgid="2726271795913042295">"ខូគី"</string> <string name="spoken_emoji_1F36B" msgid="6342163604299875931">"សូកូឡា"</string> <string name="spoken_emoji_1F36C" msgid="2168934753998218790">"ស្ករគ្រាប់"</string> - <string name="spoken_emoji_1F36D" msgid="3671507903799975792">"ស្ករគ្រាប់មានដងកាន់"</string> + <string name="spoken_emoji_1F36D" msgid="3671507903799975792">"Lollipop"</string> <string name="spoken_emoji_1F36E" msgid="4630541402785165902">"សង់ខ្យា"</string> <string name="spoken_emoji_1F36F" msgid="5577915387425169439">"ថូ"</string> <string name="spoken_emoji_1F370" msgid="7243244547866114951">"នំខេក"</string> diff --git a/java/res/values-pt/strings.xml b/java/res/values-pt/strings.xml index 2e0cd3b55..2cc86e12f 100644 --- a/java/res/values-pt/strings.xml +++ b/java/res/values-pt/strings.xml @@ -102,8 +102,7 @@ <string name="subtype_with_layout_hi_ZZ" msgid="6827402953860547044">"Híndi-inglês (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string> <string name="subtype_with_layout_sr_ZZ" msgid="2859024772719772407">"Sérvio (<xliff:g id="KEYBOARD_LAYOUT">%s</xliff:g>)"</string> <string name="subtype_generic_traditional" msgid="8584594350973800586">"<xliff:g id="LANGUAGE_NAME">%s</xliff:g> (tradicional)"</string> - <!-- no translation found for subtype_generic_compact (3353673321203202922) --> - <skip /> + <string name="subtype_generic_compact" msgid="3353673321203202922">"<xliff:g id="LANGUAGE_NAME">%s</xliff:g> (compacto)"</string> <string name="subtype_no_language" msgid="7137390094240139495">"Nenhum idioma (alfabeto)"</string> <string name="subtype_no_language_qwerty" msgid="244337630616742604">"Alfabeto (QWERTY)"</string> <string name="subtype_no_language_qwertz" msgid="443066912507547976">"Alfabeto (QWERTZ)"</string> diff --git a/java/res/xml/kbd_emoji_category1.xml b/java/res/xml/kbd_emoji_category1.xml index 2770cfb15..5145ea9d3 100644 --- a/java/res/xml/kbd_emoji_category1.xml +++ b/java/res/xml/kbd_emoji_category1.xml @@ -27,5 +27,5 @@ <GridRows latin:codesArray="@array/emoji_faces" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_category2.xml b/java/res/xml/kbd_emoji_category2.xml index d547056e1..ac8784f4b 100644 --- a/java/res/xml/kbd_emoji_category2.xml +++ b/java/res/xml/kbd_emoji_category2.xml @@ -27,5 +27,5 @@ <GridRows latin:codesArray="@array/emoji_objects" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_category3.xml b/java/res/xml/kbd_emoji_category3.xml index 2172d9880..88c4db92b 100644 --- a/java/res/xml/kbd_emoji_category3.xml +++ b/java/res/xml/kbd_emoji_category3.xml @@ -27,5 +27,5 @@ <GridRows latin:codesArray="@array/emoji_nature" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_category4.xml b/java/res/xml/kbd_emoji_category4.xml index 46b6d46e8..262384d80 100644 --- a/java/res/xml/kbd_emoji_category4.xml +++ b/java/res/xml/kbd_emoji_category4.xml @@ -27,5 +27,5 @@ <GridRows latin:codesArray="@array/emoji_places" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_category5.xml b/java/res/xml/kbd_emoji_category5.xml index 4304701d4..bf823f978 100644 --- a/java/res/xml/kbd_emoji_category5.xml +++ b/java/res/xml/kbd_emoji_category5.xml @@ -27,5 +27,5 @@ <GridRows latin:codesArray="@array/emoji_symbols" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_category6.xml b/java/res/xml/kbd_emoji_category6.xml index 516ed7a42..edb82fc64 100644 --- a/java/res/xml/kbd_emoji_category6.xml +++ b/java/res/xml/kbd_emoji_category6.xml @@ -28,5 +28,5 @@ <GridRows latin:textsArray="@array/emoji_emoticons" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/res/xml/kbd_emoji_recents.xml b/java/res/xml/kbd_emoji_recents.xml index 4953c1079..edf3872c1 100644 --- a/java/res/xml/kbd_emoji_recents.xml +++ b/java/res/xml/kbd_emoji_recents.xml @@ -28,5 +28,5 @@ <GridRows latin:codesArray="@array/emoji_recents" latin:keyLabelFlags="fontNormal" - latin:backgroundType="normal" /> + latin:backgroundType="empty" /> </Keyboard> diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java index db4315f8f..ce23eb752 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java @@ -47,7 +47,8 @@ public class MetadataDbHelper extends SQLiteOpenHelper { // used to identify the versions for upgrades. This should never change going forward. private static final int METADATA_DATABASE_VERSION_WITH_CLIENTID = 6; // The current database version. - private static final int CURRENT_METADATA_DATABASE_VERSION = 10; + // This MUST be increased every time the dictionary pack metadata URL changes. + private static final int CURRENT_METADATA_DATABASE_VERSION = 11; private final static long NOT_A_DOWNLOAD_ID = -1; diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java index bd6152119..aeb666704 100644 --- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java @@ -40,6 +40,7 @@ import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.compat.NotificationCompatUtils; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.common.LocaleUtils; +import com.android.inputmethod.latin.makedict.FormatSpec; import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.DebugLogUtils; @@ -79,7 +80,8 @@ public final class UpdateHandler { // DownloadManager uses as an ID numbers returned out of an AUTOINCREMENT column // in SQLite, so it should never return anything < 0. public static final int NOT_AN_ID = -1; - public static final int MAXIMUM_SUPPORTED_FORMAT_VERSION = 2; + public static final int MAXIMUM_SUPPORTED_FORMAT_VERSION = + FormatSpec.MAXIMUM_SUPPORTED_STATIC_VERSION; // Arbitrary. Probably good if it's a power of 2, and a couple thousand bytes long. private static final int FILE_COPY_BUFFER_SIZE = 8192; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java index 51f37fdc6..b1051385d 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardLayoutSet.java @@ -294,7 +294,7 @@ public final class KeyboardLayoutSet { : subtype; mParams.mSubtype = keyboardSubtype; mParams.mKeyboardLayoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX - + SubtypeLocaleUtils.getKeyboardLayoutSetName(keyboardSubtype); + + keyboardSubtype.getKeyboardLayoutSetName(); return this; } diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index b07693c76..01980ea6e 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -25,7 +25,6 @@ import android.graphics.Paint; import android.graphics.Paint.Align; import android.graphics.PorterDuff; import android.graphics.Rect; -import android.graphics.Region; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.graphics.drawable.NinePatchDrawable; @@ -41,6 +40,7 @@ import com.android.inputmethod.latin.utils.TypefaceUtils; import java.util.HashSet; +import javax.annotation.Nonnull; import javax.annotation.Nullable; /** @@ -100,6 +100,8 @@ public class KeyboardView extends View { private static final float MAX_LABEL_RATIO = 0.90f; // Main keyboard + // TODO: Consider having a dummy keyboard object to make this @Nonnull + @Nullable private Keyboard mKeyboard; protected final KeyDrawParams mKeyDrawParams = new KeyDrawParams(); @@ -108,14 +110,14 @@ public class KeyboardView extends View { private boolean mInvalidateAllKeys; /** The keys that should be drawn */ private final HashSet<Key> mInvalidatedKeys = new HashSet<>(); - /** The working rectangle variable */ - private final Rect mWorkingRect = new Rect(); + /** The working rectangle for clipping */ + private final Rect mClipRect = new Rect(); /** The keyboard bitmap buffer for faster updates */ - /** The clip region to draw keys */ - private final Region mClipRegion = new Region(); private Bitmap mOffscreenBuffer; /** The canvas for the above mutable keyboard bitmap */ + @Nonnull private final Canvas mOffscreenCanvas = new Canvas(); + @Nonnull private final Paint mPaint = new Paint(); private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics(); public KeyboardView(final Context context, final AttributeSet attrs) { @@ -161,11 +163,12 @@ public class KeyboardView extends View { mPaint.setAntiAlias(true); } + @Nullable public KeyVisualAttributes getKeyVisualAttribute() { return mKeyVisualAttributes; } - private static void blendAlpha(final Paint paint, final int alpha) { + private static void blendAlpha(@Nonnull final Paint paint, final int alpha) { final int color = paint.getColor(); paint.setARGB((paint.getAlpha() * alpha) / Constants.Color.ALPHA_OPAQUE, Color.red(color), Color.green(color), Color.blue(color)); @@ -184,7 +187,7 @@ public class KeyboardView extends View { * @see #getKeyboard() * @param keyboard the keyboard to display in this view */ - public void setKeyboard(final Keyboard keyboard) { + public void setKeyboard(@Nonnull final Keyboard keyboard) { mKeyboard = keyboard; final int keyHeight = keyboard.mMostCommonKeyHeight - keyboard.mVerticalGap; mKeyDrawParams.updateParams(keyHeight, mKeyVisualAttributes); @@ -198,6 +201,7 @@ public class KeyboardView extends View { * @return the currently attached keyboard * @see #setKeyboard(Keyboard) */ + @Nullable public Keyboard getKeyboard() { return mKeyboard; } @@ -212,13 +216,14 @@ public class KeyboardView extends View { @Override protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { - if (mKeyboard == null) { + final Keyboard keyboard = getKeyboard(); + if (keyboard == null) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } // The main keyboard expands to the entire this {@link KeyboardView}. - final int width = mKeyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); - final int height = mKeyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); + final int width = keyboard.mOccupiedWidth + getPaddingLeft() + getPaddingRight(); + final int height = keyboard.mOccupiedHeight + getPaddingTop() + getPaddingBottom(); setMeasuredDimension(width, height); } @@ -266,52 +271,45 @@ public class KeyboardView extends View { } } - private void onDrawKeyboard(final Canvas canvas) { - if (mKeyboard == null) return; + private void onDrawKeyboard(@Nonnull final Canvas canvas) { + final Keyboard keyboard = getKeyboard(); + if (keyboard == null) { + return; + } - final int width = getWidth(); - final int height = getHeight(); final Paint paint = mPaint; - + final Drawable background = getBackground(); // Calculate clip region and set. final boolean drawAllKeys = mInvalidateAllKeys || mInvalidatedKeys.isEmpty(); final boolean isHardwareAccelerated = canvas.isHardwareAccelerated(); // TODO: Confirm if it's really required to draw all keys when hardware acceleration is on. if (drawAllKeys || isHardwareAccelerated) { - mClipRegion.set(0, 0, width, height); - } else { - mClipRegion.setEmpty(); - for (final Key key : mInvalidatedKeys) { - if (mKeyboard.hasKey(key)) { - final int x = key.getX() + getPaddingLeft(); - final int y = key.getY() + getPaddingTop(); - mWorkingRect.set(x, y, x + key.getWidth(), y + key.getHeight()); - mClipRegion.union(mWorkingRect); - } - } - } - if (!isHardwareAccelerated) { - canvas.clipRegion(mClipRegion, Region.Op.REPLACE); - // Draw keyboard background. - canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR); - final Drawable background = getBackground(); - if (background != null) { + if (!isHardwareAccelerated && background != null) { + // Need to draw keyboard background on {@link #mOffscreenBuffer}. + canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR); background.draw(canvas); } - } - - // TODO: Confirm if it's really required to draw all keys when hardware acceleration is on. - if (drawAllKeys || isHardwareAccelerated) { // Draw all keys. - for (final Key key : mKeyboard.getSortedKeys()) { + for (final Key key : keyboard.getSortedKeys()) { onDrawKey(key, canvas, paint); } } else { - // Draw invalidated keys. for (final Key key : mInvalidatedKeys) { - if (mKeyboard.hasKey(key)) { - onDrawKey(key, canvas, paint); + if (!keyboard.hasKey(key)) { + continue; } + if (background != null) { + // Need to redraw key's background on {@link #mOffscreenBuffer}. + final int x = key.getX() + getPaddingLeft(); + final int y = key.getY() + getPaddingTop(); + mClipRect.set(x, y, x + key.getWidth(), y + key.getHeight()); + canvas.save(); + canvas.clipRect(mClipRect); + canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR); + background.draw(canvas); + canvas.restore(); + } + onDrawKey(key, canvas, paint); } } @@ -319,20 +317,22 @@ public class KeyboardView extends View { mInvalidateAllKeys = false; } - private void onDrawKey(final Key key, final Canvas canvas, final Paint paint) { + private void onDrawKey(@Nonnull final Key key, @Nonnull final Canvas canvas, + @Nonnull final Paint paint) { final int keyDrawX = key.getDrawX() + getPaddingLeft(); final int keyDrawY = key.getY() + getPaddingTop(); canvas.translate(keyDrawX, keyDrawY); - final int keyHeight = mKeyboard.mMostCommonKeyHeight - mKeyboard.mVerticalGap; final KeyVisualAttributes attr = key.getVisualAttributes(); - final KeyDrawParams params = mKeyDrawParams.mayCloneAndUpdateParams(keyHeight, attr); + final KeyDrawParams params = mKeyDrawParams.mayCloneAndUpdateParams(key.getHeight(), attr); params.mAnimAlpha = Constants.Color.ALPHA_OPAQUE; if (!key.isSpacer()) { final Drawable background = key.selectBackgroundDrawable( mKeyBackground, mFunctionalKeyBackground, mSpacebarBackground); - onDrawKeyBackground(key, canvas, background); + if (background != null) { + onDrawKeyBackground(key, canvas, background); + } } onDrawKeyTopVisuals(key, canvas, paint, params); @@ -340,8 +340,8 @@ public class KeyboardView extends View { } // Draw key background. - protected void onDrawKeyBackground(final Key key, final Canvas canvas, - final Drawable background) { + protected void onDrawKeyBackground(@Nonnull final Key key, @Nonnull final Canvas canvas, + @Nonnull final Drawable background) { final int keyWidth = key.getDrawWidth(); final int keyHeight = key.getHeight(); final int bgWidth, bgHeight, bgX, bgY; @@ -373,15 +373,17 @@ public class KeyboardView extends View { } // Draw key top visuals. - protected void onDrawKeyTopVisuals(final Key key, final Canvas canvas, final Paint paint, - final KeyDrawParams params) { + protected void onDrawKeyTopVisuals(@Nonnull final Key key, @Nonnull final Canvas canvas, + @Nonnull final Paint paint, @Nonnull final KeyDrawParams params) { final int keyWidth = key.getDrawWidth(); final int keyHeight = key.getHeight(); final float centerX = keyWidth * 0.5f; final float centerY = keyHeight * 0.5f; // Draw key label. - final Drawable icon = key.getIcon(mKeyboard.mIconsSet, params.mAnimAlpha); + final Keyboard keyboard = getKeyboard(); + final Drawable icon = (keyboard == null) ? null + : key.getIcon(keyboard.mIconsSet, params.mAnimAlpha); float labelX = centerX; float labelBaseline = centerY; final String label = key.getLabel(); @@ -500,8 +502,8 @@ public class KeyboardView extends View { } // Draw popup hint "..." at the bottom right corner of the key. - protected void drawKeyPopupHint(final Key key, final Canvas canvas, final Paint paint, - final KeyDrawParams params) { + protected void drawKeyPopupHint(@Nonnull final Key key, @Nonnull final Canvas canvas, + @Nonnull final Paint paint, @Nonnull final KeyDrawParams params) { if (TextUtils.isEmpty(mKeyPopupHintLetter)) { return; } @@ -518,15 +520,15 @@ public class KeyboardView extends View { canvas.drawText(mKeyPopupHintLetter, hintX, hintY, paint); } - protected static void drawIcon(final Canvas canvas, final Drawable icon, final int x, - final int y, final int width, final int height) { + protected static void drawIcon(@Nonnull final Canvas canvas,@Nonnull final Drawable icon, + final int x, final int y, final int width, final int height) { canvas.translate(x, y); icon.setBounds(0, 0, width, height); icon.draw(canvas); canvas.translate(-x, -y); } - public Paint newLabelPaint(final Key key) { + public Paint newLabelPaint(@Nullable final Key key) { final Paint paint = new Paint(); paint.setAntiAlias(true); if (key == null) { @@ -560,7 +562,7 @@ public class KeyboardView extends View { * @see #invalidateAllKeys */ public void invalidateKey(@Nullable final Key key) { - if (key == null || mInvalidateAllKeys) { + if (mInvalidateAllKeys || key == null) { return; } mInvalidatedKeys.add(key); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java index c739bf3e0..51f89c122 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java @@ -36,7 +36,6 @@ import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.common.Constants; import com.android.inputmethod.latin.common.StringUtils; import com.android.inputmethod.latin.utils.ResourceUtils; -import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.XmlParseUtils; import com.android.inputmethod.latin.utils.XmlParseUtils.ParseException; @@ -648,7 +647,7 @@ public class KeyboardBuilder<KP extends KeyboardParams> { try { final boolean keyboardLayoutSetMatched = matchString(caseAttr, R.styleable.Keyboard_Case_keyboardLayoutSet, - SubtypeLocaleUtils.getKeyboardLayoutSetName(id.mSubtype)); + id.mSubtype.getKeyboardLayoutSetName()); final boolean keyboardLayoutSetElementMatched = matchTypedValue(caseAttr, R.styleable.Keyboard_Case_keyboardLayoutSetElement, id.mElementId, KeyboardId.elementIdToName(id.mElementId)); diff --git a/java/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelper.java b/java/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelper.java index 2a70ef51a..8ed80107a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelper.java +++ b/java/src/com/android/inputmethod/keyboard/internal/LanguageOnSpacebarHelper.java @@ -52,7 +52,7 @@ public final class LanguageOnSpacebarHelper { return FORMAT_TYPE_MULTIPLE; } final String keyboardLanguage = locales[0].getLanguage(); - final String keyboardLayout = SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype); + final String keyboardLayout = subtype.getKeyboardLayoutSetName(); int sameLanguageAndLayoutCount = 0; for (final InputMethodSubtype ims : mEnabledSubtypes) { final String language = SubtypeLocaleUtils.getSubtypeLocale(ims).getLanguage(); diff --git a/java/src/com/android/inputmethod/latin/AssetFileAddress.java b/java/src/com/android/inputmethod/latin/AssetFileAddress.java index 923f43cbe..f8d02d6ea 100644 --- a/java/src/com/android/inputmethod/latin/AssetFileAddress.java +++ b/java/src/com/android/inputmethod/latin/AssetFileAddress.java @@ -62,4 +62,9 @@ public final class AssetFileAddress { public void deleteUnderlyingFile() { FileUtils.deleteRecursively(new File(mFilename)); } + + @Override + public String toString() { + return String.format("%s (offset=%d, length=%d)", mFilename, mOffset, mLength); + } } diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java index 46c8d5562..5afb62b69 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionaryGetter.java @@ -284,7 +284,8 @@ final public class BinaryDictionaryGetter { final AssetFileAddress afa = AssetFileAddress.makeFromFileName(f.getPath()); if (null != afa) fileList.add(afa); } else { - Log.e(TAG, "Found a cached dictionary file but cannot read or use it"); + Log.e(TAG, "Found a cached dictionary file for " + locale.toString() + + " but cannot read or use it"); } } diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodSubtype.java b/java/src/com/android/inputmethod/latin/RichInputMethodSubtype.java index 03f6d60ab..ea8d4a210 100644 --- a/java/src/com/android/inputmethod/latin/RichInputMethodSubtype.java +++ b/java/src/com/android/inputmethod/latin/RichInputMethodSubtype.java @@ -135,13 +135,18 @@ public final class RichInputMethodSubtype { public boolean isRtlSubtype() { // The subtype is considered RTL if the language of the main subtype is RTL. - return SubtypeLocaleUtils.isRtlLanguage(mLocales[0]); + return LocaleUtils.isRtlLanguage(mLocales[0]); } // TODO: remove this method @Nonnull public InputMethodSubtype getRawSubtype() { return mSubtype; } + @Nonnull + public String getKeyboardLayoutSetName() { + return SubtypeLocaleUtils.getKeyboardLayoutSetName(mSubtype); + } + // Dummy no language QWERTY subtype. See {@link R.xml.method}. private static final int SUBTYPE_ID_OF_DUMMY_NO_LANGUAGE_SUBTYPE = 0xdde0bfd3; private static final String EXTRA_VALUE_OF_DUMMY_NO_LANGUAGE_SUBTYPE = diff --git a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java index 4ef504856..eba9654a5 100644 --- a/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java +++ b/java/src/com/android/inputmethod/latin/makedict/FormatSpec.java @@ -179,8 +179,8 @@ public final class FormatSpec { public static final int VERSION403 = 403; public static final int VERSION4 = VERSION403; public static final int VERSION4_DEV = VERSION403; - static final int MINIMUM_SUPPORTED_STATIC_VERSION = VERSION202; - static final int MAXIMUM_SUPPORTED_STATIC_VERSION = VERSION202; + public static final int MINIMUM_SUPPORTED_STATIC_VERSION = VERSION202; + public static final int MAXIMUM_SUPPORTED_STATIC_VERSION = VERSION202; static final int MINIMUM_SUPPORTED_DYNAMIC_VERSION = VERSION4; static final int MAXIMUM_SUPPORTED_DYNAMIC_VERSION = VERSION4_DEV; diff --git a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java index ac2fc07c2..8c5eb0aa7 100644 --- a/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java +++ b/java/src/com/android/inputmethod/latin/personalization/PersonalizationHelper.java @@ -28,32 +28,45 @@ import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + +/** + * Helps handle and manage personalized dictionaries such as {@link UserHistoryDictionary} and + * {@link PersonalizationDictionary}. + */ public class PersonalizationHelper { private static final String TAG = PersonalizationHelper.class.getSimpleName(); private static final boolean DEBUG = false; + private static final ConcurrentHashMap<String, SoftReference<UserHistoryDictionary>> sLangUserHistoryDictCache = new ConcurrentHashMap<>(); private static final ConcurrentHashMap<String, SoftReference<PersonalizationDictionary>> sLangPersonalizationDictCache = new ConcurrentHashMap<>(); + @Nonnull public static UserHistoryDictionary getUserHistoryDictionary( - final Context context, final Locale locale) { - final String localeStr = locale.toString(); + final Context context, final Locale locale, @Nullable final String accountName) { + String lookupStr = locale.toString(); + if (accountName != null) { + lookupStr += "." + accountName; + } synchronized (sLangUserHistoryDictCache) { - if (sLangUserHistoryDictCache.containsKey(localeStr)) { + if (sLangUserHistoryDictCache.containsKey(lookupStr)) { final SoftReference<UserHistoryDictionary> ref = - sLangUserHistoryDictCache.get(localeStr); + sLangUserHistoryDictCache.get(lookupStr); final UserHistoryDictionary dict = ref == null ? null : ref.get(); if (dict != null) { if (DEBUG) { - Log.w(TAG, "Use cached UserHistoryDictionary for " + locale); + Log.d(TAG, "Use cached UserHistoryDictionary for " + locale + + " & account" + accountName); } dict.reloadDictionaryIfRequired(); return dict; } } final UserHistoryDictionary dict = new UserHistoryDictionary(context, locale); - sLangUserHistoryDictCache.put(localeStr, new SoftReference<>(dict)); + sLangUserHistoryDictCache.put(lookupStr, new SoftReference<>(dict)); return dict; } } diff --git a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java index 58782c646..946835cbc 100644 --- a/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java +++ b/java/src/com/android/inputmethod/latin/personalization/UserHistoryDictionary.java @@ -17,30 +17,73 @@ package com.android.inputmethod.latin.personalization; import android.content.Context; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; import com.android.inputmethod.annotations.ExternallyReferenced; +import com.android.inputmethod.annotations.UsedForTesting; import com.android.inputmethod.latin.Dictionary; import com.android.inputmethod.latin.ExpandableBinaryDictionary; import com.android.inputmethod.latin.NgramContext; import com.android.inputmethod.latin.common.Constants; +import com.android.inputmethod.latin.define.ProductionFlags; +import com.android.inputmethod.latin.settings.LocalSettingsConstants; import com.android.inputmethod.latin.utils.DistracterFilter; import java.io.File; import java.util.Locale; import javax.annotation.Nonnull; +import javax.annotation.Nullable; /** * Locally gathers stats about the words user types and various other signals like auto-correction * cancellation or manual picks. This allows the keyboard to adapt to the typist over time. */ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBase { - /* package */ static final String NAME = UserHistoryDictionary.class.getSimpleName(); + static final String NAME = UserHistoryDictionary.class.getSimpleName(); // TODO: Make this constructor private - /* package */ UserHistoryDictionary(final Context context, final Locale locale) { - super(context, getDictName(NAME, locale, null /* dictFile */), locale, - Dictionary.TYPE_USER_HISTORY, null /* dictFile */); + UserHistoryDictionary(final Context context, final Locale locale) { + super(context, + getUserHistoryDictName( + NAME, + locale, + null /* dictFile */, + context), + locale, + Dictionary.TYPE_USER_HISTORY, + null /* dictFile */); + } + + /** + * @returns the name of the {@link UserHistoryDictionary}. + */ + @UsedForTesting + static String getUserHistoryDictName(final String name, final Locale locale, + @Nullable final File dictFile, final Context context) { + if (!ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) { + return getDictName(name, locale, dictFile); + } + return getUserHistoryDictNamePerAccount(name, locale, dictFile, context); + } + + /** + * Uses the currently signed in account to determine the dictionary name. + */ + private static String getUserHistoryDictNamePerAccount(final String name, final Locale locale, + @Nullable final File dictFile, final Context context) { + if (dictFile != null) { + return dictFile.getName(); + } + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + final String account = prefs.getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, + null /* default */); + String dictName = name + "." + locale.toString(); + if (account != null) { + dictName += "." + account; + } + return dictName; } // Note: This method is called by {@link DictionaryFacilitator} using Java reflection. @@ -48,7 +91,14 @@ public class UserHistoryDictionary extends DecayingExpandableBinaryDictionaryBas @ExternallyReferenced public static UserHistoryDictionary getDictionary(final Context context, final Locale locale, final File dictFile, final String dictNamePrefix) { - return PersonalizationHelper.getUserHistoryDictionary(context, locale); + final String account; + if (ProductionFlags.ENABLE_PER_ACCOUNT_USER_HISTORY_DICTIONARY) { + account = PreferenceManager.getDefaultSharedPreferences(context) + .getString(LocalSettingsConstants.PREF_ACCOUNT_NAME, null /* default */); + } else { + account = null; + } + return PersonalizationHelper.getUserHistoryDictionary(context, locale, account); } /** diff --git a/java/src/com/android/inputmethod/latin/settings/CustomInputStylePreference.java b/java/src/com/android/inputmethod/latin/settings/CustomInputStylePreference.java index 01398f467..b749aa51a 100644 --- a/java/src/com/android/inputmethod/latin/settings/CustomInputStylePreference.java +++ b/java/src/com/android/inputmethod/latin/settings/CustomInputStylePreference.java @@ -346,8 +346,10 @@ final class CustomInputStylePreference extends DialogPreference super(context, android.R.layout.simple_spinner_item); setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); + final String[] predefinedKeyboardLayoutSet = context.getResources().getStringArray( + R.array.predefined_layouts); // TODO: Should filter out already existing combinations of locale and layout. - for (final String layout : SubtypeLocaleUtils.getPredefinedKeyboardLayoutSet()) { + for (final String layout : predefinedKeyboardLayoutSet) { // This is a dummy subtype with NO_LANGUAGE, only for display. final InputMethodSubtype subtype = AdditionalSubtypeUtils.createDummyAdditionalSubtype( diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index 27a0f62ff..7991a2473 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -50,10 +50,10 @@ import com.android.inputmethod.latin.PunctuationSuggestions; import com.android.inputmethod.latin.R; import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; +import com.android.inputmethod.latin.common.LocaleUtils; import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.utils.ResourceUtils; -import com.android.inputmethod.latin.utils.SubtypeLocaleUtils; import com.android.inputmethod.latin.utils.ViewLayoutUtils; import java.util.ArrayList; @@ -570,8 +570,7 @@ final class SuggestionStripLayoutHelper { final boolean isRtlLanguage = (ViewCompat.getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL); final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW; - final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage( - res.getConfiguration().locale); + final boolean isRtlSystem = LocaleUtils.isRtlLanguage(res.getConfiguration().locale); final CharSequence hint = res.getText(R.string.hint_add_to_dictionary); hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow); hintWidth = width - wordWidth; diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java index b36168b6c..013f024c0 100644 --- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java @@ -27,11 +27,9 @@ import android.util.Log; import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.latin.R; -import com.android.inputmethod.latin.RichInputMethodSubtype; import com.android.inputmethod.latin.common.LocaleUtils; import com.android.inputmethod.latin.common.StringUtils; -import java.util.Arrays; import java.util.HashMap; import java.util.Locale; @@ -56,7 +54,6 @@ public final class SubtypeLocaleUtils { private static volatile boolean sInitialized = false; private static final Object sInitializeLock = new Object(); private static Resources sResources; - private static String[] sPredefinedKeyboardLayoutSet; // Keyboard layout to its display name map. private static final HashMap<String, String> sKeyboardLayoutToDisplayNameMap = new HashMap<>(); // Keyboard layout to subtype name resource id map. @@ -103,7 +100,6 @@ public final class SubtypeLocaleUtils { sResources = res; final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts); - sPredefinedKeyboardLayoutSet = predefinedLayoutSet; final String[] layoutDisplayNames = res.getStringArray( R.array.predefined_layout_display_names); for (int i = 0; i < predefinedLayoutSet.length; i++) { @@ -152,10 +148,6 @@ public final class SubtypeLocaleUtils { } } - public static String[] getPredefinedKeyboardLayoutSet() { - return sPredefinedKeyboardLayoutSet; - } - public static boolean isExceptionalLocale(final String localeString) { return sExceptionalLocaleToNameIdsMap.containsKey(localeString); } @@ -334,10 +326,6 @@ public final class SubtypeLocaleUtils { } @Nonnull - public static String getKeyboardLayoutSetName(@Nonnull final RichInputMethodSubtype subtype) { - return getKeyboardLayoutSetName(subtype.getRawSubtype()); - } - public static String getKeyboardLayoutSetName(final InputMethodSubtype subtype) { String keyboardLayoutSet = subtype.getExtraValueOf(KEYBOARD_LAYOUT_SET); if (keyboardLayoutSet == null) { @@ -357,22 +345,6 @@ public final class SubtypeLocaleUtils { return keyboardLayoutSet; } - // TODO: Get this information from the framework instead of maintaining here by ourselves. - // Sorted list of known Right-To-Left language codes. - private static final String[] SORTED_RTL_LANGUAGES = { - "ar", // Arabic - "fa", // Persian - "iw", // Hebrew - }; - static { - Arrays.sort(SORTED_RTL_LANGUAGES); - } - - public static boolean isRtlLanguage(final Locale locale) { - final String language = locale.getLanguage(); - return Arrays.binarySearch(SORTED_RTL_LANGUAGES, language) >= 0; - } - public static String getCombiningRulesExtraValue(final InputMethodSubtype subtype) { return subtype.getExtraValueOf(COMBINING_RULES); } |