use of com.ichi2.anki.CardBrowser.Column.EDITED in project AnkiChinaAndroid by ankichinateam.
the class AbstractFlashcardViewer method updateCard.
private void updateCard(final String newContent) {
Timber.d("updateCard()");
mCacheContent = newContent;
mUseTimerDynamicMS = 0;
// Add CSS for font color and font size
if (mCurrentCard == null) {
processCardAction(cardWebView -> cardWebView.getSettings().setDefaultFontSize(calculateDynamicFontSize(newContent)));
}
if (sDisplayAnswer) {
addAnswerSounds(newContent);
} else {
// reset sounds each time first side of card is displayed, which may happen repeatedly without ever
// leaving the card (such as when edited)
mSoundPlayer.resetSounds();
mAnswerSoundsAdded = false;
mSoundPlayer.addSounds(mBaseUrl, newContent, SoundSide.QUESTION);
if (mUseTimer && !mAnswerSoundsAdded && getConfigForCurrentCard().optBoolean("autoplay", false)) {
addAnswerSounds(mCurrentCard.a());
}
}
String content = Sound.expandSounds(mBaseUrl, newContent);
content = CardAppearance.fixBoldStyle(content);
Timber.v("content card = \n %s", content);
String style = mCardAppearance.getStyle();
Timber.v("::style:: / %s", style);
// CSS class for card-specific styling
String cardClass = mCardAppearance.getCardClass(mCurrentCard.getOrd() + 1, Themes.getCurrentTheme(this));
if (Template.textContainsMathjax(content)) {
cardClass += " mathjax-needs-to-render";
}
if (isInNightMode()) {
if (!mCardAppearance.hasUserDefinedNightMode(mCurrentCard)) {
content = HtmlColors.invertColors(content);
}
}
content = CardAppearance.convertSmpToHtmlEntity(content);
SharedPreferences prefs = AnkiDroidApp.getSharedPrefs(this);
String localViewSettingStr = prefs.getString(Consts.KEY_LOCAL_LAYOUT_CONFIG, "");
boolean dark = false;
if (AnkiDroidApp.getSharedPrefs(this).getBoolean("invertedColors", false)) {
int theme = Integer.parseInt(prefs.getString("nightTheme", "0"));
dark = theme == THEME_NIGHT_DARK || theme == THEME_NIGHT_BLACK;
}
if (mCurrentCSS.isEmpty() || mCurrentCSSModelID != mCurrentCard.model().getLong("id")) {
mCurrentCSSModelID = mCurrentCard.model().getLong("id");
Timber.i("find new model id css %s", mCurrentCSS);
if (localViewSettingStr != null && !localViewSettingStr.isEmpty()) {
try {
JSONObject viewSetting = new JSONObject(localViewSettingStr);
JSONObject currentModelSetting = viewSetting.getJSONObject(String.valueOf(mCurrentCSSModelID));
if (currentModelSetting != null) {
mCurrentCSS = convertJson2Css(currentModelSetting, false);
} else {
mCurrentCSS = "";
}
} catch (Exception e) {
e.printStackTrace();
mCurrentCSS = "";
}
}
}
Timber.i("now theme is dark:%s", dark);
if (!dark) {
if (!mCurrentCSS.isEmpty()) {
Matcher bgMatcher = Pattern.compile("background-color:(.+?);").matcher(mCurrentCSS);
Window window = getWindow();
if (bgMatcher.find()) {
String fld1 = bgMatcher.group(1).trim();
if (shouldChangeToolbarBgLikeCss2()) {
findViewById(R.id.toolbar).setBackgroundColor(Color.parseColor(fld1));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(Color.parseColor(fld1));
}
}
mCardWebView.setBackgroundColor(Color.parseColor(fld1));
findViewById(R.id.bottom_area_layout).setBackgroundColor(Color.parseColor(fld1));
} else {
if (shouldChangeToolbarBgLikeCss2()) {
int[] attrs = new int[] { R.attr.reviewStatusBarColor };
TypedArray ta = obtainStyledAttributes(attrs);
findViewById(R.id.toolbar).setBackground(ta.getDrawable(0));
ta.recycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
window.setStatusBarColor(Themes.getColorFromAttr(this, getStatusBarColorAttr()));
}
}
mCardWebView.setBackgroundColor(Color.WHITE);
findViewById(R.id.bottom_area_layout).setBackgroundColor(Color.TRANSPARENT);
}
} else {
if (shouldChangeToolbarBgLikeCss2()) {
int[] attrs = new int[] { R.attr.reviewStatusBarColor };
TypedArray ta = obtainStyledAttributes(attrs);
findViewById(R.id.toolbar).setBackground(ta.getDrawable(0));
ta.recycle();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.setStatusBarColor(Themes.getColorFromAttr(this, getStatusBarColorAttr()));
}
}
mCardWebView.setBackgroundColor(Color.WHITE);
findViewById(R.id.bottom_area_layout).setBackgroundColor(Color.TRANSPARENT);
}
}
// if (mCurrentCSS.isEmpty()) {//保存的配置文件没有,则直接找默认的css
// mCurrentCSS = mCurrentCard.css().replace("<style>", "").replace("</style>", "");
// }
mCardContent = mCardTemplate.replace("::content::", content).replace("::style::", style).replace("::class::", cardClass).replace("::style2::", mCurrentCSS).replace("::class2::", sDisplayAnswer ? "ck-back" : "ck-front");
Timber.d("base url = %s", mBaseUrl);
Timber.v("::content:: / %s", content);
Timber.v("::style2:: / %s", mCurrentCSS);
if (AnkiDroidApp.getSharedPrefs(this).getBoolean("html_javascript_debugging", false)) {
try {
try (FileOutputStream f = new FileOutputStream(new File(CollectionHelper.getCurrentAnkiDroidDirectory(this), "card.html"))) {
f.write(mCardContent.getBytes());
}
} catch (IOException e) {
Timber.d(e, "failed to save card");
}
}
fillFlashcard();
if (!mConfigurationChanged) {
playSoundsVIP(false);
}
}
use of com.ichi2.anki.CardBrowser.Column.EDITED in project Anki-Android by ankidroid.
the class CardTemplateEditor method showDiscardChangesDialog.
@VisibleForTesting
public MaterialDialog showDiscardChangesDialog() {
MaterialDialog discardDialog = DiscardChangesDialog.getDefault(this).onPositive((dialog, which) -> {
Timber.i("TemplateEditor:: OK button pressed to confirm discard changes");
// Clear the edited model from any cache files, and clear it from this objects memory to discard changes
TemporaryModel.clearTempModelFiles();
mTempModel = null;
finishWithAnimation(END);
}).build();
discardDialog.show();
return discardDialog;
}
use of com.ichi2.anki.CardBrowser.Column.EDITED in project AnkiChinaAndroid by ankichinateam.
the class CardTemplateEditor method showDiscardChangesDialog.
@VisibleForTesting
public MaterialDialog showDiscardChangesDialog() {
MaterialDialog discardDialog = DiscardChangesDialog.getDefault(this).onPositive((dialog, which) -> {
Timber.i("TemplateEditor:: OK button pressed to confirm discard changes");
// Clear the edited model from any cache files, and clear it from this objects memory to discard changes
TemporaryModel.clearTempModelFiles();
mTempModel = null;
finishWithAnimation(ActivityTransitionAnimation.RIGHT);
}).build();
discardDialog.show();
return discardDialog;
}
Aggregations