Common
Convert Dp to Pixel
This function converts a value in density-independent pixels (dp) to pixels (px).
Parameters:
dp
(the value in dp),context
(used to get resources and display metrics).Process: Uses the display metrics to convert dp to pixels.
Return: The equivalent value in pixels.
Get Bitmap from Drawable
This function converts a Drawable
to a Bitmap
.
Parameters:
drawable
(the drawable to convert).Process: Creates a bitmap, draws the drawable onto a canvas, and returns the bitmap.
Return: A
Bitmap
representation of the drawable.
Get Colored String
This function creates a SpannableString
with a specified color.
Parameters:
text
(the string to color),color
(the color to apply).Process: Creates a
SpannableString
and applies aForegroundColorSpan
.Return: A colored
SpannableString
.
Get Current Date
This function returns the current date in a specified format and locale.
Parameters:
format
(date format),locale
(locale for the format).Process: Uses
SimpleDateFormat
to format the current date.Return: A string representing the current date in the specified format and locale.
Get Device ID
This function returns the device's unique ID.
Parameters:
context
(used to access system settings).Process: Retrieves the device's unique ID from the system settings.
Return: The device's unique ID as a string.
Get Screen Width
This function returns the screen width in pixels.
Parameters: None.
Process: Uses system resources to get the screen width.
Return: The screen width in pixels.
Hide Soft Keyboard
This function hides the soft keyboard.
Parameters:
view
(the view currently holding the keyboard focus),context
(used to get the input method manager).Process: Hides the soft keyboard using the input method manager.
Return: None.
is Network Connected
This function checks if the device is connected to a network.
Parameters: None.
Process: Uses
ConnectivityManager
to check network connection and capabilities.Return:
true
if connected,false
otherwise.
Load Json from Asset
This function loads a JSON file from the assets folder.
Parameters:
context
(to access assets),jsonFileName
(the name of the JSON file).Process: Reads the JSON file from assets and returns its content as a string.
Return: The JSON content as a string.
Show Keyboard
This function shows the soft keyboard.
Parameters:
view
(the view to focus),context
(to access the input method manager).Process: Requests focus for the view and shows the soft keyboard using the input method manager.
Return: None.
Last updated