use of android.text.SpannableString in project Anki-Android by Ramblurr.
the class PreviewClass method displayCardAnswer.
private void displayCardAnswer() {
// prevent answering (by e.g. gestures) before card is loaded
if (mCurrentCard == null) {
return;
}
sDisplayAnswer = true;
String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
answer = typeAnsAnswerFilter(answer);
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(answer);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
Sound.stopSounds();
if (mPrefFixArabic) {
// reshape
answer = ArabicUtilities.reshapeSentence(answer, true);
}
// If the user wrote an answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.GONE);
if (mCurrentCard != null) {
if (mPrefFixArabic) {
// reshape
mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
}
// Obtain the user answer and the correct answer
String userAnswer = mAnswerField.getText().toString();
Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
String correctAnswer = matcher.replaceAll("");
matcher = sBrPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("\n");
matcher = Sound.sSoundPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("");
// Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);
// Obtain the diff and send it to updateCard
DiffEngine diff = new DiffEngine();
StringBuffer span = new StringBuffer();
span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ").append(12).append("px\">");
span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
span.append("</span>");
span.append("<br/>").append(answer);
displayString = enrichWithQADiv(span.toString(), true);
}
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
} else {
displayString = enrichWithQADiv(answer, true);
}
}
updateCard(displayString);
}
use of android.text.SpannableString in project Anki-Android by Ramblurr.
the class PreviewClass method displayCardQuestion.
private void displayCardQuestion() {
// show timer, if activated in the deck's preferences
sDisplayAnswer = false;
setInterface();
String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
question = typeAnsQuestionFilter(question);
if (mPrefFixArabic) {
question = ArabicUtilities.reshapeSentence(question, true);
}
// Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(question);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
// If the user wants to write the answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.VISIBLE);
// Show soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
}
displayString = enrichWithQADiv(question, false);
if (mSpeakText) {
// ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
// mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
}
}
updateCard(displayString);
}
use of android.text.SpannableString in project Anki-Android by Ramblurr.
the class Reviewer method displayCardAnswer.
private void displayCardAnswer() {
Log.i(AnkiDroidApp.TAG, "displayCardAnswer");
// prevent answering (by e.g. gestures) before card is loaded
if (mCurrentCard == null) {
return;
}
sDisplayAnswer = true;
setFlipCardAnimation();
String answer = mCurrentCard.getAnswer(mCurrentSimpleInterface);
answer = typeAnsAnswerFilter(answer);
if (mDisplayKanjiInfo) {
answer = answer + addKanjiInfo(mCurrentCard.getQuestion(mCurrentSimpleInterface));
}
String displayString = "";
if (mCurrentSimpleInterface) {
mCardContent = convertToSimple(answer);
if (mCardContent.length() == 0) {
SpannableString hint = new SpannableString(getResources().getString(R.string.simple_interface_hint, R.string.card_details_answer));
hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mCardContent = hint;
}
} else {
Sound.stopSounds();
if (mPrefFixArabic) {
// reshape
answer = ArabicUtilities.reshapeSentence(answer, true);
}
// If the user wrote an answer
if (typeAnswer()) {
mAnswerField.setVisibility(View.GONE);
if (mCurrentCard != null) {
if (mPrefFixArabic) {
// reshape
mTypeCorrect = ArabicUtilities.reshapeSentence(mTypeCorrect, true);
}
// Obtain the user answer and the correct answer
String userAnswer = mAnswerField.getText().toString();
Matcher matcher = sSpanPattern.matcher(Utils.stripHTMLMedia(mTypeCorrect));
String correctAnswer = matcher.replaceAll("");
matcher = sBrPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("\n");
matcher = Sound.sSoundPattern.matcher(correctAnswer);
correctAnswer = matcher.replaceAll("");
Log.i(AnkiDroidApp.TAG, "correct answer = " + correctAnswer);
// Obtain the diff and send it to updateCard
DiffEngine diff = new DiffEngine();
StringBuffer span = new StringBuffer();
span.append("<span style=\"font-family: '").append(mTypeFont).append("'; font-size: ").append(mTypeSize).append("px\">");
span.append(diff.diff_prettyHtml(diff.diff_main(userAnswer, correctAnswer), mNightMode));
span.append("</span>");
span.append("<br/>").append(answer);
displayString = enrichWithQADiv(span.toString(), true);
}
// Hide soft keyboard
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(mAnswerField.getWindowToken(), 0);
} else {
displayString = enrichWithQADiv(answer, true);
}
}
mIsSelecting = false;
updateCard(displayString);
showEaseButtons();
// If the user want to show next question automatically
if (mPrefUseTimer) {
mTimeoutHandler.removeCallbacks(mShowQuestionTask);
mTimeoutHandler.postDelayed(mShowQuestionTask, mWaitQuestionSecond * 1000);
}
}
use of android.text.SpannableString in project KeepScore by nolanlawson.
the class AbstractHistoryTableFragment method createHistoryItemView.
protected View createHistoryItemView(ViewGroup parent, HistoryItem historyItem, int layoutResId, int rowId, boolean weightIsOne, Activity activity) {
View view = getInflater().inflate(layoutResId, parent, false);
// alternating colors for the background, from gray to white
view.setBackgroundColor(getResources().getColor(rowId % 2 == 0 ? android.R.color.background_light : R.color.light_gray));
TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
if (historyItem == null) {
// null indicates to leave the text views empty
setDummyTextView(textView1);
setDummyTextView(textView2);
return weightIsOne ? setLayoutWeightToOne(view) : view;
}
textView2.setVisibility(View.VISIBLE);
if (historyItem.isHideDelta()) {
setDummyTextView(textView1);
// set as gone to ensure that
textView1.setVisibility(View.GONE);
// the first line isn't too tall
// when we use
// history_item_tall.xml
} else {
int delta = historyItem.getDelta();
SpannableString deltaSpannable = new SpannableString(IntegerUtil.toCharSequenceWithSign(delta));
int colorResId = delta >= 0 ? (PreferenceHelper.getGreenTextPreference(activity) ? // green
ColorScheme.Light.getGreenPositiveColorResId() : // blue
ColorScheme.Light.getPositiveColorResId()) : // red
ColorScheme.Light.getNegativeColorResId();
ForegroundColorSpan colorSpan = new ForegroundColorSpan(getResources().getColor(colorResId));
deltaSpannable.setSpan(colorSpan, 0, deltaSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView1.setVisibility(View.VISIBLE);
textView1.setText(deltaSpannable);
}
textView2.setText(Long.toString(historyItem.getRunningTotal()));
return weightIsOne ? setLayoutWeightToOne(view) : view;
}
use of android.text.SpannableString in project KeepScore by nolanlawson.
the class PlayerView method fromHistory.
/**
* Add green color for positive entries and red color for negative entries,
* and convert ints to strings.
*
* @param currentTime
*/
private Spannable fromHistory(List<Delta> history, long currentTime) {
history = historyToShow(history, currentTime);
if (history.isEmpty()) {
return null;
}
history = CollectionUtil.reversedCopy(history);
// if e.g. there is a double-digit delta (e.g. "+10"), then all other
// strings need to be padded
// so that they line up correctly
// but ensure there's always at least enough space for 3 chars (e.g.
// '+10'), because
// I think it looks nicer and more consistent with most games
int maxChars = Math.max(MIN_NUM_HISTORY_CHARS, CollectionUtil.maxValue(history, DELTA_TO_LENGTH_WITH_SIGN));
List<Spannable> spannables = CollectionUtil.transform(history, historyToSpan(maxChars));
Spannable result = new SpannableString(StringUtil.joinSpannables("\n", CollectionUtil.toArray(spannables, Spannable.class)));
return result;
}
Aggregations