private void appendEntryToView(String text, long timestamp) { Date date = new Date(timestamp); // Add a newline if needed or clear the text view (to get rid of the hint). if (!mIsHistoryEmpty) { mHistoryTextView.append("\n"); } else { mHistoryTextView.setText(""); } // Add the representation of the new entry to the text view. mHistoryTextView.append(String.format("%s [%s]", text, mSimpleDateFormatter.format(date))); mIsHistoryEmpty = false; } }
@Override public void onError(Throwable e) { textView.append(" First onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " First onError : " + e.getMessage()); }
@Override public void onError(Throwable e) { textView.append(" Second onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " Second onError : " + e.getMessage()); }
@Override public void onError(Throwable e) { textView.append(" onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " onError : " + e.getMessage()); }
@Override public void onError(Throwable e) { textView.append(" Second onError : " + e.getMessage()); textView.append(AppConstant.LINE_SEPARATOR); Log.d(TAG, " Second onError : " + e.getMessage()); }
private void infoAppend(final String msg, final long start) { infoTv.append(String.format(" %s: %d\n", msg, System.currentTimeMillis() - start)); scrollView.post(new Runnable() { @Override public void run() { if (scrollView != null) { scrollView.fullScroll(View.FOCUS_DOWN); } } }); }
private void updateDisplay(final CharSequence msg) { if (downloadMsgTv.getLineCount() > 2500) { downloadMsgTv.setText(""); } downloadMsgTv.append(String.format("\n %s", msg)); tipMsgTv.setText(String.format("%d/%d", finalCounts, totalCounts)); if (needAuto2Bottom) { scrollView.post(scroll2Bottom); } }
TextView TV = (TextView)findViewById(R.id.mytextview01); Spannable word = new SpannableString("Your message"); word.setSpan(new ForegroundColorSpan(Color.BLUE), 0, word.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TV.setText(word); Spannable wordTwo = new SpannableString("Your new message"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TV.append(wordTwo);
@Test public void testNoArgAppend() { textView.setText("a"); textView.append("b"); assertThat(textView.getText().toString()).isEqualTo("ab"); }
@Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(TestFinishedEvent event) { Test test = event.test; String text = "<b>" + test.getDisplayName() + "</b><br/>" + // test.getPrimaryResultMicros() + " micro seconds<br/>" + // ((int) test.getPrimaryResultRate()) + "/s<br/>"; if (test.getOtherTestResults() != null) { text += test.getOtherTestResults(); } text += "<br/>----------------<br/>"; textViewResult.append(Html.fromHtml(text)); if (event.isLastEvent) { findViewById(R.id.buttonCancel).setVisibility(View.GONE); findViewById(R.id.textViewTestRunning).setVisibility(View.GONE); findViewById(R.id.buttonKillProcess).setVisibility(View.VISIBLE); } }
@Test public void whenAppendingText_ShouldAppendNewTextAfterOldOne() { textView.setText(INITIAL_TEXT); textView.append(NEW_TEXT); assertThat(textView.getText().toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT); }
@Test public void whenAppendingText_ShouldFireBeforeTextChangedWithCorrectArguments() { textView.setText(INITIAL_TEXT); TextWatcher mockTextWatcher = mock(TextWatcher.class); textView.addTextChangedListener(mockTextWatcher); textView.append(NEW_TEXT); verify(mockTextWatcher).beforeTextChanged(eq(INITIAL_TEXT), eq(0), eq(INITIAL_TEXT.length()), eq(INITIAL_TEXT.length())); }
@Test public void whenAppendingText_ShouldFireOnTextChangedWithCorrectArguments() { textView.setText(INITIAL_TEXT); TextWatcher mockTextWatcher = mock(TextWatcher.class); textView.addTextChangedListener(mockTextWatcher); textView.append(NEW_TEXT); ArgumentCaptor<SpannableStringBuilder> builderCaptor = ArgumentCaptor.forClass(SpannableStringBuilder.class); verify(mockTextWatcher).onTextChanged(builderCaptor.capture(), eq(0), eq(INITIAL_TEXT.length()), eq(INITIAL_TEXT.length())); assertThat(builderCaptor.getValue().toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv=(TextView)findViewById(R.id.text); for (SmsMessage pdu : Telephony.Sms.Intents.getMessagesFromIntent(getIntent())) { tv.append(pdu.getDisplayMessageBody()); } } }
@Test public void whenAppendingText_ShouldFireAfterTextChangedWithCorrectArgument() { textView.setText(INITIAL_TEXT); MockTextWatcher mockTextWatcher = new MockTextWatcher(); textView.addTextChangedListener(mockTextWatcher); textView.append(NEW_TEXT); assertThat(mockTextWatcher.afterTextChangeArgument.toString()).isEqualTo(INITIAL_TEXT + NEW_TEXT); }
@Test public void append_whenSelectionReachesToEnd_shouldExtendSelectionToTheEnd() throws Exception { textView.setText("12", TextView.BufferType.EDITABLE); Selection.setSelection(textView.getEditableText(), 0, 2); textView.append("3"); assertEquals(3, textView.getSelectionEnd()); assertEquals(0, textView.getSelectionStart()); }
@Test public void append_whenSelectionIsAtTheEnd_shouldKeepSelectionAtTheEnd() throws Exception { textView.setText("1", TextView.BufferType.EDITABLE); Selection.setSelection(textView.getEditableText(), 0, 0); textView.append("2"); assertEquals(0, textView.getSelectionEnd()); assertEquals(0, textView.getSelectionStart()); Selection.setSelection(textView.getEditableText(), 2, 2); textView.append("3"); assertEquals(3, textView.getSelectionEnd()); assertEquals(3, textView.getSelectionStart()); }