Android Open Source - Sharinger Expandable Text View






From Project

Back to project page Sharinger.

License

The source code is released under:

Apache License

If you think the Android project Sharinger listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package mobi.tarantio.tools.sharinger.app;
//  w w  w  .  j a  va  2s  .  c  o m
import android.content.Context;
import android.content.res.TypedArray;
import android.text.SpannableStringBuilder;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

/**
 * User: Bazlur Rahman Rokon http://codexplo.wordpress.com/2013/09/07/android-expandable-textview/
 * Date: 9/7/13 - 3:33 AM
 */
public class ExpandableTextView extends TextView {
    private static final int DEFAULT_TRIM_LENGTH = 96;
    private static final String ELLIPSIS = '\u0000' + " \u21E3";

    private CharSequence originalText;
    private CharSequence trimmedText;
    private BufferType bufferType;
    private boolean trim = true;
    private int trimLength;

    public void setTrim(boolean trim) {
        this.trim = trim;
    }

    public ExpandableTextView(Context context) {
        this(context, null);
    }

    public ExpandableTextView(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
        this.trimLength = typedArray.getInt(R.styleable.ExpandableTextView_trimLength, DEFAULT_TRIM_LENGTH);
        typedArray.recycle();

        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                trim = !trim;
                setText();
                requestFocusFromTouch();
            }
        });
    }

    private void setText() {
        super.setText(getDisplayableText(), bufferType);
    }

    private CharSequence getDisplayableText() {
        return trim ? trimmedText : originalText;
    }

    @Override
    public void setText(CharSequence text, BufferType type) {
        originalText = text;
        trimmedText = getTrimmedText(text);
        bufferType = type;
        setText();
    }

    private CharSequence getTrimmedText(CharSequence text) {
        if (originalText != null && originalText.length() > trimLength) {
            return new SpannableStringBuilder(originalText, 0, trimLength + 1).append(ELLIPSIS);
        } else {
            return originalText;
        }
    }

    public CharSequence getOriginalText() {
        return originalText;
    }

    public void setTrimLength(int trimLength) {
        this.trimLength = trimLength;
        trimmedText = getTrimmedText(originalText);
        setText();
    }

    public int getTrimLength() {
        return trimLength;
    }
}




Java Source Code List

mobi.tarantio.tools.sharinger.app.CopyToClipboardActivity.java
mobi.tarantio.tools.sharinger.app.ExpandableTextView.java
mobi.tarantio.tools.sharinger.app.IntentHandler.java
mobi.tarantio.tools.sharinger.app.ShareIntentListBuilder.java
mobi.tarantio.tools.sharinger.app.ShareListActivity.java
mobi.tarantio.tools.sharinger.app.SystemBarTintManager.java
mobi.tarantio.tools.sharinger.app.TextViewActivity.java
mobi.tarantio.tools.sharinger.app.test.java