Java Code Examples for android.text.TextUtils.TruncateAt

The following are Jave code examples for showing how to use TruncateAt of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: GitHub   File: PickerView.java   View Source Code Vote up 5 votes
private TextUtils.TruncateAt getEllipsizeType() {
    switch (mTextEllipsize) {
        case TEXT_ELLIPSIZE_START:
            return TextUtils.TruncateAt.START;
        case TEXT_ELLIPSIZE_MIDDLE:
            return TextUtils.TruncateAt.MIDDLE;
        case TEXT_ELLIPSIZE_END:
            return TextUtils.TruncateAt.END;
        default:
            throw new IllegalArgumentException("Illegal text ellipsize type.");
    }
}
 
Example 2
Project: LuaViewPlayground   File: UDTextView.java   View Source Code Vote up 5 votes
/**
 * 设置超出部分的显示方式
 *
 * @param truncateAt
 * @return
 */
public UDTextView setEllipsize(TextUtils.TruncateAt truncateAt) {
    final T view = getView();
    if (view != null) {
        view.setEllipsize(truncateAt);
    }
    return this;
}
 
Example 3
Project: LuaViewPlayground   File: UDEllipsize.java   View Source Code Vote up 5 votes
public static TextUtils.TruncateAt parse(String ellipsizeName, TextUtils.TruncateAt defaultValue) {
    try {
        return TextUtils.TruncateAt.valueOf(ellipsizeName);
    } catch (Exception e) {
        e.printStackTrace();
        return defaultValue;
    }
}
 
Example 4
Project: QMUI_Android   File: QMUIQQFaceView.java   View Source Code Vote up 5 votes
public void setEllipsize(TextUtils.TruncateAt where) {
    if (mEllipsize != where) {
        mEllipsize = where;
        requestLayout();
        invalidate();
    }
}
 
Example 5
Project: SmartChart   File: NumberPickerView.java   View Source Code Vote up 5 votes
private TextUtils.TruncateAt getEllipsizeType() {
    switch (mTextEllipsize) {
        case TEXT_ELLIPSIZE_START:
            return TextUtils.TruncateAt.START;
        case TEXT_ELLIPSIZE_MIDDLE:
            return TextUtils.TruncateAt.MIDDLE;
        case TEXT_ELLIPSIZE_END:
            return TextUtils.TruncateAt.END;
        default:
            throw new IllegalArgumentException("Illegal text ellipsize type.");
    }
}
 
Example 6
Project: baselibrary-master   File: NumberPickerView.java   View Source Code Vote up 5 votes
private TextUtils.TruncateAt getEllipsizeType() {
    switch (mTextEllipsize) {
        case TEXT_ELLIPSIZE_START:
            return TextUtils.TruncateAt.START;
        case TEXT_ELLIPSIZE_MIDDLE:
            return TextUtils.TruncateAt.MIDDLE;
        case TEXT_ELLIPSIZE_END:
            return TextUtils.TruncateAt.END;
        default:
            throw new IllegalArgumentException("Illegal text ellipsize type.");
    }
}
 
Example 7
Project: FastTextView   File: FastTextView.java   View Source Code Vote up 5 votes
protected TextUtils.TruncateAt getTruncateAt() {
  switch (mAttrsHelper.mEllipsize) {
    // do not support marque
    case 1:
      return TextUtils.TruncateAt.START;
    case 2:
      return TextUtils.TruncateAt.MIDDLE;
    case 3:
      return TextUtils.TruncateAt.END;
    default:
      return null;
  }
}
 
Example 8
Project: LuaViewPlayground   File: UITextViewMethodMapper.java   View Source Code Vote up 4 votes
public LuaValue setEllipsize(U view, Varargs varargs) {
    //TODO 这里需要统一
    final String ellipsizeName = varargs.optjstring(2, TextUtils.TruncateAt.END.name());
    final TextUtils.TruncateAt ellipsize = UDEllipsize.parse(ellipsizeName);
    return view.setEllipsize(ellipsize);
}
 
Example 9
Project: airgram   File: StaticLayoutEx.java   View Source Code Vote up 4 votes
public static void init() {
    if (initialized) {
        return;
    }

    try {
        final Class<?> textDirClass;
        if (Build.VERSION.SDK_INT >= 18) {
            textDirClass = TextDirectionHeuristic.class;
            sTextDirection = TextDirectionHeuristics.FIRSTSTRONG_LTR;
        } else {
            ClassLoader loader = StaticLayoutEx.class.getClassLoader();
            textDirClass = loader.loadClass(TEXT_DIR_CLASS);
            Class<?> textDirsClass = loader.loadClass(TEXT_DIRS_CLASS);
            sTextDirection = textDirsClass.getField(TEXT_DIR_FIRSTSTRONG_LTR).get(textDirsClass);
        }

        final Class<?>[] signature = new Class[]{
                CharSequence.class,
                int.class,
                int.class,
                TextPaint.class,
                int.class,
                Layout.Alignment.class,
                textDirClass,
                float.class,
                float.class,
                boolean.class,
                TextUtils.TruncateAt.class,
                int.class,
                int.class
        };

        sConstructor = StaticLayout.class.getDeclaredConstructor(signature);
        sConstructor.setAccessible(true);
        sConstructorArgs = new Object[signature.length];
        initialized = true;
    } catch (Throwable e) {
        FileLog.e("tmessages", e);
    }
}
 
Example 10
Project: airgram   File: StaticLayoutEx.java   View Source Code Vote up 4 votes
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);
}
 
Example 11
Project: airgram   File: StaticLayoutEx.java   View Source Code Vote up 4 votes
public static StaticLayout createStaticLayout(CharSequence source, int bufstart, int bufend, TextPaint paint, int outerWidth, Layout.Alignment align, float spacingMult, float spacingAdd, boolean includePad, TextUtils.TruncateAt ellipsize, int ellipsisWidth, int maxLines) {
    /*if (Build.VERSION.SDK_INT >= 14) {
        init();
        try {
            sConstructorArgs[0] = source;
            sConstructorArgs[1] = bufstart;
            sConstructorArgs[2] = bufend;
            sConstructorArgs[3] = paint;
            sConstructorArgs[4] = outerWidth;
            sConstructorArgs[5] = align;
            sConstructorArgs[6] = sTextDirection;
            sConstructorArgs[7] = spacingMult;
            sConstructorArgs[8] = spacingAdd;
            sConstructorArgs[9] = includePad;
            sConstructorArgs[10] = ellipsize;
            sConstructorArgs[11] = ellipsisWidth;
            sConstructorArgs[12] = maxLines;
            return sConstructor.newInstance(sConstructorArgs);
        } catch (Exception e) {
            FileLog.e("tmessages", e);
        }
    }*/
    try {
        if (maxLines == 1) {
            CharSequence text = TextUtils.ellipsize(source, paint, ellipsisWidth, TextUtils.TruncateAt.END);
            return new StaticLayout(text, 0, text.length(), paint, outerWidth, align, spacingMult, spacingAdd, includePad);
        } else {
            StaticLayout layout = new StaticLayout(source, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
            if (layout.getLineCount() <= maxLines) {
                return layout;
            } else {
                int off;
                float left = layout.getLineLeft(maxLines - 1);
                if (left != 0) {
                    off = layout.getOffsetForHorizontal(maxLines - 1, left);
                } else {
                    off = layout.getOffsetForHorizontal(maxLines - 1, layout.getLineWidth(maxLines - 1));
                }
                SpannableStringBuilder stringBuilder = new SpannableStringBuilder(source.subSequence(0, Math.max(0, off - 1)));
                stringBuilder.append("\u2026");
                return new StaticLayout(stringBuilder, paint, outerWidth, align, spacingMult, spacingAdd, includePad);
            }
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    return null;
}
 
Example 12
Project: RNLearn_Project1   File: RCTText.java   View Source Code Vote up 4 votes
private static Layout createTextLayout(
    int width,
    YogaMeasureMode widthMode,
    TextUtils.TruncateAt ellipsize,
    boolean shouldIncludeFontPadding,
    int maxLines,
    boolean isSingleLine,
    CharSequence text,
    int textSize,
    float extraSpacing,
    float spacingMultiplier,
    int textStyle,
    Layout.Alignment textAlignment) {
  Layout newLayout;

  final @TextLayoutBuilder.MeasureMode int textMeasureMode;
  switch (widthMode) {
    case UNDEFINED:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_UNSPECIFIED;
      break;
    case EXACTLY:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_EXACTLY;
      break;
    case AT_MOST:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_AT_MOST;
      break;
    default:
      throw new IllegalStateException("Unexpected size mode: " + widthMode);
  }

  sTextLayoutBuilder
      .setEllipsize(ellipsize)
      .setMaxLines(maxLines)
      .setSingleLine(isSingleLine)
      .setText(text)
      .setTextSize(textSize)
      .setWidth(width, textMeasureMode);

  sTextLayoutBuilder.setTextStyle(textStyle);

  sTextLayoutBuilder.setTextDirection(TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR);
  sTextLayoutBuilder.setIncludeFontPadding(shouldIncludeFontPadding);
  sTextLayoutBuilder.setTextSpacingExtra(extraSpacing);
  sTextLayoutBuilder.setTextSpacingMultiplier(spacingMultiplier);
  sTextLayoutBuilder.setAlignment(textAlignment);

  newLayout = sTextLayoutBuilder.build();

  sTextLayoutBuilder.setText(null);

  return newLayout;
}
 
Example 13
Project: PlusGram   File: StaticLayoutEx.java   View Source Code Vote up 4 votes
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);
}
 
Example 14
Project: RNLearn_Project1   File: RCTText.java   View Source Code Vote up 4 votes
private static Layout createTextLayout(
    int width,
    YogaMeasureMode widthMode,
    TextUtils.TruncateAt ellipsize,
    boolean shouldIncludeFontPadding,
    int maxLines,
    boolean isSingleLine,
    CharSequence text,
    int textSize,
    float extraSpacing,
    float spacingMultiplier,
    int textStyle,
    Layout.Alignment textAlignment) {
  Layout newLayout;

  final @TextLayoutBuilder.MeasureMode int textMeasureMode;
  switch (widthMode) {
    case UNDEFINED:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_UNSPECIFIED;
      break;
    case EXACTLY:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_EXACTLY;
      break;
    case AT_MOST:
      textMeasureMode = TextLayoutBuilder.MEASURE_MODE_AT_MOST;
      break;
    default:
      throw new IllegalStateException("Unexpected size mode: " + widthMode);
  }

  sTextLayoutBuilder
      .setEllipsize(ellipsize)
      .setMaxLines(maxLines)
      .setSingleLine(isSingleLine)
      .setText(text)
      .setTextSize(textSize)
      .setWidth(width, textMeasureMode);

  sTextLayoutBuilder.setTextStyle(textStyle);

  sTextLayoutBuilder.setTextDirection(TextDirectionHeuristicsCompat.FIRSTSTRONG_LTR);
  sTextLayoutBuilder.setIncludeFontPadding(shouldIncludeFontPadding);
  sTextLayoutBuilder.setTextSpacingExtra(extraSpacing);
  sTextLayoutBuilder.setTextSpacingMultiplier(spacingMultiplier);
  sTextLayoutBuilder.setAlignment(textAlignment);

  newLayout = sTextLayoutBuilder.build();

  sTextLayoutBuilder.setText(null);

  return newLayout;
}
 
Example 15
Project: CommentView   File: CanvasTextArea.java   View Source Code Vote up 4 votes
public void setEllipsize(TextUtils.TruncateAt truncateAt) {
    if (this.mEllipsize != truncateAt) {
        this.mEllipsize = truncateAt;
    }
}
 
Example 16
Project: Sega   File: AutoResizeTextView.java   View Source Code Vote up 4 votes
@Override
public void setEllipsize(TextUtils.TruncateAt where) {
    super.setEllipsize(where);
    requestLayout();
}
 
Example 17
Project: Aurora   File: ExpandTextView.java   View Source Code Vote up 4 votes
public void setEllipsize(TextUtils.TruncateAt ell) {
    mText.setEllipsize(ell);
}
 
Example 18
Project: RNLearn_Project1   File: ReactTextView.java   View Source Code Vote up 4 votes
public void updateView() {
  @Nullable TextUtils.TruncateAt ellipsizeLocation = mNumberOfLines == ViewDefaults.NUMBER_OF_LINES ? null : mEllipsizeLocation;
  setEllipsize(ellipsizeLocation);
}
 
Example 19
Project: RNLearn_Project1   File: ReactTextView.java   View Source Code Vote up 4 votes
public void setEllipsizeLocation(TextUtils.TruncateAt ellipsizeLocation) {
  mEllipsizeLocation = ellipsizeLocation;
}
 
Example 20
Project: LuaViewPlayground   File: UDEllipsize.java   View Source Code Vote up 2 votes
/**
 * parse ellipsize
 *
 * @param ellipsizeName
 * @return
 */
public static TextUtils.TruncateAt parse(String ellipsizeName) {
    return parse(ellipsizeName, TextUtils.TruncateAt.END);
}