[sword-svn] r117 - in trunk/micro/src/org/crosswire/flashcards: . mobile

Apache apache at www.crosswire.org
Wed Mar 21 20:59:33 MST 2007


Author: 
Date: 2007-03-21 20:59:32 -0700 (Wed, 21 Mar 2007)
New Revision: 117

Modified:
   trunk/micro/src/org/crosswire/flashcards/Properties.java
   trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java
   trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
Log:
Removed UTF8 translation (this didn't do anything anyway)
First attempt to cater to width and height of device


Modified: trunk/micro/src/org/crosswire/flashcards/Properties.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/Properties.java	2007-03-10 18:58:56 UTC (rev 116)
+++ trunk/micro/src/org/crosswire/flashcards/Properties.java	2007-03-22 03:59:32 UTC (rev 117)
@@ -76,6 +76,7 @@
     }
   }
 
+/*
   public static String getInputStreamContents(InputStream is) {
     InputStreamReader isr = null;
     StringBuffer buffer = null;
@@ -96,9 +97,31 @@
       System.out.println(ex);
     }
     return buffer.toString();
+  }
+*/
+public static String getInputStreamContents(InputStream is) {
+  InputStreamReader isr = null;
+  StringBuffer buffer = null;
+  try {
+    isr = new InputStreamReader(is);//, "UTF8");
 
+    buffer = new StringBuffer();
+    int ch;
+    while ( (ch = isr.read()) > -1) {
+      buffer.append( (char) ch);
+    }
+    if (isr != null) {
+      isr.close();
+    }
   }
+  catch (Exception ex) {
+    System.out.println(ex);
+  }
+  return buffer.toString();
 
+}
+
+
   public void setProperty(String key, String value) {
     values.put(key, value);
   }

Modified: trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java	2007-03-10 18:58:56 UTC (rev 116)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/FlashCards.java	2007-03-22 03:59:32 UTC (rev 117)
@@ -50,7 +50,7 @@
   public void loadLessons() {
     Properties l = new Properties();
     try {
-      l.load("/lessons.properties");
+      l.load("/lessons/lessons.properties");
     }
     catch (Exception e) {}
     if (l != null) {
@@ -59,7 +59,7 @@
         if (ld != null) {
           String desc = l.getProperty("LessonDescription" + Integer.toString(i));
           lessonGroups.lessonGroupChoice.setLabel("Loading ["+desc+"]...");
-          LessonSet ls = new MicroLessonSet("/" + ld);
+          LessonSet ls = new MicroLessonSet("/lessons/" + ld);
           ls.setDescription( (desc != null) ? desc : ld);
           lessonSets.addElement(ls);
         }

Modified: trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java
===================================================================
--- trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java	2007-03-10 18:58:56 UTC (rev 116)
+++ trunk/micro/src/org/crosswire/flashcards/mobile/Quiz.java	2007-03-22 03:59:32 UTC (rev 117)
@@ -24,6 +24,8 @@
   ImageItem wordImage = new ImageItem("", null, ImageItem.LAYOUT_DEFAULT, "");
   ChoiceGroup answersDisplay = new ChoiceGroup("", ChoiceGroup.EXCLUSIVE);
   StringItem statusBar = new StringItem("", "");
+  int maxWidth = 10000;
+  int maxHeight = 10000;
 
   Quizer quizer = new Quizer();
   FlashCard currentWord = null;
@@ -48,11 +50,38 @@
     this.append(answersDisplay);
     this.append(statusBar);
     answersDisplay.setLabel(null);
-//    answersDisplay.setLayout(Item.LAYOUT_LEFT | Item.LAYOUT_TOP |
+    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;
+    }
   }
 
   void show() {
@@ -80,14 +109,14 @@
         int a = answersDisplay.getSelectedIndex();
         String ans = answersDisplay.getString(a);
         String right = currentWord.getBack();
-	if (right.length() > 23) {
-	  right = right.substring(0, 20) + "...";
+	if (right.length() > maxWidth) {
+	  right = right.substring(0, maxWidth-3) + "...";
 	}
         if (ans.equals(right)) {
           wordDisplay(wrongThisTime, "Correct");
         }
         else {
-          setStatus("Try again.");
+          setStatus("Try again");
           wrongThisTime++;
         }
       }
@@ -116,20 +145,21 @@
       wordImage.setImage(null);
       wordImage.setLabel(currentWord.getFront());
     }
-    Vector answers = quizer.getRandomAnswers(4);
+    Vector answers = quizer.getRandomAnswers(maxHeight);
     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) {
-        a = a.substring(0, 20) + "...";
+      if (a.length() > maxWidth) {
+        a = a.substring(0, maxWidth-3) + "...";
       }
       answersDisplay.append(a, null);
+//      if (answersDisplay.get
     }
   }
 
   private void setStatus(String text) {
-    statusBar.setText(text + " | " + Integer.toString(quizer.getNotLearnedCount()) + " | " + Integer.toString(quizer.getTotalAsked() - quizer.getTotalWrong()) + "/" + Integer.toString(quizer.getTotalAsked()) + "("+quizer.getPercentage()+"%)");
+    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