Java Code Examples for android.widget.TextView#setTextScaleX()

The following examples show how to use android.widget.TextView#setTextScaleX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SuggestionStripLayoutHelper.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}
 
Example 2
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}
 
Example 3
Source File: SuggestionStripLayoutHelper.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}
 
Example 4
Source File: SuggestionStripLayoutHelper.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 */
private TextView layoutWord(final Context context, final int positionInStrip, final int width) {
    final TextView wordView = mWordViews.get(positionInStrip);
    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(
                null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(
            TextUtils.isEmpty(word)
                ? context.getResources().getString(R.string.spoken_empty_suggestion)
                : word.toString());
    final CharSequence text = getEllipsizedTextWithSettingScaleX(
            word, width, wordView.getPaint());
    final float scaleX = wordView.getTextScaleX();
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(scaleX);
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(!TextUtils.isEmpty(word)
            || AccessibilityUtils.Companion.getInstance().isTouchExplorationEnabled());
    return wordView;
}
 
Example 5
Source File: SuggestionStripLayoutHelper.java    From openboard with GNU General Public License v3.0 5 votes vote down vote up
public void layoutImportantNotice(final View importantNoticeStrip,
        final String importantNoticeTitle) {
    final TextView titleView = importantNoticeStrip.findViewById(
            R.id.important_notice_title);
    final int width = titleView.getWidth() - titleView.getPaddingLeft()
            - titleView.getPaddingRight();
    titleView.setTextColor(mColorAutoCorrect);
    titleView.setText(importantNoticeTitle); // TextView.setText() resets text scale x to 1.0.
    final float titleScaleX = getTextScaleX(importantNoticeTitle, width, titleView.getPaint());
    titleView.setTextScaleX(titleScaleX);
}
 
Example 6
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 */
private TextView layoutWord(final Context context, final int positionInStrip, final int width) {
    final TextView wordView = mWordViews.get(positionInStrip);
    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(
                null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(
            TextUtils.isEmpty(word)
                ? context.getResources().getString(R.string.spoken_empty_suggestion)
                : word.toString());
    final CharSequence text = getEllipsizedTextWithSettingScaleX(
            word, width, wordView.getPaint());
    final float scaleX = wordView.getTextScaleX();
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(scaleX);
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(!TextUtils.isEmpty(word)
            || AccessibilityUtils.getInstance().isTouchExplorationEnabled());
    return wordView;
}
 
Example 7
Source File: SuggestionStripLayoutHelper.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public void layoutImportantNotice(final View importantNoticeStrip,
        final String importantNoticeTitle) {
    final TextView titleView = (TextView)importantNoticeStrip.findViewById(
            R.id.important_notice_title);
    final int width = titleView.getWidth() - titleView.getPaddingLeft()
            - titleView.getPaddingRight();
    titleView.setTextColor(mColorAutoCorrect);
    titleView.setText(importantNoticeTitle); // TextView.setText() resets text scale x to 1.0.
    final float titleScaleX = getTextScaleX(importantNoticeTitle, width, titleView.getPaint());
    titleView.setTextScaleX(titleScaleX);
}
 
Example 8
Source File: SuggestionStripLayoutHelper.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 */
private TextView layoutWord(final Context context, final int positionInStrip, final int width) {
    final TextView wordView = mWordViews.get(positionInStrip);
    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(
                null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(
            TextUtils.isEmpty(word)
                ? context.getResources().getString(R.string.spoken_empty_suggestion)
                : word.toString());
    final CharSequence text = getEllipsizedTextWithSettingScaleX(
            word, width, wordView.getPaint());
    final float scaleX = wordView.getTextScaleX();
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(scaleX);
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(!TextUtils.isEmpty(word)
            || AccessibilityUtils.getInstance().isTouchExplorationEnabled());
    return wordView;
}
 
Example 9
Source File: SuggestionStripLayoutHelper.java    From Indic-Keyboard with Apache License 2.0 5 votes vote down vote up
public void layoutImportantNotice(final View importantNoticeStrip,
        final String importantNoticeTitle) {
    final TextView titleView = (TextView)importantNoticeStrip.findViewById(
            R.id.important_notice_title);
    final int width = titleView.getWidth() - titleView.getPaddingLeft()
            - titleView.getPaddingRight();
    titleView.setTextColor(mColorAutoCorrect);
    titleView.setText(importantNoticeTitle); // TextView.setText() resets text scale x to 1.0.
    final float titleScaleX = getTextScaleX(importantNoticeTitle, width, titleView.getPaint());
    titleView.setTextScaleX(titleScaleX);
}
 
Example 10
Source File: AuthenticatorActivity.java    From google-authenticator-android with Apache License 2.0 4 votes vote down vote up
/**
 * Displays the user and OTP for the specified position. For HOTP, displays the button for
 * generating the next OTP value; for TOTP, displays the countdown indicator.
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
  LayoutInflater inflater = getLayoutInflater();
  PinInfo currentPin = getItem(position);

  View row;
  if (convertView != null) {
    // Reuse an existing view
    row = convertView;
  } else {
    // Create a new view
    row = inflater.inflate(R.layout.user_row, null);

    // This is a workaround to address the issue on DragSortListView that complex
    // LinearLayout doesn't take the full width.
    // https://github.com/bauerca/drag-sort-listview/issues/73
    row.setLayoutParams(
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
  }

  TextView pinView = row.findViewById(R.id.pin_value);
  TextView userView = row.findViewById(R.id.current_user);
  View buttonView = row.findViewById(R.id.next_otp);
  CountdownIndicator countdownIndicator = row.findViewById(R.id.countdown_icon);

  // We only show drag handle on selected item when the number of items is larger than 1.
  boolean showDragHandle = false;
  try {
    if (getMultiSelectListSingleCheckedItemPosition(userList) == position && getCount() >= 2) {
      showDragHandle = true;
    }
  } catch (IllegalStateException ignored) {
    // No pin code is selected.
  }
  row.findViewById(R.id.user_row_drag_handle_image)
      .setVisibility(showDragHandle ? View.VISIBLE : View.GONE);

  if (currentPin.isHotp()) {
    buttonView.setVisibility(View.VISIBLE);
    buttonView.setEnabled(currentPin.isHotpCodeGenerationAllowed());
    ((ViewGroup) row)
        .setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS); // makes long press work
    NextOtpButtonListener clickListener = new NextOtpButtonListener(currentPin);
    buttonView.setOnClickListener(clickListener);
    row.setTag(clickListener);

    countdownIndicator.setVisibility(View.GONE);
  } else { // TOTP, so no button needed
    buttonView.setVisibility(View.GONE);
    buttonView.setOnClickListener(null);
    row.setTag(null);

    countdownIndicator.setVisibility(View.VISIBLE);
    countdownIndicator.setPhase(totpCountdownPhase);
  }

  if (getString(R.string.empty_pin).equals(currentPin.getPin())) {
    pinView.setTextScaleX(PIN_TEXT_SCALEX_UNDERSCORE); // smaller gap between underscores
  } else {
    pinView.setTextScaleX(PIN_TEXT_SCALEX_NORMAL);
  }
  pinView.setText(Utilities.getStyledPincode(currentPin.getPin()));
  userView.setText(
      Utilities.getCombinedTextForIssuerAndAccountName(
          currentPin.getIndex().getIssuer(), currentPin.getIndex().getStrippedName()));

  return row;
}