From c82e99caa0ef01f7d997d0b22052c644d3b85e20 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 28 Nov 2013 18:45:39 +0900 Subject: [PATCH] Move MainKeyboardView.DrawingHandler to top level class Change-Id: I7a785725d5eb0b594485ceb25695a89c017cc60f --- .../keyboard/MainKeyboardView.java | 50 ++------------ .../MainKeyboardViewDrawingHandler.java | 66 +++++++++++++++++++ 2 files changed, 71 insertions(+), 45 deletions(-) create mode 100644 java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 0fe245561..9110ba802 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -57,6 +57,7 @@ import com.android.inputmethod.keyboard.internal.GestureFloatingPreviewText; import com.android.inputmethod.keyboard.internal.GestureTrailsPreview; import com.android.inputmethod.keyboard.internal.KeyDrawParams; import com.android.inputmethod.keyboard.internal.KeyPreviewDrawParams; +import com.android.inputmethod.keyboard.internal.MainKeyboardViewDrawingHandler; import com.android.inputmethod.keyboard.internal.NonDistinctMultitouchHelper; import com.android.inputmethod.keyboard.internal.PreviewPlacerView; import com.android.inputmethod.keyboard.internal.SlidingKeyInputPreview; @@ -387,49 +388,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack } } - private final DrawingHandler mDrawingHandler = new DrawingHandler(this); - - public static class DrawingHandler extends StaticInnerHandlerWrapper { - private static final int MSG_DISMISS_KEY_PREVIEW = 0; - private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; - - public DrawingHandler(final MainKeyboardView outerInstance) { - super(outerInstance); - } - - @Override - public void handleMessage(final Message msg) { - final MainKeyboardView mainKeyboardView = getOuterInstance(); - if (mainKeyboardView == null) return; - switch (msg.what) { - case MSG_DISMISS_KEY_PREVIEW: - mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); - break; - case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: - mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY); - break; - } - } - - public void dismissKeyPreview(final long delay, final Key key) { - sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, key), delay); - } - - private void cancelAllDismissKeyPreviews() { - removeMessages(MSG_DISMISS_KEY_PREVIEW); - final MainKeyboardView mainKeyboardView = getOuterInstance(); - if (mainKeyboardView == null) return; - mainKeyboardView.dismissAllKeyPreviews(); - } - - public void dismissGestureFloatingPreviewText(final long delay) { - sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay); - } - - public void cancelAllMessages() { - cancelAllDismissKeyPreviews(); - } - } + private final MainKeyboardViewDrawingHandler mDrawingHandler = + new MainKeyboardViewDrawingHandler(this); public MainKeyboardView(final Context context, final AttributeSet attrs) { this(context, attrs, R.attr.mainKeyboardViewStyle); @@ -721,7 +681,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return previewTextView; } - private void dismissAllKeyPreviews() { + public void dismissAllKeyPreviews() { for (final Key key : new HashSet(mShowingKeyPreviewTextViews.keySet())) { dismissKeyPreviewWithoutDelay(key); } @@ -915,7 +875,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack } // TODO: Take this method out of this class. - private void dismissKeyPreviewWithoutDelay(final Key key) { + public void dismissKeyPreviewWithoutDelay(final Key key) { if (key == null) { return; } diff --git a/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java b/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java new file mode 100644 index 000000000..53845534e --- /dev/null +++ b/java/src/com/android/inputmethod/keyboard/internal/MainKeyboardViewDrawingHandler.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.inputmethod.keyboard.internal; + +import android.os.Message; + +import com.android.inputmethod.keyboard.Key; +import com.android.inputmethod.keyboard.MainKeyboardView; +import com.android.inputmethod.latin.SuggestedWords; +import com.android.inputmethod.latin.utils.StaticInnerHandlerWrapper; + +public class MainKeyboardViewDrawingHandler extends StaticInnerHandlerWrapper { + private static final int MSG_DISMISS_KEY_PREVIEW = 0; + private static final int MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT = 1; + + public MainKeyboardViewDrawingHandler(final MainKeyboardView outerInstance) { + super(outerInstance); + } + + @Override + public void handleMessage(final Message msg) { + final MainKeyboardView mainKeyboardView = getOuterInstance(); + if (mainKeyboardView == null) return; + switch (msg.what) { + case MSG_DISMISS_KEY_PREVIEW: + mainKeyboardView.dismissKeyPreviewWithoutDelay((Key)msg.obj); + break; + case MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT: + mainKeyboardView.showGestureFloatingPreviewText(SuggestedWords.EMPTY); + break; + } + } + + public void dismissKeyPreview(final long delay, final Key key) { + sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, key), delay); + } + + private void cancelAllDismissKeyPreviews() { + removeMessages(MSG_DISMISS_KEY_PREVIEW); + final MainKeyboardView mainKeyboardView = getOuterInstance(); + if (mainKeyboardView == null) return; + mainKeyboardView.dismissAllKeyPreviews(); + } + + public void dismissGestureFloatingPreviewText(final long delay) { + sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay); + } + + public void cancelAllMessages() { + cancelAllDismissKeyPreviews(); + } +}