0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 12:02:16 +02:00

Added several new preferences to have more question/answer display options:

* Only parse for ruby annotations if wanted
* Choose between relative font size and absolute font size
* Possibility to show the question again, when the answer is shown
* Made categories in preferences to give better guidance
This commit is contained in:
Ubuntu 2010-04-18 18:15:10 +00:00
parent 852e54ab03
commit deae51361e
4 changed files with 189 additions and 96 deletions

View File

@ -17,26 +17,57 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:title="@string/show_whiteboard"
android:defaultValue="true"
android:summary="@string/show_whiteboard_summ"
android:key="timerAndWhiteboard" />
<CheckBoxPreference
android:title="@string/sample_deck"
android:defaultValue="true"
android:summary="@string/sample_deck_summ"
android:key="generateSampleDeck" />
<CheckBoxPreference
android:title="@string/corporal_punishments"
android:defaultValue="false"
android:summary="@string/corporal_punishments_summ"
android:key="corporalPunishments" />
<CheckBoxPreference
android:title="@string/write_answers"
android:defaultValue="false"
android:summary="@string/write_answers_summ"
android:key="writeAnswers" />
<PreferenceCategory android:title="@string/pref_cat_decks">
<CheckBoxPreference
android:title="@string/sample_deck"
android:defaultValue="true"
android:summary="@string/sample_deck_summ"
android:key="generateSampleDeck" />
<EditTextPreference
android:title="@string/deck_path"
android:defaultValue="/sdcard"
android:summary="@string/deck_path_summ"
android:key="deckPath" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cat_study">
<CheckBoxPreference
android:title="@string/show_whiteboard"
android:defaultValue="true"
android:summary="@string/show_whiteboard_summ"
android:key="timerAndWhiteboard" />
<CheckBoxPreference
android:title="@string/corporal_punishments"
android:defaultValue="false"
android:summary="@string/corporal_punishments_summ"
android:key="corporalPunishments" />
<CheckBoxPreference
android:title="@string/write_answers"
android:defaultValue="false"
android:summary="@string/write_answers_summ"
android:key="writeAnswers" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_cat_qadisplay">
<CheckBoxPreference
android:title="@string/use_ruby_support"
android:defaultValue="false"
android:summary="@string/use_ruby_support_summ"
android:key="useRubySupport" />
<ListPreference
android:title="@string/qa_font_size"
android:summary="@string/qa_font_size_summ"
android:key="qaFontSize"
android:defaultValue="0"
android:entries="@array/qaFontSizeLabels"
android:entryValues="@array/qaFontSizeVals" />
<CheckBoxPreference
android:title="@string/show_question_answer"
android:defaultValue="false"
android:summary="@string/show_question_answer_summ"
android:key="showQuestionAnswer" />
</PreferenceCategory>
<!-- TODO implement this preference. Right now: always use notifications
<CheckBoxPreference
android:title="Update notifications"
@ -44,9 +75,4 @@
android:summary="Notify me when AnkiDroid is updated"
android:key="enabled"/>
-->
<EditTextPreference
android:title="@string/deck_path"
android:defaultValue="/sdcard"
android:summary="@string/deck_path_summ"
android:key="deckPath" />
</PreferenceScreen>

View File

@ -15,59 +15,89 @@
~ this program. If not, see <http://www.gnu.org/licenses/>.
-->
<resources>
<!-- WARNING: Many values here match static values defined in Deck.java
DO NOT edit them, unless you change their corresponding values -->
<!-- Used in deck preferences -->
<string-array name="newCardOrderLabels">
<item>Random order</item>
<item>Order added</item>
<item>Reverse order added</item>
</string-array>
<string-array name="newCardOrderVals">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="newCardSchedulingLabels">
<item>Spread out through reviews</item>
<item>After reviews</item>
<item>Before reviews</item>
</string-array>
<string-array name="newCardSchedulingVals">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="revCardOrderLabels">
<item>Largest interval first</item>
<item>Smallest interval first</item>
<item>Order due</item>
<item>Random order</item>
</string-array>
<string-array name="revCardOrderVals">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="failedCardOptionLabels">
<item>Show failed cards soon</item>
<item>Show failed cards at end</item>
<item>Show failed cards in 10 minutes</item>
<item>Show failed cards in 8 hours</item>
<item>Show failed cards in 3 days</item>
</string-array>
<string-array name="failedCardOptionVals">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<!-- WARNING: Many values here match static values defined in Deck.java
DO NOT edit them, unless you change their corresponding values -->
<!-- Used in deck preferences -->
<string-array name="newCardOrderLabels">
<item>Random order</item>
<item>Order added</item>
<item>Reverse order added</item>
</string-array>
<string-array name="newCardOrderVals">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="newCardSchedulingLabels">
<item>Spread out through reviews</item>
<item>After reviews</item>
<item>Before reviews</item>
</string-array>
<string-array name="newCardSchedulingVals">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
<string-array name="revCardOrderLabels">
<item>Largest interval first</item>
<item>Smallest interval first</item>
<item>Order due</item>
<item>Random order</item>
</string-array>
<string-array name="revCardOrderVals">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
</string-array>
<string-array name="failedCardOptionLabels">
<item>Show failed cards soon</item>
<item>Show failed cards at end</item>
<item>Show failed cards in 10 minutes</item>
<item>Show failed cards in 8 hours</item>
<item>Show failed cards in 3 days</item>
</string-array>
<string-array name="failedCardOptionVals">
<item>0</item>
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>
<!-- The values below match MIN_QA_FONT_SIZE and MAX_QA_FONT_SIZE in AnkiDroid.java.
This is a convenience, not at requirement -->
<string-array name="qaFontSizeLabels">
<item>Relative</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
</string-array>
<string-array name="qaFontSizeVals">
<item>0</item>
<item>3</item>
<item>4</item>
<item>5</item>
<item>6</item>
<item>7</item>
<item>8</item>
<item>9</item>
<item>10</item>
<item>11</item>
<item>12</item>
<item>13</item>
<item>14</item>
</string-array>
</resources>

View File

@ -20,8 +20,8 @@
<resources>
<string name="CardEditorCancelButton">Cancel</string>
<string name="CardEditorSaveButton">Save</string>
<string name="app_name">AnkiDroid</string>
<string name="yes">Yes</string>
@ -87,6 +87,9 @@
<!-- preferences.xml strings -->
<string name="pref_cat_decks">Decks</string>
<string name="pref_cat_study">Study options</string>
<string name="pref_cat_qadisplay">Question and answer display</string>
<string name="show_whiteboard">Show timer / whiteboard</string>
<string name="show_whiteboard_summ">Lets you write on the screen</string>
<string name="sample_deck">Sample deck</string>
@ -95,6 +98,12 @@
<string name="corporal_punishments_summ">Vibrate on error, that will teach you</string>
<string name="write_answers">Write answers</string>
<string name="write_answers_summ">Lets you write the answer and compare it with the correct one</string>
<string name="use_ruby_support">Provide ruby annotation support</string>
<string name="use_ruby_support_summ">If the characters '[' and ']' are found, then the enclosed text is handled as a ruby annotation</string>
<string name="qa_font_size">Font size</string>
<string name="qa_font_size_summ">Default font size. Using 'Relative' changes the font dynamically based on space</string>
<string name="show_question_answer">Show question in answer</string>
<string name="show_question_answer_summ">Shows the question also when displaying the answer unless user entered answer.</string>
<string name="deck_path">Deck path</string>
<string name="deck_path_summ">Path to where the your decks are stored</string>

View File

@ -75,11 +75,14 @@ public class AnkiDroid extends Activity
*/
private static final String TAG = "AnkiDroid";
/**
* Max and min size of the font of the questions and answers
*/
private static final int MAX_FONT_SIZE = 14;
private static final int MIN_FONT_SIZE = 3;
/** Max size of the font of the questions and answers for relative calculation */
private static final int MAX_QA_FONT_SIZE = 14;
/** Min size of the font of the questions and answers for relative calculation */
private static final int MIN_QA_FONT_SIZE = 3;
/** The font size specified in shared preferences. If 0 then font is calculated with MAX/MIN_FONT_SIZE */
private int qaFontSize = 0;
/**
* Menus
@ -94,7 +97,7 @@ public class AnkiDroid extends Activity
public static final int MENU_SUSPEND = 4;
private static final int MENU_EDIT = 5;
private static final int MENU_EDIT = 5;
/**
* Possible outputs trying to load a deck
@ -112,9 +115,7 @@ public class AnkiDroid extends Activity
public static final int PREFERENCES_UPDATE = 1;
public static final int EDIT_CURRENT_CARD = 2;
public static final int EDIT_CURRENT_CARD = 2;
/**
* Variables to hold the state
@ -123,7 +124,7 @@ public class AnkiDroid extends Activity
private AlertDialog updateDialog;
private BroadcastReceiver mUnmountReceiver = null;
private BroadcastReceiver mUnmountReceiver = null;
/**
* Name of the last deck loaded
@ -150,6 +151,12 @@ public class AnkiDroid extends Activity
private boolean timerAndWhiteboard;
private boolean writeAnswers;
/** Preference: parse for ruby annotations */
private boolean useRubySupport;
/** Preference: show the question when showing the answer */
private boolean showQuestionAnswer;
private boolean updateNotifications; // TODO use Veecheck only if this is true
@ -773,17 +780,25 @@ public class AnkiDroid extends Activity
// We want to modify the font size depending on how long is the content
// Replace each <br> with 15 spaces, then remove all html tags and spaces
String realContent = content.replaceAll("\\<br.*?\\>", " ");
//TODO: replacement for <hr/> in case of showQuestionAnswer = true
realContent = realContent.replaceAll("\\<.*?\\>", "");
realContent = realContent.replaceAll("&nbsp;", " ");
// Calculate the size of the font depending on the length of the content
int size = Math.max(MIN_FONT_SIZE, MAX_FONT_SIZE - (int)(realContent.length()/5));
mCard.getSettings().setDefaultFontSize(size);
if (0 == qaFontSize) {
int size = Math.max(MIN_QA_FONT_SIZE, MAX_QA_FONT_SIZE - (int)(realContent.length()/5));
mCard.getSettings().setDefaultFontSize(size);
} else {
mCard.getSettings().setDefaultFontSize(qaFontSize);
}
// In order to display the bold style correctly, we have to change font-weight to 700
content = content.replaceAll("font-weight:600;", "font-weight:700;");
content = RubyParser.ankiRubyToMarkup(content);
// If ruby annotation support is activated, then parse and add markup
if (useRubySupport) {
content = RubyParser.ankiRubyToMarkup(content);
}
Log.i(TAG, "content card = \n" + content);
String card = cardTemplate.replace("::content::", content);
@ -834,7 +849,15 @@ public class AnkiDroid extends Activity
}
else
{
updateCard(currentCard.answer);
if (true == showQuestionAnswer) {
StringBuffer sb = new StringBuffer();
sb.append(currentCard.question);
sb.append("<hr/>");
sb.append(currentCard.answer);
updateCard(sb.toString());
} else {
updateCard(currentCard.answer);
}
}
}
@ -874,6 +897,11 @@ public class AnkiDroid extends Activity
timerAndWhiteboard = preferences.getBoolean("timerAndWhiteboard", true);
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 qaFontSizeString = preferences.getString("qaFontSize", "0");
qaFontSize = Integer.parseInt(qaFontSizeString);
showQuestionAnswer = preferences.getBoolean("showQuestionAnswer", false);
updateNotifications = preferences.getBoolean("enabled", true);
return preferences;