diff options
author | Danesh M <daneshm90@gmail.com> | 2015-11-04 14:28:10 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2015-11-05 15:14:46 -0800 |
commit | 6d2f22ad19537c95b6afebca2f960805c7eca37a (patch) | |
tree | e29afabdacb662be15468bd23d72815e28470158 /src | |
parent | b56f346814dd36e7660267fd239f7a23ed954b6a (diff) | |
download | vendor_cmsdk-6d2f22ad19537c95b6afebca2f960805c7eca37a.zip vendor_cmsdk-6d2f22ad19537c95b6afebca2f960805c7eca37a.tar.gz vendor_cmsdk-6d2f22ad19537c95b6afebca2f960805c7eca37a.tar.bz2 |
CMSDK : Add functions for delimited strings
Change-Id: Ifccd6c7266cacdcd1413b221546be77eade9c501
Diffstat (limited to 'src')
-rw-r--r-- | src/java/cyanogenmod/providers/CMSettings.java | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/java/cyanogenmod/providers/CMSettings.java b/src/java/cyanogenmod/providers/CMSettings.java index 7fd751b..723520f 100644 --- a/src/java/cyanogenmod/providers/CMSettings.java +++ b/src/java/cyanogenmod/providers/CMSettings.java @@ -25,10 +25,14 @@ import android.os.RemoteException; import android.os.SystemProperties; import android.os.UserHandle; import android.provider.Settings; +import android.text.TextUtils; import android.util.AndroidException; import android.util.Log; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; +import java.util.regex.Pattern; /** * CMSettings contains CM specific preferences in System, Secure, and Global. @@ -274,6 +278,44 @@ public final class CMSettings { // region Methods /** + * Put a delimited list as a string + * @param resolver to access the database with + * @param name to store + * @param delimiter to split + * @param list to join and store + * @hide + */ + public static void putListAsDelimitedString(ContentResolver resolver, String name, + String delimiter, List<String> list) { + String store = TextUtils.join(delimiter, list); + putString(resolver, name, store); + } + + /** + * Get a delimited string returned as a list + * @param resolver to access the database with + * @param name to store + * @param delimiter to split the list with + * @return list of strings for a specific Settings.Secure item + * @hide + */ + public static List<String> getDelimitedStringAsList(ContentResolver resolver, String name, + String delimiter) { + String baseString = getString(resolver, name); + List<String> list = new ArrayList<String>(); + if (!TextUtils.isEmpty(baseString)) { + final String[] array = TextUtils.split(baseString, Pattern.quote(delimiter)); + for (String item : array) { + if (TextUtils.isEmpty(item)) { + continue; + } + list.add(item); + } + } + return list; + } + + /** * Construct the content URI for a particular name/value pair, useful for monitoring changes * with a ContentObserver. * @param name to look up in the table @@ -710,6 +752,45 @@ public final class CMSettings { // region Methods + + /** + * Put a delimited list as a string + * @param resolver to access the database with + * @param name to store + * @param delimiter to split + * @param list to join and store + * @hide + */ + public static void putListAsDelimitedString(ContentResolver resolver, String name, + String delimiter, List<String> list) { + String store = TextUtils.join(delimiter, list); + putString(resolver, name, store); + } + + /** + * Get a delimited string returned as a list + * @param resolver to access the database with + * @param name to store + * @param delimiter to split the list with + * @return list of strings for a specific Settings.Secure item + * @hide + */ + public static List<String> getDelimitedStringAsList(ContentResolver resolver, String name, + String delimiter) { + String baseString = getString(resolver, name); + List<String> list = new ArrayList<String>(); + if (!TextUtils.isEmpty(baseString)) { + final String[] array = TextUtils.split(baseString, Pattern.quote(delimiter)); + for (String item : array) { + if (TextUtils.isEmpty(item)) { + continue; + } + list.add(item); + } + } + return list; + } + /** * Construct the content URI for a particular name/value pair, useful for monitoring changes * with a ContentObserver. @@ -1211,6 +1292,45 @@ public final class CMSettings { // region Methods + + /** + * Put a delimited list as a string + * @param resolver to access the database with + * @param name to store + * @param delimiter to split + * @param list to join and store + * @hide + */ + public static void putListAsDelimitedString(ContentResolver resolver, String name, + String delimiter, List<String> list) { + String store = TextUtils.join(delimiter, list); + putString(resolver, name, store); + } + + /** + * Get a delimited string returned as a list + * @param resolver to access the database with + * @param name to store + * @param delimiter to split the list with + * @return list of strings for a specific Settings.Secure item + * @hide + */ + public static List<String> getDelimitedStringAsList(ContentResolver resolver, String name, + String delimiter) { + String baseString = getString(resolver, name); + List<String> list = new ArrayList<String>(); + if (!TextUtils.isEmpty(baseString)) { + final String[] array = TextUtils.split(baseString, Pattern.quote(delimiter)); + for (String item : array) { + if (TextUtils.isEmpty(item)) { + continue; + } + list.add(item); + } + } + return list; + } + /** * Construct the content URI for a particular name/value pair, useful for monitoring changes * with a ContentObserver. |