forked from github/cordova-android
making preference reading code more robust
This commit is contained in:
parent
3af4d6b139
commit
ffa76246e3
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user