Package-level declarations

Types

Link copied to clipboard

Wraps Log so that Braze log messages can be set to a configurable level.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Useful validation methods for checking user input.

Link copied to clipboard

Functions

Link copied to clipboard

If both null, returns true.

Link copied to clipboard
fun calculateInSampleSize(options: BitmapFactory.Options, destinationWidth: Int, destinationHeight: Int): Int

Gets the sample factor given a bitmap's dimensions and destination view's bounds.

Link copied to clipboard

Creates a new JSONArray containing the contents of the input array.

Link copied to clipboard

Converts a JSONObject to a Map, String>.

Link copied to clipboard

Converts the contents of the JSONArray to an List of Strings. Non-strings will be logged and skipped

Link copied to clipboard
Link copied to clipboard

Helper method used to convert seconds from epoch to a new Date object. The resulting date is in UTC.

fun createDate(year: Int, month: Int, day: Int, hours: Int = 0, minutes: Int = 0, seconds: Int = 0): Date

Helper method used to create a new Date object. The resulting date is in UTC.

Link copied to clipboard
Link copied to clipboard
fun deleteFileOrDirectory(fileOrDirectory: File)

Recursively deletes all the files under a directory. If the input file is not a directory, then this only deletes the file. This is recursive since directories must be empty before deletion.

Link copied to clipboard

Deletes the android.content.SharedPreferences file. Expects the filename to end in ".xml".

Link copied to clipboard
fun downloadFileToPath(downloadDirectoryAbsolutePath: String, remoteFileUrl: String, outputFilename: String, extension: String? = null): Pair<File, HttpHeaders>
Link copied to clipboard

If input is empty or only contains whitespace, returns null. No null checking is performed.

Link copied to clipboard
fun Date.formatDate(dateFormat: BrazeDateFormat, timeZone: TimeZone = UTC_TIME_ZONE): String

Formats the date using the specified DateFormat pattern.

Link copied to clipboard

Formats the current time with the specified format in the current timezone.

Link copied to clipboard

Retrieve the string contents of a file from Android assets.

Link copied to clipboard
fun getBitmap(context: Context, uri: Uri, viewBounds: BrazeViewBounds = BrazeViewBounds.NO_BOUNDS): Bitmap?

Downloads an image from the internet or loads an image locally and returns a bitmap object. This should always be run in a background thread.

Link copied to clipboard

Gets the image metadata from an input stream without having to allocate memory for the image's pixels, see android.graphics.BitmapFactory.Options.inJustDecodeBounds. Note that the stream's position is changed as a result. The input stream is not closed by this method and must be closed the caller.

Link copied to clipboard

Gets the number of bytes in UTF-8 encoding.

Link copied to clipboard
fun getCacheFileSuffix(context: Context, userId: String?): String

Gets a MD5 hash of the userId. If userId is null, a MD5 hash of the String "null" is returned.

fun getCacheFileSuffix(context: Context, userId: String?, apiKey: String?): String

There is the potential for having a too-long filename, but Android doesn't actually have anything about that in the docs. Stack overflow suggests < 127 characters, so with the API key 36 characters and 31 characters of prefix, that leaves 60 characters for userId. We'll use the MD5 hash to make sure it fits.

Link copied to clipboard
fun getDensityDpi(context: Context): Int
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Gets the size in bytes to give the image loader's cache.

Link copied to clipboard
fun getLocalBitmap(uri: Uri, destinationWidth: Int, destinationHeight: Int): Bitmap?
Link copied to clipboard

Calculates the MD5 hash for some text.

Link copied to clipboard

Returns the string value for key, or null if the key is not mapped in the object.

Link copied to clipboard
fun getPermissionRequestCount(context: Context, permission: String): Int

Helper method to determine how many times a permission has been requested through this util. Does not cover situations where the permission was requested by the integrator!!!

Link copied to clipboard
Link copied to clipboard

Returns the JSONArray.toString result if possible. Returns an empty string if the input JSONArray is null or on any thrown Throwable.

Returns the JSONObject.toString result if possible. Returns an empty string if the input JSONObject is null or on any thrown Throwable.

Link copied to clipboard
fun Context?.hasPermission(permission: String): Boolean

Helper method for checking if a permission is allowed. In case of error the permission is reported as denied.

Link copied to clipboard
fun String?.ifNonEmpty(block: (String) -> Unit)

Invokes the input block iff the string is non-null and non-empty.

Link copied to clipboard
Link copied to clipboard
fun isBlank(reference: String?): Boolean

Checks if the string is empty or only contains whitespace characters. This will call String.trim to ascertain whether the string contains only whitespace.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun isNullOrBlank(reference: String?): Boolean

Checks if the string is null or only contains whitespace characters. This will call String.trim to ascertain whether the string contains only whitespace.

Link copied to clipboard
fun isNullOrEmpty(reference: String?): Boolean

Checks if the string is null or has a length of 0.

Link copied to clipboard
Link copied to clipboard

Helper method to determine if a timeZoneId is valid.

Link copied to clipboard
inline operator fun <T> JSONArray?.iterator(): Iterator<T>
inline operator fun <T> JSONObject.iterator(): Iterator<T>
Link copied to clipboard

Merges key-values from oldJson and newJson into a new JSONObject. Keys which exist in both oldJson and newJson will be overridden by the values in newJson. Key-values present in oldJson but not newJson will be preserved.

Link copied to clipboard

Returns the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC (Unix time).

Link copied to clipboard

Returns the difference, measured in seconds, between the current time and midnight, January 1, 1970 UTC (Unix time).

Link copied to clipboard

Returns the difference, measured in seconds, between the current time and midnight, January 1, 1970 UTC (Unix time) with millisecond precision to 3 places.

Link copied to clipboard
inline fun <TargetEnum : Enum<TargetEnum>> optEnum(jsonObject: JSONObject, key: String): TargetEnum?
inline fun <TargetEnum : Enum<TargetEnum>> optEnum(jsonObject: JSONObject, key: String, defaultEnum: TargetEnum): TargetEnum
fun <TargetEnum : Enum<TargetEnum>?> optEnum(jsonObject: JSONObject, key: String, targetEnumClass: Class<TargetEnum>, defaultEnum: TargetEnum): TargetEnum
Link copied to clipboard

Returns a Date object parsed from a BrazeDateFormat formatted date string.

Link copied to clipboard

Parses the JSON into a bundle. The JSONObject parsed from the input string must be a flat dictionary with all string values.

Link copied to clipboard
operator fun JSONObject.plus(otherJson: JSONObject): JSONObject
Link copied to clipboard

Requests the push permission prompt to be shown if on Android API 13+ and the push permission hasn't already been granted.

Link copied to clipboard

Resizes the ImageView to match the aspect ratio derived from the bitmap. Note that the width of the ImageView will be unchanged. Calls directly on the caller thread.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Converts a Bundle to a Map for all string values. Non-string values are skipped.

Link copied to clipboard
fun String.truncateToByteLength(desiredByteLength: Int): String

Truncates and returns the input text to the desired number of UTF-8 bytes.

Properties

Link copied to clipboard

A MD5 hash of "null". Check http://onlinemd5.com/ to verify

Link copied to clipboard

The amount that the image loader's runtime memory is divided by.

Link copied to clipboard