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;
|
|
|
|
|
2015-04-19 09:14:08 +02:00
|
|
|
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-04-12 18:37:54 +02:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-04-12 18:37:54 +02:00
|
|
|
@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
|
|
|
}
|