Example usage for android.widget TextView getTextScaleX

List of usage examples for android.widget TextView getTextScaleX

Introduction

In this page you can find the example usage for android.widget TextView getTextScaleX.

Prototype

public float getTextScaleX() 

Source Link

Document

Gets the extent by which text should be stretched horizontally.

Usage

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

public void layoutAddToDictionaryHint(final String word, final ViewGroup addToDictionaryStrip) {
    final boolean shouldShowUiToAcceptTypedWord = Settings.getInstance()
            .getCurrent().mShouldShowUiToAcceptTypedWord;
    final int stripWidth = addToDictionaryStrip.getWidth();
    final int width = shouldShowUiToAcceptTypedWord ? stripWidth : stripWidth - mDividerWidth - mPadding * 2;

    final TextView wordView = (TextView) addToDictionaryStrip.findViewById(R.id.word_to_save);
    wordView.setTextColor(mColorTypedWord);
    final int wordWidth = (int) (width * mCenterSuggestionWeight);
    final CharSequence wordToSave = getEllipsizedText(word, wordWidth, wordView.getPaint());
    final float wordScaleX = wordView.getTextScaleX();
    wordView.setText(wordToSave);//from ww w  . j  av  a 2 s  .  c  o m
    wordView.setTextScaleX(wordScaleX);
    setLayoutWeight(wordView, mCenterSuggestionWeight, ViewGroup.LayoutParams.MATCH_PARENT);
    final int wordVisibility = shouldShowUiToAcceptTypedWord ? View.GONE : View.VISIBLE;
    wordView.setVisibility(wordVisibility);
    addToDictionaryStrip.findViewById(R.id.word_to_save_divider).setVisibility(wordVisibility);

    final Resources res = addToDictionaryStrip.getResources();
    final CharSequence hintText;
    final int hintWidth;
    final float hintWeight;
    final TextView hintView = (TextView) addToDictionaryStrip.findViewById(R.id.hint_add_to_dictionary);
    if (shouldShowUiToAcceptTypedWord) {
        hintText = res.getText(R.string.hint_add_to_dictionary_without_word);
        hintWidth = width;
        hintWeight = 1.0f;
        hintView.setGravity(Gravity.CENTER);
    } else {
        final boolean isRtlLanguage = (ViewCompat
                .getLayoutDirection(addToDictionaryStrip) == ViewCompat.LAYOUT_DIRECTION_RTL);
        final String arrow = isRtlLanguage ? RIGHTWARDS_ARROW : LEFTWARDS_ARROW;
        final boolean isRtlSystem = SubtypeLocaleUtils.isRtlLanguage(res.getConfiguration().locale);
        final CharSequence hint = res.getText(R.string.hint_add_to_dictionary);
        hintText = (isRtlLanguage == isRtlSystem) ? (arrow + hint) : (hint + arrow);
        hintWidth = width - wordWidth;
        hintWeight = 1.0f - mCenterSuggestionWeight;
        hintView.setGravity(Gravity.CENTER_VERTICAL | Gravity.START);
    }
    hintView.setTextColor(mColorAutoCorrect);
    final float hintScaleX = getTextScaleX(hintText, hintWidth, hintView.getPaint());
    hintView.setText(hintText);
    hintView.setTextScaleX(hintScaleX);
    setLayoutWeight(hintView, hintWeight, ViewGroup.LayoutParams.MATCH_PARENT);
}