[sword-svn] r118 - in trunk: app/src/org/crosswire/flashcards lessons/HebrewWegner2 micro/src/org/crosswire/flashcards/mobile
Apache
apache at www.crosswire.org
Mon Apr 30 18:34:18 MST 2007
Author:
Date: 2007-04-30 18:34:17 -0700 (Mon, 30 Apr 2007)
New Revision: 118
Added:
trunk/lessons/HebrewWegner2/lesson21.flash
trunk/lessons/HebrewWegner2/lesson22.flash
Modified:
trunk/app/src/org/crosswire/flashcards/LessonManager.java
trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java
trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java
trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
Log:
Added 2 new lessons.
Reworked Quiz screen to be owner drawn and use keypad entry
Added commandline option on LessonManager to genImages
Modified: trunk/app/src/org/crosswire/flashcards/LessonManager.java
===================================================================
--- trunk/app/src/org/crosswire/flashcards/LessonManager.java 2007-03-22 03:59:32 UTC (rev 117)
+++ trunk/app/src/org/crosswire/flashcards/LessonManager.java 2007-05-01 01:34:17 UTC (rev 118)
@@ -256,7 +256,7 @@
}
/**
- * Save all the modified lesson sets to persistent store named by the lesson's <code>LESSON_ROOT</code>.
+ * Generate pre-rendered images for each card (useful on mobile phones)
*/
public void genImages() {
for (int i = 0; i < lessonSets.size(); i++) {
@@ -276,4 +276,12 @@
return name.toUpperCase(Locale.ENGLISH).endsWith(".JAR");
}
}
+ public static void main( String [ ] arguments ) {
+ // Parse the command line arguments
+ for( int index = 0; arguments.length > index; ++ index ) {
+ if( ( arguments [ index ] ).equals( "-genImages" ) ) {
+ LessonManager.instance().genImages();
+ }
+ }
+ }
}
Added: trunk/lessons/HebrewWegner2/lesson21.flash
===================================================================
--- trunk/lessons/HebrewWegner2/lesson21.flash (rev 0)
+++ trunk/lessons/HebrewWegner2/lesson21.flash 2007-05-01 01:34:17 UTC (rev 118)
@@ -0,0 +1,32 @@
+#Flash Lesson
+#Wed Apr 04 11:40:43 MST 2007
+word13=\u05EA\u05BC\u05D5\u05B9\u05E2\u05B5\u05D1\u05B8\u05D4
+word1=\u05E0\u05B8\u05E9\u05C2\u05B4\u05D9\u05D0
+word12=\u05DC\u05B8\u05E9\u05C1\u05D5\u05B9\u05DF
+word0=\u05E0\u05B0\u05D7\u05A3\u05B9\u05E9\u05C1\u05B6\u05EA
+word11=\u05E8\u05B6\u05AB\u05DB\u05B6\u05D1
+word10=\u05E4\u05BC\u05B0\u05E8\u05B4\u05D9
+answers13=abomination (118)
+answers12=tongue (117)
+answers11=chariot, chariotry (120)
+answers10=fruit (119)
+answers9=assembly, congregation (123)
+answers8=bone (126)
+answers7=strength, power (126)
+answers6=half (125)
+answers5=heat, rage, wrath (125)
+answers4=firstborn (120)
+answers3=light (120)
+wordCount=14
+answers2=evening (134)
+answers1=chief, prince (130)
+answers0=copper, bronze (139)
+word9=\u05E7\u05B8\u05D4\u05B8\u05DC
+word8=\u05E2\u05B6\u05AB\u05E6\u05B6\u05DD
+lessonTitle=Hebrew 502 Lesson 21
+word7=\u05DB\u05BC\u05B9\u05D7
+word6=\u05D7\u05B2\u05E2\u05B4\u05D9
+word5=\u05D7\u05B5\u05DE\u05B8\u05D4
+word4=\u05D1\u05BC\u05B0\u05DB\u05B9\u05E8
+word3=\u05D0\u05D5\u05B9\u05E8
+word2=\u05E2\u05B6\u05AB\u05E8\u05B6\u05D1
Added: trunk/lessons/HebrewWegner2/lesson22.flash
===================================================================
--- trunk/lessons/HebrewWegner2/lesson22.flash (rev 0)
+++ trunk/lessons/HebrewWegner2/lesson22.flash 2007-05-01 01:34:17 UTC (rev 118)
@@ -0,0 +1,34 @@
+#Flash Lesson
+#Tue Apr 17 23:17:09 MST 2007
+word13=\u05D9\u05B8\u05E9\u05C1\u05B7\u05E2
+word1=\u05E9\u05C1\u05B8\u05DE\u05B7\u05D3
+word12=\u05D9\u05B8\u05EA\u05B7\u05E8
+word0=\u05E8\u05D5\u05BC\u05E5
+word11=\u05DB\u05BC\u05D5\u05BC\u05DF
+word10=\u05DC\u05B8\u05D7\u05B7\u05DD
+answers14=to be steady, firm, trustworthy, faithful; (Hiphil) believe (97)
+answers13=to be saved; (Hiphil) save (205)
+answers12=to be left, remain (106)
+answers11=to be firm, established (219)
+answers10=to fight (171)
+answers9=to escape (94)
+answers8=to be sorry, repent; (Piel) comfort, console (108)
+answers7=to be hit; (Hiphil) smite (501)
+answers6=to take one's stand, be stationed (75)
+answers5=to be delivered; (Hiphil) snatch away (213)
+answers4=to conceal, hide; (Hiphil) hide someone (82)
+answers3=to be extraordinary, wonderful (71)
+wordCount=15
+answers2=to be corrupt, spoiled; (Hiphil) destroy (152)
+answers1=to destroyed, exterminated; (Hiphil) exterminate (90)
+answers0=to run (104)
+word9=\u05DE\u05B8\u05DC\u05B7\u05D8
+word8=\u05E0\u05B8\u05D7\u05B7\u05DD
+lessonTitle=Hebrew 502 Lesson 22
+word7=\u05E0\u05B8\u05DB\u05B8\u05D4
+word6=\u05E0\u05B8\u05E2\u05B7\u05D1
+word5=\u05E0\u05B8\u05E2\u05B7\u05DC
+word4=\u05E1\u05B8\u05EA\u05B7\u05E8
+word3=\u05E4\u05BC\u05B8\u05DC\u05B8\u05D0
+word14=\u05D0\u05B8\u05DE\u05B5\u05DF
+word2=\u05E9\u05C1\u05B8\u05D7\u05B8\u05EA
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java 2007-03-22 03:59:32 UTC (rev 117)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java 2007-05-01 01:34:17 UTC (rev 118)
@@ -25,13 +25,14 @@
public boolean loaded = false;
public Vector lessonSets = new Vector();
+
public FlashCards() {
instance = this;
}
public void startApp() {
- lessonGroups.show();
if (!loaded) {
+ lessonGroups.show();
loadLessons();
}
}
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java 2007-03-22 03:59:32 UTC (rev 117)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java 2007-05-01 01:34:17 UTC (rev 118)
@@ -59,8 +59,7 @@
public LessonSet getLessonSet() {
int lessonGroup = FlashCards.instance.lessonGroups.lessonGroupChoice.getSelectedIndex();
- return (LessonSet)FlashCards.instance.lessonSets.elementAt(lessonGroup);
-
+ return (lessonGroup < 0) ? null : (LessonSet)FlashCards.instance.lessonSets.elementAt(lessonGroup);
}
public void loadLessonGroups() {
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java 2007-03-22 03:59:32 UTC (rev 117)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java 2007-05-01 01:34:17 UTC (rev 118)
@@ -19,20 +19,20 @@
* @author not attributable
* @version 1.0
*/
-public class Quiz extends Form implements CommandListener {
+public class Quiz extends Canvas implements CommandListener {
ImageItem wordImage = new ImageItem("", null, ImageItem.LAYOUT_DEFAULT, "");
- ChoiceGroup answersDisplay = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE);
- StringItem statusBar = new StringItem("", "");
- int maxWidth = 10000;
- int maxHeight = 10000;
+ Vector answers = new Vector();
+ Image image = null;
+ boolean showAnswer = false;
+ String statusBar = "";
Quizer quizer = new Quizer();
FlashCard currentWord = null;
int wrongThisTime = 0;
public Quiz() {
- super("Quiz");
+ super();
try {
jbInit();
}
@@ -42,46 +42,9 @@
}
private void jbInit() throws Exception {
- // Set up this Displayable to listen to command events
setCommandListener(this);
- addCommand(new Command("End", Command.BACK, 1));
- addCommand(new Command("Answer", Command.SCREEN, 2));
- this.append(wordImage);
- this.append(answersDisplay);
- this.append(statusBar);
- answersDisplay.setLabel(null);
- try {
- // MIDP 2.0 only. can we avoid this?
- answersDisplay.setFitPolicy(Choice.TEXT_WRAP_OFF);
- }
- catch (Exception e) {
- e.printStackTrace();
- maxWidth = 20;
- }
- // answersDisplay.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP |
-// Item.LAYOUT_VEXPAND);
- statusBar.setText("StatusBar");
-// wordImage.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP |
-// Item.LAYOUT_VSHRINK);
-// maxWidth =
- try {
- // MIDP 2.0 only. can we avoid this?
- int thisHeight = this.getHeight();
-
- thisHeight -= 40; // subtract image height
- thisHeight -= 4; // subtract likely border
-// Font choiceFont = answersDisplay.getFont(0);
- // MIDP 2.0 only. can we avoid this?
- Font choiceFont = statusBar.getFont();
- int fontHeight = choiceFont.getHeight();
- fontHeight += 1; // likely buffer space between entries
- maxHeight = thisHeight / fontHeight;
- maxHeight -= 1; // space for status bar
- }
- catch (Exception e) {
- e.printStackTrace();
- maxHeight = 4;
- }
+ addCommand(new Command("Help", Command.HELP, 1));
+ addCommand(new Command("Quit", Command.BACK, 2));
}
void show() {
@@ -99,67 +62,154 @@
}
public void commandAction(Command command, Displayable displayable) {
- if (command.getCommandType() == Command.BACK) {
- Display.getDisplay(FlashCards.instance).setCurrent(FlashCards.instance.lessons);
+ if ("Quit".equals(command.getLabel())) {
+ Display.getDisplay(FlashCards.instance).setCurrent(FlashCards.instance.
+ lessons);
}
- else if (command.getCommandType() == Command.SCREEN) {
- if (command.getPriority() == 2) {
- // show answer
- // for now let's use this as our answer picker button
- int a = answersDisplay.getSelectedIndex();
- String ans = answersDisplay.getString(a);
- String right = currentWord.getBack();
- if (right.length() > maxWidth) {
- right = right.substring(0, maxWidth-3) + "...";
- }
- if (ans.equals(right)) {
- wordDisplay(wrongThisTime, "Correct");
- }
- else {
- setStatus("Try again");
- wrongThisTime++;
- }
+ else if ("Help".equals(command.getLabel())) {
+ if (showAnswer) {
+ wordDisplay(-1, "Begin");
}
+ else {
+ showAnswer = true;
+ repaint();
+ }
}
}
public void wordDisplay(int wrong, String status) {
+ showAnswer = false;
currentWord = quizer.getRandomWord(wrong);
+ image = null;
+ answers.removeAllElements();
// we do this here cuz we first need to update stats from line above this
wrongThisTime = 0;
- if (status != null) setStatus(status);
+ if (status != null)
+ setStatus(status);
if (currentWord == null) {
- setStatus("Great Job!");
+ setStatus("Score");
return;
}
- boolean hasImage = false;
+ // default to something sane
+ int wordHeight = 20;
try {
- Image image = MicroLesson.getImage(currentWord);
- wordImage.setImage(image);
- wordImage.setLabel(null);
- hasImage = true;
+ image = MicroLesson.getImage(currentWord);
}
- catch (Exception e) { e.printStackTrace();}
- if (!hasImage) {
- wordImage.setImage(null);
- wordImage.setLabel(currentWord.getFront());
+ catch (Exception e) {
}
- Vector answers = quizer.getRandomAnswers(maxHeight);
- while (answersDisplay.size() > 0) {
- answersDisplay.delete(0);
+ repaint();
+ }
+
+ private void setStatus(String text) {
+ statusBar = text + "|" + Integer.toString(quizer.getNotLearnedCount()) + "|" + Integer.toString(quizer.getTotalAsked() - quizer.getTotalWrong()) + "/" + Integer.toString(quizer.getTotalAsked()) + "|"+quizer.getPercentage()+"%";
+ this.repaint();
+ }
+
+ protected void keyPressed(int keyCode) {
+ if ((currentWord != null) && (keyCode >= this.KEY_NUM1) && (keyCode <= this.KEY_NUM9)) {
+ int a = keyCode - this.KEY_NUM1;
+ String ans = (String)answers.elementAt(a);
+ String right = currentWord.getBack();
+ /*
+ if (right.length() > maxWidth) {
+ right = right.substring(0, maxWidth-3) + "...";
+ }
+ */
+ if (ans.equals(right)) {
+ wordDisplay(wrongThisTime, "Correct");
+ }
+ else {
+ setStatus("Try again");
+ wrongThisTime++;
+ }
}
- for (int i = 0; i < answers.size(); i++) {
- String a = (String) answers.elementAt(i);
- if (a.length() > maxWidth) {
- a = a.substring(0, maxWidth-3) + "...";
+ else {
+ super.keyPressed(keyCode);
+ }
+ repaint();
+ }
+
+ public void paint (Graphics g) {
+
+
+ Font gf = g.getFont();
+ Font normFont = Font.getFont(gf.getFace(), Font.STYLE_PLAIN, gf.getSize());
+ Font boldFont = Font.getFont(gf.getFace(), Font.STYLE_BOLD, gf.getSize());
+ Font largeFont = Font.getFont(gf.getFace(), Font.STYLE_BOLD, Font.SIZE_LARGE);
+
+ int spacer = 2;
+ int rowHeight = boldFont.getHeight() + spacer;
+ int y = 0;
+
+ g.setGrayScale(255);
+ g.fillRect (0, 0, getWidth (), getHeight ());
+ g.setColor(0x0);
+
+ if (currentWord == null) {
+ String str = "Great Job!!!";
+ g.setFont(largeFont);
+ g.drawString(str, (getWidth() / 2) - (largeFont.stringWidth(str) / 2), (getHeight() / 2), Graphics.TOP|Graphics.LEFT);
+ }
+ else {
+
+ // draw the word image
+ if (image != null) {
+ g.drawImage(image, 0, 0, Graphics.TOP | Graphics.LEFT);
+ y = image.getHeight() + spacer;
}
- answersDisplay.append(a, null);
-// if (answersDisplay.get
+ else {
+ g.setFont(largeFont);
+ g.drawString(currentWord.getFront(), 0, 0, Graphics.TOP | Graphics.LEFT);
+ y = largeFont.getHeight() + spacer;
+ }
+
+ g.drawLine(0,y, getWidth(), y);
+ y += spacer;
+
+ if (answers.size() == 0) {
+ // compute how many rows we have for displaying answers
+ int height = getHeight();
+ height -= (y + rowHeight);
+ int answerCount = height / (rowHeight);
+ if (answerCount > 9)
+ answerCount = 9;
+ answers = quizer.getRandomAnswers(answerCount);
+ }
+
+ // draw the answers
+ for (int i = 0; i < answers.size(); i++) {
+ String ans = (String) answers.elementAt(i);
+ String right = currentWord.getBack();
+ /*
+ if (right.length() > maxWidth) {
+ right = right.substring(0, maxWidth-3) + "...";
+ }
+ */
+ String a = String.valueOf(i + 1) + "." + ans;
+ if (showAnswer && ans.equals(right)) {
+ g.setFont(boldFont);
+ g.drawLine(0, y-1, boldFont.stringWidth(a), y-1);
+ g.drawLine(0, y+boldFont.getHeight()+1, boldFont.stringWidth(a), y+boldFont.getHeight()+1);
+ g.drawLine(boldFont.stringWidth(a)+1, y-1, boldFont.stringWidth(a)+1, y+boldFont.getHeight()+1);
+ }
+ else {
+ g.setFont(normFont);
+ }
+ g.drawString(a, 0, y, Graphics.TOP | Graphics.LEFT);
+ y += rowHeight;
+ }
+
}
+ // draw status bar
+ g.setFont(normFont);
+ y = getHeight() - normFont.getHeight() - spacer;
+ g.drawLine(0, y, getWidth(), y);
+ g.drawString(statusBar, 0, this.getHeight(), Graphics.BOTTOM|Graphics.LEFT);
+
+ // set the font back to original value (is this necessary?)
+ g.setFont(gf);
}
- private void setStatus(String text) {
- statusBar.setText(text + "|" + Integer.toString(quizer.getNotLearnedCount()) + "|" + Integer.toString(quizer.getTotalAsked() - quizer.getTotalWrong()) + "/" + Integer.toString(quizer.getTotalAsked()) + "|"+quizer.getPercentage()+"%");
- }
}
+
More information about the sword-cvs
mailing list