SuggestionStripView.java revision 2dae79b1966a7970c25c8b79beec1c95c13f6c87
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; 21c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaokaimport android.content.res.TypedArray; 22c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaokaimport android.graphics.Color; 23c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaokaimport android.graphics.drawable.Drawable; 24bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaokaimport android.support.v4.view.ViewCompat; 256abc852255072e9c5741a7d8f264bec99b0ce14eTadashi G. Takaokaimport android.text.TextUtils; 26923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.util.AttributeSet; 27c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaokaimport android.util.TypedValue; 283fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaokaimport android.view.GestureDetector; 29923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.LayoutInflater; 3029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport android.view.MotionEvent; 31923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.view.View; 32e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaokaimport android.view.View.OnClickListener; 33ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaokaimport android.view.View.OnLongClickListener; 34e26ef1bccddc942fdaeada3409c8e8ff18a35008Tadashi G. Takaokaimport android.view.ViewGroup; 359ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaokaimport android.view.ViewParent; 36a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaokaimport android.view.accessibility.AccessibilityEvent; 37c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaokaimport android.widget.ImageButton; 38c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaokaimport android.widget.RelativeLayout; 39923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Projectimport android.widget.TextView; 40923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 417339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaokaimport com.android.inputmethod.keyboard.Keyboard; 42d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MainKeyboardView; 4329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaokaimport com.android.inputmethod.keyboard.MoreKeysPanel; 446f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaokaimport com.android.inputmethod.latin.AudioAndHapticFeedbackManager; 455faf41951929301af80026bc3191812ef874fd5aTadashi G. Takaokaimport com.android.inputmethod.latin.Constants; 468c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.R; 478c3d5b6961a9b9d40c4bf21ad495f852971c24f4Tadashi G. Takaokaimport com.android.inputmethod.latin.SuggestedWords; 489310f42a36eabe99ed7dcd3b835d6cdaa3c6fdcaJean Chalardimport com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; 492dae79b1966a7970c25c8b79beec1c95c13f6c87Tadashi G. Takaokaimport com.android.inputmethod.latin.define.DebugFlags; 50ce78a2d8ab7630cff509c2b21b4b11abd8db4795Tadashi G. Takaokaimport com.android.inputmethod.latin.settings.Settings; 51aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaokaimport com.android.inputmethod.latin.settings.SettingsValues; 5201748cde4e692c970617e4478368f83b710a86b6Tadashi G. Takaokaimport com.android.inputmethod.latin.suggestions.MoreSuggestionsView.MoreSuggestionsListener; 538dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaokaimport com.android.inputmethod.latin.utils.ImportantNoticeUtils; 54ddb61ea461b920d87be4ad78c8a36eec1013b965Tadashi G. Takaoka 55179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaokaimport java.util.ArrayList; 56179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka 57a28a05e971cc242b338331a3b78276fa95188d19Tadashi G. Takaokapublic final class SuggestionStripView extends RelativeLayout implements OnClickListener, 58c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka OnLongClickListener { 59c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka public interface Listener { 6018d688c94bb8e1e26de2d12445cb3096c6126f75Jean Chalard public void addWordToUserDictionary(String word); 618a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka public void showImportantNoticeContents(); 6235c37dbef8a65cc1e199a60090d1b4e60da69fe6Jean Chalard public void pickSuggestionManually(SuggestedWordInfo word); 63c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka public void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat); 64c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka } 65c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka 662dae79b1966a7970c25c8b79beec1c95c13f6c87Tadashi G. Takaoka static final boolean DBG = DebugFlags.DEBUG_ENABLED; 67c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f; 686f7218627eda110a8454053f8ecb7b80edfdc8cesatok 69913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka private final ViewGroup mSuggestionsStrip; 70c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka private final ImageButton mVoiceKey; 71148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final ViewGroup mAddToDictionaryStrip; 728a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka private final View mImportantNoticeStrip; 73d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka MainKeyboardView mMainKeyboardView; 7474b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 7529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final View mMoreSuggestionsContainer; 7629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreSuggestionsView mMoreSuggestionsView; 7729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreSuggestions.Builder mMoreSuggestionsBuilder; 7829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 79a91561aa58db1c43092c1caecc051a11fa5391c7Tadashi G. Takaoka private final ArrayList<TextView> mWordViews = new ArrayList<>(); 80a91561aa58db1c43092c1caecc051a11fa5391c7Tadashi G. Takaoka private final ArrayList<TextView> mDebugInfoViews = new ArrayList<>(); 81a91561aa58db1c43092c1caecc051a11fa5391c7Tadashi G. Takaoka private final ArrayList<View> mDividerViews = new ArrayList<>(); 8274b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 833e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka Listener mListener; 846f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY; 854f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka private int mSuggestionsCountInStrip; 866a6075caba3865383eeeb52cccc63a28e4ae5900Amith Yamasani 87653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka private final SuggestionStripLayoutHelper mLayoutHelper; 88148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final StripVisibilityGroup mStripVisibilityGroup; 89148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 90148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private static class StripVisibilityGroup { 91630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka private final View mSuggestionStripView; 92148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final View mSuggestionsStrip; 93148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka private final View mAddToDictionaryStrip; 948a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka private final View mImportantNoticeStrip; 95148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 96630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka public StripVisibilityGroup(final View suggestionStripView, 97aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka final ViewGroup suggestionsStrip, final ViewGroup addToDictionaryStrip, 98aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka final View importantNoticeStrip) { 99630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka mSuggestionStripView = suggestionStripView; 100148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip = suggestionsStrip; 101148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip = addToDictionaryStrip; 1028a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip = importantNoticeStrip; 103aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka showSuggestionsStrip(); 104148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 105148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 106630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka public void setLayoutDirection(final boolean isRtlLanguage) { 107630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL 108630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka : ViewCompat.LAYOUT_DIRECTION_LTR; 109630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka ViewCompat.setLayoutDirection(mSuggestionStripView, layoutDirection); 110bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection); 111bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection); 1128a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection); 113bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka } 114bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka 115aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka public void showSuggestionsStrip() { 116148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip.setVisibility(VISIBLE); 117148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setVisibility(INVISIBLE); 1188a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(INVISIBLE); 119148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 120148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 121148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka public void showAddToDictionaryStrip() { 122148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mSuggestionsStrip.setVisibility(INVISIBLE); 123148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setVisibility(VISIBLE); 1248a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(INVISIBLE); 1258a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 1268a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka 127aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka public void showImportantNoticeStrip() { 1288a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mSuggestionsStrip.setVisibility(INVISIBLE); 1298a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mAddToDictionaryStrip.setVisibility(INVISIBLE); 1308a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setVisibility(VISIBLE); 131148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 132148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 133148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka public boolean isShowingAddToDictionaryStrip() { 134148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return mAddToDictionaryStrip.getVisibility() == VISIBLE; 135148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 136148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 13774b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 138923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project /** 1394702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka * Construct a {@link SuggestionStripView} for showing suggestions to be picked by the user. 140923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param context 141923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param attrs 142923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */ 1433e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public SuggestionStripView(final Context context, final AttributeSet attrs) { 1444702671ea4feb0c79a879e2e3013afdd6ed800b1Tadashi G. Takaoka this(context, attrs, R.attr.suggestionStripViewStyle); 14508a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka } 14608a6f2aea71d998206c47c16dcda4eaa90f8c9eaTadashi G. Takaoka 1473e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public SuggestionStripView(final Context context, final AttributeSet attrs, 1483e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka final int defStyle) { 149c412309b7a32308b1b0a175dafc13f90254353c5Tadashi G. Takaoka super(context, attrs, defStyle); 150923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 15116713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka final LayoutInflater inflater = LayoutInflater.from(context); 152913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka inflater.inflate(R.layout.suggestions_strip, this); 15386e815a142c8aa13213151e381a8a24ef23073d3Tadashi G. Takaoka 154913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip); 155c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key); 156148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip); 1578a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip = findViewById(R.id.important_notice_strip); 158aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip, 159c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka mAddToDictionaryStrip, mImportantNoticeStrip); 160148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka 161a1ed211c4e80eb81ce399e0eaff88bbdf1e3199fJean Chalard for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { 162c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); 1632442e779857e7eda253aadcb1c4dff5ccb3e53f4Tadashi G. Takaoka word.setOnClickListener(this); 164ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka word.setOnLongClickListener(this); 165500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mWordViews.add(word); 166913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka final View divider = inflater.inflate(R.layout.suggestion_divider, null); 167500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mDividerViews.add(divider); 168c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka final TextView info = new TextView(context, null, R.attr.suggestionWordStyle); 169c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka info.setTextColor(Color.WHITE); 170c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP); 171c2ea3f7dd95e7e9dccc61ac2ef9b56b1db8e5b48Tadashi G. Takaoka mDebugInfoViews.add(info); 172c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka } 173179ada958b0bb46c6b9c8eb8b220d84dd3db855aTadashi G. Takaoka 174653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka mLayoutHelper = new SuggestionStripLayoutHelper( 175500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews); 17629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 17729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null); 17829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer 17929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka .findViewById(R.id.more_suggestions_view); 18008ae0d5ca03ed455827e82222df249d1cafb5d71Tadashi G. Takaoka mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView); 181bfc1d732ac92fa1bd5b19ad9e7c71ce9a1f9dc00Tadashi G. Takaoka 18250e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka final Resources res = context.getResources(); 18350e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset( 1842fa3693c264a4c150ac307d9bb7f6f8f18cc4ffcKen Wakasa R.dimen.config_more_suggestions_modal_tolerance); 1853fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka mMoreSuggestionsSlidingDetector = new GestureDetector( 1863fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka context, mMoreSuggestionsSlidingListener); 187c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka 188c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs, 189c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka R.styleable.Keyboard, defStyle, R.style.SuggestionStripView); 190c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey); 191c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka keyboardAttr.recycle(); 192c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka mVoiceKey.setImageDrawable(iconVoice); 193c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka mVoiceKey.setOnClickListener(this); 194923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 195c9716b28ce438e06b5cacc07fc002944bcbe24a0Tadashi G. Takaoka 196923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project /** 197c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka * A connection back to the input method. 198923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project * @param listener 199923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project */ 2003e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public void setListener(final Listener listener, final View inputView) { 201c97810693dfe83bf37c09f73c8d4b40f2ba8dddbTadashi G. Takaoka mListener = listener; 202d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view); 203923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 204923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 205aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka public void updateVisibility(final boolean shouldBeVisible, final boolean isFullscreenMode) { 206aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka final int visibility = shouldBeVisible ? VISIBLE : (isFullscreenMode ? GONE : INVISIBLE); 207aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka setVisibility(visibility); 208aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka final SettingsValues currentSettingsValues = Settings.getInstance().getCurrent(); 209987bff9136ec101d06db7903ebb3f505e4ea78d6Tadashi G. Takaoka mVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : INVISIBLE); 210c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka } 211c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka 212bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747Tadashi G. Takaoka public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { 213e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka clear(); 214630a24141eeb80063648bc1bc4678439117321d2Tadashi G. Takaoka mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); 215e79b1a83126b41e09a8ec0a8dbb751ae0e02c7f6Tadashi G. Takaoka mSuggestedWords = suggestedWords; 2164f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip( 2174f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka mSuggestedWords, mSuggestionsStrip, this); 218aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka mStripVisibilityGroup.showSuggestionsStrip(); 21916713e5630b93fb5625df26745eb73271f189457Tadashi G. Takaoka } 22074b6897a12ec603ef835aaa77a01f0c32f49aa1cTadashi G. Takaoka 221c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa public int setMoreSuggestionsHeight(final int remainingHeight) { 222c160a3932f74fea72c5347798c001d4ae961864cKen Wakasa return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight); 223c8b0e5797e20d3fa25d319a9709aabc9149f8ff9Tadashi G. Takaoka } 224b47319867ef3834a222865b8cb6abe62962e70f7Tadashi G. Takaoka 225b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani public boolean isShowingAddToDictionaryHint() { 226148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return mStripVisibilityGroup.isShowingAddToDictionaryStrip(); 227b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani } 228b00a1d0c0adbdfc507676772201e979e539a2801Amith Yamasani 2299b1a66843ddde552ea626a7b24c2c71ba23aa63aTadashi G. Takaoka public void showAddToDictionaryHint(final String word) { 2302b479cccaeb0bb54121730cb5e47cca3f7517c67Tadashi G. Takaoka mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip); 231148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word 232148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // will be extracted at {@link #onClick(View)}. 233148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setTag(word); 234148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mAddToDictionaryStrip.setOnClickListener(this); 235148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mStripVisibilityGroup.showAddToDictionaryStrip(); 23666a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani } 23766a787b953d703201c6b827abbee74e8cd9bb063Amith Yamasani 2386558253160e2039c87f424bd814f402ecd31de3bKen Wakasa public boolean dismissAddToDictionaryHint() { 239c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka if (isShowingAddToDictionaryHint()) { 240c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka clear(); 241c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka return true; 242c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka } 243c04bbc1ae9be81d25a356407c27a8e7fa22028bfTadashi G. Takaoka return false; 2446558253160e2039c87f424bd814f402ecd31de3bKen Wakasa } 2456558253160e2039c87f424bd814f402ecd31de3bKen Wakasa 2468dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // This method checks if we should show the important notice (checks on permanent storage if 2478dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // it has been shown once already or not, and if in the setup wizard). If applicable, it shows 2488dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // the notice. In all cases, it returns true if it was shown, false otherwise. 249987bff9136ec101d06db7903ebb3f505e4ea78d6Tadashi G. Takaoka public boolean maybeShowImportantNoticeTitle() { 250987bff9136ec101d06db7903ebb3f505e4ea78d6Tadashi G. Takaoka if (!ImportantNoticeUtils.shouldShowImportantNotice(getContext())) { 2518dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka return false; 2528dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka } 25314e908c3486ae5996e66625e959ff45c5f3740efTadashi G. Takaoka if (getWidth() <= 0) { 254affdd364232549d2062fc180f924f5b6496c26fdTadashi G. Takaoka return false; 255affdd364232549d2062fc180f924f5b6496c26fdTadashi G. Takaoka } 2561672ccbbb6167f434842093feaadc2bcd5634eabTadashi G. Takaoka final String importantNoticeTitle = ImportantNoticeUtils.getNextImportantNoticeTitle( 2576abc852255072e9c5741a7d8f264bec99b0ce14eTadashi G. Takaoka getContext()); 2586abc852255072e9c5741a7d8f264bec99b0ce14eTadashi G. Takaoka if (TextUtils.isEmpty(importantNoticeTitle)) { 2596abc852255072e9c5741a7d8f264bec99b0ce14eTadashi G. Takaoka return false; 2606abc852255072e9c5741a7d8f264bec99b0ce14eTadashi G. Takaoka } 261c8abd13c77ed90b209301ea379e1142e0d60e3f5Tadashi G. Takaoka if (isShowingMoreSuggestionPanel()) { 262c8abd13c77ed90b209301ea379e1142e0d60e3f5Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 263c8abd13c77ed90b209301ea379e1142e0d60e3f5Tadashi G. Takaoka } 26414e908c3486ae5996e66625e959ff45c5f3740efTadashi G. Takaoka mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, importantNoticeTitle); 265aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka mStripVisibilityGroup.showImportantNoticeStrip(); 2668a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mImportantNoticeStrip.setOnClickListener(this); 2678dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka return true; 2688a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 2698a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka 270923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project public void clear() { 271913e2aeef26f172d500a4ebfc644b5f47778841aTadashi G. Takaoka mSuggestionsStrip.removeAllViews(); 2729ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka removeAllDebugInfoViews(); 273aa4b2c71270576f25e7c80a4b63a1956cec5f4e2Tadashi G. Takaoka mStripVisibilityGroup.showSuggestionsStrip(); 27419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 275923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 276923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project 2779ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka private void removeAllDebugInfoViews() { 2789ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka // The debug info views may be placed as children views of this {@link SuggestionStripView}. 2799ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka for (final View debugInfoView : mDebugInfoViews) { 2809ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka final ViewParent parent = debugInfoView.getParent(); 2819ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka if (parent instanceof ViewGroup) { 2829ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka ((ViewGroup)parent).removeView(debugInfoView); 2839ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2849ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2859ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka } 2869ac6c9064d24a3a0e96db470bb76c997c51bb5c8Tadashi G. Takaoka 2876f7905ae757c30ac0f8080f025b88afc61a6f6b1Tadashi G. Takaoka private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() { 28829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 28935c37dbef8a65cc1e199a60090d1b4e60da69fe6Jean Chalard public void onSuggestionSelected(final SuggestedWordInfo wordInfo) { 29035c37dbef8a65cc1e199a60090d1b4e60da69fe6Jean Chalard mListener.pickSuggestionManually(wordInfo); 29119dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 29229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 29329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 29429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 29529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka public void onCancelInput() { 29619dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 29729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 29829e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka }; 29929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 30029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka private final MoreKeysPanel.Controller mMoreSuggestionsController = 30129e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka new MoreKeysPanel.Controller() { 30229e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 3031f215a58c99f0eb2f536e9cccd51371f2883e201Tadashi G. Takaoka public void onDismissMoreKeysPanel() { 3041f215a58c99f0eb2f536e9cccd51371f2883e201Tadashi G. Takaoka mMainKeyboardView.onDismissMoreKeysPanel(); 305fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang } 306fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang 307fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang @Override 308a729377395967f7652d93992cbcf50cd2ff522d1Tadashi G. Takaoka public void onShowMoreKeysPanel(final MoreKeysPanel panel) { 309d9449ccf3ce9e5eabb022aed6a45bba680bce115Tadashi G. Takaoka mMainKeyboardView.onShowMoreKeysPanel(panel); 31029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 311ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang 312ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang @Override 3131f215a58c99f0eb2f536e9cccd51371f2883e201Tadashi G. Takaoka public void onCancelMoreKeysPanel() { 31419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 315ac69ab400d1ea4f90b4ca24486d62212decf1069Tom Ouyang } 31629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka }; 31729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 31819dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka public boolean isShowingMoreSuggestionPanel() { 31919dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka return mMoreSuggestionsView.isShowingInParent(); 32019dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka } 32119dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka 32219dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka public void dismissMoreSuggestionsPanel() { 32319dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka mMoreSuggestionsView.dismissMoreKeysPanel(); 32419dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka } 32519dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka 326e49bd1c43acad08f103b38430a8bbcba23f325b3Tadashi G. Takaoka @Override 3273e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public boolean onLongClick(final View view) { 328ab16237e69061bb0aa7f882e48e5d93459c22ef3Tadashi G. Takaoka AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( 3296f9105383a56c9ae15e35d3abf19c33d1efe5636Tadashi G. Takaoka Constants.NOT_A_CODE, this); 3303fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return showMoreSuggestions(); 3313fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3323fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka 3333e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka boolean showMoreSuggestions() { 33456e0373b5c0c516cd57352cebf882e2b358f168cTadashi G. Takaoka final Keyboard parentKeyboard = mMainKeyboardView.getKeyboard(); 3357339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka if (parentKeyboard == null) { 3367339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return false; 337ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka } 338653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka final SuggestionStripLayoutHelper layoutHelper = mLayoutHelper; 339653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka if (!layoutHelper.mMoreSuggestionsAvailable) { 3407339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return false; 3417339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka } 34256e0373b5c0c516cd57352cebf882e2b358f168cTadashi G. Takaoka // Dismiss another {@link MoreKeysPanel} that may be being showed, for example 34356e0373b5c0c516cd57352cebf882e2b358f168cTadashi G. Takaoka // {@link MoreKeysKeyboardView}. 3441f215a58c99f0eb2f536e9cccd51371f2883e201Tadashi G. Takaoka mMainKeyboardView.onDismissMoreKeysPanel(); 345ddc21f5bd1113c24840fd436d09de62c8e476335Tadashi G. Takaoka // Dismiss all key previews and sliding key input preview that may be being showed. 346ddc21f5bd1113c24840fd436d09de62c8e476335Tadashi G. Takaoka mMainKeyboardView.dismissAllKeyPreviews(); 347ddc21f5bd1113c24840fd436d09de62c8e476335Tadashi G. Takaoka mMainKeyboardView.dismissSlidingKeyInputPreview(); 3487339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int stripWidth = getWidth(); 3497339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final View container = mMoreSuggestionsContainer; 3507339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight(); 3517339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder; 3524f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka builder.layout(mSuggestedWords, mSuggestionsCountInStrip, maxWidth, 353653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka (int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth), 354653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard); 3557339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mMoreSuggestionsView.setKeyboard(builder.build()); 3567339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 3577339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka 3587339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final MoreKeysPanel moreKeysPanel = mMoreSuggestionsView; 3597339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka final int pointX = stripWidth / 2; 360653603b7253d96c7fad674ed301de5bc8050b68cTadashi G. Takaoka final int pointY = -layoutHelper.mMoreSuggestionsBottomGap; 3617339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka moreKeysPanel.showMoreKeysPanel(this, mMoreSuggestionsController, pointX, pointY, 362fa2d543785c52f639ad3157c57420f58a199c550Tom Ouyang mMoreSuggestionsListener); 3637339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mOriginX = mLastX; 3647339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka mOriginY = mLastY; 3654f8a8f125e329b55e49d31a98b5368113440c755Tadashi G. Takaoka for (int i = 0; i < mSuggestionsCountInStrip; i++) { 366500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka mWordViews.get(i).setPressed(false); 3677339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka } 3687339a62a1368b632c0cedaf1d876a0e8590a47edTadashi G. Takaoka return true; 369ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka } 370ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka 371e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // Working variables for {@link #onLongClick(View)} and 372e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // {@link onInterceptTouchEvent(MotionEvent)}. 37350e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mLastX; 37450e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mLastY; 37550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mOriginX; 37650e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private int mOriginY; 37750e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka private final int mMoreSuggestionsModalTolerance; 3783fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka private final GestureDetector mMoreSuggestionsSlidingDetector; 3793fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka private final GestureDetector.OnGestureListener mMoreSuggestionsSlidingListener = 3803fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka new GestureDetector.SimpleOnGestureListener() { 3813fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka @Override 3823fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka public boolean onScroll(MotionEvent down, MotionEvent me, float deltaX, float deltaY) { 3833fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka final float dy = me.getY() - down.getY(); 3843fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka if (deltaY > 0 && dy < 0) { 3853fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return showMoreSuggestions(); 3863fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3873fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka return false; 3883fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka } 3893fc4ddec68b4f56f53ed6da80b5e44f38c085740Tadashi G. Takaoka }; 39050e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka 391ae5c736e37973e26b201d45ff6c139862a6e05cfTadashi G. Takaoka @Override 392e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka public boolean onInterceptTouchEvent(final MotionEvent me) { 39351c38a441a09a4920703e765cb26179e7a80f029Tadashi G. Takaoka if (!mMoreSuggestionsView.isShowingInParent()) { 39450e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mLastX = (int)me.getX(); 39550e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka mLastY = (int)me.getY(); 396e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka return mMoreSuggestionsSlidingDetector.onTouchEvent(me); 39729e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 3988ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka 39929e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka final int action = me.getAction(); 40029e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka final int index = me.getActionIndex(); 4018ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka final int x = (int)me.getX(index); 4028ac6d505b7ceab020a4085b3dfbea5b47362b030Tadashi G. Takaoka final int y = (int)me.getY(index); 403e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance 404e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka || mOriginY - y >= mMoreSuggestionsModalTolerance) { 405e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // Decided to be in the sliding input mode only when the touch point has been moved 406e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // upward. Further {@link MotionEvent}s will be delivered to 407e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // {@link #onTouchEvent(MotionEvent)}. 40850e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka return true; 40950e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka } 41050e1073e11240fe51b3baf0e2ed80dac0d9f001dTadashi G. Takaoka 411e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) { 412e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // Decided to be in the modal input mode. 413e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka mMoreSuggestionsView.adjustVerticalCorrectionForModalMode(); 414e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka } 415e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka return false; 416e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka } 417e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka 418e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka @Override 419a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka public boolean dispatchPopulateAccessibilityEvent(final AccessibilityEvent event) { 420a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka // Don't populate accessibility event with suggested words and voice key. 421a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka return true; 422a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka } 423a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka 424a2e365da0acf80c1bcd8413d72f697a0da374779Tadashi G. Takaoka @Override 425e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka public boolean onTouchEvent(final MotionEvent me) { 426e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // In the sliding input mode. {@link MotionEvent} should be forwarded to 427e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka // {@link MoreSuggestionsView}. 428e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka final int index = me.getActionIndex(); 429e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka final int x = (int)me.getX(index); 430e32548f32d32bc2fbf07ccd373bc55ece80388ceTadashi G. Takaoka final int y = (int)me.getY(index); 43133482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka me.setLocation(mMoreSuggestionsView.translateX(x), mMoreSuggestionsView.translateY(y)); 43233482a9b9ccf605c63fab7c9b8273a240bbc2035Tadashi G. Takaoka mMoreSuggestionsView.onTouchEvent(me); 43329e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka return true; 43429e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka } 43529e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka 43629e7b7ed6ef88c3e10cc6469801fef87241c9cb5Tadashi G. Takaoka @Override 4373e5a3c18bebbfb56012383411b24ee81ffde09cbTadashi G. Takaoka public void onClick(final View view) { 438874a600dc805b6ab9fe92fccddfe4765b8d29a35Tadashi G. Takaoka AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback( 439874a600dc805b6ab9fe92fccddfe4765b8d29a35Tadashi G. Takaoka Constants.CODE_UNSPECIFIED, this); 4408a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka if (view == mImportantNoticeStrip) { 4418a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka mListener.showImportantNoticeContents(); 4428a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka return; 4438a296e43c903a3377f28943ba4a59082ae7fe60aTadashi G. Takaoka } 444c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka if (view == mVoiceKey) { 445c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka mListener.onCodeInput(Constants.CODE_SHORTCUT, 446c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE, 447c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka false /* isKeyRepeat */); 448c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka return; 449c41d261b7e1e626aaa4e333c9c4cc73ec13cb68aTadashi G. Takaoka } 450148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final Object tag = view.getTag(); 451148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}. 452148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (tag instanceof String) { 453148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final String wordToSave = (String)tag; 454148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka mListener.addWordToUserDictionary(wordToSave); 455717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka clear(); 456717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka return; 457717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka } 458717a8f50aec421f74e4d43432059c2fb41cb32c7Tadashi G. Takaoka 459148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka // {@link Integer} tag is set at 4609b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka // {@link SuggestionStripLayoutHelper#setupWordViewsTextAndColor(SuggestedWords,int)} and 4619b570b5e62581f41c40c4558d95c77ad5896934cTadashi G. Takaoka // {@link SuggestionStripLayoutHelper#layoutPunctuationSuggestions(SuggestedWords,ViewGroup} 462148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (tag instanceof Integer) { 463148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final int index = (Integer) tag; 464148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka if (index >= mSuggestedWords.size()) { 465148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka return; 466148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka } 467148dedbc5dfa22d6db30b28ae9ede139206af429Tadashi G. Takaoka final SuggestedWordInfo wordInfo = mSuggestedWords.getInfo(index); 46835c37dbef8a65cc1e199a60090d1b4e60da69fe6Jean Chalard mListener.pickSuggestionManually(wordInfo); 469500a9752b1e61885f37b0fb26f09dfdd65da4e5eTadashi G. Takaoka } 470923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project } 47182411d47ba7e8133ed2390c6920945e139a738cesatok 4726ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani @Override 47373cd4c1428ac370e1c15c5f61b1ce499f0d4f4c7Tadashi G. Takaoka protected void onDetachedFromWindow() { 4746ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani super.onDetachedFromWindow(); 47519dd753c0ccaea8dee71eeae7edc724c58c6f024Tadashi G. Takaoka dismissMoreSuggestionsPanel(); 4766ec55a1599c74150e82ea7e4371ec815f0d2df27Amith Yamasani } 4778dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka 4788dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka @Override 479affdd364232549d2062fc180f924f5b6496c26fdTadashi G. Takaoka protected void onSizeChanged(final int w, final int h, final int oldw, final int oldh) { 4808dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // Called by the framework when the size is known. Show the important notice if applicable. 4818dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka // This may be overriden by showing suggestions later, if applicable. 482affdd364232549d2062fc180f924f5b6496c26fdTadashi G. Takaoka if (oldw <= 0 && w > 0) { 483987bff9136ec101d06db7903ebb3f505e4ea78d6Tadashi G. Takaoka maybeShowImportantNoticeTitle(); 484affdd364232549d2062fc180f924f5b6496c26fdTadashi G. Takaoka } 4858dda9e480b6519ca57565c8aa507e14bff739b60Tadashi G. Takaoka } 486923bf41f853a544fd0d71fbf7dc90359ec35981The Android Open Source Project} 487