Merge "Make PreviewPlacerView final" into jb-mr1-dev

main
Tadashi G. Takaoka 2012-07-27 03:59:15 -07:00 committed by Android (Google) Code Review
commit d148c23a33
1 changed files with 18 additions and 22 deletions

View File

@ -106,7 +106,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
protected final KeyPreviewDrawParams mKeyPreviewDrawParams; protected final KeyPreviewDrawParams mKeyPreviewDrawParams;
private boolean mShowKeyPreviewPopup = true; private boolean mShowKeyPreviewPopup = true;
private int mDelayAfterPreview; private int mDelayAfterPreview;
private PreviewPlacerView mPreviewPlacer; private final PreviewPlacerView mPreviewPlacerView;
/** True if {@link KeyboardView} should handle gesture events. */ /** True if {@link KeyboardView} should handle gesture events. */
protected boolean mShouldHandleGesture; protected boolean mShouldHandleGesture;
@ -376,6 +376,8 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout; mDelayAfterPreview = mKeyPreviewDrawParams.mLingerTimeout;
mPaint.setAntiAlias(true); mPaint.setAntiAlias(true);
mPreviewPlacerView = new PreviewPlacerView(context);
} }
// Read fraction value in TypedArray as float. // Read fraction value in TypedArray as float.
@ -876,39 +878,35 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
} }
private void addKeyPreview(TextView keyPreview) { private void addKeyPreview(TextView keyPreview) {
if (mPreviewPlacer == null) { locatePreviewPlacerView();
createPreviewPlacer(); mPreviewPlacerView.addView(
} keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacerView, 0, 0));
mPreviewPlacer.addView(
keyPreview, ViewLayoutUtils.newLayoutParam(mPreviewPlacer, 0, 0));
} }
private void createPreviewPlacer() { private void locatePreviewPlacerView() {
mPreviewPlacer = new PreviewPlacerView(getContext()); if (mPreviewPlacerView.getParent() != null) {
return;
}
final int[] viewOrigin = new int[2]; final int[] viewOrigin = new int[2];
getLocationInWindow(viewOrigin); getLocationInWindow(viewOrigin);
mPreviewPlacer.setOrigin(viewOrigin[0], viewOrigin[1]); mPreviewPlacerView.setOrigin(viewOrigin[0], viewOrigin[1]);
final ViewGroup windowContentView = final ViewGroup windowContentView =
(ViewGroup)getRootView().findViewById(android.R.id.content); (ViewGroup)getRootView().findViewById(android.R.id.content);
windowContentView.addView(mPreviewPlacer); windowContentView.addView(mPreviewPlacerView);
} }
public void showGesturePreviewText(String gesturePreviewText) { public void showGesturePreviewText(String gesturePreviewText) {
// TDOD: Add user settings option to control drawing gesture trail. // TDOD: Add user settings option to control drawing gesture trail.
if (mPreviewPlacer == null) { locatePreviewPlacerView();
createPreviewPlacer(); mPreviewPlacerView.setGesturePreviewText(gesturePreviewText);
} mPreviewPlacerView.invalidate();
mPreviewPlacer.setGesturePreviewText(gesturePreviewText);
mPreviewPlacer.invalidate();
} }
@Override @Override
public void showGestureTrail(PointerTracker tracker) { public void showGestureTrail(PointerTracker tracker) {
// TDOD: Add user settings option to control drawing gesture trail. // TDOD: Add user settings option to control drawing gesture trail.
if (mPreviewPlacer == null) { locatePreviewPlacerView();
createPreviewPlacer(); mPreviewPlacerView.invalidatePointer(tracker);
}
mPreviewPlacer.invalidatePointer(tracker);
} }
@SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16 @SuppressWarnings("deprecation") // setBackgroundDrawable is replaced by setBackground in API16
@ -1051,9 +1049,7 @@ public class KeyboardView extends View implements PointerTracker.DrawingProxy {
protected void onDetachedFromWindow() { protected void onDetachedFromWindow() {
super.onDetachedFromWindow(); super.onDetachedFromWindow();
closing(); closing();
if (mPreviewPlacer != null) { mPreviewPlacerView.removeAllViews();
mPreviewPlacer.removeAllViews();
}
if (mBuffer != null) { if (mBuffer != null) {
mBuffer.recycle(); mBuffer.recycle();
mBuffer = null; mBuffer = null;