2009-03-13 22:11:42 +00:00
|
|
|
/*
|
2011-09-01 05:54:28 +00:00
|
|
|
* Copyright (C) 2011 The Android Open Source Project
|
2010-12-06 12:26:38 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2010-12-06 12:26:38 +00:00
|
|
|
*
|
2013-01-21 12:52:57 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-12-06 12:26:38 +00:00
|
|
|
*
|
2009-03-13 22:11:42 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
2013-01-21 12:52:57 +00:00
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
2009-03-13 22:11:42 +00:00
|
|
|
*/
|
|
|
|
|
2011-12-16 02:26:14 +00:00
|
|
|
package com.android.inputmethod.latin.suggestions;
|
2009-03-13 22:11:42 +00:00
|
|
|
|
|
|
|
import android.content.Context;
|
2010-02-11 01:45:35 +00:00
|
|
|
import android.content.res.Resources;
|
2014-01-28 10:22:27 +00:00
|
|
|
import android.graphics.Color;
|
2014-01-27 10:04:40 +00:00
|
|
|
import android.support.v4.view.ViewCompat;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.util.AttributeSet;
|
2014-01-28 10:22:27 +00:00
|
|
|
import android.util.TypedValue;
|
2011-09-20 10:17:19 +00:00
|
|
|
import android.view.GestureDetector;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.LayoutInflater;
|
2011-08-24 05:44:46 +00:00
|
|
|
import android.view.MotionEvent;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.view.View;
|
2010-12-06 12:26:38 +00:00
|
|
|
import android.view.View.OnClickListener;
|
2011-08-06 07:45:58 +00:00
|
|
|
import android.view.View.OnLongClickListener;
|
2010-12-10 06:24:28 +00:00
|
|
|
import android.view.ViewGroup;
|
2014-01-28 02:14:09 +00:00
|
|
|
import android.view.ViewParent;
|
2011-09-05 07:15:28 +00:00
|
|
|
import android.widget.RelativeLayout;
|
2009-03-13 22:11:42 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
2012-10-01 05:26:38 +00:00
|
|
|
import com.android.inputmethod.keyboard.Keyboard;
|
|
|
|
import com.android.inputmethod.keyboard.KeyboardSwitcher;
|
2013-01-21 05:41:33 +00:00
|
|
|
import com.android.inputmethod.keyboard.MainKeyboardView;
|
2011-08-24 05:44:46 +00:00
|
|
|
import com.android.inputmethod.keyboard.MoreKeysPanel;
|
2013-05-21 22:32:08 +00:00
|
|
|
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
|
2012-10-15 20:59:35 +00:00
|
|
|
import com.android.inputmethod.latin.Constants;
|
2011-12-16 02:26:14 +00:00
|
|
|
import com.android.inputmethod.latin.LatinImeLogger;
|
|
|
|
import com.android.inputmethod.latin.R;
|
|
|
|
import com.android.inputmethod.latin.SuggestedWords;
|
2013-04-04 08:45:21 +00:00
|
|
|
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
|
2012-04-09 17:53:17 +00:00
|
|
|
import com.android.inputmethod.latin.define.ProductionFlag;
|
2013-05-01 08:02:27 +00:00
|
|
|
import com.android.inputmethod.latin.suggestions.MoreSuggestions.MoreSuggestionsListener;
|
2013-06-23 16:11:32 +00:00
|
|
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
2014-02-03 02:49:34 +00:00
|
|
|
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
|
2012-07-20 18:02:39 +00:00
|
|
|
import com.android.inputmethod.research.ResearchLogger;
|
2011-06-06 08:23:18 +00:00
|
|
|
|
2010-09-29 05:30:01 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2012-09-27 09:16:16 +00:00
|
|
|
public final class SuggestionStripView extends RelativeLayout implements OnClickListener,
|
2011-09-05 07:15:28 +00:00
|
|
|
OnLongClickListener {
|
2011-06-09 05:22:37 +00:00
|
|
|
public interface Listener {
|
2012-12-13 12:59:13 +00:00
|
|
|
public void addWordToUserDictionary(String word);
|
2014-01-28 07:19:29 +00:00
|
|
|
public void showImportantNoticeContents();
|
2013-04-04 08:45:21 +00:00
|
|
|
public void pickSuggestionManually(int index, SuggestedWordInfo word);
|
2011-06-09 05:22:37 +00:00
|
|
|
}
|
|
|
|
|
2011-12-16 02:26:14 +00:00
|
|
|
static final boolean DBG = LatinImeLogger.sDBG;
|
2014-01-28 10:22:27 +00:00
|
|
|
private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f;
|
2011-01-19 08:29:27 +00:00
|
|
|
|
2011-09-01 05:54:28 +00:00
|
|
|
private final ViewGroup mSuggestionsStrip;
|
2014-01-27 05:50:02 +00:00
|
|
|
private final ViewGroup mAddToDictionaryStrip;
|
2014-01-28 07:19:29 +00:00
|
|
|
private final View mImportantNoticeStrip;
|
2013-01-21 05:41:33 +00:00
|
|
|
MainKeyboardView mMainKeyboardView;
|
2011-06-30 01:09:21 +00:00
|
|
|
|
2011-08-24 05:44:46 +00:00
|
|
|
private final View mMoreSuggestionsContainer;
|
|
|
|
private final MoreSuggestionsView mMoreSuggestionsView;
|
|
|
|
private final MoreSuggestions.Builder mMoreSuggestionsBuilder;
|
|
|
|
|
2013-05-30 10:44:26 +00:00
|
|
|
private final ArrayList<TextView> mWordViews = CollectionUtils.newArrayList();
|
|
|
|
private final ArrayList<TextView> mDebugInfoViews = CollectionUtils.newArrayList();
|
|
|
|
private final ArrayList<View> mDividerViews = CollectionUtils.newArrayList();
|
2011-06-30 01:09:21 +00:00
|
|
|
|
2012-10-03 05:46:47 +00:00
|
|
|
Listener mListener;
|
2013-05-01 08:02:27 +00:00
|
|
|
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
2014-02-12 06:22:13 +00:00
|
|
|
private int mSuggestionsCountInStrip;
|
2010-02-03 23:35:49 +00:00
|
|
|
|
2013-05-30 10:31:55 +00:00
|
|
|
private final SuggestionStripLayoutHelper mLayoutHelper;
|
2014-01-27 05:50:02 +00:00
|
|
|
private final StripVisibilityGroup mStripVisibilityGroup;
|
|
|
|
|
|
|
|
private static class StripVisibilityGroup {
|
|
|
|
private final View mSuggestionsStrip;
|
|
|
|
private final View mAddToDictionaryStrip;
|
2014-01-28 07:19:29 +00:00
|
|
|
private final View mImportantNoticeStrip;
|
2014-01-27 05:50:02 +00:00
|
|
|
|
2014-01-28 07:19:29 +00:00
|
|
|
public StripVisibilityGroup(final View suggestionsStrip, final View addToDictionaryStrip,
|
|
|
|
final View importantNoticeStrip) {
|
2014-01-27 05:50:02 +00:00
|
|
|
mSuggestionsStrip = suggestionsStrip;
|
|
|
|
mAddToDictionaryStrip = addToDictionaryStrip;
|
2014-01-28 07:19:29 +00:00
|
|
|
mImportantNoticeStrip = importantNoticeStrip;
|
2014-01-27 05:50:02 +00:00
|
|
|
showSuggestionsStrip();
|
|
|
|
}
|
|
|
|
|
2014-01-27 10:04:40 +00:00
|
|
|
public void setLayoutDirection(final boolean isRtlLanguage) {
|
|
|
|
final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
|
|
|
|
: ViewCompat.LAYOUT_DIRECTION_LTR;
|
|
|
|
ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
|
|
|
|
ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection);
|
2014-01-28 07:19:29 +00:00
|
|
|
ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
|
2014-01-27 10:04:40 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:50:02 +00:00
|
|
|
public void showSuggestionsStrip() {
|
|
|
|
mSuggestionsStrip.setVisibility(VISIBLE);
|
|
|
|
mAddToDictionaryStrip.setVisibility(INVISIBLE);
|
2014-01-28 07:19:29 +00:00
|
|
|
mImportantNoticeStrip.setVisibility(INVISIBLE);
|
2014-01-27 05:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void showAddToDictionaryStrip() {
|
|
|
|
mSuggestionsStrip.setVisibility(INVISIBLE);
|
|
|
|
mAddToDictionaryStrip.setVisibility(VISIBLE);
|
2014-01-28 07:19:29 +00:00
|
|
|
mImportantNoticeStrip.setVisibility(INVISIBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void showImportantNoticeStrip() {
|
|
|
|
mSuggestionsStrip.setVisibility(INVISIBLE);
|
|
|
|
mAddToDictionaryStrip.setVisibility(INVISIBLE);
|
|
|
|
mImportantNoticeStrip.setVisibility(VISIBLE);
|
2014-01-27 05:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isShowingAddToDictionaryStrip() {
|
|
|
|
return mAddToDictionaryStrip.getVisibility() == VISIBLE;
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 01:09:21 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
2012-07-23 06:28:28 +00:00
|
|
|
* Construct a {@link SuggestionStripView} for showing suggestions to be picked by the user.
|
2009-03-13 22:11:42 +00:00
|
|
|
* @param context
|
|
|
|
* @param attrs
|
|
|
|
*/
|
2012-10-03 05:46:47 +00:00
|
|
|
public SuggestionStripView(final Context context, final AttributeSet attrs) {
|
2012-07-23 06:28:28 +00:00
|
|
|
this(context, attrs, R.attr.suggestionStripViewStyle);
|
2011-06-15 02:49:57 +00:00
|
|
|
}
|
|
|
|
|
2012-10-03 05:46:47 +00:00
|
|
|
public SuggestionStripView(final Context context, final AttributeSet attrs,
|
|
|
|
final int defStyle) {
|
2011-09-05 07:15:28 +00:00
|
|
|
super(context, attrs, defStyle);
|
2009-03-13 22:11:42 +00:00
|
|
|
|
2011-08-04 09:18:45 +00:00
|
|
|
final LayoutInflater inflater = LayoutInflater.from(context);
|
2011-09-01 05:54:28 +00:00
|
|
|
inflater.inflate(R.layout.suggestions_strip, this);
|
2011-06-14 07:28:57 +00:00
|
|
|
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
|
2014-01-27 05:50:02 +00:00
|
|
|
mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip);
|
2014-01-28 07:19:29 +00:00
|
|
|
mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
|
|
|
|
mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mAddToDictionaryStrip,
|
|
|
|
mImportantNoticeStrip);
|
2014-01-27 05:50:02 +00:00
|
|
|
|
2014-01-23 04:08:21 +00:00
|
|
|
for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
|
2014-01-28 10:22:27 +00:00
|
|
|
final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
|
2011-06-24 05:19:59 +00:00
|
|
|
word.setOnClickListener(this);
|
2011-08-06 07:45:58 +00:00
|
|
|
word.setOnLongClickListener(this);
|
2013-05-30 10:44:26 +00:00
|
|
|
mWordViews.add(word);
|
2011-09-01 05:54:28 +00:00
|
|
|
final View divider = inflater.inflate(R.layout.suggestion_divider, null);
|
2011-07-28 21:15:24 +00:00
|
|
|
divider.setOnClickListener(this);
|
2013-05-30 10:44:26 +00:00
|
|
|
mDividerViews.add(divider);
|
2014-01-28 10:22:27 +00:00
|
|
|
final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
|
|
|
|
info.setTextColor(Color.WHITE);
|
|
|
|
info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
|
|
|
|
mDebugInfoViews.add(info);
|
2010-09-30 03:10:03 +00:00
|
|
|
}
|
2010-09-29 05:30:01 +00:00
|
|
|
|
2013-05-30 10:31:55 +00:00
|
|
|
mLayoutHelper = new SuggestionStripLayoutHelper(
|
2013-05-30 10:44:26 +00:00
|
|
|
context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews);
|
2011-08-24 05:44:46 +00:00
|
|
|
|
|
|
|
mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
|
|
|
|
mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
|
|
|
|
.findViewById(R.id.more_suggestions_view);
|
2013-04-11 03:08:36 +00:00
|
|
|
mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);
|
2011-09-29 05:11:21 +00:00
|
|
|
|
2011-09-06 02:37:51 +00:00
|
|
|
final Resources res = context.getResources();
|
|
|
|
mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
|
2013-12-13 08:09:16 +00:00
|
|
|
R.dimen.config_more_suggestions_modal_tolerance);
|
2011-09-20 10:17:19 +00:00
|
|
|
mMoreSuggestionsSlidingDetector = new GestureDetector(
|
|
|
|
context, mMoreSuggestionsSlidingListener);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2010-09-30 03:10:03 +00:00
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
/**
|
2011-06-09 05:22:37 +00:00
|
|
|
* A connection back to the input method.
|
2009-03-13 22:11:42 +00:00
|
|
|
* @param listener
|
|
|
|
*/
|
2012-10-03 05:46:47 +00:00
|
|
|
public void setListener(final Listener listener, final View inputView) {
|
2011-06-09 05:22:37 +00:00
|
|
|
mListener = listener;
|
2013-01-21 05:41:33 +00:00
|
|
|
mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view);
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 10:04:40 +00:00
|
|
|
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
|
2010-12-06 12:26:38 +00:00
|
|
|
clear();
|
2014-01-27 10:04:40 +00:00
|
|
|
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
|
2012-03-05 13:08:16 +00:00
|
|
|
mSuggestedWords = suggestedWords;
|
2014-02-12 06:22:13 +00:00
|
|
|
mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip(
|
|
|
|
mSuggestedWords, mSuggestionsStrip, this);
|
2013-03-18 09:21:18 +00:00
|
|
|
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
|
2012-07-23 06:28:28 +00:00
|
|
|
ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords);
|
2012-04-09 17:53:17 +00:00
|
|
|
}
|
2014-01-28 07:19:29 +00:00
|
|
|
mStripVisibilityGroup.showSuggestionsStrip();
|
2011-08-04 09:18:45 +00:00
|
|
|
}
|
2011-06-30 01:09:21 +00:00
|
|
|
|
2013-08-30 07:50:37 +00:00
|
|
|
public int setMoreSuggestionsHeight(final int remainingHeight) {
|
|
|
|
return mLayoutHelper.setMoreSuggestionsHeight(remainingHeight);
|
2012-03-07 06:30:16 +00:00
|
|
|
}
|
2011-06-25 18:00:51 +00:00
|
|
|
|
2010-08-26 19:22:58 +00:00
|
|
|
public boolean isShowingAddToDictionaryHint() {
|
2014-01-27 05:50:02 +00:00
|
|
|
return mStripVisibilityGroup.isShowingAddToDictionaryStrip();
|
2010-08-26 19:22:58 +00:00
|
|
|
}
|
|
|
|
|
2014-01-30 07:52:29 +00:00
|
|
|
public void showAddToDictionaryHint(final String word) {
|
|
|
|
mLayoutHelper.layoutAddToDictionaryHint(word, mAddToDictionaryStrip, getWidth());
|
2014-01-27 05:50:02 +00:00
|
|
|
// {@link TextView#setTag()} is used to hold the word to be added to dictionary. The word
|
|
|
|
// will be extracted at {@link #onClick(View)}.
|
|
|
|
mAddToDictionaryStrip.setTag(word);
|
|
|
|
mAddToDictionaryStrip.setOnClickListener(this);
|
|
|
|
mStripVisibilityGroup.showAddToDictionaryStrip();
|
2010-02-11 01:45:35 +00:00
|
|
|
}
|
|
|
|
|
2010-08-03 18:47:42 +00:00
|
|
|
public boolean dismissAddToDictionaryHint() {
|
2011-08-26 06:13:30 +00:00
|
|
|
if (isShowingAddToDictionaryHint()) {
|
|
|
|
clear();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-08-03 18:47:42 +00:00
|
|
|
}
|
|
|
|
|
2014-02-03 02:49:34 +00:00
|
|
|
// This method checks if we should show the important notice (checks on permanent storage if
|
|
|
|
// it has been shown once already or not, and if in the setup wizard). If applicable, it shows
|
|
|
|
// the notice. In all cases, it returns true if it was shown, false otherwise.
|
|
|
|
public boolean maybeShowImportantNoticeTitle() {
|
2014-02-12 07:52:44 +00:00
|
|
|
if (!ImportantNoticeUtils.hasNewImportantNoticeAndNotInSetupWizard(getContext())) {
|
2014-02-03 02:49:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final int width = getWidth();
|
|
|
|
if (width <= 0) return false;
|
|
|
|
mLayoutHelper.layoutImportantNotice(mImportantNoticeStrip, width);
|
2014-01-28 07:19:29 +00:00
|
|
|
mStripVisibilityGroup.showImportantNoticeStrip();
|
|
|
|
mImportantNoticeStrip.setOnClickListener(this);
|
2014-02-03 02:49:34 +00:00
|
|
|
return true;
|
2014-01-28 07:19:29 +00:00
|
|
|
}
|
|
|
|
|
2009-03-13 22:11:42 +00:00
|
|
|
public void clear() {
|
2011-09-01 05:54:28 +00:00
|
|
|
mSuggestionsStrip.removeAllViews();
|
2014-01-28 02:14:09 +00:00
|
|
|
removeAllDebugInfoViews();
|
2014-01-27 05:50:02 +00:00
|
|
|
mStripVisibilityGroup.showSuggestionsStrip();
|
2013-12-16 09:02:58 +00:00
|
|
|
dismissMoreSuggestionsPanel();
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-28 02:14:09 +00:00
|
|
|
private void removeAllDebugInfoViews() {
|
|
|
|
// The debug info views may be placed as children views of this {@link SuggestionStripView}.
|
|
|
|
for (final View debugInfoView : mDebugInfoViews) {
|
|
|
|
final ViewParent parent = debugInfoView.getParent();
|
|
|
|
if (parent instanceof ViewGroup) {
|
|
|
|
((ViewGroup)parent).removeView(debugInfoView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-01 08:02:27 +00:00
|
|
|
private final MoreSuggestionsListener mMoreSuggestionsListener = new MoreSuggestionsListener() {
|
2011-08-24 05:44:46 +00:00
|
|
|
@Override
|
2013-05-01 08:02:27 +00:00
|
|
|
public void onSuggestionSelected(final int index, final SuggestedWordInfo wordInfo) {
|
2013-04-04 08:45:21 +00:00
|
|
|
mListener.pickSuggestionManually(index, wordInfo);
|
2013-12-16 09:02:58 +00:00
|
|
|
dismissMoreSuggestionsPanel();
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCancelInput() {
|
2013-12-16 09:02:58 +00:00
|
|
|
dismissMoreSuggestionsPanel();
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private final MoreKeysPanel.Controller mMoreSuggestionsController =
|
|
|
|
new MoreKeysPanel.Controller() {
|
|
|
|
@Override
|
2013-07-25 09:07:46 +00:00
|
|
|
public void onDismissMoreKeysPanel(final MoreKeysPanel panel) {
|
|
|
|
mMainKeyboardView.onDismissMoreKeysPanel(panel);
|
2012-12-03 06:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2013-01-22 05:32:47 +00:00
|
|
|
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
|
2013-01-21 05:41:33 +00:00
|
|
|
mMainKeyboardView.onShowMoreKeysPanel(panel);
|
2011-08-24 05:44:46 +00:00
|
|
|
}
|
2012-12-10 20:38:29 +00:00
|
|
|
|
|
|
|
@Override
|
2013-07-25 09:07:46 +00:00
|
|
|
public void onCancelMoreKeysPanel(final MoreKeysPanel panel) {
|
2013-12-16 09:02:58 +00:00
|
|
|
dismissMoreSuggestionsPanel();
|
2012-12-10 20:38:29 +00:00
|
|
|
}
|
2011-08-24 05:44:46 +00:00
|
|
|
};
|
|
|
|
|
2013-12-16 09:02:58 +00:00
|
|
|
public boolean isShowingMoreSuggestionPanel() {
|
|
|
|
return mMoreSuggestionsView.isShowingInParent();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void dismissMoreSuggestionsPanel() {
|
|
|
|
mMoreSuggestionsView.dismissMoreKeysPanel();
|
|
|
|
}
|
|
|
|
|
2011-08-06 07:45:58 +00:00
|
|
|
@Override
|
2012-10-03 05:46:47 +00:00
|
|
|
public boolean onLongClick(final View view) {
|
2013-08-13 03:10:26 +00:00
|
|
|
AudioAndHapticFeedbackManager.getInstance().performHapticAndAudioFeedback(
|
2013-05-21 22:32:08 +00:00
|
|
|
Constants.NOT_A_CODE, this);
|
2011-09-20 10:17:19 +00:00
|
|
|
return showMoreSuggestions();
|
|
|
|
}
|
|
|
|
|
2012-10-03 05:46:47 +00:00
|
|
|
boolean showMoreSuggestions() {
|
2012-10-01 05:26:38 +00:00
|
|
|
final Keyboard parentKeyboard = KeyboardSwitcher.getInstance().getKeyboard();
|
|
|
|
if (parentKeyboard == null) {
|
|
|
|
return false;
|
2011-08-06 07:45:58 +00:00
|
|
|
}
|
2013-05-30 10:31:55 +00:00
|
|
|
final SuggestionStripLayoutHelper layoutHelper = mLayoutHelper;
|
|
|
|
if (!layoutHelper.mMoreSuggestionsAvailable) {
|
2012-10-01 05:26:38 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final int stripWidth = getWidth();
|
|
|
|
final View container = mMoreSuggestionsContainer;
|
|
|
|
final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight();
|
|
|
|
final MoreSuggestions.Builder builder = mMoreSuggestionsBuilder;
|
2014-02-12 06:22:13 +00:00
|
|
|
builder.layout(mSuggestedWords, mSuggestionsCountInStrip, maxWidth,
|
2013-05-30 10:31:55 +00:00
|
|
|
(int)(maxWidth * layoutHelper.mMinMoreSuggestionsWidth),
|
|
|
|
layoutHelper.getMaxMoreSuggestionsRow(), parentKeyboard);
|
2012-10-01 05:26:38 +00:00
|
|
|
mMoreSuggestionsView.setKeyboard(builder.build());
|
|
|
|
container.measure(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
|
|
|
|
|
|
|
|
final MoreKeysPanel moreKeysPanel = mMoreSuggestionsView;
|
|
|
|
final int pointX = stripWidth / 2;
|
2013-05-30 10:31:55 +00:00
|
|
|
final int pointY = -layoutHelper.mMoreSuggestionsBottomGap;
|
2012-10-01 05:26:38 +00:00
|
|
|
moreKeysPanel.showMoreKeysPanel(this, mMoreSuggestionsController, pointX, pointY,
|
2012-12-03 06:49:10 +00:00
|
|
|
mMoreSuggestionsListener);
|
2012-10-01 05:26:38 +00:00
|
|
|
mMoreSuggestionsMode = MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING;
|
|
|
|
mOriginX = mLastX;
|
|
|
|
mOriginY = mLastY;
|
2014-02-12 06:22:13 +00:00
|
|
|
for (int i = 0; i < mSuggestionsCountInStrip; i++) {
|
2013-05-30 10:44:26 +00:00
|
|
|
mWordViews.get(i).setPressed(false);
|
2012-10-01 05:26:38 +00:00
|
|
|
}
|
|
|
|
return true;
|
2011-08-06 07:45:58 +00:00
|
|
|
}
|
|
|
|
|
2011-09-06 02:37:51 +00:00
|
|
|
// Working variables for onLongClick and dispatchTouchEvent.
|
2011-09-16 09:24:03 +00:00
|
|
|
private int mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
|
|
|
|
private static final int MORE_SUGGESTIONS_IN_MODAL_MODE = 0;
|
|
|
|
private static final int MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING = 1;
|
|
|
|
private static final int MORE_SUGGESTIONS_IN_SLIDING_MODE = 2;
|
2011-09-06 02:37:51 +00:00
|
|
|
private int mLastX;
|
|
|
|
private int mLastY;
|
|
|
|
private int mOriginX;
|
|
|
|
private int mOriginY;
|
|
|
|
private final int mMoreSuggestionsModalTolerance;
|
2011-09-20 10:17:19 +00:00
|
|
|
private final GestureDetector mMoreSuggestionsSlidingDetector;
|
|
|
|
private final GestureDetector.OnGestureListener mMoreSuggestionsSlidingListener =
|
|
|
|
new GestureDetector.SimpleOnGestureListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onScroll(MotionEvent down, MotionEvent me, float deltaX, float deltaY) {
|
|
|
|
final float dy = me.getY() - down.getY();
|
|
|
|
if (deltaY > 0 && dy < 0) {
|
|
|
|
return showMoreSuggestions();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
2011-09-06 02:37:51 +00:00
|
|
|
|
2010-12-06 12:26:38 +00:00
|
|
|
@Override
|
2012-10-03 05:46:47 +00:00
|
|
|
public boolean dispatchTouchEvent(final MotionEvent me) {
|
2013-04-15 03:57:10 +00:00
|
|
|
if (!mMoreSuggestionsView.isShowingInParent()) {
|
2011-09-06 02:37:51 +00:00
|
|
|
mLastX = (int)me.getX();
|
|
|
|
mLastY = (int)me.getY();
|
2011-09-20 10:17:19 +00:00
|
|
|
if (mMoreSuggestionsSlidingDetector.onTouchEvent(me)) {
|
|
|
|
return true;
|
|
|
|
}
|
2011-08-24 05:44:46 +00:00
|
|
|
return super.dispatchTouchEvent(me);
|
|
|
|
}
|
2011-09-06 06:25:58 +00:00
|
|
|
|
2011-08-24 05:44:46 +00:00
|
|
|
final int action = me.getAction();
|
|
|
|
final int index = me.getActionIndex();
|
2011-09-06 06:25:58 +00:00
|
|
|
final int x = (int)me.getX(index);
|
|
|
|
final int y = (int)me.getY(index);
|
|
|
|
|
2011-09-16 09:24:03 +00:00
|
|
|
if (mMoreSuggestionsMode == MORE_SUGGESTIONS_CHECKING_MODAL_OR_SLIDING) {
|
2011-09-13 03:50:12 +00:00
|
|
|
if (Math.abs(x - mOriginX) >= mMoreSuggestionsModalTolerance
|
|
|
|
|| mOriginY - y >= mMoreSuggestionsModalTolerance) {
|
|
|
|
// Decided to be in the sliding input mode only when the touch point has been moved
|
|
|
|
// upward.
|
2011-09-16 09:24:03 +00:00
|
|
|
mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_SLIDING_MODE;
|
2011-09-06 02:37:51 +00:00
|
|
|
} else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP) {
|
|
|
|
// Decided to be in the modal input mode
|
2011-09-16 09:24:03 +00:00
|
|
|
mMoreSuggestionsMode = MORE_SUGGESTIONS_IN_MODAL_MODE;
|
2013-04-15 03:57:10 +00:00
|
|
|
mMoreSuggestionsView.adjustVerticalCorrectionForModalMode();
|
2011-09-06 02:37:51 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-09-16 09:24:03 +00:00
|
|
|
// MORE_SUGGESTIONS_IN_SLIDING_MODE
|
2013-08-01 07:55:55 +00:00
|
|
|
me.setLocation(mMoreSuggestionsView.translateX(x), mMoreSuggestionsView.translateY(y));
|
|
|
|
mMoreSuggestionsView.onTouchEvent(me);
|
2011-08-24 05:44:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2012-10-03 05:46:47 +00:00
|
|
|
public void onClick(final View view) {
|
2014-01-28 07:19:29 +00:00
|
|
|
if (view == mImportantNoticeStrip) {
|
|
|
|
mListener.showImportantNoticeContents();
|
|
|
|
return;
|
|
|
|
}
|
2014-01-27 05:50:02 +00:00
|
|
|
final Object tag = view.getTag();
|
|
|
|
// {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}.
|
|
|
|
if (tag instanceof String) {
|
|
|
|
final String wordToSave = (String)tag;
|
|
|
|
mListener.addWordToUserDictionary(wordToSave);
|
2011-06-27 07:57:18 +00:00
|
|
|
clear();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:50:02 +00:00
|
|
|
// {@link Integer} tag is set at
|
2013-06-21 01:44:14 +00:00
|
|
|
// {@link SuggestionStripLayoutHelper#setupWordViewsTextAndColor(SuggestedWords,int)} and
|
|
|
|
// {@link SuggestionStripLayoutHelper#layoutPunctuationSuggestions(SuggestedWords,ViewGroup}
|
2014-01-27 05:50:02 +00:00
|
|
|
if (tag instanceof Integer) {
|
|
|
|
final int index = (Integer) tag;
|
|
|
|
if (index >= mSuggestedWords.size()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final SuggestedWordInfo wordInfo = mSuggestedWords.getInfo(index);
|
|
|
|
mListener.pickSuggestionManually(index, wordInfo);
|
2013-05-30 10:44:26 +00:00
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|
2011-01-18 08:22:01 +00:00
|
|
|
|
2009-03-31 21:50:26 +00:00
|
|
|
@Override
|
2011-09-27 06:18:02 +00:00
|
|
|
protected void onDetachedFromWindow() {
|
2009-03-31 21:50:26 +00:00
|
|
|
super.onDetachedFromWindow();
|
2013-12-16 09:02:58 +00:00
|
|
|
dismissMoreSuggestionsPanel();
|
2009-03-31 21:50:26 +00:00
|
|
|
}
|
2014-02-03 02:49:34 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
|
|
|
// Called by the framework when the size is known. Show the important notice if applicable.
|
|
|
|
// This may be overriden by showing suggestions later, if applicable.
|
|
|
|
maybeShowImportantNoticeTitle();
|
|
|
|
}
|
2009-03-13 22:11:42 +00:00
|
|
|
}
|