下面列出了android.widget.TextView#BufferType ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
MarkwonImpl(
@NonNull TextView.BufferType bufferType,
@Nullable TextSetter textSetter,
@NonNull Parser parser,
@NonNull MarkwonVisitorFactory visitorFactory,
@NonNull MarkwonConfiguration configuration,
@NonNull List<MarkwonPlugin> plugins,
boolean fallbackToRawInputWhenEmpty
) {
this.bufferType = bufferType;
this.textSetter = textSetter;
this.parser = parser;
this.visitorFactory = visitorFactory;
this.configuration = configuration;
this.plugins = plugins;
this.fallbackToRawInputWhenEmpty = fallbackToRawInputWhenEmpty;
}
public void setText(int resId, TextView.BufferType type, int... ids) {
for (int id : ids) {
Button button = getButton(id);
if (button != null) {
button.setText(resId, type);
}
}
}
@Override
@CallSuper
public void setText(CharSequence rawText, TextView.BufferType type) {
final CharSequence text = rawText == null ? "" : rawText;
final SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
if (mEmoticonProvider != null)
EmoticonUtils.replaceWithImages(getContext(), spannableStringBuilder, mEmoticonProvider, mEmoticonSize);
super.setText(spannableStringBuilder, type);
}
@Override
public void setText(
@NonNull TextView textView,
@NonNull final Spanned markdown,
@NonNull final TextView.BufferType bufferType,
@NonNull final Runnable onComplete) {
// insert version check and do not execute on a device < 21
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
// it's still no-op, so there is no need to start background execution
applyText(textView, markdown, bufferType, onComplete);
return;
}
final WeakReference<TextView> reference = new WeakReference<>(textView);
executor.execute(new Runnable() {
@Override
public void run() {
try {
final PrecomputedTextCompat precomputedTextCompat = precomputedText(reference.get(), markdown);
if (precomputedTextCompat != null) {
applyText(reference.get(), precomputedTextCompat, bufferType, onComplete);
}
} catch (Throwable t) {
Log.e("PrecomputdTxtSetterCmpt", "Exception during pre-computing text", t);
// apply initial markdown
applyText(reference.get(), markdown, bufferType, onComplete);
}
}
});
}
private static void applyText(
@Nullable final TextView textView,
@NonNull final Spanned text,
@NonNull final TextView.BufferType bufferType,
@NonNull final Runnable onComplete) {
if (textView != null) {
textView.post(new Runnable() {
@Override
public void run() {
textView.setText(text, bufferType);
onComplete.run();
}
});
}
}
public void setText(CharSequence text, TextView.BufferType type, int... ids) {
for (int id : ids) {
Button button = getButton(id);
if (button != null) {
button.setText(text, type);
}
}
}
@NonNull
@Override
public ViewFinder setText(final int ID, final CharSequence text, final TextView.BufferType type) {
((TextView) find(ID)).setText(text, type);
return this;
}
@NonNull
ViewFinder setText(@IdRes int ID, CharSequence text, TextView.BufferType type);
@Test
public void text_setter() {
final Markwon.TextSetter textSetter = mock(Markwon.TextSetter.class);
final MarkwonPlugin plugin = mock(MarkwonPlugin.class);
final MarkwonImpl impl = new MarkwonImpl(
TextView.BufferType.EDITABLE,
textSetter,
mock(Parser.class),
mock(MarkwonVisitorFactory.class),
mock(MarkwonConfiguration.class),
Collections.singletonList(plugin),
true
);
final TextView textView = mock(TextView.class);
final Spanned spanned = mock(Spanned.class);
impl.setParsedMarkdown(textView, spanned);
final ArgumentCaptor<TextView> textViewArgumentCaptor =
ArgumentCaptor.forClass(TextView.class);
final ArgumentCaptor<Spanned> spannedArgumentCaptor =
ArgumentCaptor.forClass(Spanned.class);
final ArgumentCaptor<TextView.BufferType> bufferTypeArgumentCaptor =
ArgumentCaptor.forClass(TextView.BufferType.class);
final ArgumentCaptor<Runnable> runnableArgumentCaptor =
ArgumentCaptor.forClass(Runnable.class);
verify(textSetter, times(1)).setText(
textViewArgumentCaptor.capture(),
spannedArgumentCaptor.capture(),
bufferTypeArgumentCaptor.capture(),
runnableArgumentCaptor.capture());
assertEquals(textView, textViewArgumentCaptor.getValue());
assertEquals(spanned, spannedArgumentCaptor.getValue());
assertEquals(TextView.BufferType.EDITABLE, bufferTypeArgumentCaptor.getValue());
assertNotNull(runnableArgumentCaptor.getValue());
}
public void setText(CharSequence text, TextView.BufferType type) {
mEditText.setText(text, type);
}
/**
* Delegate method for the input widget
*/
public void setInputWidgetText(CharSequence text, TextView.BufferType type) {
getInputWidget().setText(text, type);
}
/**
* Delegate method for the input widget
*/
public void setInputWidgetText(CharSequence text, TextView.BufferType type) {
getInputWidget().setText(text, type);
}
@Override
public void setText(CharSequence text, TextView.BufferType type) {
super.setText(text, type);
resetIfNeeded();
}
/**
* Sets the EditText's text with label animation
*
* @param resid int String resource ID
* @param type TextView.BufferType
*/
public void setText(int resid, TextView.BufferType type) {
mEditText.setText(resid, type);
}
/**
* Sets the EditText's text without animating the label
*
* @param text CharSequence to set
* @param type TextView.BufferType
*/
public void setTextWithoutAnimation(CharSequence text, TextView.BufferType type) {
mSkipAnimation = true;
mEditText.setText(text, type);
}
/**
* Sets the EditText's text with label animation
*
* @param resid int String resource ID
* @param type TextView.BufferType
*/
public void setText(int resid, TextView.BufferType type) {
mEditText.setText(resid, type);
}
/**
* Sets the EditText's text with label animation
*
* @param text CharSequence to set
* @param type TextView.BufferType
*/
public void setText(CharSequence text, TextView.BufferType type) {
mEditText.setText(text, type);
}
/**
* Sets the EditText's text without animating the label
*
* @param resid int String resource ID
* @param type TextView.BufferType
*/
public void setTextWithoutAnimation(int resid, TextView.BufferType type) {
mSkipAnimation = true;
mEditText.setText(resid, type);
}
/**
* Sets the EditText's text without animating the label
*
* @param text CharSequence to set
* @param type TextView.BufferType
*/
public void setTextWithoutAnimation(CharSequence text, TextView.BufferType type) {
mSkipAnimation = true;
mEditText.setText(text, type);
}
void setText(CharSequence text, TextView.BufferType type);