SuggestionStripView.java revision ce78a2d8ab7630cff509c2b21b4b11abd8db4795
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; 21c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaokaimport android.graphics.Color; 22bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaokaimport android.support.v4.view.ViewCompat; 23923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.util.AttributeSet; 24c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaokaimport android.util.TypedValue; 253fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaokaimport android.view.GestureDetector; 26923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.LayoutInflater; 2729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport android.view.MotionEvent; 28923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.View; 29e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaokaimport android.view.View.OnClickListener; 30ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaokaimport android.view.View.OnLongClickListener; 31e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaokaimport android.view.ViewGroup; 329ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaokaimport android.view.ViewParent; 33c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaokaimport android.widget.RelativeLayout; 34923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.widget.TextView; 35923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 367339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaokaimport com.android.inputmethod.keyboard.Keyboard; 377339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaokaimport com.android.inputmethod.keyboard.KeyboardSwitcher; 38d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MainKeyboardView; 3929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MoreKeysPanel; 406f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaokaimport com.android.inputmethod.latin.AudioAndHapticFeedbackManager; 415faf41951929301af80026bc3191812ef874fd5aTadashi G. Takaokaimport com.android.inputmethod.latin.Constants; 42ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaokaimport com.android.inputmethod.latin.InputAttributes; 438c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.LatinImeLogger; 448c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.R; 458c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.SuggestedWords; 469310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalardimport com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; 47a9ca7867b5a7c0be115966211a05f5d460c8638cKurt Partridgeimport com.android.inputmethod.latin.define.ProductionFlag; 48ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaokaimport com.android.inputmethod.latin.settings.Settings; 496f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaokaimport com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener; 50e28eba5074664d5716b8e58b8d0a235746b261ebKen Wakasaimport com.android.inputmethod.latin.utils.CollectionUtils; 518dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaokaimport com.android.inputmethod.latin.utils.ImportantNoticeUtils; 526b966160ac8570271547bf63217efa5e228d4accKurt Partridgeimport com.android.inputmethod.research.ResearchLogger; 53ddb61ea461b920d87be4ad78c8a36eec1013b965Tadashi G. Takaoka 54179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaokaimport java.util.ArrayList; 55179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka 56a28a05e971cc242b338331a3b78276fa95188d19Tadashi G. Takaokapublic final class SuggestionStripView extends RelativeLayout implements OnClickListener, 57c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka OnLongClickListener { 58c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka public interface Listener { 5918d688c94bb8e1e26de2d12445cb3096c6126f75Jean Chalard public void addWordToUserDictionary(String word); 608a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka public void showImportantNoticeContents(); 619310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalard public void pickSuggestionManually(int index, SuggestedWordInfo word); 62c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka } 63c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka 648c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaoka static final boolean DBG = LatinImeLogger.sDBG; 65c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f; 666f7218627eda110a8454053f8ecb7b80edfdc8cesatok 67913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka private final ViewGroup mSuggestionsStrip; 68148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final ViewGroup mAddToDictionaryStrip; 698a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka private final View mImportantNoticeStrip; 70d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka MainKeyboardView mMainKeyboardView; 7174b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 7229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final View mMoreSuggestionsContainer; 7329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreSuggestionsView mMoreSuggestionsView; 7429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreSuggestions.Builder mMoreSuggestionsBuilder; 7529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 76500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka private final ArrayList<TextView> mWordViews = CollectionUtils.newArrayList(); 77500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka private final ArrayList<TextView> mDebugInfoViews = CollectionUtils.newArrayList(); 78500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka private final ArrayList<View> mDividerViews = CollectionUtils.newArrayList(); 7974b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 803e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka Listener mListener; 816f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; 824f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka private int mSuggestionsCountInStrip; 836a6075caba3865383eeeb52cccc63a28e4ae5900Amith Yamasani 84653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka private final SuggestionStripLayoutHelper mLayoutHelper; 85148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final StripVisibilityGroup mStripVisibilityGroup; 86148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 87148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private static class StripVisibilityGroup { 88148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final View mSuggestionsStrip; 89148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final View mAddToDictionaryStrip; 908a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka private final View mImportantNoticeStrip; 91148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 928a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka public StripVisibilityGroup(final View suggestionsStrip, final View addToDictionaryStrip, 938a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka final View importantNoticeStrip) { 94148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip = suggestionsStrip; 95148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip = addToDictionaryStrip; 968a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip = importantNoticeStrip; 97148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka showSuggestionsStrip(); 98148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 99148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 100bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka public void setLayoutDirection(final boolean isRtlLanguage) { 101bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL 102bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka : ViewCompat.LAYOUT_DIRECTION_LTR; 103bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection); 104bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection); 1058a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection); 106bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka } 107bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka 108148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka public void showSuggestionsStrip() { 109148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip.setVisibility(VISIBLE); 110148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setVisibility(INVISIBLE); 1118a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(INVISIBLE); 112148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 113148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 114148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka public void showAddToDictionaryStrip() { 115148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip.setVisibility(INVISIBLE); 116148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setVisibility(VISIBLE); 1178a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(INVISIBLE); 1188a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 1198a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka 1208a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka public void showImportantNoticeStrip() { 1218a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mSuggestionsStrip.setVisibility(INVISIBLE); 1228a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mAddToDictionaryStrip.setVisibility(INVISIBLE); 1238a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(VISIBLE); 124148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 125148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 126148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka public boolean isShowingAddToDictionaryStrip() { 127148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return mAddToDictionaryStrip.getVisibility() == VISIBLE; 128148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 129148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 13074b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 131923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project /** 1324702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka * Construct a {@link SuggestionStripView} for showing suggestions to be picked by the user. 133923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param context 134923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param attrs 135923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */ 1363e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public SuggestionStripView(final Context context, final AttributeSet attrs) { 1374702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka this(context, attrs, R.attr.suggestionStripViewStyle); 13808a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka } 13908a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka 1403e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public SuggestionStripView(final Context context, final AttributeSet attrs, 1413e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka final int defStyle) { 142c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka super(context, attrs, defStyle); 143923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 14416713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka final LayoutInflater inflater = LayoutInflater.from(context); 145913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka inflater.inflate(R.layout.suggestions_strip, this); 14686e815a142c8aa13213151e381a8a24ef23073d3Tadashi G. Takaoka 147913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip); 148148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip); 1498a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip = findViewById(R.id.important_notice_strip); 1508a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mAddToDictionaryStrip, 1518a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip); 152148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 153a1ed211c4e80eb81ce399e0eaff88bbdf1e3199fJean Chalard for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { 154c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); 1552442e779857e7eda253aadcb1c4dff5ccb3e53f4Tadashi G. Takaoka word.setOnClickListener(this); 156ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka word.setOnLongClickListener(this); 157500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mWordViews.add(word); 158913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka final View divider = inflater.inflate(R.layout.suggestion_divider, null); 159a1aab83a24e74cb0fad4b1c1e59b18d23ecbdad3Tadashi G. Takaoka divider.setOnClickListener(this); 160500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mDividerViews.add(divider); 161c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka final TextView info = new TextView(context, null, R.attr.suggestionWordStyle); 162c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka info.setTextColor(Color.WHITE); 163c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP); 164c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka mDebugInfoViews.add(info); 165c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka } 166179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka 167653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka mLayoutHelper = new SuggestionStripLayoutHelper( 168500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews); 16929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 17029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null); 17129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer 17229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka .findViewById(R.id.more_suggestions_view); 17308ae0d5ca03ed455827e82222df249d1cafb5d71Tadashi G. Takaoka mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView); 174bfc1d732ac92fa1bd5b19ad9e7c71ce9a1f9dc00Tadashi G. Takaoka 17550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka final Resources res = context.getResources(); 17650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset( 1772fa3693c264a4c150ac307d9bb7f6f8f18cc4ffcKen Wakasa R.dimen.config_more_suggestions_modal_tolerance); 1783fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka mMoreSuggestionsSlidingDetector = new GestureDetector( 1793fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka context, mMoreSuggestionsSlidingListener); 180923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 181c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka 182923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project /** 183c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka * A connection back to the input method. 184923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param listener 185923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */ 1863e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public void setListener(final Listener listener, final View inputView) { 187c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka mListener = listener; 188d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view); 189923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 190923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 191bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { 192e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka clear(); 193bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); 194e79b1a83126b41e09a8ec0a8dbb751ae0e02c7f6Tadashi G. Takaoka mSuggestedWords = suggestedWords; 1954f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip( 1964f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka mSuggestedWords, mSuggestionsStrip, this); 1979c3860ce461c3791891bf667edc77fe798c8d332Ken Wakasa if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { 1984702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords); 199a9ca7867b5a7c0be115966211a05f5d460c8638cKurt Partridge } 2008a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mStripVisibilityGroup.showSuggestionsStrip(); 20116713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka } 20274b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 203c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa public int setMoreSuggestionsHeight(final int remainingHeight) { 204c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight); 205c8b0e5797e20d3fa25d319a9709aabc9149f8ff9Tadashi G. Takaoka } 206b47319867ef3834a222865b8cb6abe62962e70f7Tadashi G. Takaoka 207b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani public boolean isShowingAddToDictionaryHint() { 208148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return mStripVisibilityGroup.isShowingAddToDictionaryStrip(); 209b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani } 210b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani 2119b1a66843ddde552ea626a7b24c2c71ba23aa63aTadashi G. Takaoka public void showAddToDictionaryHint(final String word) { 2129b1a66843ddde552ea626a7b24c2c71ba23aa63aTadashi G. Takaoka mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth()); 213148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word 214148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // will be extracted at {@link #onClick(View)}. 215148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setTag(word); 216148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setOnClickListener(this); 217148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mStripVisibilityGroup.showAddToDictionaryStrip(); 21866a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani } 21966a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani 2206558253160e2039c87f424bd814f402ecd31de3bKen Wakasa public boolean dismissAddToDictionaryHint() { 221c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka if (isShowingAddToDictionaryHint()) { 222c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka clear(); 223c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka return true; 224c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka } 225c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka return false; 2266558253160e2039c87f424bd814f402ecd31de3bKen Wakasa } 2276558253160e2039c87f424bd814f402ecd31de3bKen Wakasa 2288dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // This method checks if we should show the important notice (checks on permanent storage if 2298dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // it has been shown once already or not, and if in the setup wizard). If applicable, it shows 2308dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // the notice. In all cases, it returns true if it was shown, false otherwise. 231ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaoka public boolean maybeShowImportantNoticeTitle(final InputAttributes inputAttributes) { 232ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaoka if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext(), inputAttributes)) { 2338dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka return false; 2348dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka } 2358dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka final int width = getWidth(); 2368dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka if (width <= 0) return false; 2378dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width); 2388a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mStripVisibilityGroup.showImportantNoticeStrip(); 2398a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setOnClickListener(this); 2408dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka return true; 2418a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 2428a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka 243923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project public void clear() { 244913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka mSuggestionsStrip.removeAllViews(); 2459ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka removeAllDebugInfoViews(); 246148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mStripVisibilityGroup.showSuggestionsStrip(); 24719dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 248923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 249923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 2509ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka private void removeAllDebugInfoViews() { 2519ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka // The debug info views may be placed as children views of this {@link SuggestionStripView}. 2529ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka for (final View debugInfoView : mDebugInfoViews) { 2539ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka final ViewParent parent = debugInfoView.getParent(); 2549ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka if (parent instanceof ViewGroup) { 2559ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka ((ViewGroup)parent).removeView(debugInfoView); 2569ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2579ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2589ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2599ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka 2606f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() { 26129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 2626f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) { 2639310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalard mListener.pickSuggestionManually(index, wordInfo); 26419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 26529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 26629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 26729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 26829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka public void onCancelInput() { 26919dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 27029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 27129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka }; 27229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 27329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreKeysPanel.Controller mMoreSuggestionsController = 27429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka new MoreKeysPanel.Controller() { 27529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 2760e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka public void onDismissMoreKeysPanel(final MoreKeysPanel panel) { 2770e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka mMainKeyboardView.onDismissMoreKeysPanel(panel); 278fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang } 279fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang 280fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang @Override 281a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka public void onShowMoreKeysPanel(final MoreKeysPanel panel) { 282d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMainKeyboardView.onShowMoreKeysPanel(panel); 28329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 284ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang 285ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang @Override 2860e08d70fe52737582b6c83dbf48aaf4d83063566Tadashi G. Takaoka public void onCancelMoreKeysPanel(final MoreKeysPanel panel) { 28719dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 288ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang } 28929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka }; 29029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 29119dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka public boolean isShowingMoreSuggestionPanel() { 29219dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka return mMoreSuggestionsView.isShowingInParent(); 29319dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka } 29419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka 29519dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka public void dismissMoreSuggestionsPanel() { 29619dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka mMoreSuggestionsView.dismissMoreKeysPanel(); 29719dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka } 29819dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka 299e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka @Override 3003e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public boolean onLongClick(final View view) { 301ab16237e69061bb0aa7f882e48e5d93459c22ef3Tadashi G. Takaoka AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( 3026f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaoka Constants.NOT_A_CODE, this); 3033fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return showMoreSuggestions(); 3043fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3053fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka 3063e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka boolean showMoreSuggestions() { 3077339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final Keyboard parentKeyboard = KeyboardSwitcher.getInstance().getKeyboard(); 3087339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka if (parentKeyboard == null) { 3097339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return false; 310ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka } 311653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka final SuggestionStripLayoutHelper layoutHelper = mLayoutHelper; 312653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka if (!layoutHelper.mMoreSuggestionsAvailable) { 3137339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return false; 3147339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka } 3157339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int stripWidth = getWidth(); 3167339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final View container = mMoreSuggestionsContainer; 3177339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight(); 3187339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; 3194f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka builder.layout(mSuggestedWords, mSuggestionsCountInStrip, maxWidth, 320653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka (int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth), 321653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard); 3227339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mMoreSuggestionsView.setKeyboard(builder.build()); 3237339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 3247339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka 3257339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final MoreKeysPanel moreKeysPanel = mMoreSuggestionsView; 3267339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int pointX = stripWidth / 2; 327653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka final int pointY = -layoutHelper.mMoreSuggestionsBottomGap; 3287339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka moreKeysPanel.showMoreKeysPanel(this, mMoreSuggestionsController, pointX, pointY, 329fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang mMoreSuggestionsListener); 3307339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING; 3317339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mOriginX = mLastX; 3327339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mOriginY = mLastY; 3334f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka for (int i = 0; i < mSuggestionsCountInStrip; i++) { 334500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mWordViews.get(i).setPressed(false); 3357339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka } 3367339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return true; 337ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka } 338ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka 33950e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka // Working variables for onLongClick and dispatchTouchEvent. 340d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE; 341d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0; 342d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1; 343d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2; 34450e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mLastX; 34550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mLastY; 34650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mOriginX; 34750e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mOriginY; 34850e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private final int mMoreSuggestionsModalTolerance; 3493fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka private final GestureDetector mMoreSuggestionsSlidingDetector; 3503fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka private final GestureDetector.OnGestureListener mMoreSuggestionsSlidingListener = 3513fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka new GestureDetector.SimpleOnGestureListener() { 3523fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka @Override 3533fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka public boolean onScroll(MotionEvent down, MotionEvent me, float deltaX, float deltaY) { 3543fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka final float dy = me.getY() - down.getY(); 3553fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka if (deltaY > 0 && dy < 0) { 3563fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return showMoreSuggestions(); 3573fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3583fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return false; 3593fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3603fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka }; 36150e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka 362ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka @Override 3633e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public boolean dispatchTouchEvent(final MotionEvent me) { 36451c38a441a09a4920703e765cb26179e7a80f029Tadashi G. Takaoka if (!mMoreSuggestionsView.isShowingInParent()) { 36550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mLastX = (int)me.getX(); 36650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mLastY = (int)me.getY(); 3673fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka if (mMoreSuggestionsSlidingDetector.onTouchEvent(me)) { 3683fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return true; 3693fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 37029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka return super.dispatchTouchEvent(me); 37129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 3728ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka 37329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka final int action = me.getAction(); 37429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka final int index = me.getActionIndex(); 3758ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka final int x = (int)me.getX(index); 3768ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka final int y = (int)me.getY(index); 3778ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka 378d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) { 37987104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance 38087104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka || mOriginY - y >= mMoreSuggestionsModalTolerance) { 38187104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka // Decided to be in the sliding input mode only when the touch point has been moved 38287104bace9cb9ed1a700f05a37743a21c2722fffTadashi G. Takaoka // upward. 383d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE; 38450e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { 38550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka // Decided to be in the modal input mode 386d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE; 38751c38a441a09a4920703e765cb26179e7a80f029Tadashi G. Takaoka mMoreSuggestionsView.adjustVerticalCorrectionForModalMode(); 38850e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka } 38950e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka return true; 39050e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka } 39150e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka 392d7b00f34904c61f955e439160e2dbaa3a4b6983cTadashi G. Takaoka // MORE_SUGGESTIONS_IN_SLIDING_MODE 39333482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka me.setLocation(mMoreSuggestionsView.translateX(x), mMoreSuggestionsView.translateY(y)); 39433482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka mMoreSuggestionsView.onTouchEvent(me); 39529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka return true; 39629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 39729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 39829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 3993e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public void onClick(final View view) { 4008a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka if (view == mImportantNoticeStrip) { 4018a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mListener.showImportantNoticeContents(); 4028a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka return; 4038a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 404148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final Object tag = view.getTag(); 405148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}. 406148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (tag instanceof String) { 407148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final String wordToSave = (String)tag; 408148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mListener.addWordToUserDictionary(wordToSave); 409717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka clear(); 410717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka return; 411717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka } 412717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka 413148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link Integer} tag is set at 4149b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka // {@link SuggestionStripLayoutHelper#setupWordViewsTextAndColor(SuggestedWords,int)} and 4159b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka // {@link SuggestionStripLayoutHelper#layoutPunctuationSuggestions(SuggestedWords,ViewGroup} 416148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (tag instanceof Integer) { 417148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final int index = (Integer) tag; 418148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (index >= mSuggestedWords.size()) { 419148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return; 420148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 421148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final SuggestedWordInfo wordInfo = mSuggestedWords.getInfo(index); 422148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mListener.pickSuggestionManually(index, wordInfo); 423500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka } 424923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 42582411d47ba7e8133ed2390c6920945e139a738cesatok 4266ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani @Override 42773cd4c1428ac370e1c15c5f61b1ce499f0d4f4c7Tadashi G. Takaoka protected void onDetachedFromWindow() { 4286ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani super.onDetachedFromWindow(); 42919dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 4306ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani } 4318dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka 4328dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka @Override 4338dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka protected void onSizeChanged(int w, int h, int oldw, int oldh) { 4348dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // Called by the framework when the size is known. Show the important notice if applicable. 4358dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // This may be overriden by showing suggestions later, if applicable. 436ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaoka maybeShowImportantNoticeTitle(Settings.getInstance().getCurrent().mInputAttributes); 4378dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka } 438923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project} 439