From 105767088196b9539c373ddcc7f3ff9d8e3e54fc Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 27 Jul 2012 19:32:47 +0900 Subject: [PATCH] Make PreviewPlacerView final This is a groundwork for the bug. Bug: 6883053 Change-Id: I51e9235d3bc7021790a88a44596c4314125a1ab3 --- .../inputmethod/keyboard/KeyboardView.java | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardView.java b/java/src/com/android/inputmethod/keyboard/KeyboardView.java index f1f942ccb..9c6543b61 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardView.java @@ -106,7 +106,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { protected final KeyPreviewDrawParams mKeyPreviewDrawParams; private boolean mShowKeyPreviewPopup = true; private int mDelayAfterPreview; - private PreviewPlacerView mPreviewPlacer; + private final PreviewPlacerView mPreviewPlacerView; /** True if {@link KeyboardView} should handle gesture events. */ protected boolean mShouldHandleGesture; @@ -376,6 +376,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mPaint.setAntiAlias(true); + + mPreviewPlacerView = new PreviewPlacerView(context); } // Read fraction value in TypedArray as float. @@ -876,39 +878,35 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { } private void addKeyPreview(TextView keyPreview) { - if (mPreviewPlacer == null) { - createPreviewPlacer(); - } - mPreviewPlacer.addView( - keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacer, 0, 0)); + locatePreviewPlacerView(); + mPreviewPlacerView.addView( + keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0)); } - private void createPreviewPlacer() { - mPreviewPlacer = new PreviewPlacerView(getContext()); + private void locatePreviewPlacerView() { + if (mPreviewPlacerView.getParent() != null) { + return; + } final int[] viewOrigin = new int[2]; getLocationInWindow(viewOrigin); - mPreviewPlacer.setOrigin(viewOrigin[0], viewOrigin[1]); + mPreviewPlacerView.setOrigin(viewOrigin[0], viewOrigin[1]); final ViewGroup windowContentView = (ViewGroup)getRootView().findViewById(android.R.id.content); - windowContentView.addView(mPreviewPlacer); + windowContentView.addView(mPreviewPlacerView); } public void showGesturePreviewText(String gesturePreviewText) { // TDOD: Add user settings option to control drawing gesture trail. - if (mPreviewPlacer == null) { - createPreviewPlacer(); - } - mPreviewPlacer.setGesturePreviewText(gesturePreviewText); - mPreviewPlacer.invalidate(); + locatePreviewPlacerView(); + mPreviewPlacerView.setGesturePreviewText(gesturePreviewText); + mPreviewPlacerView.invalidate(); } @Override public void showGestureTrail(PointerTracker tracker) { // TDOD: Add user settings option to control drawing gesture trail. - if (mPreviewPlacer == null) { - createPreviewPlacer(); - } - mPreviewPlacer.invalidatePointer(tracker); + locatePreviewPlacerView(); + mPreviewPlacerView.invalidatePointer(tracker); } @SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16 @@ -1051,9 +1049,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy { protected void onDetachedFromWindow() { super.onDetachedFromWindow(); closing(); - if (mPreviewPlacer != null) { - mPreviewPlacer.removeAllViews(); - } + mPreviewPlacerView.removeAllViews(); if (mBuffer != null) { mBuffer.recycle(); mBuffer = null;