am c41d261b: Add voice key to suggestions strip

* commit 'c41d261b7e1e626aaa4e333c9c4cc73ec13cb68a':
  Add voice key to suggestions strip
main
Tadashi G. Takaoka 2014-05-12 06:19:46 +00:00 committed by Android Git Automerger
commit 20b91c3314
8 changed files with 64 additions and 14 deletions

View File

@ -64,4 +64,12 @@
android:textSize="16sp" android:textSize="16sp"
style="?attr/suggestionWordStyle" /> style="?attr/suggestionWordStyle" />
</LinearLayout> </LinearLayout>
<ImageButton
android:id="@+id/suggestions_strip_voice_key"
android:layout_width="@dimen/config_suggestions_strip_edge_key_width"
android:layout_height="fill_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
style="?attr/suggestionWordStyle" />
</merge> </merge>

View File

@ -59,6 +59,7 @@
<dimen name="config_suggestions_strip_height">36dp</dimen> <dimen name="config_suggestions_strip_height">36dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">54dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">54dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">54dp</dimen>
<dimen name="config_more_suggestions_row_height">36dp</dimen> <dimen name="config_more_suggestions_row_height">36dp</dimen>
<integer name="config_max_more_suggestions_row">2</integer> <integer name="config_max_more_suggestions_row">2</integer>
<fraction name="config_min_more_suggestions_width">60%</fraction> <fraction name="config_min_more_suggestions_width">60%</fraction>

View File

@ -50,6 +50,7 @@
<dimen name="config_suggestions_strip_height">44dp</dimen> <dimen name="config_suggestions_strip_height">44dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">180.0dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">180.0dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">54dp</dimen>
<integer name="config_max_more_suggestions_row">5</integer> <integer name="config_max_more_suggestions_row">5</integer>
<fraction name="config_min_more_suggestions_width">50%</fraction> <fraction name="config_min_more_suggestions_width">50%</fraction>

View File

@ -63,7 +63,8 @@
<fraction name="config_key_shifted_letter_hint_ratio_5row">27%</fraction> <fraction name="config_key_shifted_letter_hint_ratio_5row">27%</fraction>
<dimen name="config_suggestions_strip_height">44dp</dimen> <dimen name="config_suggestions_strip_height">44dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">0dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">54dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">54dp</dimen>
<dimen name="config_more_suggestions_row_height">44dp</dimen> <dimen name="config_more_suggestions_row_height">44dp</dimen>
<integer name="config_max_more_suggestions_row">6</integer> <integer name="config_max_more_suggestions_row">6</integer>
<fraction name="config_min_more_suggestions_width">90%</fraction> <fraction name="config_min_more_suggestions_width">90%</fraction>

View File

@ -51,6 +51,7 @@
<dimen name="config_suggestions_strip_height">44dp</dimen> <dimen name="config_suggestions_strip_height">44dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">340dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">340dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">54dp</dimen>
<fraction name="config_min_more_suggestions_width">50%</fraction> <fraction name="config_min_more_suggestions_width">50%</fraction>
<!-- Gesture floating preview text parameters --> <!-- Gesture floating preview text parameters -->

View File

@ -62,6 +62,7 @@
<dimen name="config_suggestions_strip_height">44dp</dimen> <dimen name="config_suggestions_strip_height">44dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">100dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">100dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">54dp</dimen>
<dimen name="config_more_suggestions_row_height">44dp</dimen> <dimen name="config_more_suggestions_row_height">44dp</dimen>
<integer name="config_max_more_suggestions_row">6</integer> <integer name="config_max_more_suggestions_row">6</integer>
<fraction name="config_min_more_suggestions_width">90%</fraction> <fraction name="config_min_more_suggestions_width">90%</fraction>

View File

@ -64,7 +64,8 @@
<fraction name="config_key_shifted_letter_hint_ratio_5row">41%</fraction> <fraction name="config_key_shifted_letter_hint_ratio_5row">41%</fraction>
<dimen name="config_suggestions_strip_height">40dp</dimen> <dimen name="config_suggestions_strip_height">40dp</dimen>
<dimen name="config_suggestions_strip_horizontal_margin">0dp</dimen> <dimen name="config_suggestions_strip_horizontal_margin">36dp</dimen>
<dimen name="config_suggestions_strip_edge_key_width">36dp</dimen>
<dimen name="config_more_suggestions_row_height">40dp</dimen> <dimen name="config_more_suggestions_row_height">40dp</dimen>
<integer name="config_max_more_suggestions_row">6</integer> <integer name="config_max_more_suggestions_row">6</integer>
<fraction name="config_min_more_suggestions_width">90%</fraction> <fraction name="config_min_more_suggestions_width">90%</fraction>

View File

@ -18,7 +18,9 @@ package com.android.inputmethod.latin.suggestions;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -31,6 +33,7 @@ import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewParent; import android.view.ViewParent;
import android.widget.ImageButton;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -59,12 +62,14 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void addWordToUserDictionary(String word); public void addWordToUserDictionary(String word);
public void showImportantNoticeContents(); public void showImportantNoticeContents();
public void pickSuggestionManually(int index, SuggestedWordInfo word); public void pickSuggestionManually(int index, SuggestedWordInfo word);
public void onCodeInput(int primaryCode, int x, int y, boolean isKeyRepeat);
} }
static final boolean DBG = LatinImeLogger.sDBG; static final boolean DBG = LatinImeLogger.sDBG;
private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f; private static final float DEBUG_INFO_TEXT_SIZE_IN_DIP = 6.0f;
private final ViewGroup mSuggestionsStrip; private final ViewGroup mSuggestionsStrip;
private final ImageButton mVoiceKey;
private final ViewGroup mAddToDictionaryStrip; private final ViewGroup mAddToDictionaryStrip;
private final View mImportantNoticeStrip; private final View mImportantNoticeStrip;
MainKeyboardView mMainKeyboardView; MainKeyboardView mMainKeyboardView;
@ -86,39 +91,42 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
private static class StripVisibilityGroup { private static class StripVisibilityGroup {
private final View mSuggestionsStrip; private final View mSuggestionsStrip;
private final View mVoiceKey;
private final View mAddToDictionaryStrip; private final View mAddToDictionaryStrip;
private final View mImportantNoticeStrip; private final View mImportantNoticeStrip;
public StripVisibilityGroup(final View suggestionsStrip, final View addToDictionaryStrip, public StripVisibilityGroup(final View suggestionsStrip, final View voiceKey,
final View importantNoticeStrip) { final View addToDictionaryStrip, final View importantNoticeStrip) {
mSuggestionsStrip = suggestionsStrip; mSuggestionsStrip = suggestionsStrip;
mVoiceKey = voiceKey;
mAddToDictionaryStrip = addToDictionaryStrip; mAddToDictionaryStrip = addToDictionaryStrip;
mImportantNoticeStrip = importantNoticeStrip; mImportantNoticeStrip = importantNoticeStrip;
showSuggestionsStrip(); showSuggestionsStrip(false /* voiceKeyEnabled */);
} }
public void setLayoutDirection(final boolean isRtlLanguage) { public void setLayoutDirection(final int layoutDirection) {
final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
: ViewCompat.LAYOUT_DIRECTION_LTR;
ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection); ViewCompat.setLayoutDirection(mSuggestionsStrip, layoutDirection);
ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection); ViewCompat.setLayoutDirection(mAddToDictionaryStrip, layoutDirection);
ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection); ViewCompat.setLayoutDirection(mImportantNoticeStrip, layoutDirection);
} }
public void showSuggestionsStrip() { public void showSuggestionsStrip(final boolean enableVoiceKey) {
mSuggestionsStrip.setVisibility(VISIBLE); mSuggestionsStrip.setVisibility(VISIBLE);
mVoiceKey.setVisibility(enableVoiceKey ? VISIBLE : INVISIBLE);
mAddToDictionaryStrip.setVisibility(INVISIBLE); mAddToDictionaryStrip.setVisibility(INVISIBLE);
mImportantNoticeStrip.setVisibility(INVISIBLE); mImportantNoticeStrip.setVisibility(INVISIBLE);
} }
public void showAddToDictionaryStrip() { public void showAddToDictionaryStrip() {
mSuggestionsStrip.setVisibility(INVISIBLE); mSuggestionsStrip.setVisibility(INVISIBLE);
mVoiceKey.setVisibility(INVISIBLE);
mAddToDictionaryStrip.setVisibility(VISIBLE); mAddToDictionaryStrip.setVisibility(VISIBLE);
mImportantNoticeStrip.setVisibility(INVISIBLE); mImportantNoticeStrip.setVisibility(INVISIBLE);
} }
public void showImportantNoticeStrip() { public void showImportantNoticeStrip() {
mSuggestionsStrip.setVisibility(INVISIBLE); mSuggestionsStrip.setVisibility(INVISIBLE);
mVoiceKey.setVisibility(INVISIBLE);
mAddToDictionaryStrip.setVisibility(INVISIBLE); mAddToDictionaryStrip.setVisibility(INVISIBLE);
mImportantNoticeStrip.setVisibility(VISIBLE); mImportantNoticeStrip.setVisibility(VISIBLE);
} }
@ -145,10 +153,11 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
inflater.inflate(R.layout.suggestions_strip, this); inflater.inflate(R.layout.suggestions_strip, this);
mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip); mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key);
mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip); mAddToDictionaryStrip = (ViewGroup)findViewById(R.id.add_to_dictionary_strip);
mImportantNoticeStrip = findViewById(R.id.important_notice_strip); mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mAddToDictionaryStrip, mStripVisibilityGroup = new StripVisibilityGroup(mSuggestionsStrip, mVoiceKey,
mImportantNoticeStrip); mAddToDictionaryStrip, mImportantNoticeStrip);
for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) { for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
final TextView word = new TextView(context, null, R.attr.suggestionWordStyle); final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
@ -177,6 +186,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
R.dimen.config_more_suggestions_modal_tolerance); R.dimen.config_more_suggestions_modal_tolerance);
mMoreSuggestionsSlidingDetector = new GestureDetector( mMoreSuggestionsSlidingDetector = new GestureDetector(
context, mMoreSuggestionsSlidingListener); context, mMoreSuggestionsSlidingListener);
final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs,
R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
keyboardAttr.recycle();
mVoiceKey.setImageDrawable(iconVoice);
mVoiceKey.setOnClickListener(this);
} }
/** /**
@ -188,16 +204,30 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view); mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view);
} }
private boolean isVoiceKeyEnabled() {
if (mMainKeyboardView == null) {
return false;
}
final Keyboard keyboard = mMainKeyboardView.getKeyboard();
if (keyboard == null) {
return false;
}
return keyboard.mId.mHasShortcutKey;
}
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
clear(); clear();
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage); final int layoutDirection = isRtlLanguage ? ViewCompat.LAYOUT_DIRECTION_RTL
: ViewCompat.LAYOUT_DIRECTION_LTR;
setLayoutDirection(layoutDirection);
mStripVisibilityGroup.setLayoutDirection(layoutDirection);
mSuggestedWords = suggestedWords; mSuggestedWords = suggestedWords;
mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip( mSuggestionsCountInStrip = mLayoutHelper.layoutAndReturnSuggestionCountInStrip(
mSuggestedWords, mSuggestionsStrip, this); mSuggestedWords, mSuggestionsStrip, this);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords); ResearchLogger.suggestionStripView_setSuggestions(mSuggestedWords);
} }
mStripVisibilityGroup.showSuggestionsStrip(); mStripVisibilityGroup.showSuggestionsStrip(isVoiceKeyEnabled());
} }
public int setMoreSuggestionsHeight(final int remainingHeight) { public int setMoreSuggestionsHeight(final int remainingHeight) {
@ -252,7 +282,7 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
public void clear() { public void clear() {
mSuggestionsStrip.removeAllViews(); mSuggestionsStrip.removeAllViews();
removeAllDebugInfoViews(); removeAllDebugInfoViews();
mStripVisibilityGroup.showSuggestionsStrip(); mStripVisibilityGroup.showSuggestionsStrip(false /* enableVoiceKey */);
dismissMoreSuggestionsPanel(); dismissMoreSuggestionsPanel();
} }
@ -415,6 +445,12 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mListener.showImportantNoticeContents(); mListener.showImportantNoticeContents();
return; return;
} }
if (view == mVoiceKey) {
mListener.onCodeInput(Constants.CODE_SHORTCUT,
Constants.SUGGESTION_STRIP_COORDINATE, Constants.SUGGESTION_STRIP_COORDINATE,
false /* isKeyRepeat */);
return;
}
final Object tag = view.getTag(); final Object tag = view.getTag();
// {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}. // {@link String} tag is set at {@link #showAddToDictionaryHint(String,CharSequence)}.
if (tag instanceof String) { if (tag instanceof String) {