aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java34
-rw-r--r--java/src/com/android/inputmethod/keyboard/Keyboard.java3
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardView.java81
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java6
5 files changed, 87 insertions, 39 deletions
diff --git a/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
new file mode 100644
index 000000000..0befa7a66
--- /dev/null
+++ b/java/src/com/android/inputmethod/compat/InputMethodServiceCompatUtils.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 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.
+ */
+
+package com.android.inputmethod.compat;
+
+import android.inputmethodservice.InputMethodService;
+
+import java.lang.reflect.Method;
+
+public class InputMethodServiceCompatUtils {
+ private static final Method METHOD_enableHardwareAcceleration =
+ CompatUtils.getMethod(InputMethodService.class, "enableHardwareAcceleration");
+
+ private InputMethodServiceCompatUtils() {
+ // This utility class is not publicly instantiable.
+ }
+
+ public static boolean enableHardwareAcceleration(InputMethodService ims) {
+ return (Boolean)CompatUtils.invoke(ims, false, METHOD_enableHardwareAcceleration);
+ }
+}
diff --git a/java/src/com/android/inputmethod/keyboard/Keyboard.java b/java/src/com/android/inputmethod/keyboard/Keyboard.java
index f1a35b212..3abe890cb 100644
--- a/java/src/com/android/inputmethod/keyboard/Keyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/Keyboard.java
@@ -604,9 +604,6 @@ public class Keyboard {
}
public float getKeyX(TypedArray keyAttr) {
- final int widthType = Builder.getEnumValue(keyAttr,
- R.styleable.Keyboard_Key_keyWidth, KEYWIDTH_NOT_ENUM);
-
final int keyboardRightEdge = mParams.mOccupiedWidth
- mParams.mHorizontalEdgesPadding;
if (keyAttr.hasValue(R.styleable.Keyboard_Key_keyXPos)) {
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
index d7ce659e7..6b1320d66 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java
@@ -25,7 +25,7 @@ import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.PorterDuff;
import android.graphics.Rect;
-import android.graphics.Region.Op;
+import android.graphics.Region;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Message;
@@ -120,12 +120,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
private boolean mInvalidateAllKeys;
/** The keys that should be drawn */
private final HashSet<Key> mInvalidatedKeys = new HashSet<Key>();
- /** The region of invalidated keys */
- private final Rect mInvalidatedKeysRect = new Rect();
+ /** The working rectangle variable */
+ private final Rect mWorkingRect = new Rect();
/** The keyboard bitmap buffer for faster updates */
- private Bitmap mBuffer;
+ private Bitmap mOffscreenBuffer;
/** The canvas for the above mutable keyboard bitmap */
- private Canvas mCanvas;
+ private Canvas mOffscreenCanvas;
private final Paint mPaint = new Paint();
private final Paint.FontMetrics mFontMetrics = new Paint.FontMetrics();
// This sparse array caches key label text height in pixel indexed by key label text size.
@@ -457,46 +457,61 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
- if (mBufferNeedsUpdate || mBuffer == null) {
+ if (mBufferNeedsUpdate || mOffscreenBuffer == null) {
mBufferNeedsUpdate = false;
- onBufferDraw();
+ if (maybeAllocateOffscreenBuffer()) {
+ mInvalidateAllKeys = true;
+ if (mOffscreenCanvas != null) {
+ mOffscreenCanvas.setBitmap(mOffscreenBuffer);
+ } else {
+ mOffscreenCanvas = new Canvas(mOffscreenBuffer);
+ }
+ }
+ onDrawKeyboard(mOffscreenCanvas);
}
- canvas.drawBitmap(mBuffer, 0, 0, null);
+ canvas.drawBitmap(mOffscreenBuffer, 0, 0, null);
}
- private void onBufferDraw() {
+ private boolean maybeAllocateOffscreenBuffer() {
final int width = getWidth();
final int height = getHeight();
- if (width == 0 || height == 0)
- return;
- if (mBuffer == null || mBuffer.getWidth() != width || mBuffer.getHeight() != height) {
- if (mBuffer != null)
- mBuffer.recycle();
- mBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
- mInvalidateAllKeys = true;
- if (mCanvas != null) {
- mCanvas.setBitmap(mBuffer);
- } else {
- mCanvas = new Canvas(mBuffer);
- }
+ if (width == 0 || height == 0) {
+ return false;
+ }
+ if (mOffscreenBuffer != null && mOffscreenBuffer.getWidth() == width
+ && mOffscreenBuffer.getHeight() == height) {
+ return false;
}
+ freeOffscreenBuffer();
+ mOffscreenBuffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ return true;
+ }
+ private void freeOffscreenBuffer() {
+ if (mOffscreenBuffer != null) {
+ mOffscreenBuffer.recycle();
+ mOffscreenBuffer = null;
+ }
+ }
+
+ private void onDrawKeyboard(final Canvas canvas) {
if (mKeyboard == null) return;
- final Canvas canvas = mCanvas;
+ final int width = getWidth();
+ final int height = getHeight();
final Paint paint = mPaint;
final KeyDrawParams params = mKeyDrawParams;
if (mInvalidateAllKeys || mInvalidatedKeys.isEmpty()) {
- mInvalidatedKeysRect.set(0, 0, width, height);
- canvas.clipRect(mInvalidatedKeysRect, Op.REPLACE);
+ mWorkingRect.set(0, 0, width, height);
+ canvas.clipRect(mWorkingRect, Region.Op.REPLACE);
canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
// Draw all keys.
for (final Key key : mKeyboard.mKeys) {
onDrawKey(key, canvas, paint, params);
}
if (mNeedsToDimEntireKeyboard) {
- drawDimRectangle(canvas, mInvalidatedKeysRect, mBackgroundDimAlpha, paint);
+ drawDimRectangle(canvas, mWorkingRect, mBackgroundDimAlpha, paint);
}
} else {
// Draw invalidated keys.
@@ -506,12 +521,12 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
final int x = key.mX + getPaddingLeft();
final int y = key.mY + getPaddingTop();
- mInvalidatedKeysRect.set(x, y, x + key.mWidth, y + key.mHeight);
- canvas.clipRect(mInvalidatedKeysRect, Op.REPLACE);
+ mWorkingRect.set(x, y, x + key.mWidth, y + key.mHeight);
+ canvas.clipRect(mWorkingRect, Region.Op.REPLACE);
canvas.drawColor(Color.BLACK, PorterDuff.Mode.CLEAR);
onDrawKey(key, canvas, paint, params);
if (mNeedsToDimEntireKeyboard) {
- drawDimRectangle(canvas, mInvalidatedKeysRect, mBackgroundDimAlpha, paint);
+ drawDimRectangle(canvas, mWorkingRect, mBackgroundDimAlpha, paint);
}
}
}
@@ -524,7 +539,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
}
mInvalidatedKeys.clear();
- mInvalidatedKeysRect.setEmpty();
mInvalidateAllKeys = false;
}
@@ -1026,9 +1040,9 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mInvalidatedKeys.add(key);
final int x = key.mX + getPaddingLeft();
final int y = key.mY + getPaddingTop();
- mInvalidatedKeysRect.union(x, y, x + key.mWidth, y + key.mHeight);
+ mWorkingRect.set(x, y, x + key.mWidth, y + key.mHeight);
mBufferNeedsUpdate = true;
- invalidate(mInvalidatedKeysRect);
+ invalidate(mWorkingRect);
}
public void closing() {
@@ -1054,9 +1068,6 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
super.onDetachedFromWindow();
closing();
mPreviewPlacerView.removeAllViews();
- if (mBuffer != null) {
- mBuffer.recycle();
- mBuffer = null;
- }
+ freeOffscreenBuffer();
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index 0a284cc8e..e7e11f481 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -408,7 +408,7 @@ public class PointerTracker {
if (mDrawingProxy != null) {
setReleasedKeyGraphics(mCurrentKey);
}
- mCurrentKey = newKey;
+ // Keep {@link #mCurrentKey} that comes from previous keyboard.
}
final int keyQuarterWidth = mKeyboard.mMostCommonKeyWidth / 4;
mKeyQuarterWidthSquared = keyQuarterWidth * keyQuarterWidth;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 30edd2052..8dc1081f5 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -60,6 +60,7 @@ import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.CompatUtils;
import com.android.inputmethod.compat.InputMethodManagerCompatWrapper;
+import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.compat.SuggestionSpanUtils;
import com.android.inputmethod.keyboard.KeyDetector;
import com.android.inputmethod.keyboard.Keyboard;
@@ -175,6 +176,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private AlertDialog mOptionsDialog;
+ private final boolean mIsHardwareAcceleratedDrawingEnabled;
+
public final UIHandler mHandler = new UIHandler(this);
public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> {
@@ -347,6 +350,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
super();
mSubtypeSwitcher = SubtypeSwitcher.getInstance();
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
+ mIsHardwareAcceleratedDrawingEnabled =
+ InputMethodServiceCompatUtils.enableHardwareAcceleration(this);
+ Log.i(TAG, "Hardware accelerated drawing: " + mIsHardwareAcceleratedDrawingEnabled);
}
@Override