incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [12/17] git commit: making preference reading code more robust
Date Mon, 23 Jan 2012 23:05:55 GMT
making preference reading code more robust


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/ffa76246
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/ffa76246
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/ffa76246

Branch: refs/heads/master
Commit: ffa76246e3171240db916fa7fadc6ad92bbb6ee7
Parents: 3af4d6b
Author: alunny <alunny@gmail.com>
Authored: Mon Jan 2 22:40:08 2012 -0800
Committer: alunny <alunny@gmail.com>
Committed: Mon Jan 9 17:31:58 2012 -0800

----------------------------------------------------------------------
 framework/src/com/phonegap/DroidGap.java           |    5 +++--
 framework/src/com/phonegap/PreferenceSet.java      |   10 ++++++++++
 framework/test/com/phonegap/PreferenceSetTest.java |   14 ++++++++++++++
 3 files changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ffa76246/framework/src/com/phonegap/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java
index 893471f..149b49b 100755
--- a/framework/src/com/phonegap/DroidGap.java
+++ b/framework/src/com/phonegap/DroidGap.java
@@ -329,7 +329,7 @@ public class DroidGap extends PhonegapActivity {
 
         getWindow().requestFeature(Window.FEATURE_NO_TITLE);
 
-        if (preferences.pref("fullscreen").equals("true")) {
+        if (preferences.prefMatches("fullscreen","true")) {
             getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                     WindowManager.LayoutParams.FLAG_FULLSCREEN);
         } else {
@@ -1901,7 +1901,8 @@ public class DroidGap extends PhonegapActivity {
                     String value = xml.getAttributeValue(null, "value");
                     String readonlyString = xml.getAttributeValue(null, "readonly");
 
-                    boolean readonly = (readonlyString.equals("true"));
+                    boolean readonly = (readonlyString != null &&
+                                        readonlyString.equals("true"));
 
                     LOG.i("PhoneGapLog", "Found preference for %s", name);
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ffa76246/framework/src/com/phonegap/PreferenceSet.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/PreferenceSet.java b/framework/src/com/phonegap/PreferenceSet.java
index 4e6f79e..8603460 100644
--- a/framework/src/com/phonegap/PreferenceSet.java
+++ b/framework/src/com/phonegap/PreferenceSet.java
@@ -30,4 +30,14 @@ public class PreferenceSet {
 
         return null;
     }
+
+    public boolean prefMatches(String prefName, String prefValue) {
+        String value = pref(prefName);
+
+        if (value == null) {
+            return false;
+        } else {
+            return value.equals(prefValue);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/ffa76246/framework/test/com/phonegap/PreferenceSetTest.java
----------------------------------------------------------------------
diff --git a/framework/test/com/phonegap/PreferenceSetTest.java b/framework/test/com/phonegap/PreferenceSetTest.java
index fa56560..2eba245 100644
--- a/framework/test/com/phonegap/PreferenceSetTest.java
+++ b/framework/test/com/phonegap/PreferenceSetTest.java
@@ -38,4 +38,18 @@ public class PreferenceSetTest {
             // return null if the preference is not defined
             assertEquals(null, preferences.pref("antigravity"));
         }
+
+    @Test
+        public void testUnsetPreferenceChecking() {
+            PreferenceSet emptySet = new PreferenceSet();
+            boolean value = emptySet.prefMatches("fullscreen", "true");
+            assertEquals(false, value);
+        }
+
+    @Test
+        public void testSetPreferenceChecking() {
+            preferences.add(screen);
+            boolean value = preferences.prefMatches("fullscreen", "true");
+            assertEquals(true, value);
+        }
 }


Mime
View raw message