Skip to content

Commit

Permalink
Merge "Release bitmap buffer when KeyboardView is detached from Windo…
Browse files Browse the repository at this point in the history
…w" into ics-mr0
  • Loading branch information
tgtakaoka authored and Android (Google) Code Review committed Oct 14, 2011
2 parents 59a55fc + 28d8415 commit 5ad37ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions java/src/com/android/inputmethod/keyboard/KeyboardView.java
Expand Up @@ -974,5 +974,9 @@ protected void onDetachedFromWindow() {
if (mPreviewPlacer != null) {
mPreviewPlacer.removeAllViews();
}
if (mBuffer != null) {
mBuffer.recycle();
mBuffer = null;
}
}
}
16 changes: 8 additions & 8 deletions java/src/com/android/inputmethod/keyboard/LatinKeyboard.java
Expand Up @@ -59,8 +59,8 @@ public class LatinKeyboard extends Keyboard {
private final int mSpacebarTextColor;
private final int mSpacebarTextShadowColor;
private float mSpacebarTextFadeFactor = 0.0f;
private final HashMap<Integer, SoftReference<BitmapDrawable>> mSpaceDrawableCache =
new HashMap<Integer, SoftReference<BitmapDrawable>>();
private final HashMap<Integer, BitmapDrawable> mSpaceDrawableCache =
new HashMap<Integer, BitmapDrawable>();
private final boolean mIsSpacebarTriggeringPopupByLongPress;

/* Shortcut key and its icons if available */
Expand Down Expand Up @@ -249,13 +249,13 @@ private static String layoutSpacebar(Paint paint, Locale locale, int width,
private BitmapDrawable getSpaceDrawable(Locale locale, boolean isAutoCorrection) {
final Integer hashCode = Arrays.hashCode(
new Object[] { locale, isAutoCorrection, mSpacebarTextFadeFactor });
final SoftReference<BitmapDrawable> ref = mSpaceDrawableCache.get(hashCode);
BitmapDrawable drawable = (ref == null) ? null : ref.get();
if (drawable == null) {
drawable = new BitmapDrawable(mRes, drawSpacebar(
locale, isAutoCorrection, mSpacebarTextFadeFactor));
mSpaceDrawableCache.put(hashCode, new SoftReference<BitmapDrawable>(drawable));
final BitmapDrawable cached = mSpaceDrawableCache.get(hashCode);
if (cached != null) {
return cached;
}
final BitmapDrawable drawable = new BitmapDrawable(mRes, drawSpacebar(
locale, isAutoCorrection, mSpacebarTextFadeFactor));
mSpaceDrawableCache.put(hashCode, drawable);
return drawable;
}

Expand Down

0 comments on commit 5ad37ba

Please sign in to comment.