am ade1aa55: [IL107] Add an interface to access the suggestion view.

* commit 'ade1aa55b6be938a44b92f7ca6829c53c6258664':
  [IL107] Add an interface to access the suggestion view.
main
Jean Chalard 2014-02-04 22:01:00 -08:00 committed by Android Git Automerger
commit d1b062f408
2 changed files with 48 additions and 6 deletions

View File

@ -75,6 +75,7 @@ import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.settings.SettingsActivity; import com.android.inputmethod.latin.settings.SettingsActivity;
import com.android.inputmethod.latin.settings.SettingsValues; import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.suggestions.SuggestionStripView; 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.ApplicationUtils;
import com.android.inputmethod.latin.utils.CapsModeUtils; import com.android.inputmethod.latin.utils.CapsModeUtils;
import com.android.inputmethod.latin.utils.CompletionInfoUtils; import com.android.inputmethod.latin.utils.CompletionInfoUtils;
@ -97,7 +98,7 @@ import java.util.concurrent.TimeUnit;
* Input method implementation for Qwerty'ish keyboard. * Input method implementation for Qwerty'ish keyboard.
*/ */
public class LatinIME extends InputMethodService implements KeyboardActionListener, public class LatinIME extends InputMethodService implements KeyboardActionListener,
SuggestionStripView.Listener, SuggestionStripView.Listener, SuggestionStripViewAccessor,
DictionaryFacilitatorForSuggest.DictionaryInitializationListener { DictionaryFacilitatorForSuggest.DictionaryInitializationListener {
private static final String TAG = LatinIME.class.getSimpleName(); private static final String TAG = LatinIME.class.getSimpleName();
private static final boolean TRACE = false; 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 // TODO[IL]: Move this to InputLogic and make it private
// Outside LatinIME, only used by the test suite. @Override
@UsedForTesting
public boolean isShowingPunctuationList() { public boolean isShowingPunctuationList() {
if (mInputLogic.mSuggestedWords == null) return false; if (mInputLogic.mSuggestedWords == null) return false;
return mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList return mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList
@ -1330,6 +1330,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
return currentSettings.isSuggestionsRequested(); return currentSettings.isSuggestionsRequested();
} }
@Override
public boolean hasSuggestionStripView() {
return null != mSuggestionStripView;
}
@Override
public boolean isShowingAddToDictionaryHint() {
return hasSuggestionStripView() && mSuggestionStripView.isShowingAddToDictionaryHint();
}
@Override
public void dismissAddToDictionaryHint() { public void dismissAddToDictionaryHint() {
if (null != mSuggestionStripView) { if (null != mSuggestionStripView) {
mSuggestionStripView.dismissAddToDictionaryHint(); 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 // the "add to dictionary" hint, we need to revert to suggestions - although it is unclear
// how we can come here if it's displayed. // how we can come here if it's displayed.
if (suggestedWords.size() > 1 || typedWord.length() <= 1 if (suggestedWords.size() > 1 || typedWord.length() <= 1
|| null == mSuggestionStripView || null == mSuggestionStripView || isShowingAddToDictionaryHint()) {
|| mSuggestionStripView.isShowingAddToDictionaryHint()) {
return suggestedWords; return suggestedWords;
} else { } else {
final SuggestedWords punctuationList = 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) { public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) {
final SuggestedWords suggestedWords = final SuggestedWords suggestedWords =
sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords; sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
@ -1539,6 +1549,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Define a clean interface for this // TODO[IL]: Define a clean interface for this
// This will show either an empty suggestion strip (if prediction is enabled) or // This will show either an empty suggestion strip (if prediction is enabled) or
// punctuation suggestions (if it's disabled). // punctuation suggestions (if it's disabled).
@Override
public void setNeutralSuggestionStrip() { public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
if (currentSettings.mBigramPredictionEnabled) { if (currentSettings.mBigramPredictionEnabled) {

View File

@ -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);
}