Permalink
Browse files

New Preference model now works

  • Loading branch information...
1 parent c58d2b3 commit 533a62a41e60257415b4f0f4e0a1e9ef9cb1842a @matburt committed May 27, 2010
Showing with 9 additions and 33 deletions.
  1. +2 −2 res/values/arrays.xml
  2. +5 −29 src/com/matburt/mobileorg/Capture.java
  3. +2 −2 src/com/matburt/mobileorg/Synchronizer.java
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="storageModes">
- <item>Internal</item>
- <item>Storage Card</item>
+ <item>internal</item>
+ <item>sdcard</item>
</string-array>
<string-array name="storageModesVals">
<item>internal</item>
@@ -5,13 +5,15 @@
import android.os.Environment;
import android.util.Log;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.widget.EditText;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
+import android.preference.PreferenceManager;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.StringWriter;
@@ -29,14 +31,13 @@
{
private EditText orgEditDisplay;
private Button saveButton;
- private Map<String, String> appSettings;
+ private SharedPreferences appSettings;
public static final String LT = "MobileOrg";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- this.appSettings = new HashMap<String, String>();
- this.populateApplicationSettings();
+ this.appSettings = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
setContentView(R.layout.simpleedittext);
this.saveButton = (Button)this.findViewById(R.id.captureSave);
this.orgEditDisplay = (EditText)this.findViewById(R.id.orgEditTxt);
@@ -45,7 +46,7 @@ public void onCreate(Bundle savedInstanceState) {
public boolean onSave() {
String newNote = this.transformBuffer(this.orgEditDisplay.getText().toString());
- String storageMode = this.appSettings.get("storage");
+ String storageMode = this.appSettings.getString("storageMode", "");
BufferedWriter writer = new BufferedWriter(new StringWriter());
if (storageMode.equals("internal") || storageMode == null) {
@@ -150,29 +151,4 @@ public void addOrUpdateFile(String filename, String name) {
result.close();
appdb.close();
}
-
- public int populateApplicationSettings() {
- SQLiteDatabase appdb = this.openOrCreateDatabase(
- "MobileOrg", 0, null);
- Cursor result = appdb.rawQuery("SELECT * FROM settings", null);
- int rc = 0;
- if (result != null) {
- if (result.getCount() > 0) {
- result.moveToFirst();
- do {
- this.appSettings.put(result.getString(0),
- result.getString(1));
- } while (result.moveToNext());
- }
- else {
- rc = -1;// need to start settings display
- }
- }
- else {
- rc = -1;// need to start settings display
- }
- result.close();
- appdb.close();
- return rc;
- }
}
@@ -37,7 +37,7 @@
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
-import android.preferences.PreferenceManager;
+import android.preference.PreferenceManager;
import android.content.SharedPreferences;
import android.util.Log;
import android.os.Environment;
@@ -56,7 +56,7 @@
public boolean push() {
String urlActual = this.getRootUrl() + "mobileorg.org";
- String storageMode = this.appSettings.get("storageMode", "");
+ String storageMode = this.appSettings.getString("storageMode", "");
BufferedReader reader = null;
String fileContents = "";

0 comments on commit 533a62a

Please sign in to comment.