Java 类android.text.TextUtils.TruncateAt 实例源码
项目:PeSanKita-android
文件:EmojiTextView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int size = MeasureSpec.getSize(widthMeasureSpec);
final int mode = MeasureSpec.getMode(widthMeasureSpec);
if (!useSystemEmoji() &&
getEllipsize() == TruncateAt.END &&
!TextUtils.isEmpty(source) &&
(mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) &&
getPaint().breakText(source, 0, source.length()-1, true, size, null) != source.length())
{
needsEllipsizing = true;
FontMetricsInt font = getPaint().getFontMetricsInt();
super.onMeasure(MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(Math.abs(font.top - font.bottom), MeasureSpec.EXACTLY));
} else {
needsEllipsizing = false;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
项目:chromium-for-android-56-debug-video
文件:TemplatePreservingTextView.java
private CharSequence getTruncatedText(int availWidth) {
final TextPaint paint = getPaint();
// Calculate the width the template takes.
final String emptyTemplate = String.format(mTemplate, "");
final float emptyTemplateWidth = paint.measureText(emptyTemplate);
// Calculate the available width for the content.
final float contentWidth = Math.max(availWidth - emptyTemplateWidth, 0.f);
// Ellipsize the content to the available width.
CharSequence clipped = TextUtils.ellipsize(mContent, paint, contentWidth, TruncateAt.END);
// Build the full string, which should fit within availWidth.
return String.format(mTemplate, clipped);
}
项目:letv
文件:TaskGuide.java
private void a() {
this.b = new TextView(this.a.F);
this.b.setTextColor(Color.rgb(255, 255, 255));
this.b.setTextSize(15.0f);
this.b.setShadowLayer(1.0f, 1.0f, 1.0f, Color.rgb(242, 211, 199));
this.b.setGravity(3);
this.b.setEllipsize(TruncateAt.END);
this.b.setIncludeFontPadding(false);
this.b.setSingleLine(true);
ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, -2);
layoutParams.weight = 1.0f;
layoutParams.leftMargin = this.a.a(4);
addView(this.b, layoutParams);
this.c = new Button(this.a.F);
this.c.setPadding(0, 0, 0, 0);
this.c.setTextSize(16.0f);
this.c.setTextColor(Color.rgb(255, 255, 255));
this.c.setShadowLayer(1.0f, 1.0f, 1.0f, Color.rgb(242, 211, 199));
this.c.setIncludeFontPadding(false);
this.c.setOnClickListener(new f(this.a, this.d.a));
layoutParams = new LinearLayout.LayoutParams(this.a.a(TaskGuide.p), this.a.a(TaskGuide.q));
layoutParams.leftMargin = this.a.a(2);
layoutParams.rightMargin = this.a.a(8);
addView(this.c, layoutParams);
}
项目:boohee_v5.6
文件:BooheeNoticeActivity.java
private void findView() {
this.txt_notice_good_morning_sub_title = (TextView) findViewById(R.id
.txt_notice_good_morning_sub_title);
this.txt_notice_diet_sub_title = (TextView) findViewById(R.id.txt_notice_diet_sub_title);
this.txt_notice_sport_sub_title = (TextView) findViewById(R.id.txt_notice_sport_sub_title);
this.txt_notice_water_sub_title = (TextView) findViewById(R.id.txt_notice_water_sub_title);
this.txt_notice_box_count = (TextView) findViewById(R.id.txt_notice_box_count);
this.txt_notice_good_morning_sub_title.setEllipsize(TruncateAt.END);
this.txt_notice_diet_sub_title.setEllipsize(TruncateAt.END);
this.txt_notice_sport_sub_title.setEllipsize(TruncateAt.END);
this.txt_notice_water_sub_title.setEllipsize(TruncateAt.END);
this.tb_notice_good_morning = (ToggleButton) findViewById(R.id.tb_notice_good_morning);
this.tb_notice_diet = (ToggleButton) findViewById(R.id.tb_notice_diet);
this.tb_notice_sport = (ToggleButton) findViewById(R.id.tb_notice_sport);
this.tb_notice_water = (ToggleButton) findViewById(R.id.tb_notice_water);
}
项目:boohee_v5.6
文件:Toolbar.java
public void setTitle(CharSequence title) {
if (!TextUtils.isEmpty(title)) {
if (this.mTitleTextView == null) {
Context context = getContext();
this.mTitleTextView = new TextView(context);
this.mTitleTextView.setSingleLine();
this.mTitleTextView.setEllipsize(TruncateAt.END);
if (this.mTitleTextAppearance != 0) {
this.mTitleTextView.setTextAppearance(context, this.mTitleTextAppearance);
}
if (this.mTitleTextColor != 0) {
this.mTitleTextView.setTextColor(this.mTitleTextColor);
}
}
if (!isChildOrHidden(this.mTitleTextView)) {
addSystemView(this.mTitleTextView, true);
}
} else if (this.mTitleTextView != null && isChildOrHidden(this.mTitleTextView)) {
removeView(this.mTitleTextView);
this.mHiddenViews.remove(this.mTitleTextView);
}
if (this.mTitleTextView != null) {
this.mTitleTextView.setText(title);
}
this.mTitleText = title;
}
项目:boohee_v5.6
文件:Toolbar.java
public void setSubtitle(CharSequence subtitle) {
if (!TextUtils.isEmpty(subtitle)) {
if (this.mSubtitleTextView == null) {
Context context = getContext();
this.mSubtitleTextView = new TextView(context);
this.mSubtitleTextView.setSingleLine();
this.mSubtitleTextView.setEllipsize(TruncateAt.END);
if (this.mSubtitleTextAppearance != 0) {
this.mSubtitleTextView.setTextAppearance(context, this.mSubtitleTextAppearance);
}
if (this.mSubtitleTextColor != 0) {
this.mSubtitleTextView.setTextColor(this.mSubtitleTextColor);
}
}
if (!isChildOrHidden(this.mSubtitleTextView)) {
addSystemView(this.mSubtitleTextView, true);
}
} else if (this.mSubtitleTextView != null && isChildOrHidden(this.mSubtitleTextView)) {
removeView(this.mSubtitleTextView);
this.mHiddenViews.remove(this.mSubtitleTextView);
}
if (this.mSubtitleTextView != null) {
this.mSubtitleTextView.setText(subtitle);
}
this.mSubtitleText = subtitle;
}
项目:simple-share-android
文件:RecentsCreateFragment.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
if (convertView == null) {
final LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
}
final ImageView iconMime = (ImageView) convertView.findViewById(R.id.icon_mime);
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final View line2 = convertView.findViewById(R.id.line2);
final DocumentStack stack = getItem(position);
iconMime.setImageDrawable(stack.root.loadIcon(context));
final Drawable crumb = ContextCompat.getDrawable(context, R.drawable.ic_breadcrumb_arrow);
crumb.setBounds(0, 0, crumb.getIntrinsicWidth(), crumb.getIntrinsicHeight());
final SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(stack.root.title);
for (int i = stack.size() - 2; i >= 0; i--) {
appendDrawable(builder, crumb);
builder.append(stack.get(i).displayName);
}
title.setText(builder);
title.setEllipsize(TruncateAt.MIDDLE);
if (line2 != null) line2.setVisibility(View.GONE);
return convertView;
}
项目:Cable-Android
文件:EmojiTextView.java
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int size = MeasureSpec.getSize(widthMeasureSpec);
final int mode = MeasureSpec.getMode(widthMeasureSpec);
if (!useSystemEmoji() &&
getEllipsize() == TruncateAt.END &&
!TextUtils.isEmpty(source) &&
(mode == MeasureSpec.AT_MOST || mode == MeasureSpec.EXACTLY) &&
getPaint().breakText(source, 0, source.length()-1, true, size, null) != source.length())
{
needsEllipsizing = true;
FontMetricsInt font = getPaint().getFontMetricsInt();
super.onMeasure(MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(Math.abs(font.top - font.bottom), MeasureSpec.EXACTLY));
} else {
needsEllipsizing = false;
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
项目:solved-hacking-problem
文件:Toolbar.java
public void setSubtitle(CharSequence charSequence) {
if (!TextUtils.isEmpty(charSequence)) {
if (this.f1243d == null) {
Context context = getContext();
this.f1243d = new TextView(context);
this.f1243d.setSingleLine();
this.f1243d.setEllipsize(TruncateAt.END);
if (this.f1252m != 0) {
this.f1243d.setTextAppearance(context, this.f1252m);
}
if (this.f1264y != 0) {
this.f1243d.setTextColor(this.f1264y);
}
}
if (!m2431d(this.f1243d)) {
m2421a(this.f1243d, true);
}
} else if (this.f1243d != null && m2431d(this.f1243d)) {
removeView(this.f1243d);
this.f1228C.remove(this.f1243d);
}
if (this.f1243d != null) {
this.f1243d.setText(charSequence);
}
this.f1262w = charSequence;
}
项目:solved-hacking-problem
文件:Toolbar.java
public void setTitle(CharSequence charSequence) {
if (!TextUtils.isEmpty(charSequence)) {
if (this.f1242c == null) {
Context context = getContext();
this.f1242c = new TextView(context);
this.f1242c.setSingleLine();
this.f1242c.setEllipsize(TruncateAt.END);
if (this.f1251l != 0) {
this.f1242c.setTextAppearance(context, this.f1251l);
}
if (this.f1263x != 0) {
this.f1242c.setTextColor(this.f1263x);
}
}
if (!m2431d(this.f1242c)) {
m2421a(this.f1242c, true);
}
} else if (this.f1242c != null && m2431d(this.f1242c)) {
removeView(this.f1242c);
this.f1228C.remove(this.f1242c);
}
if (this.f1242c != null) {
this.f1242c.setText(charSequence);
}
this.f1261v = charSequence;
}
项目:solved-hacking-problem
文件:Toolbar.java
public void setSubtitle(CharSequence charSequence) {
if (!TextUtils.isEmpty(charSequence)) {
if (this.f1243d == null) {
Context context = getContext();
this.f1243d = new TextView(context);
this.f1243d.setSingleLine();
this.f1243d.setEllipsize(TruncateAt.END);
if (this.f1252m != 0) {
this.f1243d.setTextAppearance(context, this.f1252m);
}
if (this.f1264y != 0) {
this.f1243d.setTextColor(this.f1264y);
}
}
if (!m2431d(this.f1243d)) {
m2421a(this.f1243d, true);
}
} else if (this.f1243d != null && m2431d(this.f1243d)) {
removeView(this.f1243d);
this.f1228C.remove(this.f1243d);
}
if (this.f1243d != null) {
this.f1243d.setText(charSequence);
}
this.f1262w = charSequence;
}
项目:solved-hacking-problem
文件:Toolbar.java
public void setTitle(CharSequence charSequence) {
if (!TextUtils.isEmpty(charSequence)) {
if (this.f1242c == null) {
Context context = getContext();
this.f1242c = new TextView(context);
this.f1242c.setSingleLine();
this.f1242c.setEllipsize(TruncateAt.END);
if (this.f1251l != 0) {
this.f1242c.setTextAppearance(context, this.f1251l);
}
if (this.f1263x != 0) {
this.f1242c.setTextColor(this.f1263x);
}
}
if (!m2431d(this.f1242c)) {
m2421a(this.f1242c, true);
}
} else if (this.f1242c != null && m2431d(this.f1242c)) {
removeView(this.f1242c);
this.f1228C.remove(this.f1242c);
}
if (this.f1242c != null) {
this.f1242c.setText(charSequence);
}
this.f1261v = charSequence;
}
项目:AndroidChromium
文件:TemplatePreservingTextView.java
private CharSequence getTruncatedText(int availWidth) {
final TextPaint paint = getPaint();
// Calculate the width the template takes.
final String emptyTemplate = String.format(mTemplate, "");
final float emptyTemplateWidth = paint.measureText(emptyTemplate);
// Calculate the available width for the content.
final float contentWidth = Math.max(availWidth - emptyTemplateWidth, 0.f);
// Ellipsize the content to the available width.
CharSequence clipped = TextUtils.ellipsize(mContent, paint, contentWidth, TruncateAt.END);
// Build the full string, which should fit within availWidth.
return String.format(mTemplate, clipped);
}
项目:j2se_for_android
文件:JMenuItem.java
private void addText(boolean isLeftToRight) {
textView = new TextView(ActivityManager.getActivity());
textView.setText(text);
textView.setSingleLine(true);
textView.setTextColor(isEnable?AndroidUIUtil.WIN_FONT_COLOR.toAndroid():AndroidUIUtil.WIN_FONT_DISABLE_COLOR.toAndroid());
UICore.setTextSize(textView, getScreenAdapterAdAPI());
textView.setMaxWidth(300);
textView.setEllipsize(TruncateAt.MARQUEE);
textView.setGravity(Gravity.CENTER_VERTICAL | (isLeftToRight?Gravity.LEFT:Gravity.RIGHT));
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.gravity = textView.getGravity();
if(isLeftToRight){
lp.leftMargin = 5;
}else{
lp.rightMargin = 5;
}
AndroidUIUtil.addView(defaultLinearLayout, textView, lp, viewRelation);
}
项目:msb-android
文件:FavoriteFolderItemView.java
private TextView createQuestionTextView(MQuestion question, boolean isLastItem) {
TextView textView = new TextView(getContext());
textView.setMaxLines(3);
textView.setEllipsize(TruncateAt.END);
String description = removeBlankLine(question.description);
textView.setText(description);
int vPadding = getResources().getDimensionPixelSize(R.dimen.question_item_padding_v);
textView.setPadding(mPadding, vPadding, mPadding, isLastItem ? vPadding : 0);
int textColor = getResources().getColor(R.color.favorite_folder_question_desc);
textView.setTextColor(textColor);
int textSize = getResources().getDimensionPixelSize(R.dimen.favorite_folder_question_text_size);
textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
return textView;
}
项目:Vafrinn
文件:TemplatePreservingTextView.java
private CharSequence getTruncatedText(int availWidth) {
final TextPaint paint = getPaint();
// Calculate the width the template takes.
final String emptyTemplate = String.format(mTemplate, "");
final float emptyTemplateWidth = paint.measureText(emptyTemplate);
// Calculate the available width for the content.
final float contentWidth = Math.max(availWidth - emptyTemplateWidth, 0.f);
// Ellipsize the content to the available width.
CharSequence clipped = TextUtils.ellipsize(mContent, paint, contentWidth, TruncateAt.END);
// Build the full string, which should fit within availWidth.
return String.format(mTemplate, clipped);
}
项目:FMTech
文件:dzn.java
public dzn(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
super(paramContext, paramAttributeSet, paramInt);
this.a = loj.a(paramContext);
this.g = new dzo(paramContext);
if (!this.c) {}
for (int i1 = 19;; i1 = 10)
{
Button localButton = lur.a(paramContext, paramAttributeSet, paramInt, i1, this.a.aQ, 0);
localButton.setSingleLine(true);
localButton.setEllipsize(TextUtils.TruncateAt.END);
localButton.setCompoundDrawablePadding(this.a.n);
localButton.setOnClickListener(this);
this.i = localButton;
this.i.setText(getContext().getString(aau.iJ));
this.l = new MediaView(paramContext, paramAttributeSet, paramInt);
this.l.setOnClickListener(this);
this.l.setContentDescription(getResources().getString(aau.dg));
this.h = new ArrayList();
this.j = new ImageView(paramContext, paramAttributeSet, paramInt);
this.j.setImageBitmap(this.a.f);
this.j.setScaleType(ImageView.ScaleType.CENTER);
this.o = new TextView(paramContext, paramAttributeSet, paramInt);
return;
}
}
项目:FMTech
文件:dxm.java
private dxm(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
super(paramContext, paramAttributeSet, 0);
this.a = new TextView(paramContext);
this.a.setGravity(17);
this.a.setMaxLines(2);
this.a.setEllipsize(TextUtils.TruncateAt.END);
this.a.setGravity(1);
this.a.setTextAppearance(paramContext, efj.yu);
this.b = new ImageView(paramContext);
this.b.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
this.i = ((lwj)mbb.a(paramContext, lwj.class));
Resources localResources = paramContext.getResources();
setBackgroundResource(da.aY);
if (e == 0)
{
e = (int)localResources.getDimension(efj.mq);
f = (int)localResources.getDimension(efj.mo);
g = (int)localResources.getDimension(efj.ml);
}
}
项目:FMTech
文件:dws.java
public dws(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
super(paramContext, paramAttributeSet, paramInt);
if (!f)
{
Resources localResources = paramContext.getResources();
a = localResources.getString(aau.gh);
g = localResources.getDimension(efj.nK);
h = localResources.getColor(efj.ko);
f = true;
}
float f1 = g;
int i = h;
TextView localTextView = new TextView(paramContext, paramAttributeSet, paramInt);
localTextView.setTextSize(0, f1);
localTextView.setSingleLine(true);
localTextView.setTextColor(i);
localTextView.setEllipsize(TextUtils.TruncateAt.END);
this.c = localTextView;
addView(this.c);
this.b = new dvb(paramContext, paramAttributeSet, paramInt);
addView(this.b);
this.d = 0;
this.e = 0;
}
项目:FMTech
文件:dwq.java
public dwq(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
super(paramContext, paramAttributeSet, paramInt);
this.j = paramContext;
this.i = paramAttributeSet;
this.k = paramInt;
Resources localResources = paramContext.getResources();
if (!d)
{
e = localResources.getColor(efj.kp);
f = localResources.getDimension(efj.nK);
g = localResources.getColor(efj.kp);
h = localResources.getDimension(efj.nJ);
d = true;
}
float f1 = f;
int m = e;
TextView localTextView = new TextView(paramContext, paramAttributeSet, paramInt);
localTextView.setTextSize(0, f1);
localTextView.setSingleLine(true);
localTextView.setTextColor(m);
localTextView.setEllipsize(TextUtils.TruncateAt.END);
localTextView.setTypeface(Typeface.DEFAULT_BOLD);
this.a = localTextView;
addView(this.a);
}
项目:FMTech
文件:lha.java
public final void a(Context paramContext, int paramInt, View paramView, boolean paramBoolean)
{
SquareAvatarView localSquareAvatarView = (SquareAvatarView)paramView.findViewById(dl.am);
lgu locallgu = (lgu)this.ab.get(paramInt);
String str = locallgu.b;
if (str != null) {
localSquareAvatarView.a.a(null, str);
}
TextView localTextView = (TextView)paramView.findViewById(dl.an);
localTextView.setText(locallgu.a.b);
localTextView.setTextSize(0, g().getDimension(ehr.dS));
localTextView.setTypeface(localTextView.getTypeface(), 1);
localTextView.setMaxLines(2);
localTextView.setEllipsize(TextUtils.TruncateAt.END);
localTextView.setIncludeFontPadding(false);
localTextView.setTextColor(g().getColor(aau.CC));
efj.a(paramView, new kuw(pjo.u, locallgu.a.a));
}
项目:FMTech
文件:hfq.java
public hfq(Context paramContext)
{
super(paramContext);
Context localContext = getContext();
this.d = ((hfr)mbb.a(localContext, hfr.class));
Resources localResources = localContext.getResources();
int i = localResources.getDimensionPixelOffset(aaw.nr);
this.b = localResources.getInteger(aau.yQ);
setPadding(i, i, i, i);
this.a = lur.b(localContext, null, 0, 3, i, 0);
this.a.setClickable(false);
addView(this.a);
ImageButton localImageButton = this.a;
nj.a.c(localImageButton, 2);
this.a.setFocusable(false);
this.a.setFocusableInTouchMode(false);
this.c = new TextView(localContext);
this.c.setTextAppearance(localContext, aaw.nI);
this.c.setMaxLines(1);
this.c.setEllipsize(TextUtils.TruncateAt.END);
addView(this.c);
this.e = new gqw(this);
}
项目:FMTech
文件:dvk.java
public dvk(Context paramContext, AttributeSet paramAttributeSet, int paramInt)
{
super(paramContext, paramAttributeSet, paramInt);
this.b = new TextView(paramContext, paramAttributeSet, paramInt);
this.b.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
this.b.setTextAppearance(paramContext, efj.yr);
this.b.setSingleLine();
this.b.setEllipsize(TextUtils.TruncateAt.END);
addView(this.b);
this.e = new Point();
this.a = new TextView(paramContext, paramAttributeSet, paramInt);
this.a.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
this.a.setTextAppearance(paramContext, efj.yD);
this.a.setSingleLine();
this.a.setEllipsize(TextUtils.TruncateAt.END);
addView(this.a);
this.g = new Point();
this.c = new TextView(paramContext, paramAttributeSet, paramInt);
this.c.setTextAppearance(paramContext, efj.yo);
this.c.setMovementMethod(lxy.a());
addView(this.c);
}
项目:FMTech
文件:hgl.java
public final void a(String paramString)
{
if (this.m == null)
{
Context localContext = getContext();
this.m = new TextView(localContext);
this.m.setSingleLine(true);
this.m.setEllipsize(TextUtils.TruncateAt.END);
this.m.setGravity(16);
this.m.setLayoutParams(new ViewGroup.LayoutParams(-2, -2));
this.m.setTextAppearance(localContext, efj.Hr);
addView(this.m);
}
this.m.setText(paramString);
this.m.setVisibility(0);
this.D = true;
}
项目:TextSecureSMP
文件:EmojiFilter.java
@Override public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend)
{
char[] v = new char[end - start];
TextUtils.getChars(source, start, end, v, 0);
Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);
if (source instanceof Spanned) {
TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
}
view.getViewTreeObserver().addOnGlobalLayoutListener(this);
if (view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return emojified;
} else {
return TextUtils.ellipsize(emojified,
view.getPaint(),
view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(),
TruncateAt.END);
}
}
项目:QuickControlPanel
文件:MusicViewFactory.java
private TextView getMetadataTextView(ViewGroup.LayoutParams params, OnClickListener l) {
final ColorStateList colors = new ColorStateList(
new int[][]{
new int[]{android.R.attr.state_pressed},
new int[] { android.R.attr.state_enabled}
},
new int[] {
ColorsResolver.getPressedColor(mContext),
ColorsResolver.getTextColor(mContext)
});
TextView result = new TextView(mContext);
result.setLayoutParams(params);
result.setText(R.string.unknown);
result.setOnClickListener(l);
result.setMaxLines(1);
result.setSingleLine();
result.setMarqueeRepeatLimit(-1);
result.setSelected(true);
result.setGravity(Gravity.CENTER);
result.setEllipsize(TruncateAt.MARQUEE);
result.setTextColor(colors);
result.setTextSize(TypedValue.COMPLEX_UNIT_SP, MusicResolver.getMetadataTextSize(mContext));
return result;
}
项目:sticky-dictionary
文件:EllipsizingTextView.java
/**
* Causes words in the text that are longer than the view is wide to be ellipsized
* instead of broken in the middle. Use {@code null} to turn off ellipsizing.
* <p/>
* Note: Method does nothing for {@link android.text.TextUtils.TruncateAt#MARQUEE}
* ellipsizing type.
*
* @param where part of text to ellipsize
*/
@Override
public void setEllipsize(TruncateAt where) {
if (where == null) {
mEllipsizeStrategy = new EllipsizeNoneStrategy();
return;
}
switch (where) {
case END:
mEllipsizeStrategy = new EllipsizeEndStrategy();
break;
case START:
mEllipsizeStrategy = new EllipsizeStartStrategy();
break;
case MIDDLE:
mEllipsizeStrategy = new EllipsizeMiddleStrategy();
break;
case MARQUEE:
default:
mEllipsizeStrategy = new EllipsizeNoneStrategy();
break;
}
}
项目:365browser
文件:PaymentRequestSection.java
@Override
public void setDisplayMode(int displayMode) {
// Displays the summary left text view in at most three lines if in focus mode,
// otherwise display it in a single line.
if (displayMode == DISPLAY_MODE_FOCUSED) {
setSummaryProperties(TruncateAt.END, false /* leftIsSingleLine */,
null /* rightTruncate */, false /* rightIsSingleLine */);
getSummaryLeftTextView().setMaxLines(3);
} else {
setSummaryProperties(TruncateAt.END, true /* leftIsSingleLine */,
null /* rightTruncate */, false /* rightIsSingleLine */);
getSummaryLeftTextView().setMaxLines(1);
}
super.setDisplayMode(displayMode);
}
项目:365browser
文件:TemplatePreservingTextView.java
private CharSequence getTruncatedText(int availWidth) {
final TextPaint paint = getPaint();
// Calculate the width the template takes.
final String emptyTemplate = String.format(mTemplate, "");
final float emptyTemplateWidth = paint.measureText(emptyTemplate);
// Calculate the available width for the content.
final float contentWidth = Math.max(availWidth - emptyTemplateWidth, 0.f);
// Ellipsize the content to the available width.
CharSequence clipped = TextUtils.ellipsize(mContent, paint, contentWidth, TruncateAt.END);
// Build the full string, which should fit within availWidth.
return String.format(mTemplate, clipped);
}
项目:PeSanKita-android
文件:ViewUtil.java
public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) {
if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return text;
} else {
return TextUtils.ellipsize(text,
view.getPaint(),
view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(),
TruncateAt.END);
}
}
项目:easyfilemanager
文件:RecentsCreateFragment.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
if (convertView == null) {
final LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
}
final ImageView iconMime = (ImageView) convertView.findViewById(R.id.icon_mime);
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final View line2 = convertView.findViewById(R.id.line2);
final DocumentStack stack = getItem(position);
iconMime.setImageDrawable(stack.root.loadIcon(context));
final Drawable crumb = ContextCompat.getDrawable(context, R.drawable.ic_breadcrumb_arrow);
crumb.setBounds(0, 0, crumb.getIntrinsicWidth(), crumb.getIntrinsicHeight());
final SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(stack.root.title);
for (int i = stack.size() - 2; i >= 0; i--) {
appendDrawable(builder, crumb);
builder.append(stack.get(i).displayName);
}
title.setText(builder);
title.setEllipsize(TruncateAt.MIDDLE);
if (line2 != null) line2.setVisibility(View.GONE);
return convertView;
}
项目:chromium-for-android-56-debug-video
文件:PaymentRequestSection.java
/**
* Sets how the summary text should be displayed.
*
* @param leftTruncate How to truncate the left summary text. Set to null to clear.
* @param rightTruncate How to truncate the right summary text. Set to null to clear.
*/
public void setSummaryProperties(@Nullable TruncateAt leftTruncate, boolean leftIsSingleLine,
@Nullable TruncateAt rightTruncate, boolean rightIsSingleLine) {
mSummaryLeftTextView.setEllipsize(leftTruncate);
mSummaryLeftTextView.setSingleLine(leftIsSingleLine);
mSummaryRightTextView.setEllipsize(rightTruncate);
mSummaryRightTextView.setSingleLine(rightIsSingleLine);
}
项目:chromium-for-android-56-debug-video
文件:PaymentRequestSection.java
/**
* Sets how the extra texts should be displayed.
*
* @param textsTruncate How to truncate the extra texts. Set the element to null to clear.
* @param textsAreSingleLine Whether the extra texts should be displayed in a single line.
*/
public void setExtraTextsProperties(
TruncateAt[] textsTruncate, boolean[] textsAreSingleLine) {
assert textsTruncate.length == mExtraTextViews.length;
assert textsAreSingleLine.length == mExtraTextViews.length;
for (int i = 0; i < mExtraTextViews.length; i++) {
mExtraTextViews[i].setEllipsize(textsTruncate[i]);
mExtraTextViews[i].setSingleLine(textsAreSingleLine[i]);
}
}
项目:letv
文件:WeiboSdkBrowser.java
private View initTitleBar() {
RelativeLayout titleBar = new RelativeLayout(this);
titleBar.setLayoutParams(new LayoutParams(-1, ResourceManager.dp2px(this, 45)));
titleBar.setBackgroundDrawable(ResourceManager.getNinePatchDrawable(this, "weibosdk_navigationbar_background.9.png"));
this.mLeftBtn = new TextView(this);
this.mLeftBtn.setClickable(true);
this.mLeftBtn.setTextSize(2, 17.0f);
this.mLeftBtn.setTextColor(ResourceManager.createColorStateList(-32256, 1728020992));
this.mLeftBtn.setText(ResourceManager.getString(this, CANCEL_EN, "关闭", "关闭"));
RelativeLayout.LayoutParams leftBtnLp = new RelativeLayout.LayoutParams(-2, -2);
leftBtnLp.addRule(5);
leftBtnLp.addRule(15);
leftBtnLp.leftMargin = ResourceManager.dp2px(this, 10);
leftBtnLp.rightMargin = ResourceManager.dp2px(this, 10);
this.mLeftBtn.setLayoutParams(leftBtnLp);
titleBar.addView(this.mLeftBtn);
this.mTitleText = new TextView(this);
this.mTitleText.setTextSize(2, 18.0f);
this.mTitleText.setTextColor(-11382190);
this.mTitleText.setEllipsize(TruncateAt.END);
this.mTitleText.setSingleLine(true);
this.mTitleText.setGravity(17);
this.mTitleText.setMaxWidth(ResourceManager.dp2px(this, 160));
RelativeLayout.LayoutParams titleTextLy = new RelativeLayout.LayoutParams(-2, -2);
titleTextLy.addRule(13);
this.mTitleText.setLayoutParams(titleTextLy);
titleBar.addView(this.mTitleText);
return titleBar;
}
项目:PlusGram
文件:EditTextCaption.java
@SuppressLint({"DrawAllocation"})
protected void onMeasure(int i, int i2) {
try {
super.onMeasure(i, i2);
} catch (Throwable e) {
FirebaseCrash.report(e);
setMeasuredDimension(MeasureSpec.getSize(i), AndroidUtilities.dp(51.0f));
FileLog.e("tmessages", e);
}
this.f399b = null;
if (this.f398a != null && this.f398a.length() > 0) {
CharSequence text = getText();
if (text.length() > 1 && text.charAt(0) == '@') {
int indexOf = TextUtils.indexOf(text, ' ');
if (indexOf != -1) {
TextPaint paint = getPaint();
int ceil = (int) Math.ceil((double) paint.measureText(text, 0, indexOf + 1));
int measuredWidth = (getMeasuredWidth() - getPaddingLeft()) - getPaddingRight();
this.f400c = text.subSequence(0, indexOf + 1).length();
CharSequence ellipsize = TextUtils.ellipsize(this.f398a, paint, (float) (measuredWidth - ceil), TruncateAt.END);
this.f401d = ceil;
try {
this.f399b = new StaticLayout(ellipsize, getPaint(), measuredWidth - ceil, Alignment.ALIGN_NORMAL, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT, 0.0f, false);
if (this.f399b.getLineCount() > 0) {
this.f401d = (int) (((float) this.f401d) + (-this.f399b.getLineLeft(0)));
}
this.f402e = ((getMeasuredHeight() - this.f399b.getLineBottom(0)) / 2) + AndroidUtilities.dp(0.5f);
} catch (Throwable e2) {
FirebaseCrash.report(e2);
FileLog.e("tmessages", e2);
}
}
}
}
}
项目:FireFiles
文件:RecentsCreateFragment.java
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final Context context = parent.getContext();
if (convertView == null) {
final LayoutInflater inflater = LayoutInflater.from(context);
convertView = inflater.inflate(R.layout.item_doc_list, parent, false);
}
final ImageView iconMime = (ImageView) convertView.findViewById(R.id.icon_mime);
final TextView title = (TextView) convertView.findViewById(android.R.id.title);
final View line2 = convertView.findViewById(R.id.line2);
final DocumentStack stack = getItem(position);
iconMime.setImageDrawable(stack.root.loadIcon(context));
final Drawable crumb = ContextCompat.getDrawable(context, R.drawable.ic_breadcrumb_arrow);
crumb.setBounds(0, 0, crumb.getIntrinsicWidth(), crumb.getIntrinsicHeight());
final SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(stack.root.title);
for (int i = stack.size() - 2; i >= 0; i--) {
appendDrawable(builder, crumb);
builder.append(stack.get(i).displayName);
}
title.setText(builder);
title.setEllipsize(TruncateAt.MIDDLE);
if (line2 != null) line2.setVisibility(View.GONE);
return convertView;
}
项目:threed
文件:Threed.java
public static void init(TextView view, AttributeSet attrs, int defStyleAttr) {
Threed t = getThreed(view);
TypedArray a = view.getContext().obtainStyledAttributes(attrs, MoreTextView, 0, defStyleAttr);
t.moreText = a.getString(MoreTextView_moreText);
t.moreTextColor = a.getColor(MoreTextView_moreTextColor, view.getTextColors().getDefaultColor());
a.recycle();
view.setEllipsize(TruncateAt.END);
if (!isEmpty(t.moreText)) {
view.setOnClickListener(t);
}
}
项目:boohee_v5.6
文件:DietKeyboard.java
public void initUnit() {
if (this.mUnits != null && this.mUnits.size() != 0 && this.currentUnit != null) {
LayoutParams parms = new LayoutParams(-1, -2, 1.0f);
this.ll_diet_unit.removeAllViews();
this.unitTextViews.clear();
for (int i = 0; i < this.mUnits.size(); i++) {
TextView textView = new TextView(getContext());
textView.setText(((Unit) this.mUnits.get(i)).unit_name);
textView.setGravity(17);
textView.setTextSize(18.0f);
textView.setTextColor(getResources().getColor(R.color.color_light));
textView.setBackgroundColor(getResources().getColor(R.color.color_divider));
textView.setSingleLine(true);
textView.setEllipsize(TruncateAt.END);
textView.setId(i);
textView.setOnClickListener(new UnitListener());
if (TextUtils.equals(((Unit) this.mUnits.get(i)).unit_name, this.currentUnit
.unit_name)) {
textView.setTextColor(-1);
textView.setBackgroundColor(getResources().getColor(R.color.color_bg_number));
}
this.unitTextViews.add(textView);
this.ll_diet_unit.addView(textView, parms);
}
if (this.mAmount < 0.0f) {
this.mAmount = 100.0f;
}
this.mGram = Float.parseFloat(this.currentUnit.eat_weight) * this.mAmount;
this.mCalory = this.mWeight * this.mGram;
this.txt_value.setText(this.mAmount + "");
swithTxt();
}
}
项目:Cable-Android
文件:ViewUtil.java
public static CharSequence ellipsize(@Nullable CharSequence text, @NonNull TextView view) {
if (TextUtils.isEmpty(text) || view.getWidth() == 0 || view.getEllipsize() != TruncateAt.END) {
return text;
} else {
return TextUtils.ellipsize(text,
view.getPaint(),
view.getWidth() - view.getPaddingRight() - view.getPaddingLeft(),
TruncateAt.END);
}
}
项目:AndroidChromium
文件:PaymentRequestSection.java
/**
* Sets how the summary text should be displayed.
*
* @param leftTruncate How to truncate the left summary text. Set to null to clear.
* @param rightTruncate How to truncate the right summary text. Set to null to clear.
*/
public void setSummaryProperties(@Nullable TruncateAt leftTruncate, boolean leftIsSingleLine,
@Nullable TruncateAt rightTruncate, boolean rightIsSingleLine) {
mSummaryLeftTextView.setEllipsize(leftTruncate);
mSummaryLeftTextView.setSingleLine(leftIsSingleLine);
mSummaryRightTextView.setEllipsize(rightTruncate);
mSummaryRightTextView.setSingleLine(rightIsSingleLine);
}