Twidere-App-Android-Twitter.../twidere/src/main/java/org/mariotaku/twidere/view/StatusTextView.java

68 lines
1.9 KiB
Java
Raw Normal View History

2014-07-03 07:48:39 +02:00
package org.mariotaku.twidere.view;
import android.content.Context;
2015-04-07 18:36:54 +02:00
import android.text.SpannableString;
2014-07-03 07:48:39 +02:00
import android.util.AttributeSet;
import org.mariotaku.twidere.view.themed.ThemedTextView;
public class StatusTextView extends ThemedTextView {
2014-07-03 07:48:39 +02:00
2015-01-18 17:15:38 +01:00
private OnSelectionChangeListener mOnSelectionChangeListener;
public StatusTextView(final Context context) {
super(context);
}
public StatusTextView(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
2015-01-18 17:15:38 +01:00
public StatusTextView(final Context context, final AttributeSet attrs, final int defStyle) {
super(context, attrs, defStyle);
}
public void setOnSelectionChangeListener(final OnSelectionChangeListener l) {
mOnSelectionChangeListener = l;
}
@Override
public void setText(CharSequence text, BufferType type) {
if (text == null) {
super.setText(null, type);
return;
}
super.setText(new SafeSpannableStringWrapper(text), type);
}
@Override
protected void onSelectionChanged(final int selStart, final int selEnd) {
super.onSelectionChanged(selStart, selEnd);
if (mOnSelectionChangeListener != null) {
mOnSelectionChangeListener.onSelectionChanged(selStart, selEnd);
}
}
public interface OnSelectionChangeListener {
void onSelectionChanged(int selStart, int selEnd);
2015-04-07 18:36:54 +02:00
}
private static class SafeSpannableStringWrapper extends SpannableString {
public SafeSpannableStringWrapper(CharSequence source) {
super(source);
}
@Override
public void setSpan(Object what, int start, int end, int flags) {
if (start < 0 || end < 0) {
// Silently ignore
return;
}
super.setSpan(what, start, end, flags);
}
}
2014-07-03 07:48:39 +02:00
}