From bcd30bf3e74c7c10d5b69a54cdf90c6b682a0747 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" <takaoka@google.com> Date: Mon, 27 Jan 2014 19:04:40 +0900 Subject: [PATCH] Suggestion strip honors RTL layout Bug: 9126496 Change-Id: Ia4a1c52bd2a80ea7fe6b9529f2767fee5f9e8aeb --- java/res/layout/hint_add_to_dictionary.xml | 36 ------------------- java/res/layout/suggestions_strip.xml | 2 +- .../android/inputmethod/latin/LatinIME.java | 4 ++- .../SuggestionStripLayoutHelper.java | 11 ++++-- .../suggestions/SuggestionStripView.java | 11 +++++- .../latin/utils/SubtypeLocaleUtils.java | 3 -- 6 files changed, 22 insertions(+), 45 deletions(-) delete mode 100644 java/res/layout/hint_add_to_dictionary.xml diff --git a/java/res/layout/hint_add_to_dictionary.xml b/java/res/layout/hint_add_to_dictionary.xml deleted file mode 100644 index d429082604..0000000000 --- a/java/res/layout/hint_add_to_dictionary.xml +++ /dev/null @@ -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" /> diff --git a/java/res/layout/suggestions_strip.xml b/java/res/layout/suggestions_strip.xml index 2ffac179c7..85d60e6810 100644 --- a/java/res/layout/suggestions_strip.xml +++ b/java/res/layout/suggestions_strip.xml @@ -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> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index efc14fc866..c2483eba20 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -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; @@ -1331,7 +1332,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // TODO[IL]: Define a clear interface for this public void setSuggestedWords(final SuggestedWords words) { if (mSuggestionStripView != null) { - mSuggestionStripView.setSuggestions(words); + mSuggestionStripView.setSuggestions( + words, SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype())); mKeyboardSwitcher.onAutoCorrectionStateChanged(words.mWillAutoCorrect); } mInputLogic.mSuggestedWords = words; diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java index af04de435c..3cd9d95553 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripLayoutHelper.java @@ -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); diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java index e44bd70a1c..0ebf5cba54 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java @@ -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) { diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java index fb1be30f16..0d02889238 100644 --- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java +++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java @@ -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(); -- GitLab