SuggestionStripView.java revision bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747
1923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project/*
2913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka * Copyright (C) 2011 The Android Open Source Project
3e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka *
48aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * Licensed under the Apache License, Version 2.0 (the "License");
58aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * you may not use this file except in compliance with the License.
68aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * You may obtain a copy of the License at
7e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka *
88aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka *      http://www.apache.org/licenses/LICENSE-2.0
9e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka *
10923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * Unless required by applicable law or agreed to in writing, software
118aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * distributed under the License is distributed on an "AS IS" BASIS,
128aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
138aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * See the License for the specific language governing permissions and
148aa9963a895f9dd5bb1bc92ab2e4f461e058f87aTadashi G. Takaoka * limitations under the License.
15923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */
16923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
178c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokapackage com.android.inputmethod.latin.suggestions;
18923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
19923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.content.Context;
2066a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasaniimport android.content.res.Resources;
21bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaokaimport android.support.v4.view.ViewCompat;
22923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.util.AttributeSet;
233fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaokaimport android.view.GestureDetector;
24923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.LayoutInflater;
2529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport android.view.MotionEvent;
26923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.View;
27e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaokaimport android.view.View.OnClickListener;
28ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaokaimport android.view.View.OnLongClickListener;
29e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaokaimport android.view.ViewGroup;
309ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaokaimport android.view.ViewParent;
31c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaokaimport android.widget.RelativeLayout;
32923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.widget.TextView;
33923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
347339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaokaimport com.android.inputmethod.keyboard.Keyboard;
357339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaokaimport com.android.inputmethod.keyboard.KeyboardSwitcher;
36d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MainKeyboardView;
3729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MoreKeysPanel;
386f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaokaimport com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
395faf41951929301af80026bc3191812ef874fd5aTadashi G. Takaokaimport com.android.inputmethod.latin.Constants;
408c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinImeLogger;
418c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.R;
428c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.SuggestedWords;
439310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalardimport com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
44a9ca7867b5a7c0be115966211a05f5d460c8638cKurt Partridgeimport com.android.inputmethod.latin.define.ProductionFlag;
456f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaokaimport com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
46e28eba5074664d5716b8e58b8d0a235746b261ebKen Wakasaimport com.android.inputmethod.latin.utils.CollectionUtils;
476b966160ac8570271547bf63217efa5e228d4accKurt Partridgeimport com.android.inputmethod.research.ResearchLogger;
48ddb61ea461b920d87be4ad78c8a36eec1013b965Tadashi G. Takaoka
49179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaokaimport java.util.ArrayList;
50179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka
51a28a05e971cc242b338331a3b78276fa95188d19Tadashi G. Takaokapublic final class SuggestionStripView extends RelativeLayout implements OnClickListener,
52c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka        OnLongClickListener {
53c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka    public interface Listener {
5418d688c94bb8e1e26de2d12445cb3096c6126f75Jean Chalard        public void addWordToUserDictionary(String word);
559310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalard        public void pickSuggestionManually(int index, SuggestedWordInfo word);
56c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka    }
57c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka
588c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaoka    static final boolean DBG = LatinImeLogger.sDBG;
596f7218627eda110a8454053f8ecb7b80edfdc8cesatok
60913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka    private final ViewGroup mSuggestionsStrip;
61148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka    private final ViewGroup mAddToDictionaryStrip;
62d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka    MainKeyboardView mMainKeyboardView;
6374b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka
6429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    private final View mMoreSuggestionsContainer;
6529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    private final MoreSuggestionsView mMoreSuggestionsView;
6629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    private final MoreSuggestions.Builder mMoreSuggestionsBuilder;
6729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
68500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka    private final ArrayList<TextView> mWordViews = CollectionUtils.newArrayList();
69500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka    private final ArrayList<TextView> mDebugInfoViews = CollectionUtils.newArrayList();
70500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka    private final ArrayList<View> mDividerViews = CollectionUtils.newArrayList();
7174b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka
723e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    Listener mListener;
736f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka    private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
746a6075caba3865383eeeb52cccc63a28e4ae5900Amith Yamasani
75653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka    private final SuggestionStripLayoutHelper mLayoutHelper;
76148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka    private final StripVisibilityGroup mStripVisibilityGroup;
77148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
78148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka    private static class StripVisibilityGroup {
79148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        private final View mSuggestionsStrip;
80148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        private final View mAddToDictionaryStrip;
81148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
82148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        public StripVisibilityGroup(final View suggestionsStrip, final View addToDictionaryStrip) {
83148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mSuggestionsStrip = suggestionsStrip;
84148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mAddToDictionaryStrip = addToDictionaryStrip;
85148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            showSuggestionsStrip();
86148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        }
87148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
88bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka        public void setLayoutDirection(final boolean isRtlLanguage) {
89bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka            final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
90bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka                    : ViewCompat.LAYOUT_DIRECTION_LTR;
91bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka            ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
92bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka            ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection);
93bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka        }
94bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka
95148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        public void showSuggestionsStrip() {
96148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mSuggestionsStrip.setVisibility(VISIBLE);
97148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mAddToDictionaryStrip.setVisibility(INVISIBLE);
98148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        }
99148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
100148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        public void showAddToDictionaryStrip() {
101148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mSuggestionsStrip.setVisibility(INVISIBLE);
102148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mAddToDictionaryStrip.setVisibility(VISIBLE);
103148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        }
104148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
105148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        public boolean isShowingAddToDictionaryStrip() {
106148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            return mAddToDictionaryStrip.getVisibility() == VISIBLE;
107148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        }
108148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka    }
10974b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka
110923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    /**
1114702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka     * Construct a {@link SuggestionStripView} for showing suggestions to be picked by the user.
112923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project     * @param context
113923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project     * @param attrs
114923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project     */
1153e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public SuggestionStripView(final Context context, final AttributeSet attrs) {
1164702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka        this(context, attrs, R.attr.suggestionStripViewStyle);
11708a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka    }
11808a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka
1193e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public SuggestionStripView(final Context context, final AttributeSet attrs,
1203e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka            final int defStyle) {
121c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka        super(context, attrs, defStyle);
122923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
12316713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka        final LayoutInflater inflater = LayoutInflater.from(context);
124913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka        inflater.inflate(R.layout.suggestions_strip, this);
12586e815a142c8aa13213151e381a8a24ef23073d3Tadashi G. Takaoka
126913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka        mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
127148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip);
128148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mAddToDictionaryStrip);
129148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka
130a1ed211c4e80eb81ce399e0eaff88bbdf1e3199fJean Chalard        for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
131913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka            final TextView word = (TextView)inflater.inflate(R.layout.suggestion_word, null);
1322442e779857e7eda253aadcb1c4dff5ccb3e53f4Tadashi G. Takaoka            word.setOnClickListener(this);
133ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka            word.setOnLongClickListener(this);
134500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka            mWordViews.add(word);
135913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka            final View divider = inflater.inflate(R.layout.suggestion_divider, null);
136a1aab83a24e74cb0fad4b1c1e59b18d23ecbdad3Tadashi G. Takaoka            divider.setOnClickListener(this);
137500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka            mDividerViews.add(divider);
138500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka            mDebugInfoViews.add((TextView)inflater.inflate(R.layout.suggestion_info, null));
139c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka        }
140179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka
141653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        mLayoutHelper = new SuggestionStripLayoutHelper(
142500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka                context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews);
14329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
14429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
14529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
14629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka                .findViewById(R.id.more_suggestions_view);
14708ae0d5ca03ed455827e82222df249d1cafb5d71Tadashi G. Takaoka        mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);
148bfc1d732ac92fa1bd5b19ad9e7c71ce9a1f9dc00Tadashi G. Takaoka
14950e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka        final Resources res = context.getResources();
15050e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka        mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
1512fa3693c264a4c150ac307d9bb7f6f8f18cc4ffcKen Wakasa                R.dimen.config_more_suggestions_modal_tolerance);
1523fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka        mMoreSuggestionsSlidingDetector = new GestureDetector(
1533fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka                context, mMoreSuggestionsSlidingListener);
154923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    }
155c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka
156923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    /**
157c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka     * A connection back to the input method.
158923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project     * @param listener
159923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project     */
1603e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public void setListener(final Listener listener, final View inputView) {
161c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka        mListener = listener;
162d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka        mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view);
163923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    }
164923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
165bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka    public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
166e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka        clear();
167bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka        mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
168e79b1a83126b41e09a8ec0a8dbb751ae0e02c7f6Tadashi G. Takaoka        mSuggestedWords = suggestedWords;
169500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka        mLayoutHelper.layout(mSuggestedWords, mSuggestionsStrip, this);
1709c3860ce461c3791891bf667edc77fe798c8d332Ken Wakasa        if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
1714702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka            ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords);
172a9ca7867b5a7c0be115966211a05f5d460c8638cKurt Partridge        }
17316713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka    }
17474b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka
175c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa    public int setMoreSuggestionsHeight(final int remainingHeight) {
176c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa        return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight);
177c8b0e5797e20d3fa25d319a9709aabc9149f8ff9Tadashi G. Takaoka    }
178b47319867ef3834a222865b8cb6abe62962e70f7Tadashi G. Takaoka
179b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani    public boolean isShowingAddToDictionaryHint() {
180148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        return mStripVisibilityGroup.isShowingAddToDictionaryStrip();
181b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani    }
182b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani
183bc464e2952e102219f0b977fc1e9140ad5bd03e4Tadashi G. Takaoka    public void showAddToDictionaryHint(final String word, final CharSequence hintText) {
184148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth(), hintText);
185148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word
186148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        // will be extracted at {@link #onClick(View)}.
187148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mAddToDictionaryStrip.setTag(word);
188148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mAddToDictionaryStrip.setOnClickListener(this);
189148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mStripVisibilityGroup.showAddToDictionaryStrip();
19066a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani    }
19166a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani
1926558253160e2039c87f424bd814f402ecd31de3bKen Wakasa    public boolean dismissAddToDictionaryHint() {
193c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka        if (isShowingAddToDictionaryHint()) {
194c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka            clear();
195c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka            return true;
196c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka        }
197c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka        return false;
1986558253160e2039c87f424bd814f402ecd31de3bKen Wakasa    }
1996558253160e2039c87f424bd814f402ecd31de3bKen Wakasa
200923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    public void clear() {
201913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka        mSuggestionsStrip.removeAllViews();
2029ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka        removeAllDebugInfoViews();
203148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        mStripVisibilityGroup.showSuggestionsStrip();
20419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka        dismissMoreSuggestionsPanel();
205923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    }
206923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project
2079ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka    private void removeAllDebugInfoViews() {
2089ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka        // The debug info views may be placed as children views of this {@link SuggestionStripView}.
2099ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka        for (final View debugInfoView : mDebugInfoViews) {
2109ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka            final ViewParent parent = debugInfoView.getParent();
2119ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka            if (parent instanceof ViewGroup) {
2129ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka                ((ViewGroup)parent).removeView(debugInfoView);
2139ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka            }
2149ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka        }
2159ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka    }
2169ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka
2176f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka    private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() {
21829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        @Override
2196f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka        public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) {
2209310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalard            mListener.pickSuggestionManually(index, wordInfo);
22119dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka            dismissMoreSuggestionsPanel();
22229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        }
22329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
22429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        @Override
22529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        public void onCancelInput() {
22619dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka            dismissMoreSuggestionsPanel();
22729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        }
22829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    };
22929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
23029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    private final MoreKeysPanel.Controller mMoreSuggestionsController =
23129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka            new MoreKeysPanel.Controller() {
23229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        @Override
2330e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka        public void onDismissMoreKeysPanel(final MoreKeysPanel panel) {
2340e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka            mMainKeyboardView.onDismissMoreKeysPanel(panel);
235fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang        }
236fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang
237fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang        @Override
238a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka        public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
239d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka            mMainKeyboardView.onShowMoreKeysPanel(panel);
24029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        }
241ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang
242ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang        @Override
2430e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka        public void onCancelMoreKeysPanel(final MoreKeysPanel panel) {
24419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka            dismissMoreSuggestionsPanel();
245ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang        }
24629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    };
24729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
24819dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka    public boolean isShowingMoreSuggestionPanel() {
24919dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka        return mMoreSuggestionsView.isShowingInParent();
25019dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka    }
25119dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka
25219dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka    public void dismissMoreSuggestionsPanel() {
25319dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka        mMoreSuggestionsView.dismissMoreKeysPanel();
25419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka    }
25519dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka
256e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka    @Override
2573e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public boolean onLongClick(final View view) {
258ab16237e69061bb0aa7f882e48e5d93459c22ef3Tadashi G. Takaoka        AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
2596f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaoka                Constants.NOT_A_CODE, this);
2603fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka        return showMoreSuggestions();
2613fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka    }
2623fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka
2633e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    boolean showMoreSuggestions() {
2647339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final Keyboard parentKeyboard = KeyboardSwitcher.getInstance().getKeyboard();
2657339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        if (parentKeyboard == null) {
2667339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka            return false;
267ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka        }
268653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        final SuggestionStripLayoutHelper layoutHelper = mLayoutHelper;
269653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        if (!layoutHelper.mMoreSuggestionsAvailable) {
2707339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka            return false;
2717339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        }
2727339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final int stripWidth = getWidth();
2737339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final View container = mMoreSuggestionsContainer;
2747339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight();
2757339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
276653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        builder.layout(mSuggestedWords, layoutHelper.mSuggestionsCountInStrip, maxWidth,
277653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka                (int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth),
278653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka                layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard);
2797339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        mMoreSuggestionsView.setKeyboard(builder.build());
2807339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
2817339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka
2827339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final MoreKeysPanel moreKeysPanel = mMoreSuggestionsView;
2837339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        final int pointX = stripWidth / 2;
284653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        final int pointY = -layoutHelper.mMoreSuggestionsBottomGap;
2857339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        moreKeysPanel.showMoreKeysPanel(this, mMoreSuggestionsController, pointX, pointY,
286fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang                mMoreSuggestionsListener);
2877339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
2887339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        mOriginX = mLastX;
2897339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        mOriginY = mLastY;
290653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka        for (int i = 0; i < layoutHelper.mSuggestionsCountInStrip; i++) {
291500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka            mWordViews.get(i).setPressed(false);
2927339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        }
2937339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka        return true;
294ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka    }
295ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka
29650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    // Working variables for onLongClick and dispatchTouchEvent.
297d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka    private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
298d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka    private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0;
299d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka    private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1;
300d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka    private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2;
30150e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    private int mLastX;
30250e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    private int mLastY;
30350e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    private int mOriginX;
30450e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    private int mOriginY;
30550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka    private final int mMoreSuggestionsModalTolerance;
3063fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka    private final GestureDetector mMoreSuggestionsSlidingDetector;
3073fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka    private final GestureDetector.OnGestureListener mMoreSuggestionsSlidingListener =
3083fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            new GestureDetector.SimpleOnGestureListener() {
3093fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka        @Override
3103fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka        public boolean onScroll(MotionEvent down, MotionEvent me, float deltaX, float deltaY) {
3113fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            final float dy = me.getY() - down.getY();
3123fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            if (deltaY > 0 && dy < 0) {
3133fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka                return showMoreSuggestions();
3143fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            }
3153fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            return false;
3163fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka        }
3173fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka    };
31850e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka
319ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka    @Override
3203e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public boolean dispatchTouchEvent(final MotionEvent me) {
32151c38a441a09a4920703e765cb26179e7a80f029Tadashi G. Takaoka        if (!mMoreSuggestionsView.isShowingInParent()) {
32250e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka            mLastX = (int)me.getX();
32350e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka            mLastY = (int)me.getY();
3243fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            if (mMoreSuggestionsSlidingDetector.onTouchEvent(me)) {
3253fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka                return true;
3263fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka            }
32729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka            return super.dispatchTouchEvent(me);
32829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        }
3298ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka
33029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        final int action = me.getAction();
33129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        final int index = me.getActionIndex();
3328ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka        final int x = (int)me.getX(index);
3338ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka        final int y = (int)me.getY(index);
3348ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka
335d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka        if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) {
33687104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka            if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance
33787104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka                    || mOriginY - y >= mMoreSuggestionsModalTolerance) {
33887104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka                // Decided to be in the sliding input mode only when the touch point has been moved
33987104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka                // upward.
340d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka                mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE;
34150e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka            } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
34250e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka                // Decided to be in the modal input mode
343d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka                mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
34451c38a441a09a4920703e765cb26179e7a80f029Tadashi G. Takaoka                mMoreSuggestionsView.adjustVerticalCorrectionForModalMode();
34550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka            }
34650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka            return true;
34750e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka        }
34850e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka
349d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka        // MORE_SUGGESTIONS_IN_SLIDING_MODE
35033482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka        me.setLocation(mMoreSuggestionsView.translateX(x), mMoreSuggestionsView.translateY(y));
35133482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka        mMoreSuggestionsView.onTouchEvent(me);
35229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka        return true;
35329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    }
35429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka
35529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka    @Override
3563e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka    public void onClick(final View view) {
357148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        final Object tag = view.getTag();
358148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}.
359148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        if (tag instanceof String) {
360148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            final String wordToSave = (String)tag;
361148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mListener.addWordToUserDictionary(wordToSave);
362717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka            clear();
363717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka            return;
364717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka        }
365717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka
366148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        // {@link Integer} tag is set at
3679b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka        // {@link SuggestionStripLayoutHelper#setupWordViewsTextAndColor(SuggestedWords,int)} and
3689b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka        // {@link SuggestionStripLayoutHelper#layoutPunctuationSuggestions(SuggestedWords,ViewGroup}
369148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka        if (tag instanceof Integer) {
370148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            final int index = (Integer) tag;
371148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            if (index >= mSuggestedWords.size()) {
372148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka                return;
373148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            }
374148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            final SuggestedWordInfo wordInfo = mSuggestedWords.getInfo(index);
375148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka            mListener.pickSuggestionManually(index, wordInfo);
376500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka        }
377923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project    }
37882411d47ba7e8133ed2390c6920945e139a738cesatok
3796ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani    @Override
38073cd4c1428ac370e1c15c5f61b1ce499f0d4f4c7Tadashi G. Takaoka    protected void onDetachedFromWindow() {
3816ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani        super.onDetachedFromWindow();
38219dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka        dismissMoreSuggestionsPanel();
3836ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani    }
384923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project}
385