From a207b2d340c295b8099d74b724d7983f9990bdbd Mon Sep 17 00:00:00 2001 From: vanosten Date: Sat, 1 May 2010 08:05:59 +0000 Subject: [PATCH] Corrected bug when displaying no card and hide 'Show question' when question is shown --- res/values/strings.xml | 2 +- src/com/ichi2/anki/AnkiDroid.java | 50 ++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 71039934da..dac342229c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -78,7 +78,7 @@ Whiteboard On Whiteboard Off Show Answer -Show Question +Re-display Question Flashcard Again Hard diff --git a/src/com/ichi2/anki/AnkiDroid.java b/src/com/ichi2/anki/AnkiDroid.java index d733c994d1..fa7d78ed93 100644 --- a/src/com/ichi2/anki/AnkiDroid.java +++ b/src/com/ichi2/anki/AnkiDroid.java @@ -79,8 +79,14 @@ public class AnkiDroid extends Activity */ private static final String TAG = "AnkiDroid"; + /** Max size of the font for dynamic calculation of font size */ + protected static final int MAX_DYNAMIC_FONT_SIZE = 14; + + /** Min size of the font for dynamic calculation of font size */ + protected static final int MIN_DYNAMIC_FONT_SIZE = 3; + /** The percentage of the absolute font size specified in the deck. */ - private int displayFontSize = 0; + private int displayFontSize = 100; /** * Menus @@ -847,6 +853,7 @@ public class AnkiDroid extends Activity mAnswerField.setVisibility(View.VISIBLE); } + mFlipCard.setVisibility(View.VISIBLE); mFlipCard.requestFocus(); String displayString = enrichWithQASpan(currentCard.question, false); @@ -913,6 +920,7 @@ public class AnkiDroid extends Activity sb.append("
"); sb.append(displayString); displayString = sb.toString(); + mFlipCard.setVisibility(View.GONE); } updateCard(displayString); } @@ -948,8 +956,12 @@ public class AnkiDroid extends Activity } // Add CSS for font colour and font size - Model myModel = Model.getModel(currentCard.cardModelId, false); - content = myModel.getCSSForFontColorSize(currentCard.cardModelId, displayFontSize) + content; + if (null != currentCard) { + Model myModel = Model.getModel(currentCard.cardModelId, false); + content = myModel.getCSSForFontColorSize(currentCard.cardModelId, displayFontSize) + content; + } else { + mCard.getSettings().setDefaultFontSize(calculateDynamicFontSize(content)); + } Log.i(TAG, "content card = \n" + content); String card = cardTemplate.replace("::content::", content); @@ -983,6 +995,23 @@ public class AnkiDroid extends Activity return sb.toString(); } + /** + * Calculates a dynamic font size depending on the length of the contents + * taking into account that the input string contains html-tags, which will not + * be displayed and therefore should not be taken into account. + * @param htmlContents + * @return font size respecting MIN_DYNAMIC_FONT_SIZE and MAX_DYNAMIC_FONT_SIZE + */ + protected final static int calculateDynamicFontSize(String htmlContent) { + // Replace each
with 15 spaces, each
with 30 spaces, then remove all html tags and spaces + String realContent = htmlContent.replaceAll("\\", " "); + realContent = realContent.replaceAll("\\", " "); + realContent = realContent.replaceAll("\\<.*?\\>", ""); + realContent = realContent.replaceAll(" ", " "); + return Math.max(MIN_DYNAMIC_FONT_SIZE, MAX_DYNAMIC_FONT_SIZE - (int)(realContent.length()/5)); + } + + /** * Utility method to write to a file. */ @@ -1019,11 +1048,18 @@ public class AnkiDroid extends Activity Log.i(TAG, "restorePreferences - timerAndWhiteboard: " + timerAndWhiteboard); writeAnswers = preferences.getBoolean("writeAnswers", false); useRubySupport = preferences.getBoolean("useRubySupport", false); - //A little hack to get int values from ListPreference. there should be an easier way ... - String displayFontSizeString = preferences.getString("displayFontSize", "100"); - displayFontSize = Integer.parseInt(displayFontSizeString); - hideQuestionInAnswer = Integer.parseInt(preferences.getString("hideQuestionInAnswer", "0")); + displayFontSize = Integer.parseInt(preferences.getString("displayFontSize", "100")); + hideQuestionInAnswer = Integer.parseInt(preferences.getString("hideQuestionInAnswer", Integer.toString(HQIA_DO_SHOW))); updateNotifications = preferences.getBoolean("enabled", true); + + //redraw screen with new preferences + if (null != mFlipCard) { + if (mFlipCard.isChecked()) { + displayCardAnswer(); + } else { + displayCardQuestion(); + } + } return preferences; }