Skip to main content

bfgSettings Class

Stores settings to disk automatically so that other libraries can use keys to retrieve them. More...

Static Public Member Functions

static Object get (@NonNull final String key)
 Returns the object associated with the key, or null if the key was not found. More...
 
static Object get (@NonNull final String key, @Nullable final Object withDefault)
 Returns the object associated with the key, or null if the key was not found. More...
 
static boolean getBoolean (@NonNull final String key, @Nullable final boolean withDefault)
 This version of the get() method lets the caller avoid having to do casting in order to get at the actual boolean value. More...
 
static Vector< Hashtable< String, Object > > getDictionaryArray (@NonNull final String key, @Nullable final Vector< Hashtable< String, Object > > withDefault)
 Get an array of JSON dictionary values. More...
 
static double getDouble (@NonNull final String key, final double withDefault)
 This version of the get() method lets the caller avoid having to do casting in order to get at the actual double value. More...
 
static int getInteger (@NonNull final String key, final int withDefault)
 This version of the get() method lets the caller avoid having to do casting in order to get at the actual integer value. More...
 
static long getLong (@NonNull final String key, final long withDefault)
 This version of the get() method lets the caller avoid having to do casting in order to get at the actual long value. More...
 
static String getString (@NonNull final String key, @Nullable final String withDefault)
 This version of the get() method lets the caller avoid having to do casting in order to get at the string value. More...
 
static Vector< String > getStringVector (@NonNull final String key, @Nullable final Vector< String > withDefault)
 Get a string array from Settings. More...
 
static void initializeWithContext (@NonNull final Context context)
 Initialize the bfgSettings class in cases where the BFG SDK is not initialized. More...
 
static boolean isInitialized ()
 Determine if bfgSettings has been initialized yet and is ready for use. More...
 
static void set (@NonNull final String key, @Nullable final Serializable value)
 Save a generic object. More...
 
static void write ()
 Forces a write of the settings to disk. More...
 
static String writeToJSON (@NonNull final Map< String, Object > table)
 Converts the key-value pairs in a hash table into a JSON formatted string. More...
 

Static Public Attributes

static final String BFG_SETTING_GAME_SERVICE_TOKEN = "game_service_token"
 Since 6.1.
 
static final String BFG_TOAST_ENABLED = "bfg_toast_enabled"
 Since 6.2.
 

Detailed Description

Stores settings to disk automatically so that other libraries can use keys to retrieve them. Developers can use this class to store settings used in their own libraries.
NOTE: This class requires a working context in order to function as expected. In cases where the SDK is not yet initialized (e.g., accessing settings as a result of a push notification or accessing before initializing the SDK), you MUST call: initializeWithContext(Context) before attempting to access any settings using this class.If you are using these APIs, you can become an observer for the following event:
  • NOTIFICATION_BFGSETTING_CHANGED - When a setting is changed, this notification is sent. The name and value of the property are also sent.

Member Function Documentation

◆ get() [1/2]

static Object com.bigfishgames.bfglib.bfgSettings.get (@NonNull final String key)
inlinestatic
Returns the object associated with the key, or null if the key was not found. Returned objects can be Strings or primitive type wrappers. If the key is associated with an object containing members or even an empty object, the returned object will be of type JSONObject. If the key is associated with an array, the returned object will be of type JSONArray.
Parameters
keyString whose associated object is to be returned.
Returns
The object associated with the key or null.

◆ get() [2/2]

static Object com.bigfishgames.bfglib.bfgSettings.get (@NonNull final String key,
@Nullable final Object withDefault 
)
inlinestatic
Returns the object associated with the key, or null if the key was not found. Returned objects can be Strings or primitive type wrappers. If the key is associated with an object containing members or even an empty object, the returned object will be of type JSONObject. If the key is associated with an array, the returned object will be of type JSONArray.
Parameters
keyString whose associated object is to be returned.
withDefaultObject to return if the key is not found.
Returns
The object associated with the key or the withDefault value if it does not exist.

◆ getBoolean()

static boolean com.bigfishgames.bfglib.bfgSettings.getBoolean (@NonNull final String key,
@Nullable final boolean withDefault 
)
inlinestatic
This version of the get() method lets the caller avoid having to do casting in order to get at the actual boolean value.
Parameters
keyString whose associated object is to be returned.
withDefaultBoolean value to return if the key is not found.
Returns
Value as a primitive boolean. TRUE if boolean TRUE or Integer non-zero (e.g., 0/1 for FALSE/TRUE) NOTE: Integer 0/1 is supported for compatibility with older code that stored booleans as 0/1 integers.

◆ getDictionaryArray()

static Vector< Hashtable< String, Object > > com.bigfishgames.bfglib.bfgSettings.getDictionaryArray (@NonNull final String key,
@Nullable final Vector< Hashtable< String, Object > > withDefault 
)
inlinestatic
Get an array of JSON dictionary values.
Parameters
key
withDefault
Returns
Array of dictionaries associated with the key or the withDefault value if it does not exist.

◆ getDouble()

static double com.bigfishgames.bfglib.bfgSettings.getDouble (@NonNull final String key,
final double withDefault 
)
inlinestatic
This version of the get() method lets the caller avoid having to do casting in order to get at the actual double value.
Parameters
keyString whose associated object is to be returned.
withDefaultInteger value to return if the key is not found.
Returns
Value as a primitive double.

◆ getInteger()

static int com.bigfishgames.bfglib.bfgSettings.getInteger (@NonNull final String key,
final int withDefault 
)
inlinestatic
This version of the get() method lets the caller avoid having to do casting in order to get at the actual integer value.
Parameters
keyString whose associated object is to be returned.
withDefaultInteger value to return if the key is not found.
Returns
Value as a primitive integer.

◆ getLong()

static long com.bigfishgames.bfglib.bfgSettings.getLong (@NonNull final String key,
final long withDefault 
)
inlinestatic
This version of the get() method lets the caller avoid having to do casting in order to get at the actual long value.
Parameters
keyString whose associated object is to be returned.
withDefaultLong value to return if the key is not found.
Returns
Value as a primitive long.

◆ getString()

static String com.bigfishgames.bfglib.bfgSettings.getString (@NonNull final String key,
@Nullable final String withDefault 
)
inlinestatic
This version of the get() method lets the caller avoid having to do casting in order to get at the string value.
Parameters
keyString whose associated object is to be returned.
withDefaultString to return if the key is not found.
Returns
Value as a string object or the withDefault value if it does not exist.

◆ getStringVector()

static Vector< String > com.bigfishgames.bfglib.bfgSettings.getStringVector (@NonNull final String key,
@Nullable final Vector< String > withDefault 
)
inlinestatic
Get a string array from Settings.
Parameters
key
withDefault
Returns
Vector associated with the key or the withDefault value if it does not exist.

◆ initializeWithContext()

static void com.bigfishgames.bfglib.bfgSettings.initializeWithContext (@NonNull final Context context)
inlinestatic
Initialize the bfgSettings class in cases where the BFG SDK is not initialized. This is useful for cases when one needs to access bfgSettings and the SDK is not yet running. For example, accessing this class after receiving a push notification or an intent that's broadcast, this must be called before attempting to call any other bfgSettings methods.
Parameters
context- valid context used to access filesystem

◆ isInitialized()

static boolean com.bigfishgames.bfglib.bfgSettings.isInitialized ()
inlinestatic
Determine if bfgSettings has been initialized yet and is ready for use.
Returns
TRUE if initialized.

◆ set()

static void com.bigfishgames.bfglib.bfgSettings.set (@NonNull final String key,
@Nullable final Serializable value 
)
inlinestatic
Save a generic object.
Parameters
keyName of object being saved
valueObject to save. NOTE: value must be a standard object, such as String, HashMap, int, etc. and not a custom object or the object will not be saved across cold starts.

◆ write()

static void com.bigfishgames.bfglib.bfgSettings.write ()
inlinestatic
Forces a write of the settings to disk.
Deprecated:\n No longer needed. All changes to data are automatically written to disk

◆ writeToJSON()

static String com.bigfishgames.bfglib.bfgSettings.writeToJSON (@NonNull final Map< String, Object > table)
inlinestatic
Converts the key-value pairs in a hash table into a JSON formatted string. The hash table values can be an instance of any of the following classes: String, Number, Hashtable<String, Object> or Vector<String>
Parameters
tableHashMap of Settings key-value pairs.
Returns
Table content in readable String format.
Deprecated:\n