[sword-svn] r107 - in trunk: micro micro/src/org/crosswire/flashcards micro/src/org/crosswire/flashcards/mobile src/org/crosswire/flashcards
Apache
apache at www.crosswire.org
Mon Dec 11 23:44:06 MST 2006
Author:
Date: 2006-12-11 23:44:05 -0700 (Mon, 11 Dec 2006)
New Revision: 107
Modified:
trunk/micro/FlashcardsMobile.jpx
trunk/micro/src/org/crosswire/flashcards/MicroLesson.java
trunk/micro/src/org/crosswire/flashcards/Properties.java
trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java
trunk/micro/src/org/crosswire/flashcards/mobile/Lessons.java
trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
trunk/src/org/crosswire/flashcards/Quizer.java
Log:
Reverted all code to work on CLDC 1.0 and MIDP 1.0
Modified: trunk/micro/FlashcardsMobile.jpx
===================================================================
--- trunk/micro/FlashcardsMobile.jpx 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/FlashcardsMobile.jpx 2006-12-12 06:44:05 UTC (rev 107)
@@ -32,7 +32,6 @@
<property category="sys" name="MakeStable" value="0"/>
<property category="sys" name="OutPath" value="classes"/>
<property category="sys" name="SourcePath" value="src;test;../src"/>
-<property category="sys" name="SourceVersion" value="1.5"/>
<property category="sys" name="TestPath" value="test"/>
<property category="sys" name="Title" value=""/>
<property category="sys" name="TitleLabel" value="Title:"/>
@@ -43,20 +42,21 @@
<property category="archiving" name="archiverClass" value="com.borland.jbuilder.wizard.micro.archive.MidletArchiver"/>
<property category="archiving" name="contentRules.1" value="I:**/*.*"/>
<property category="archiving" name="ignoreClasses.1" value="org.crosswire.flashcards.mobile.FlashCards"/>
-<property category="archiving" name="miscTargetPath.1" value="FlashcardsMobile.jad"/>
+<property category="archiving" name="miscTargetPath.1" value="fcm.jad"/>
<property category="archiving" name="obfuscator" value="RetroGuard for J2ME"/>
<property category="archiving" name="targetCompressed" value="1"/>
-<property category="archiving" name="targetPath" value="FlashcardsMobile.jar"/>
+<property category="archiving" name="targetPath" value="fcm.jar"/>
<property category="archiving" name="usingRules" value="1"/>
-<property category="archiving.micro" name="microEditionConfiguration" value="CLDC-1.1"/>
+<property category="archiving.micro" name="microEditionConfiguration" value="CLDC-1.0"/>
<property category="archiving.micro" name="microEditionProfile" value="MIDP-2.0"/>
<property category="archiving.micro" name="midlet-n-IconPath.1" value=""/>
<property category="archiving.micro" name="midlet-n-MainClass.1" value="org.crosswire.flashcards.mobile.FlashCards"/>
<property category="archiving.micro" name="midlet-n-Name.1" value="FlashCards"/>
+<property category="archiving.micro" name="midletIconPath" value="cbs.png"/>
<property category="archiving.micro" name="midletIgnoreClasses.1" value="org.crosswire.flashcards.mobile.FlashCards"/>
-<property category="archiving.micro" name="midletName" value="FlashcardsMobile"/>
+<property category="archiving.micro" name="midletName" value="Flashcards"/>
<property category="archiving.micro" name="midletObfuscator" value="RetroGuard for J2ME"/>
-<property category="archiving.micro" name="midletVendor" value="CrossWire Bible Society"/>
+<property category="archiving.micro" name="midletVendor" value="CrossWire"/>
<property category="archiving.micro" name="midletVersion" value="1.0"/>
</node>
<node name="HebrewFlashcards" type="MicroArchive">
Modified: trunk/micro/src/org/crosswire/flashcards/MicroLesson.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/MicroLesson.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/src/org/crosswire/flashcards/MicroLesson.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -22,6 +22,10 @@
package org.crosswire.flashcards;
import java.util.Vector;
+import javax.microedition.lcdui.Image;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.ByteArrayOutputStream;
/**
* A Lesson is an ordered list of FlashCards.
@@ -73,4 +77,37 @@
}
setModified(false);
}
+
+ static public Image getImage(FlashCard f) throws Exception {
+ String url = f.getImageURL();
+ InputStream is = null;
+ Class c = f.getClass();
+ is = c.getResourceAsStream(url);
+ if (is != null) {
+ byte [] imgBytes = getInputStreamContents(is);
+ return Image.createImage(imgBytes, 0, imgBytes.length);
+ }
+ return null;
+ }
+
+ public static byte [] getInputStreamContents(InputStream is) {
+ InputStreamReader isr = null;
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ try {
+ isr = new InputStreamReader(is, "iso8859-1");
+
+ int ch;
+ while ( (ch = isr.read()) > -1) {
+ buffer.write(ch);
+ }
+ if (isr != null) {
+ isr.close();
+ }
+ }
+ catch (Exception ex) {
+ System.out.println(ex);
+ }
+ return buffer.toByteArray();
+
+ }
}
Modified: trunk/micro/src/org/crosswire/flashcards/Properties.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/Properties.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/src/org/crosswire/flashcards/Properties.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -59,7 +59,7 @@
}
- private String getInputStreamContents(InputStream is) {
+ public static String getInputStreamContents(InputStream is) {
InputStreamReader isr = null;
StringBuffer buffer = null;
try {
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/LessonGroups.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -64,7 +64,9 @@
}
public void loadLessonGroups() {
- lessonGroupChoice.deleteAll();
+ while (lessonGroupChoice.size() > 0) {
+ lessonGroupChoice.delete(0);
+ }
Vector l = FlashCards.instance.lessonSets;
for (int i = 0; i < l.size(); i++) {
lessonGroupChoice.append(((LessonSet)l.elementAt(i)).getDescription(), null);
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/Lessons.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/Lessons.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/Lessons.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -61,7 +61,9 @@
public void loadLessons() {
lessonChoice.setLabel(FlashCards.instance.lessonGroups.getLessonSet().getDescription());
- lessonChoice.deleteAll();
+ while (lessonChoice.size() > 0) {
+ lessonChoice.delete(0);
+ }
Vector lessons = FlashCards.instance.lessonGroups.getLessonSet().getLessons();
for (int i = 0; i < lessons.size(); i++) {
Lesson l = (Lesson) lessons.elementAt(i);
Modified: trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -2,10 +2,10 @@
import javax.microedition.lcdui.*;
import org.crosswire.flashcards.Lesson;
+import org.crosswire.flashcards.MicroLesson;
import org.crosswire.flashcards.Quizer;
import org.crosswire.flashcards.FlashCard;
import java.util.Vector;
-import java.io.InputStream;
/**
* <p>Title: </p>
@@ -48,11 +48,11 @@
this.append(answersDisplay);
this.append(statusBar);
answersDisplay.setLabel(null);
- answersDisplay.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP |
- Item.LAYOUT_VEXPAND);
+// 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);
+// wordImage.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP |
+// Item.LAYOUT_VSHRINK);
}
void show() {
@@ -104,23 +104,22 @@
setStatus("Great Job!");
return;
}
- InputStream is = null;
+ boolean hasImage = false;
try {
- Class c = currentWord.getClass();
- is = c.getResourceAsStream(currentWord.getImageURL());
- if (is != null) {
- Image image = Image.createImage(is);
+ Image image = MicroLesson.getImage(currentWord);
wordImage.setImage(image);
wordImage.setLabel(null);
- }
+ hasImage = true;
}
catch (Exception e) { e.printStackTrace();}
- if (is == null) {
+ if (!hasImage) {
wordImage.setImage(null);
wordImage.setLabel(currentWord.getFront());
}
Vector answers = quizer.getRandomAnswers(5);
- answersDisplay.deleteAll();
+ while (answersDisplay.size() > 0) {
+ answersDisplay.delete(0);
+ }
for (int i = 0; i < answers.size(); i++) {
String a = (String) answers.elementAt(i);
if (a.length() > 23) {
Modified: trunk/src/org/crosswire/flashcards/Quizer.java
===================================================================
--- trunk/src/org/crosswire/flashcards/Quizer.java 2006-12-12 02:48:36 UTC (rev 106)
+++ trunk/src/org/crosswire/flashcards/Quizer.java 2006-12-12 06:44:05 UTC (rev 107)
@@ -121,6 +121,7 @@
}
}
+
int numToLearn = notLearned.size();
if (numToLearn == 0) {
return null;
@@ -129,23 +130,28 @@
WordEntry currentWord = null;
// if there are more than 1 words available be sure we don't get the same word
- if (numToLearn != 1) currentWord = lastWord;
+ if (numToLearn != 1) {
+ currentWord = lastWord;
- // if we just want a new word and not report anything, find the NEXT word
- // because we're likely cycling throw the words looking at answers and don't
- // want random answers which might include repeats
- if ( (wrongCount < 0) && (currentWord != null)) {
- int next = notLearned.indexOf(lastWord) + 1;
- if (next >= notLearned.size()) {
- next = 0;
+ // if we just want a new word and not report anything, find the NEXT word
+ // because we're likely cycling throw the words looking at answers and don't
+ // want random answers which might include repeats
+ if ( (wrongCount < 0) && (currentWord != null)) {
+ int next = notLearned.indexOf(lastWord) + 1;
+ if (next >= notLearned.size()) {
+ next = 0;
+ }
+ currentWord = (WordEntry) notLearned.elementAt(next);
}
- currentWord = (WordEntry) notLearned.elementAt(next);
+
+ // if we need to randomly find a new word, let's do it
+ while (currentWord == lastWord) {
+ int wordNum = getRandomInt(notLearned.size());
+ currentWord = (WordEntry) notLearned.elementAt(wordNum);
+ }
}
-
- // if we need to randomly find a new word, let's do it
- while (currentWord == lastWord) {
- int wordNum = rand.nextInt(notLearned.size());
- currentWord = (WordEntry) notLearned.elementAt(wordNum);
+ else {
+ currentWord = (WordEntry) notLearned.elementAt(0);
}
lastWord = currentWord;
@@ -155,8 +161,8 @@
public int getPercentage() {
int percent = 100;
if (totalAsked > 0) {
- percent = (int) ( ( ( (float) (totalAsked - totalWrong)) /
- (float) totalAsked) * 100);
+ percent = ( (totalAsked - totalWrong) * 100) /
+ totalAsked;
}
return percent;
}
@@ -168,7 +174,7 @@
}
while (count > 0) {
- int wordNum = rand.nextInt(words.size());
+ int wordNum = getRandomInt(words.size());
String b = ( (WordEntry) words.elementAt(wordNum)).flashCard.getBack();
if (ret.indexOf(b) < 0) {
ret.addElement(b);
@@ -177,7 +183,7 @@
}
// be sure the right answer is in there
if (ret.indexOf(lastWord.flashCard.getBack()) < 0) {
- int wordNum = rand.nextInt(ret.size());
+ int wordNum = getRandomInt(ret.size());
ret.setElementAt(lastWord.flashCard.getBack(), wordNum);
}
return ret;
@@ -194,4 +200,12 @@
public int getNotLearnedCount() {
return notLearned.size();
}
+
+ public int getRandomInt(int upperLimit) {
+ int ret = rand.nextInt()%upperLimit;
+ if (ret < 0) {
+ ret *= -1;
+ }
+ return ret;
+ }
}
More information about the sword-cvs
mailing list