CMSDK : Add functions for delimited strings
Change-Id: Ifccd6c7266cacdcd1413b221546be77eade9c501
This commit is contained in:
parent
b56f346814
commit
6d2f22ad19
|
@ -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.
|
||||
|
@ -273,6 +277,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.
|
||||
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue