Class Utils
- java.lang.Object
-
- org.prebid.mobile.rendering.utils.helpers.Utils
-
public final class Utils extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static floatDENSITY
-
Constructor Summary
Constructors Constructor Description Utils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <E,U>
voidaddValue(java.util.Map<E,java.util.Set<U>> map, E key, U value)static voidaddValue(org.json.JSONObject target, java.lang.String key, java.lang.Object jsonObject)static booleanatLeastICS()Check that Android SDK version at least Ice Cream Sandwich.static booleanatLeastKitKat()Check that Android SDK version at least Kit Katstatic booleanatLeastQ()static java.lang.StringbyteArrayToHexString(byte[] byteArray)This function encodes byte[] into a hexstatic intclampAutoRefresh(int refreshDelay)static intclampInMillis(int value, int lowerBound, int upperBound)static intconvertDpToPx(int dp, android.content.Context context)static intconvertPxToDp(int px, android.content.Context context)static android.view.ViewcreateCloseView(android.content.Context context)static android.view.ViewcreateCloseView(android.content.Context context, InterstitialDisplayPropertiesInternal properties)static android.view.ViewcreateSkipView(android.content.Context context, InterstitialDisplayPropertiesInternal properties)static android.view.ViewcreateSoundView(android.content.Context context)static android.view.ViewcreateWatchAgainView(android.content.Context context)static intgenerateRandomInt()static byte[]generateSHA1(byte[] bytes)This function generates a SHA1 byte[] from another byte[].static java.lang.StringgenerateSHA1(java.lang.String exp)Generate SHA1 for string expressionstatic java.lang.StringgenerateUUIDTimeBased()Generate time-based UUIDstatic java.lang.StringgetFileExtension(java.lang.String url)static longgetMsFrom(java.lang.String durationInString)static longgetMsFromSeconds(long seconds)static java.util.Map<java.lang.String,java.lang.String>getQueryMap(java.lang.String query)static intgetScreenHeight(android.view.WindowManager windowManager)static intgetScreenWidth(android.view.WindowManager windowManager)static booleanhasScreenVisibilityChanged(int oldVisibility, int newVisibility)static booleanisBlank(java.lang.CharSequence cs)Checks if a CharSequence is whitespace, empty ("") or null.static booleanisExternalStorageAvailable()Check the state that device external storage is available.static booleanisMraidActionUrl(java.lang.String url)static booleanisNotBlank(java.lang.CharSequence cs)Checks if a CharSequence is not empty (""), not null and not whitespace only.static booleanisPermissionGranted(android.content.Context context, java.lang.String permission)Checks if the permission was grantedstatic booleanisScreenVisible(int visibility)static booleanisVast(java.lang.String data)static booleanisVideoContent(java.lang.String type)static java.lang.StringloadStringFromFile(android.content.res.Resources res, int file)Load JavaScript file from resources.static java.lang.Stringmd5(java.lang.String s)Md5.static BaseNetworkTask.GetUrlParamsparseUrl(java.lang.String url)static org.json.JSONArraysubJsonArray(org.json.JSONArray array, int start, int length)Get subsection of JSONArray, starting from 'start' and has length 'length'static <E,U>
org.json.JSONObjecttoJson(java.util.Map<E,? extends java.util.Collection<U>> map)
-
-
-
Method Detail
-
isMraidActionUrl
public static boolean isMraidActionUrl(java.lang.String url)
-
isVideoContent
public static boolean isVideoContent(java.lang.String type)
-
generateSHA1
public static byte[] generateSHA1(byte[] bytes)
This function generates a SHA1 byte[] from another byte[].- Parameters:
bytes-- Returns:
-
generateUUIDTimeBased
public static java.lang.String generateUUIDTimeBased()
Generate time-based UUID- Returns:
- RFC 4122 high-quality random number
-
generateSHA1
public static java.lang.String generateSHA1(java.lang.String exp)
Generate SHA1 for string expression- Parameters:
exp- is string expression- Returns:
- SHA1 code
-
byteArrayToHexString
public static java.lang.String byteArrayToHexString(byte[] byteArray)
This function encodes byte[] into a hex- Parameters:
byteArray-- Returns:
-
md5
public static java.lang.String md5(java.lang.String s)
Md5.- Parameters:
s- the string for which MD5 hash will be generated- Returns:
- the MD5 hash
-
loadStringFromFile
public static java.lang.String loadStringFromFile(android.content.res.Resources res, int file)Load JavaScript file from resources.- Parameters:
res- the resource pathfile- the resource file name- Returns:
- the JavaScript file content
-
atLeastKitKat
public static boolean atLeastKitKat()
Check that Android SDK version at least Kit Kat- Returns:
- true if at least Kit Kat
-
atLeastQ
public static boolean atLeastQ()
-
atLeastICS
public static boolean atLeastICS()
Check that Android SDK version at least Ice Cream Sandwich.- Returns:
- true if at least Ice Cream Sandwich
-
isExternalStorageAvailable
public static boolean isExternalStorageAvailable()
Check the state that device external storage is available.- Returns:
- true if available and writeable
-
isScreenVisible
public static boolean isScreenVisible(int visibility)
-
hasScreenVisibilityChanged
public static boolean hasScreenVisibilityChanged(int oldVisibility, int newVisibility)
-
isBlank
public static boolean isBlank(java.lang.CharSequence cs)
Checks if a CharSequence is whitespace, empty ("") or null.
StringUtils.isBlank(null) = true StringUtils.isBlank("") = true StringUtils.isBlank(" ") = true StringUtils.isBlank("bob") = false StringUtils.isBlank(" bob ") = false- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is null, empty or whitespace
-
isNotBlank
public static boolean isNotBlank(java.lang.CharSequence cs)
Checks if a CharSequence is not empty (""), not null and not whitespace only.
StringUtils.isNotBlank(null) = false StringUtils.isNotBlank("") = false StringUtils.isNotBlank(" ") = false StringUtils.isNotBlank("bob") = true StringUtils.isNotBlank(" bob ") = true- Parameters:
cs- the CharSequence to check, may be null- Returns:
trueif the CharSequence is not empty and not null and not whitespace
-
subJsonArray
public static org.json.JSONArray subJsonArray(org.json.JSONArray array, int start, int length)Get subsection of JSONArray, starting from 'start' and has length 'length'
-
parseUrl
public static BaseNetworkTask.GetUrlParams parseUrl(java.lang.String url)
-
getScreenWidth
public static int getScreenWidth(android.view.WindowManager windowManager)
-
getScreenHeight
public static int getScreenHeight(android.view.WindowManager windowManager)
-
getQueryMap
public static java.util.Map<java.lang.String,java.lang.String> getQueryMap(java.lang.String query)
-
createSkipView
public static android.view.View createSkipView(android.content.Context context, InterstitialDisplayPropertiesInternal properties)
-
createCloseView
public static android.view.View createCloseView(android.content.Context context)
-
createCloseView
public static android.view.View createCloseView(android.content.Context context, InterstitialDisplayPropertiesInternal properties)
-
createSoundView
public static android.view.View createSoundView(android.content.Context context)
-
convertPxToDp
public static int convertPxToDp(int px, android.content.Context context)
-
convertDpToPx
public static int convertDpToPx(int dp, android.content.Context context)
-
createWatchAgainView
public static android.view.View createWatchAgainView(android.content.Context context)
-
isPermissionGranted
public static boolean isPermissionGranted(android.content.Context context, java.lang.String permission)Checks if the permission was granted- Parameters:
context- - Activity contextpermission- - permission to check- Returns:
-
getMsFrom
public static long getMsFrom(java.lang.String durationInString)
- Parameters:
durationInString- String time in hh:mm:ss format- Returns:
- time converted to milliseconds, -1 if failed to convert
-
getMsFromSeconds
public static long getMsFromSeconds(long seconds)
- Parameters:
seconds-- Returns:
- milliseconds value
-
isVast
public static boolean isVast(java.lang.String data)
- Parameters:
data- which is used to createVASTwith the help ofAdResponseParserVast- Returns:
- true if
VASTcreation was successful, false otherwise
-
getFileExtension
public static java.lang.String getFileExtension(java.lang.String url)
-
clampAutoRefresh
public static int clampAutoRefresh(int refreshDelay)
-
clampInMillis
public static int clampInMillis(int value, int lowerBound, int upperBound)
-
generateRandomInt
public static int generateRandomInt()
-
toJson
public static <E,U> org.json.JSONObject toJson(java.util.Map<E,? extends java.util.Collection<U>> map)
-
addValue
public static <E,U> void addValue(java.util.Map<E,java.util.Set<U>> map, E key, U value)
-
addValue
public static void addValue(org.json.JSONObject target, java.lang.String key, java.lang.Object jsonObject)
-
-