Translation setting stored in a Record.
--- a/src/jdict/Main.java Sun Jul 29 13:07:29 2007 +0200
+++ b/src/jdict/Main.java Sun Jul 29 16:36:43 2007 +0200
@@ -1,6 +1,7 @@
package jdict;
import java.io.*;
+import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
@@ -19,10 +20,20 @@
protected void loadSettings()
{
+ String val = Mem.getVariable("Lingvo");
+ if (val != null)
+ T.set_language(val);
}
protected void saveSettings()
{
+ String old = Mem.getVariable("Lingvo");
+ String language = T.get_chosen_language();
+
+ if (old == null || ! language.equals(old))
+ {
+ Mem.setVariable("Lingvo", language);
+ }
}
protected void startApp()
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/jdict/Mem.java Sun Jul 29 16:36:43 2007 +0200
@@ -0,0 +1,67 @@
+package jdict;
+
+import java.io.*;
+import javax.microedition.rms.*;
+
+public class Mem
+{
+ public static String getVariable(String var)
+ {
+ RecordStore r;
+ byte tmp[];
+ try {
+ r = RecordStore.openRecordStore(var, false);
+ tmp = r.getRecord(1);
+ r.closeRecordStore();
+ } catch (Exception e)
+ {
+ System.out.println("loadSettings() Recordstore Exception: " + e.toString());
+ return null;
+ }
+
+ String out;
+ try {
+ out = new String(tmp, 0, tmp.length, "utf-8");
+ } catch (UnsupportedEncodingException e)
+ {
+ return null;
+ }
+ return out;
+ }
+
+ public static void setVariable(String var, String val)
+ {
+ RecordStore r;
+ try {
+ r = RecordStore.openRecordStore(var, true);
+ } catch (Exception e)
+ {
+ System.out.println("saveSettings() Recordstore Exception: " + e.toString());
+ return;
+ }
+
+ byte tmp[];
+
+ try {
+ tmp = val.getBytes("utf-8");
+ } catch (Exception e)
+ {
+ System.out.println("Recordstore/Encoding Exception: " + e.toString());
+ return;
+ }
+
+ try {
+ r.setRecord(1, tmp, 0, tmp.length);
+ r.closeRecordStore();
+ } catch (Exception e)
+ {
+ try {
+ r.addRecord(tmp, 0, tmp.length);
+ r.closeRecordStore();
+ } catch (Exception f)
+ {
+ System.out.println("Recordstore addRecord Exception: " + f.toString());
+ }
+ }
+ }
+}
--- a/src/jdict/T.java Sun Jul 29 13:07:29 2007 +0200
+++ b/src/jdict/T.java Sun Jul 29 16:36:43 2007 +0200
@@ -106,7 +106,7 @@
System.out.println("Language string not found for " + from);
return from;
}
- System.out.println("Asked string '" + from + "', giving '" + out + "'");
+ /* System.out.println("Asked string '" + from + "', giving '" + out + "'");*/
return out;
}