From c8814e20b7b0ed5f7e11292480e89152618dd862 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Tue, 30 Jul 2013 20:29:19 +0900 Subject: [PATCH] Deallocate gesture trail bitmap when unneeded This frees up 1.7MB on Nexus 4 (occam), and 900KB on occam_svelte while LatinIME goes to background. The keyboard bring-up speed feels acceptable on both devices. bug: 8967766 Change-Id: I5bc980c4dc41bc304be3c190934c1f7c55c9d244 --- .../com/android/inputmethod/keyboard/MainKeyboardView.java | 4 ++++ .../inputmethod/keyboard/internal/GestureTrailsPreview.java | 5 +++++ java/src/com/android/inputmethod/latin/LatinIME.java | 1 + 3 files changed, 10 insertions(+) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index a5205d8ba..a1eed73e4 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -1370,4 +1370,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack drawIcon(canvas, mSpaceIcon, x, y, iconWidth, iconHeight); } } + + public void deallocateMemory() { + mGestureTrailsPreview.deallocateMemory(); + } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java index dff5177ce..d4c25941c 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsPreview.java @@ -104,7 +104,12 @@ public final class GestureTrailsPreview extends AbstractDrawingPreview { freeOffscreenBuffer(); } + public void deallocateMemory() { + freeOffscreenBuffer(); + } + private void freeOffscreenBuffer() { + mOffscreenCanvas.setBitmap(null); if (mOffscreenBuffer != null) { mOffscreenBuffer.recycle(); mOffscreenBuffer = null; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 093d87dac..614c14308 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -894,6 +894,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final MainKeyboardView mainKeyboardView = mKeyboardSwitcher.getMainKeyboardView(); if (mainKeyboardView != null) { mainKeyboardView.cancelAllOngoingEvents(); + mainKeyboardView.deallocateMemory(); } // Remove pending messages related to update suggestions mHandler.cancelUpdateSuggestionStrip();