Package com.mapbox.mapboxsdk.utils
Contains the Mapbox Maps Android Utility API classes.
Types
Name | Summary |
---|---|
AnimatorUtils | open class AnimatorUtils Animator utility class. |
BitmapUtils | open class BitmapUtils Utility class for creating bitmaps |
ColorUtils | open class ColorUtils Color utility class. |
Compare | open class Compare Comparisons from std sdk, which aren’t available in API level 15 and below |
FileUtils | open class FileUtils |
FontUtils | open class FontUtils Utility class to select a font from a range of font names based on the availability of fonts on the device. |
MapFragmentUtils | open class MapFragmentUtils MapFragment utility class. |
MathUtils | open class MathUtils |
StringUtils | open class StringUtils String utility class used by core from jni. |
ThreadUtils | open class ThreadUtils Utility class to verify if execution is running on the main thread. |
AnimatorUtils
open class AnimatorUtils
Animator utility class.
Types
Name | Summary |
---|---|
OnAnimationEndListener | interface OnAnimationEndListener An interface definition that is invoked when an animation ends. |
Functions
Name | Summary |
---|---|
alpha | open fun alpha(convertView: View, alpha: Float) open fun alpha(convertView: View, alpha: Float, listener: AnimatorUtils.OnAnimationEndListener) Animate a view alpha property to a value. |
animate | open fun animate(view: View, animatorRes: Int) open fun animate(view: View, animatorRes: Int, listener: AnimatorUtils.OnAnimationEndListener) open fun animate(view: View, animatorRes: Int, duration: Int) open fun animate(view: View, animatorRes: Int, duration: Int, listener: AnimatorUtils.OnAnimationEndListener) Animate a view from an animator resource. |
rotate | open fun rotate(view: View, rotation: Float) Animate a view rotation property to a value. |
rotateBy | open fun rotateBy(view: View, rotationBy: Float) Animate a view rotation property by a value. |
alpha
open fun alpha(convertView: View, alpha: Float, listener: AnimatorUtils.OnAnimationEndListener)
Animate a view alpha property to a value.
Parameters
Name | Summary |
---|---|
convertView | the view to be animated |
alpha | the value to animate to |
listener | the animator end listener |
open fun alpha(convertView: View, alpha: Float)
Animate a view alpha property to a value.
Parameters
Name | Summary |
---|---|
convertView | the view to be animated |
alpha | the value to animate to |
animate
open fun animate(view: View, animatorRes: Int, listener: AnimatorUtils.OnAnimationEndListener)
Animate a view from an animator resource.
Parameters
Name | Summary |
---|---|
view | the view to be animated |
animatorRes | the animator resource to be loaded |
listener | the animator end listener |
open fun animate(view: View, animatorRes: Int, duration: Int, listener: AnimatorUtils.OnAnimationEndListener)
Animate a view from an animator resource.
Parameters
Name | Summary |
---|---|
view | the view to be animated |
animatorRes | the animator resource to be loaded |
duration | the duration of the animator |
listener | the animator end listener |
open fun animate(view: View, animatorRes: Int)
Animate a view from an animator resource.
Parameters
Name | Summary |
---|---|
view | the view to be animated |
animatorRes | the animator resource to be loaded |
open fun animate(view: View, animatorRes: Int, duration: Int)
Animate a view from an animator resource.
Parameters
Name | Summary |
---|---|
view | the view to be animated |
animatorRes | the animator resource to be loaded |
duration | the duration of the animator |
rotateBy
open fun rotateBy(view: View, rotationBy: Float)
Animate a view rotation property by a value.
Parameters
Name | Summary |
---|---|
view | the view to be rotated |
rotationBy | the value to animate by |
rotate
open fun rotate(view: View, rotation: Float)
Animate a view rotation property to a value.
Parameters
Name | Summary |
---|---|
view | the view to be rotated |
rotation | the value to animate to |
OnAnimationEndListener
interface OnAnimationEndListener
An interface definition that is invoked when an animation ends.
Functions
Name | Summary |
---|---|
onAnimationEnd | abstract fun onAnimationEnd() |
onAnimationEnd
abstract fun onAnimationEnd()
BitmapUtils
open class BitmapUtils
Utility class for creating bitmaps
Functions
Name | Summary |
---|---|
createBitmapFromView | open fun createBitmapFromView(view: View): Bitmap Convert a view to a bitmap. |
equals | open fun equals(bitmap: Bitmap, other: Bitmap): Boolean Validates if the bytes of a bitmap matches another |
getBitmapFromDrawable | @Nullable() open fun getBitmapFromDrawable(sourceDrawable: Drawable): Bitmap Extract an underlying bitmap from a drawable |
getByteArrayFromDrawable | @Nullable() open fun getByteArrayFromDrawable(drawable: Drawable): Array Create a byte array out of drawable |
getDrawableFromByteArray | @Nullable() open fun getDrawableFromByteArray(context: Context, array: Array Decode byte array to drawable object |
getDrawableFromRes | @Nullable() open fun getDrawableFromRes(context: Context, drawableRes: Int): Drawable Get a drawable from a resource. @Nullable() open fun getDrawableFromRes(context: Context, drawableRes: Int, tintColor: Integer): Drawable Get a tinted drawable from a resource. |
mergeBitmap | open fun mergeBitmap(background: Bitmap, foreground: Bitmap): Bitmap open fun mergeBitmap(background: Bitmap, foreground: Bitmap, left: Float, top: Float): Bitmap Create a bitmap from a background and a foreground bitmap |
createBitmapFromView
open fun createBitmapFromView(view: View): Bitmap
Convert a view to a bitmap.
Return
the converted bitmap
Parameters
Name | Summary |
---|---|
view | the view to convert |
equals
open fun equals(bitmap: Bitmap, other: Bitmap): Boolean
Validates if the bytes of a bitmap matches another
Return
true if equal
Parameters
Name | Summary |
---|---|
bitmap | the bitmap to be compared against |
other | the bitmap to compare with |
getBitmapFromDrawable
@Nullable()
open fun getBitmapFromDrawable(sourceDrawable: Drawable): Bitmap
Extract an underlying bitmap from a drawable
Return
The underlying bitmap
Parameters
Name | Summary |
---|---|
sourceDrawable | The source drawable |
getByteArrayFromDrawable
@Nullable()
open fun getByteArrayFromDrawable(drawable: Drawable): Array
Create a byte array out of drawable
Return
The byte array of source drawable
Parameters
Name | Summary |
---|---|
drawable | The source drawable |
getDrawableFromByteArray
@Nullable()
open fun getDrawableFromByteArray(context: Context, array: Array
Decode byte array to drawable object
Return
The drawable created from source byte array
Parameters
Name | Summary |
---|---|
context | Context to obtain android.content.res.Resources |
array | The source byte array |
getDrawableFromRes
@Nullable()
open fun getDrawableFromRes(context: Context, drawableRes: Int): Drawable
Get a drawable from a resource.
Return
The drawable created from the resource
Parameters
Name | Summary |
---|---|
context | Context to obtain android.content.res.Resources |
drawableRes | Drawable resource |
@Nullable()
open fun getDrawableFromRes(context: Context, drawableRes: Int, tintColor: Integer): Drawable
Get a tinted drawable from a resource.
Return
The drawable created from the resource
Parameters
Name | Summary |
---|---|
context | Context to obtain android.content.res.Resources |
drawableRes | Drawable resource |
tintColor | Tint color |
mergeBitmap
open fun mergeBitmap(background: Bitmap, foreground: Bitmap): Bitmap
Create a bitmap from a background and a foreground bitmap
Return
the merged bitmap
Parameters
Name | Summary |
---|---|
background | The bitmap placed in the background |
foreground | The bitmap placed in the foreground |
open fun mergeBitmap(background: Bitmap, foreground: Bitmap, left: Float, top: Float): Bitmap
Create a bitmap from a background and a foreground bitmap
Return
the merged bitmap
Parameters
Name | Summary |
---|---|
background | The bitmap placed in the background |
foreground | The bitmap placed in the foreground |
left | position of the left side of the foreground bitmap |
top | position of the top side of the foreground bitmap |
ColorUtils
open class ColorUtils
Color utility class.
Functions
Name | Summary |
---|---|
colorToGlRgbaArray | open fun colorToGlRgbaArray(color: Int): Array Converts Android color int to GL rgba float array. |
colorToRgbaArray | open fun colorToRgbaArray(color: Int): Array Converts Android color int to rgba float array. |
colorToRgbaString | open fun colorToRgbaString(color: Int): String Converts Android color int to “rbga(r, g, b, a)” String equivalent. |
getAccentColor | open fun getAccentColor(context: Context): Int Returns a color integer associated as accent color from a theme based on a Context. |
getPrimaryColor | open fun getPrimaryColor(context: Context): Int Returns a color integer associated as primary color from a theme based on a Context. |
getPrimaryDarkColor | open fun getPrimaryDarkColor(context: Context): Int Returns a color integer associated as primary dark color from a theme based on a Context. |
getSelector | @NonNull() open fun getSelector(color: Int): ColorStateList Returns a color state list associated with a theme based on a Context. |
rgbaToColor | open fun rgbaToColor(value: String): Int Convert an rgba string to a Color int. |
setTintList | open fun setTintList(imageView: ImageView, tintColor: Int) Set a color tint list to the Drawable of an ImageView. |
colorToGlRgbaArray
open fun colorToGlRgbaArray(color: Int): Array
Converts Android color int to GL rgba float array.
Returned values range from 0-1.
Return
float rgba array, values range from 0 to 1
Parameters
Name | Summary |
---|---|
color | Android color int |
colorToRgbaArray
open fun colorToRgbaArray(color: Int): Array
Converts Android color int to rgba float array.
Returned RGB values range from 0 to 255.Alpha value ranges from 0-1.
Return
float rgba array, rgb values range from 0-255, alpha from 0-1
Parameters
Name | Summary |
---|---|
color | Android color int |
colorToRgbaString
open fun colorToRgbaString(color: Int): String
Converts Android color int to “rbga(r, g, b, a)” String equivalent.
Alpha value will be converted from 0-255 range to 0-1.
Return
String rgba color
Parameters
Name | Summary |
---|---|
color | Android color int |
getAccentColor
open fun getAccentColor(context: Context): Int
Returns a color integer associated as accent color from a theme based on a Context.
Return
The accent color value of current theme in the form 0xAARRGGBB.
Parameters
Name | Summary |
---|---|
context | The context used to style the color attributes. |
getPrimaryColor
open fun getPrimaryColor(context: Context): Int
Returns a color integer associated as primary color from a theme based on a Context.
Return
The primary color value of current theme in the form 0xAARRGGBB.
Parameters
Name | Summary |
---|---|
context | The context used to style the color attributes. |
getPrimaryDarkColor
open fun getPrimaryDarkColor(context: Context): Int
Returns a color integer associated as primary dark color from a theme based on a Context.
Return
The primary dark color value of current theme in the form 0xAARRGGBB.
Parameters
Name | Summary |
---|---|
context | The context used to style the color attributes. |
getSelector
@NonNull()
open fun getSelector(color: Int): ColorStateList
Returns a color state list associated with a theme based on a Context.
Return
A ColorStateList object containing the primary color of a theme
Parameters
Name | Summary |
---|---|
color | The color used for tinting. |
rgbaToColor
open fun rgbaToColor(value: String): Int
Convert an rgba string to a Color int.
R, G, B color components have to be in the [0-255] range, while alpha has to be in the [0.0-1.0] range.For example: “rgba(255, 128, 0, 0.7)”.
Return
the int representation of rgba
Parameters
Name | Summary |
---|---|
value | the String representation of rgba |
Throws
Name | Summary |
---|---|
com.mapbox.mapboxsdk.exceptions.ConversionException | on illegal input |
setTintList
open fun setTintList(imageView: ImageView, tintColor: Int)
Set a color tint list to the Drawable of an ImageView.
Parameters
Name | Summary |
---|---|
imageView | The view to set the default tint list. |
tintColor | The color to tint. |
Compare
open class Compare
Comparisons from std sdk, which aren’t available in API level 15 and below
Functions
Name | Summary |
---|---|
compare | open fun compare(x: Boolean, y: Boolean): Int Boolean#compare(boolean, boolean) open fun compare(x: Int, y: Int): Int Integer#compare(int, int) |
compare
open fun compare(x: Int, y: Int): Int
Return
std compare value
See also
Name | Summary |
---|---|
java.lang.Integer | Integer#compare(int, int) |
Parameters
Name | Summary |
---|---|
x | left side |
y | right side |
open fun compare(x: Boolean, y: Boolean): Int
Return
std compare value
See also
Name | Summary |
---|---|
java.lang.Boolean | Boolean#compare(boolean, boolean) |
Parameters
Name | Summary |
---|---|
x | left side |
y | right side |
FileUtils
open class FileUtils
Types
Name | Summary |
---|---|
CheckFileReadPermissionTask | open class CheckFileReadPermissionTask : AsyncTask<File, Void, Boolean> Task checking whether app’s process can read a file. |
CheckFileWritePermissionTask | open class CheckFileWritePermissionTask : AsyncTask<File, Void, Boolean> Task checking whether app’s process can write to a file. |
OnCheckFileReadPermissionListener | interface OnCheckFileReadPermissionListener Interface definition for a callback invoked when checking file’s read permissions. |
OnCheckFileWritePermissionListener | interface OnCheckFileWritePermissionListener Interface definition for a callback invoked when checking file’s write permissions. |
Functions
Name | Summary |
---|---|
deleteFile | open fun deleteFile(path: String) Deletes a file asynchronously in a separate thread. |
deleteFile
open fun deleteFile(path: String)
Deletes a file asynchronously in a separate thread.
Parameters
Name | Summary |
---|---|
path | the path of the file that should be deleted |
CheckFileReadPermissionTask
open class CheckFileReadPermissionTask : AsyncTask<File, Void, Boolean>
Task checking whether app’s process can read a file.
The callback reference is strongly kept throughout the process,so it needs to be wrapped in a weak reference or released on the client side if necessary.
Constructors
Name | Summary |
---|---|
CheckFileReadPermissionTask | open fun CheckFileReadPermissionTask(listener: FileUtils.OnCheckFileReadPermissionListener) |
Functions
Name | Summary |
---|---|
cancel | fun cancel(mayInterruptIfRunning: Boolean): Boolean |
doInBackground | abstract fun doInBackground(p: Array |
execute | fun execute(params: Array open fun [execute](#execute)(runnable: Runnable) |
executeOnExecutor | fun executeOnExecutor(exec: Executor, params: Array |
get | fun get(): Result |
getStatus | fun getStatus(): AsyncTask.Status |
isCancelled | fun isCancelled(): Boolean |
onCancelled | open fun onCancelled(result: Result) |
onPostExecute | open fun onPostExecute(result: Result) |
onPreExecute | open fun onPreExecute() |
onProgressUpdate | open fun onProgressUpdate(values: Array |
publishProgress | fun publishProgress(values: Array |
CheckFileWritePermissionTask
open class CheckFileWritePermissionTask : AsyncTask<File, Void, Boolean>
Task checking whether app’s process can write to a file.
The callback reference is strongly kept throughout the process,so it needs to be wrapped in a weak reference or released on the client side if necessary.
Constructors
Name | Summary |
---|---|
CheckFileWritePermissionTask | open fun CheckFileWritePermissionTask(listener: FileUtils.OnCheckFileWritePermissionListener) |
Functions
Name | Summary |
---|---|
cancel | fun cancel(mayInterruptIfRunning: Boolean): Boolean |
doInBackground | abstract fun doInBackground(p: Array |
execute | fun execute(params: Array open fun [execute](#execute)(runnable: Runnable) |
executeOnExecutor | fun executeOnExecutor(exec: Executor, params: Array |
get | fun get(): Result |
getStatus | fun getStatus(): AsyncTask.Status |
isCancelled | fun isCancelled(): Boolean |
onCancelled | open fun onCancelled(result: Result) |
onPostExecute | open fun onPostExecute(result: Result) |
onPreExecute | open fun onPreExecute() |
onProgressUpdate | open fun onProgressUpdate(values: Array |
publishProgress | fun publishProgress(values: Array |
OnCheckFileReadPermissionListener
interface OnCheckFileReadPermissionListener
Interface definition for a callback invoked when checking file’s read permissions.
Functions
Name | Summary |
---|---|
onError | abstract fun onError() Invoked when app’s process doesn’t have a permission to read a file or an error occurs. |
onReadPermissionGranted | abstract fun onReadPermissionGranted() Invoked when app’s process has a permission to read a file. |
onError
abstract fun onError()
Invoked when app’s process doesn’t have a permission to read a file or an error occurs.
onReadPermissionGranted
abstract fun onReadPermissionGranted()
Invoked when app’s process has a permission to read a file.
OnCheckFileWritePermissionListener
interface OnCheckFileWritePermissionListener
Interface definition for a callback invoked when checking file’s write permissions.
Functions
Name | Summary |
---|---|
onError | abstract fun onError() Invoked when app’s process doesn’t have a permission to write to a file or an error occurs. |
onWritePermissionGranted | abstract fun onWritePermissionGranted() Invoked when app’s process has a permission to write to a file. |
onError
abstract fun onError()
Invoked when app’s process doesn’t have a permission to write to a file or an error occurs.
onWritePermissionGranted
abstract fun onWritePermissionGranted()
Invoked when app’s process has a permission to write to a file.
FontUtils
open class FontUtils
Utility class to select a font from a range of font names based on the availability of fonts on the device.
Functions
Name | Summary |
---|---|
extractValidFont | open fun extractValidFont(fontNames: Array Select a font from a range of font names to match the availability of fonts on the device. |
extractValidFont
open fun extractValidFont(fontNames: Array
Select a font from a range of font names to match the availability of fonts on the device.
Return
the selected fon
Parameters
Name | Summary |
---|---|
fontNames | the range of font names to select from |
MapFragmentUtils
open class MapFragmentUtils
MapFragment utility class.
Used to extract duplicate code between com.mapbox.mapboxsdk.maps.MapFragment and com.mapbox.mapboxsdk.maps.SupportMapFragment.
Functions
Name | Summary |
---|---|
createFragmentArgs | @NonNull() open fun createFragmentArgs(options: MapboxMapOptions): Bundle Convert MapboxMapOptions to a bundle of fragment arguments. |
resolveArgs | @Nullable() open fun resolveArgs(context: Context, args: Bundle): MapboxMapOptions Convert a bundle of fragment arguments to MapboxMapOptions. |
createFragmentArgs
@NonNull()
open fun createFragmentArgs(options: MapboxMapOptions): Bundle
Convert MapboxMapOptions to a bundle of fragment arguments.
Return
a bundle of converted fragment arguments
Parameters
Name | Summary |
---|---|
options | The MapboxMapOptions to convert |
resolveArgs
@Nullable()
open fun resolveArgs(context: Context, args: Bundle): MapboxMapOptions
Convert a bundle of fragment arguments to MapboxMapOptions.
Return
converted MapboxMapOptions
Parameters
Name | Summary |
---|---|
context | The context of the activity hosting the fragment |
args | The fragment arguments |
MathUtils
open class MathUtils
Functions
Name | Summary |
---|---|
clamp | open fun clamp(value: Double, min: Double, max: Double): Double open fun clamp(value: Float, min: Float, max: Float): Float Test a value in specified range, returning minimum if it’s below, and maximum if it’s above |
normalize | open fun normalize(x: Double, dataLow: Double, dataHigh: Double, normalizedLow: Double, normalizedHigh: Double): Double Scale a value from an arbitrary range to a normalized range. |
wrap | open fun wrap(value: Double, min: Double, max: Double): Double Constrains value to the given range (including min, excluding max) via modular arithmetic. |
clamp
open fun clamp(value: Double, min: Double, max: Double): Double
Test a value in specified range, returning minimum if it’s below, and maximum if it’s above
Return
value if it’s between min and max, min if it’s below, max if it’s above
Parameters
Name | Summary |
---|---|
value | Value to test |
min | Minimum value of range |
max | Maximum value of range |
open fun clamp(value: Float, min: Float, max: Float): Float
Test a value in specified range, returning minimum if it’s below, and maximum if it’s above
Return
value if it’s between min and max, min if it’s below, max if it’s above
Parameters
Name | Summary |
---|---|
value | Value to test |
min | Minimum value of range |
max | Maximum value of range |
normalize
open fun normalize(x: Double, dataLow: Double, dataHigh: Double, normalizedLow: Double, normalizedHigh: Double): Double
Scale a value from an arbitrary range to a normalized range.
Return
The result of the normalization.
Parameters
Name | Summary |
---|---|
x | The value to be normalized. |
dataLow | lowest expected value from a data set |
dataHigh | highest expected value from a data set |
normalizedLow | normalized lowest value |
normalizedHigh | normalized highest value |
wrap
open fun wrap(value: Double, min: Double, max: Double): Double
Constrains value to the given range (including min, excluding max) via modular arithmetic.
Same formula as used in Core GL (wrap.hpp)std::fmod((std::fmod((value - min), d) + d), d) + min;
Return
Wrapped value
Parameters
Name | Summary |
---|---|
value | Value to wrap |
min | Minimum value |
max | Maximum value |
StringUtils
open class StringUtils
String utility class used by core from jni.
Functions
Name | Summary |
---|---|
unaccent | @NonNull() open fun unaccent(value: String): String Normalises String input and strip diacritics from it. |
unaccent
@NonNull()
open fun unaccent(value: String): String
Normalises String input and strip diacritics from it.
Return
normalised String with stripped diacritics.
ThreadUtils
open class ThreadUtils
Utility class to verify if execution is running on the main thread.
Verification only runs for debug builds.
Functions
Name | Summary |
---|---|
checkThread | open fun checkThread(origin: String) Validates if execution is running on the main thread. |
init | open fun init(context: Context): ThreadUtils Initialises the thread utils, verifies debug state of the consuming app. |
checkThread
open fun checkThread(origin: String)
Validates if execution is running on the main thread.
Parameters
Name | Summary |
---|---|
origin | the origin of the execution |
init
open fun init(context: Context): ThreadUtils
Initialises the thread utils, verifies debug state of the consuming app.
Return
this
Parameters
Name | Summary |
---|---|
context | Context hosting the Mapbox Maps SDK for Android |
Android SDK
SDK JS Reference
- Root
- attribution
- camera
- constants
- exceptions
- geometry
- http
- location
- location.engine
- location.modes
- location.permissions
- log
- maps
- maps.renderer
- maps.renderer.egl
- maps.renderer.glsurfaceview
- maps.renderer.textureview
- maps.widgets
- module.http
- module.loader
- net
- offline
- snapshotter
- storage
- style.expressions
- style.layers
- style.light
- style.sources
- style.types
- text
- utils