Bug 906088 - part 1b - add ArrayList getPrefs method to PrefsHelper; r=bnicholson
authorNathan Froyd <froydnj@mozilla.com>
Wed, 04 Sep 2013 09:57:49 -0400
changeset 147038 0482a7192d05e5fe98e1b077366fd74fc91b25c6
parent 147037 9de79eb78556d65cb5f9ee47e46329153b84e917
child 147039 1b551b5c270fdc61b72afe4cfdc5aa1f37ede7ba
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbnicholson
bugs906088
milestone26.0a1
Bug 906088 - part 1b - add ArrayList getPrefs method to PrefsHelper; r=bnicholson Related to the last patch, this is the lone place where we transfer an ArrayList. Just move the code into PrefsHelper in case anybody ever wants to do something similar.
mobile/android/base/GeckoPreferences.java
mobile/android/base/PrefsHelper.java
--- a/mobile/android/base/GeckoPreferences.java
+++ b/mobile/android/base/GeckoPreferences.java
@@ -671,19 +671,17 @@ public class GeckoPreferences
                 return null;
         }
 
         return dialog;
     }
 
     // Initialize preferences by requesting the preference values from Gecko
     private int getGeckoPreferences(final PreferenceGroup screen, ArrayList<String> prefs) {
-        JSONArray jsonPrefs = new JSONArray(prefs);
-
-        return PrefsHelper.getPrefs(jsonPrefs, new PrefsHelper.PrefHandlerBase() {
+        return PrefsHelper.getPrefs(prefs, new PrefsHelper.PrefHandlerBase() {
             private Preference getField(String prefName) {
                 return screen.findPreference(prefName);
             }
 
             // Handle v14 TwoStatePreference with backwards compatibility.
             class CheckBoxPrefSetter {
                 public void setBooleanPref(Preference preference, boolean value) {
                     if ((preference instanceof CheckBoxPreference) &&
--- a/mobile/android/base/PrefsHelper.java
+++ b/mobile/android/base/PrefsHelper.java
@@ -8,16 +8,17 @@ package org.mozilla.gecko;
 import org.mozilla.gecko.util.GeckoEventListener;
 
 import org.json.JSONArray;
 import org.json.JSONException;
 import org.json.JSONObject;
 
 import android.util.Log;
 
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Map;
 
 /**
  * Helper class to get/set gecko prefs.
  */
 public final class PrefsHelper {
     private static final String LOGTAG = "GeckoPrefsHelper";
@@ -35,16 +36,24 @@ public final class PrefsHelper {
     public static int getPrefs(String[] prefNames, PrefHandler callback) {
         JSONArray prefs = new JSONArray();
         for (String p : prefNames) {
             prefs.put(p);
         }
         return getPrefs(prefs, callback);
     }
 
+    public static int getPrefs(ArrayList<String> prefNames, PrefHandler callback) {
+        JSONArray prefs = new JSONArray();
+        for (String p : prefNames) {
+            prefs.put(p);
+        }
+        return getPrefs(prefs, callback);
+    }
+
     public static int getPrefs(JSONArray prefNames, PrefHandler callback) {
         int requestId;
         synchronized (PrefsHelper.class) {
             ensureRegistered();
 
             requestId = sUniqueRequestId++;
             sCallbacks.put(requestId, callback);
         }