diff options
Diffstat (limited to 'java/src')
4 files changed, 59 insertions, 14 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 71e3eeeaf..f3cfae203 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -484,11 +484,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack return; } - final TextView previewTextView = mKeyPreviewChoreographer.getKeyPreviewTextView( - key, getContext()); locatePreviewPlacerView(); - mDrawingPreviewPlacerView.addView( - previewTextView, ViewLayoutUtils.newLayoutParam(mDrawingPreviewPlacerView, 0, 0)); + final TextView previewTextView = mKeyPreviewChoreographer.getKeyPreviewTextView( + key, mDrawingPreviewPlacerView); getLocationInWindow(mOriginCoords); mKeyPreviewChoreographer.placeKeyPreview(key, previewTextView, keyboard.mIconsSet, mKeyDrawParams, getWidth(), mOriginCoords); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java index c1922b7c4..df869b2bc 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java @@ -58,7 +58,7 @@ public final class KeyPreviewChoreographer { mParams = params; } - public TextView getKeyPreviewTextView(final Key key, final Context context) { + public TextView getKeyPreviewTextView(final Key key, final ViewGroup placerView) { TextView previewTextView = mShowingKeyPreviewTextViews.remove(key); if (previewTextView != null) { return previewTextView; @@ -67,10 +67,15 @@ public final class KeyPreviewChoreographer { if (previewTextView != null) { return previewTextView; } + final Context context = placerView.getContext(); if (mParams.mLayoutId != 0) { - return (TextView)LayoutInflater.from(context).inflate(mParams.mLayoutId, null); + previewTextView = (TextView)LayoutInflater.from(context) + .inflate(mParams.mLayoutId, null); + } else { + previewTextView = new TextView(context); } - return new TextView(context); + placerView.addView(previewTextView, ViewLayoutUtils.newLayoutParam(placerView, 0, 0)); + return previewTextView; } public boolean isShowingKeyPreview(final Key key) { @@ -244,7 +249,7 @@ public final class KeyPreviewChoreographer { zoomOutAnimation.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(final Animator animation) { - dismissKeyPreview(key, true /* withAnimation */); + dismissKeyPreview(key, false /* withAnimation */); } }); return zoomOutAnimation; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2e163c4be..8d0f4128e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -75,6 +75,7 @@ import com.android.inputmethod.latin.settings.Settings; import com.android.inputmethod.latin.settings.SettingsActivity; import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.suggestions.SuggestionStripView; +import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor; import com.android.inputmethod.latin.utils.ApplicationUtils; import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CompletionInfoUtils; @@ -97,7 +98,7 @@ import java.util.concurrent.TimeUnit; * Input method implementation for Qwerty'ish keyboard. */ public class LatinIME extends InputMethodService implements KeyboardActionListener, - SuggestionStripView.Listener, + SuggestionStripView.Listener, SuggestionStripViewAccessor, DictionaryFacilitatorForSuggest.DictionaryInitializationListener { private static final String TAG = LatinIME.class.getSimpleName(); private static final boolean TRACE = false; @@ -1306,8 +1307,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // TODO[IL]: Move this to InputLogic and make it private - // Outside LatinIME, only used by the test suite. - @UsedForTesting + @Override public boolean isShowingPunctuationList() { if (mInputLogic.mSuggestedWords == null) return false; return mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList @@ -1330,6 +1330,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return currentSettings.isSuggestionsRequested(); } + @Override + public boolean hasSuggestionStripView() { + return null != mSuggestionStripView; + } + + @Override + public boolean isShowingAddToDictionaryHint() { + return hasSuggestionStripView() && mSuggestionStripView.isShowingAddToDictionaryHint(); + } + + @Override public void dismissAddToDictionaryHint() { if (null != mSuggestionStripView) { mSuggestionStripView.dismissAddToDictionaryHint(); @@ -1399,8 +1410,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the "add to dictionary" hint, we need to revert to suggestions - although it is unclear // how we can come here if it's displayed. if (suggestedWords.size() > 1 || typedWord.length() <= 1 - || null == mSuggestionStripView - || mSuggestionStripView.isShowingAddToDictionaryHint()) { + || null == mSuggestionStripView || isShowingAddToDictionaryHint()) { return suggestedWords; } else { final SuggestedWords punctuationList = @@ -1418,7 +1428,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } } - // TODO[IL]: Define a clean interface for this + @Override public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) { final SuggestedWords suggestedWords = sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords; @@ -1539,6 +1549,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // TODO[IL]: Define a clean interface for this // This will show either an empty suggestion strip (if prediction is enabled) or // punctuation suggestions (if it's disabled). + @Override public void setNeutralSuggestionStrip() { final SettingsValues currentSettings = mSettings.getCurrent(); if (currentSettings.mBigramPredictionEnabled) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java new file mode 100644 index 000000000..91bf73d30 --- /dev/null +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripViewAccessor.java @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2014 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.latin.suggestions; + +import com.android.inputmethod.latin.SuggestedWords; + +/** + * An object that gives basic control of a suggestion strip and some info on it. + */ +public interface SuggestionStripViewAccessor { + public boolean hasSuggestionStripView(); + public boolean isShowingAddToDictionaryHint(); + public void dismissAddToDictionaryHint(); + public boolean isShowingPunctuationList(); + public void setNeutralSuggestionStrip(); + public void showSuggestionStrip(final SuggestedWords suggestedWords); +} |