smart Ellipsize - Android java.lang

Android examples for java.lang:String Shorten

Description

smart Ellipsize

Demo Code


//package com.java2s;

import android.text.TextPaint;
import android.text.TextUtils;

public class Main {
    public static CharSequence smartEllipsize(CharSequence charsequence,
            TextPaint textpaint, int i,
            android.text.TextUtils.TruncateAt truncateat) {
        String s = charsequence.toString();
        int j = s.indexOf('\r');
        int k = s.indexOf('\n');
        CharSequence charsequence1;
        if (j == -1 && k == -1)
            charsequence1 = charsequence;
        else if (j == -1)
            charsequence1 = charsequence.subSequence(0, k);
        else if (k == -1)
            charsequence1 = charsequence.subSequence(0, j);
        else/* ww  w.  j av  a 2s .co m*/
            charsequence1 = charsequence.subSequence(0, Math.min(j, k));
        return TextUtils.ellipsize(charsequence1, textpaint, i, truncateat);
    }
}

Related Tutorials