Merge "Suggestion strip honors RTL layout"

This commit is contained in:
Tadashi G. Takaoka 2014-01-28 07:52:24 +00:00 committed by Android (Google) Code Review
commit 95e5e267ac
6 changed files with 22 additions and 45 deletions

View file

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2012, The Android Open Source Project
**
** 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
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** 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.
*/
-->
<!-- This is derived from suggestion_word.xml without minWidth attribute and padding -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="@dimen/config_suggestion_text_size"
android:gravity="center"
android:paddingLeft="0dp"
android:paddingTop="0dp"
android:paddingRight="0dp"
android:paddingBottom="0dp"
android:focusable="false"
android:clickable="false"
android:singleLine="true"
android:ellipsize="none"
style="?attr/suggestionWordStyle" />

View file

@ -37,7 +37,7 @@
<include
layout="@layout/suggestion_divider" />
<include
layout="@layout/hint_add_to_dictionary"
layout="@layout/suggestion_word"
android:id="@+id/hint_add_to_dictionary" />
</LinearLayout>
</merge>

View file

@ -84,6 +84,7 @@ import com.android.inputmethod.latin.utils.IntentUtils;
import com.android.inputmethod.latin.utils.JniUtils;
import com.android.inputmethod.latin.utils.LatinImeLoggerUtils;
import com.android.inputmethod.latin.utils.LeakGuardHandlerWrapper;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.research.ResearchLogger;
import java.io.FileDescriptor;
@ -1326,7 +1327,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// TODO[IL]: Define a clear interface for this
public void setSuggestedWords(final SuggestedWords words, final boolean shouldShow) {
if (mSuggestionStripView != null) {
mSuggestionStripView.setSuggestions(words);
mSuggestionStripView.setSuggestions(
words, SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
mKeyboardSwitcher.onAutoCorrectionStateChanged(words.mWillAutoCorrect);
}
mInputLogic.mSuggestedWords = words;

View file

@ -28,6 +28,8 @@ import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewCompat;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
@ -39,7 +41,6 @@ import android.text.style.UnderlineSpan;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -88,6 +89,7 @@ final class SuggestionStripLayoutHelper {
private final Drawable mMoreSuggestionsHint;
private static final String MORE_SUGGESTIONS_HINT = "\u2026";
private static final String LEFTWARDS_ARROW = "\u2190";
private static final String RIGHTWARDS_ARROW = "\u2192";
private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD);
private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan();
@ -471,10 +473,13 @@ final class SuggestionStripLayoutHelper {
final TextView hintView = (TextView)addToDictionaryStrip.findViewById(
R.id.hint_add_to_dictionary);
hintView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
hintView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL | GravityCompat.START);
hintView.setTextColor(mColorAutoCorrect);
final boolean isRtlLanguage = (ViewCompat.getLayoutDirection(addToDictionaryStrip)
== ViewCompat.LAYOUT_DIRECTION_RTL);
final String hintWithArrow = (isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW)
+ hintText;
final int hintWidth = width - wordWidth;
final String hintWithArrow = LEFTWARDS_ARROW + hintText;
final float hintScaleX = getTextScaleX(hintWithArrow, hintWidth, hintView.getPaint());
hintView.setText(hintWithArrow);
hintView.setTextScaleX(hintScaleX);

View file

@ -18,6 +18,7 @@ package com.android.inputmethod.latin.suggestions;
import android.content.Context;
import android.content.res.Resources;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.LayoutInflater;
@ -84,6 +85,13 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
showSuggestionsStrip();
}
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);
}
public void showSuggestionsStrip() {
mSuggestionsStrip.setVisibility(VISIBLE);
mAddToDictionaryStrip.setVisibility(INVISIBLE);
@ -154,8 +162,9 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
mMainKeyboardView = (MainKeyboardView)inputView.findViewById(R.id.keyboard_view);
}
public void setSuggestions(final SuggestedWords suggestedWords) {
public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) {
clear();
mStripVisibilityGroup.setLayoutDirection(isRtlLanguage);
mSuggestedWords = suggestedWords;
mLayoutHelper.layout(mSuggestedWords, mSuggestionsStrip, this);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {

View file

@ -25,7 +25,6 @@ import android.os.Build;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.DictionaryFactory;
import com.android.inputmethod.latin.R;
@ -348,8 +347,6 @@ public final class SubtypeLocaleUtils {
Arrays.sort(SORTED_RTL_LANGUAGES);
}
// TODO: Remove @UsedForTesting annotation.
@UsedForTesting
public static boolean isRtlLanguage(final InputMethodSubtype subtype) {
final Locale locale = getSubtypeLocale(subtype);
final String language = locale.getLanguage();