From afca1ddd233c03d79433931a0b6ba97ed22663ed Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Tue, 24 Dec 2013 18:26:55 +0900 Subject: [PATCH] Comprehensive memory deallocation Change-Id: I4673543c96eb342c3c977e00d44772a0d719a23e --- .../inputmethod/keyboard/MainKeyboardView.java | 2 +- .../keyboard/internal/AbstractDrawingPreview.java | 4 +--- .../keyboard/internal/DrawingPreviewPlacerView.java | 12 ++++++++---- .../internal/GestureFloatingTextDrawingPreview.java | 5 +++++ .../internal/GestureTrailsDrawingPreview.java | 6 +----- .../internal/SlidingKeyInputDrawingPreview.java | 5 +++++ 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 07bd7a651..e1c841de7 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -1228,6 +1228,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack @Override public void deallocateMemory() { super.deallocateMemory(); - mGestureTrailsDrawingPreview.deallocateMemory(); + mDrawingPreviewPlacerView.deallocateMemory(); } } diff --git a/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java index 32352ce04..cd7dd6f18 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/AbstractDrawingPreview.java @@ -50,9 +50,7 @@ public abstract class AbstractDrawingPreview { // Default implementation is empty. } - public void onDetachFromWindow() { - // Default implementation is empty. - } + public abstract void onDeallocateMemory(); /** * Draws the preview diff --git a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java index 14baf35d2..606addcc4 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java +++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingPreviewPlacerView.java @@ -59,13 +59,17 @@ public final class DrawingPreviewPlacerView extends RelativeLayout { } } + public void deallocateMemory() { + final int count = mPreviews.size(); + for (int i = 0; i < count; i++) { + mPreviews.get(i).onDeallocateMemory(); + } + } + @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); - final int count = mPreviews.size(); - for (int i = 0; i < count; i++) { - mPreviews.get(i).onDetachFromWindow(); - } + deallocateMemory(); } @Override diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingTextDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingTextDrawingPreview.java index 179031316..2fa703083 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingTextDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureFloatingTextDrawingPreview.java @@ -105,6 +105,11 @@ public class GestureFloatingTextDrawingPreview extends AbstractDrawingPreview { mParams = new GesturePreviewTextParams(typedArray); } + @Override + public void onDeallocateMemory() { + // Nothing to do here. + } + public void setSuggetedWords(final SuggestedWords suggestedWords) { if (!isPreviewEnabled()) { return; diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java index 2d23ddb75..13f2b60d6 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailsDrawingPreview.java @@ -103,11 +103,7 @@ public final class GestureTrailsDrawingPreview extends AbstractDrawingPreview { } @Override - public void onDetachFromWindow() { - freeOffscreenBuffer(); - } - - public void deallocateMemory() { + public void onDeallocateMemory() { freeOffscreenBuffer(); } diff --git a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java index aaa4072c9..76cb89160 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java +++ b/java/src/com/android/inputmethod/keyboard/internal/SlidingKeyInputDrawingPreview.java @@ -62,6 +62,11 @@ public final class SlidingKeyInputDrawingPreview extends AbstractDrawingPreview mPaint.setColor(previewColor); } + @Override + public void onDeallocateMemory() { + // Nothing to do here. + } + public void dismissSlidingKeyInputPreview() { mShowsSlidingKeyInputPreview = false; getDrawingView().invalidate();