Java Code Examples for android.text.TextUtils#TruncateAt

The following examples show how to use android.text.TextUtils#TruncateAt . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
public static StaticLayout createStaticLayout2(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
    if (Build.VERSION.SDK_INT >= 23) {
        StaticLayout.Builder builder = StaticLayout.Builder.obtain(source, 0, source.length(), paint, ellipsisWidth)
                .setAlignment(align)
                .setLineSpacing(spacingadd, spacingmult)
                .setIncludePad(includepad)
                .setEllipsize(TextUtils.TruncateAt.END)
                .setEllipsizedWidth(ellipsisWidth)
                .setMaxLines(maxLines)
                .setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY)
                .setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE);
        return builder.build();
    } else {
        return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines, true);
    }
}
 
Example 2
/**
 * Sets the ellipsis location for the layout.
 *
 * @param ellipsize The ellipsis location in the layout
 * @return This {@link TextLayoutBuilder} instance
 */
public TextLayoutBuilder setEllipsize(TextUtils.TruncateAt ellipsize) {
  if (mParams.ellipsize != ellipsize) {
    mParams.ellipsize = ellipsize;
    mSavedLayout = null;
  }
  return this;
}
 
Example 3
Source Project: Android-Music-Player   File: FMedittext.java    License: MIT License 5 votes vote down vote up
@Override
public void setEllipsize(TextUtils.TruncateAt ellipsis) {
    if (ellipsis == TextUtils.TruncateAt.MARQUEE) {
        throw new IllegalArgumentException("EditText cannot use the ellipsize mode "
                + "TextUtils.TruncateAt.MARQUEE");
    }
    super.setEllipsize(ellipsis);
}
 
Example 4
Source Project: litho   File: EditTextSpec.java    License: Apache License 2.0 4 votes vote down vote up
@OnLoadStyle
static void onLoadStyle(
    ComponentContext c,
    Output<TextUtils.TruncateAt> ellipsize,
    Output<Float> spacingMultiplier,
    Output<Integer> minLines,
    Output<Integer> maxLines,
    Output<Boolean> isSingleLine,
    Output<CharSequence> text,
    Output<ColorStateList> textColorStateList,
    Output<Integer> linkColor,
    Output<Integer> highlightColor,
    Output<Integer> textSize,
    Output<Layout.Alignment> textAlignment,
    Output<Integer> textStyle,
    Output<Float> shadowRadius,
    Output<Float> shadowDx,
    Output<Float> shadowDy,
    Output<Integer> shadowColor,
    Output<Integer> gravity,
    Output<Integer> inputType,
    Output<Integer> imeOptions) {

  final TypedArray a = c.obtainStyledAttributes(R.styleable.Text, 0);

  for (int i = 0, size = a.getIndexCount(); i < size; i++) {
    final int attr = a.getIndex(i);

    if (attr == R.styleable.Text_android_text) {
      text.set(a.getString(attr));
    } else if (attr == R.styleable.Text_android_textColor) {
      textColorStateList.set(a.getColorStateList(attr));
    } else if (attr == R.styleable.Text_android_textSize) {
      textSize.set(a.getDimensionPixelSize(attr, 0));
    } else if (attr == R.styleable.Text_android_ellipsize) {
      final int index = a.getInteger(attr, 0);
      if (index > 0) {
        ellipsize.set(TRUNCATE_AT[index - 1]);
      }
    } else if (attr == R.styleable.Text_android_textAlignment) {
      if (SDK_INT >= JELLY_BEAN_MR1) {
        int viewTextAlignment = a.getInt(attr, -1);
        textAlignment.set(getAlignment(viewTextAlignment, Gravity.NO_GRAVITY));
      }
    } else if (attr == R.styleable.Text_android_minLines) {
      minLines.set(a.getInteger(attr, -1));
    } else if (attr == R.styleable.Text_android_maxLines) {
      maxLines.set(a.getInteger(attr, -1));
    } else if (attr == R.styleable.Text_android_singleLine) {
      isSingleLine.set(a.getBoolean(attr, false));
    } else if (attr == R.styleable.Text_android_textColorLink) {
      linkColor.set(a.getColor(attr, 0));
    } else if (attr == R.styleable.Text_android_textColorHighlight) {
      highlightColor.set(a.getColor(attr, 0));
    } else if (attr == R.styleable.Text_android_textStyle) {
      textStyle.set(a.getInteger(attr, 0));
    } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) {
      spacingMultiplier.set(a.getFloat(attr, 0));
    } else if (attr == R.styleable.Text_android_shadowDx) {
      shadowDx.set(a.getFloat(attr, 0));
    } else if (attr == R.styleable.Text_android_shadowDy) {
      shadowDy.set(a.getFloat(attr, 0));
    } else if (attr == R.styleable.Text_android_shadowRadius) {
      shadowRadius.set(a.getFloat(attr, 0));
    } else if (attr == R.styleable.Text_android_shadowColor) {
      shadowColor.set(a.getColor(attr, 0));
    } else if (attr == R.styleable.Text_android_gravity) {
      gravity.set(a.getInteger(attr, 0));
    } else if (attr == R.styleable.Text_android_inputType) {
      inputType.set(a.getInteger(attr, 0));
    } else if (attr == R.styleable.Text_android_imeOptions) {
      imeOptions.set(a.getInteger(attr, 0));
    }
  }

  a.recycle();
}
 
Example 5
Source Project: FastTextView   File: FastTextView.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
protected StaticLayout makeLayout(CharSequence text, int maxWidth, boolean exactly) {
  TextUtils.TruncateAt truncateAt = getTruncateAt();
  int layoutTargetWidth = maxWidth;
  int contentWidth = maxWidth;
  if (!exactly || truncateAt != null) {
    contentWidth = getContentWidth(text);
  }
  if (!exactly) {
    layoutTargetWidth = maxWidth > 0 ? Math.min(maxWidth, contentWidth) : contentWidth;
  }


  StaticLayoutBuilderCompat layoutBuilder = createStaticLayoutBuilder(text, 0, text
      .length(), mTextPaint, layoutTargetWidth);
  layoutBuilder.setLineSpacing(mAttrsHelper.mSpacingAdd, mAttrsHelper.mSpacingMultiplier)
      .setMaxLines(mAttrsHelper.mMaxLines)
      .setAlignment(TextViewAttrsHelper.getLayoutAlignment(this, getGravity()))
      .setIncludePad(true);
  if (truncateAt != null) {
    layoutBuilder.setEllipsize(truncateAt);
    EllipsisSpannedContainer ellipsisSpanned =
        new EllipsisSpannedContainer(text instanceof Spanned ? (Spanned) text : new
            SpannableString(text));
    ellipsisSpanned.setCustomEllipsisSpan(mCustomEllipsisSpan);
    layoutBuilder.setText(ellipsisSpanned);
    if (contentWidth > layoutTargetWidth * mAttrsHelper.mMaxLines) {
      int ellipsisWithOffset = (int) mTextPaint.measureText(ReadMoreTextView.ELLIPSIS_NORMAL) - 2;

      // when StaticLayout call calculateEllipsis,
      // textWidth <= avail will cause do nothing so we should make it different with textWidth
      if (mCustomEllipsisSpan != null) {
        layoutBuilder.setEllipsizedWidth(layoutTargetWidth - mCustomEllipsisSpan.getSize
            (getPaint(), mText, 0, mText.length(), null) + ellipsisWithOffset);
      } else if (Build.VERSION.SDK_INT <= 19) {
        ReadMoreTextView.EllipsisSpan ellipsisSpan = new ReadMoreTextView.EllipsisSpan
            (ReadMoreTextView.ELLIPSIS_NORMAL);
        ellipsisSpanned.setCustomEllipsisSpan(ellipsisSpan);
        layoutBuilder.setEllipsizedWidth(layoutTargetWidth - ellipsisSpan.getSize(getPaint(),
            mText, 0, mText.length(), null) + ellipsisWithOffset);
      } else {
        layoutBuilder.setEllipsizedWidth(layoutTargetWidth);
      }
    } else {
      layoutBuilder.setEllipsizedWidth(contentWidth);
    }
    beforeStaticLayoutBuild(layoutBuilder);
    StaticLayout layout = layoutBuilder.build();
    ellipsisSpanned.setLayout(layout);
    mEllipsisSpanned = ellipsisSpanned;
    return layout;
  }
  beforeStaticLayoutBuild(layoutBuilder);
  return layoutBuilder.build();
}
 
Example 6
Source Project: anvil   File: DSL.java    License: MIT License 4 votes vote down vote up
public static Void ellipsize(TextUtils.TruncateAt arg) {
  return BaseDSL.attr("ellipsize", arg);
}
 
Example 7
Source Project: RichEditText   File: RichEditText.java    License: Apache License 2.0 4 votes vote down vote up
public void setEllipsize(TextUtils.TruncateAt ellipsis) {
    mEditText.setEllipsize(ellipsis);
}
 
Example 8
Source Project: DevUtils   File: DevToastUse.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Ellipsize 效果
 * @return
 */
@Override
public TextUtils.TruncateAt getEllipsize() {
    return null;
}
 
Example 9
Source Project: DevUtils   File: ToastTintActivity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Ellipsize 效果
 * @return
 */
@Override
public TextUtils.TruncateAt getEllipsize() {
    return null;
}
 
Example 10
Source Project: memoir   File: AutoResizeTextView.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setEllipsize(TextUtils.TruncateAt where) {
    super.setEllipsize(where);
    requestLayout();
}
 
Example 11
Source Project: watchlist   File: AutoResizeTextView.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void setEllipsize(TextUtils.TruncateAt where) {
    super.setEllipsize(where);
    requestLayout();
}
 
Example 12
public static StaticLayout createStaticLayout(CharSequence source, TextPaint paint, int width, Layout.Alignment align, float spacingmult, float spacingadd, boolean includepad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
    return createStaticLayout(source, 0, source.length(), paint, width, align, spacingmult, spacingadd, includepad, ellipsize, ellipsisWidth, maxLines, true);
}
 
Example 13
Source Project: react-native-GPay   File: ReactTextView.java    License: MIT License 4 votes vote down vote up
public void setEllipsizeLocation(TextUtils.TruncateAt ellipsizeLocation) {
  mEllipsizeLocation = ellipsizeLocation;
}
 
Example 14
Source Project: timecat   File: TEditText.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public TextUtils.TruncateAt getEllipsize() {
    return super.getEllipsize();
}
 
Example 15
Source Project: DevUtils   File: DefaultToastStyle.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 获取 Ellipsize 效果
 * @return Ellipsize 效果
 */
@Override
public TextUtils.TruncateAt getEllipsize() {
    return null;
}
 
Example 16
/**
 * Returns a StaticLayout using ICS specific constructor if possible.
 *
 * @param text The text for the layout
 * @param start The start index
 * @param end The end index
 * @param paint The {@link TextPaint} to be used
 * @param width The width of the layout
 * @param alignment The {@link Layout.Alignment}
 * @param spacingMult The line spacing multiplier
 * @param spacingAdd The line spacing extra
 * @param includePadding Whether to include font padding
 * @param ellipsize The ellipsizing behavior specified by {@link TextUtils.TruncateAt}
 * @param ellipsisWidth The width of the ellipsis
 * @param maxLines The maximum number of lines for this layout
 * @param textDirection The text direction
 * @return A {@link StaticLayout}
 */
private static StaticLayout getStaticLayoutMaybeMaxLines(
    CharSequence text,
    int start,
    int end,
    TextPaint paint,
    int width,
    Layout.Alignment alignment,
    float spacingMult,
    float spacingAdd,
    boolean includePadding,
    TextUtils.TruncateAt ellipsize,
    int ellipsisWidth,
    int maxLines,
    TextDirectionHeuristicCompat textDirection) {
  try {
    return StaticLayoutProxy.create(
        text,
        start,
        end,
        paint,
        width,
        alignment,
        spacingMult,
        spacingAdd,
        includePadding,
        ellipsize,
        ellipsisWidth,
        maxLines,
        textDirection);
  } catch (LinkageError e) {
    // Use the publicly available constructor.
  }

  return getStaticLayoutNoMaxLines(
      text,
      start,
      end,
      paint,
      width,
      alignment,
      spacingMult,
      spacingAdd,
      includePadding,
      ellipsize,
      ellipsisWidth);
}
 
Example 17
Source Project: DevUtils   File: SnackbarUse.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * TextView Ellipsize 效果
 * @return
 */
public TextUtils.TruncateAt getTextEllipsize() {
    return null;
}
 
Example 18
Source Project: DevUtils   File: TextViewUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 设置 Ellipsize 效果
 * @param view  {@link TextView}
 * @param where {@link TextUtils.TruncateAt}
 * @return {@link View}
 */
public static View setEllipsize(final View view, final TextUtils.TruncateAt where) {
    setEllipsize(getTextView(view), where);
    return view;
}
 
Example 19
Source Project: DevUtils   File: ToastTintUtils.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 获取 Ellipsize 效果
 * @return Ellipsize 效果
 */
TextUtils.TruncateAt getEllipsize();
 
Example 20
Source Project: DevUtils   File: IToast.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * 获取 Ellipsize 效果
 * @return Ellipsize 效果
 */
TextUtils.TruncateAt getEllipsize();