Class Utils


  • public final class Utils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static float DENSITY  
    • Constructor Summary

      Constructors 
      Constructor Description
      Utils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E,​U>
      void
      addValue​(java.util.Map<E,​java.util.Set<U>> map, E key, U value)  
      static void addValue​(org.json.JSONObject target, java.lang.String key, java.lang.Object jsonObject)  
      static boolean atLeastICS()
      Check that Android SDK version at least Ice Cream Sandwich.
      static boolean atLeastKitKat()
      Check that Android SDK version at least Kit Kat
      static boolean atLeastQ()  
      static java.lang.String byteArrayToHexString​(byte[] byteArray)
      This function encodes byte[] into a hex
      static int clampAutoRefresh​(int refreshDelay)  
      static int clampInMillis​(int value, int lowerBound, int upperBound)  
      static int convertDpToPx​(int dp, android.content.Context context)  
      static int convertPxToDp​(int px, android.content.Context context)  
      static android.view.View createCloseView​(android.content.Context context)  
      static android.view.View createCloseView​(android.content.Context context, InterstitialDisplayPropertiesInternal properties)  
      static android.view.View createSkipView​(android.content.Context context, InterstitialDisplayPropertiesInternal properties)  
      static android.view.View createSoundView​(android.content.Context context)  
      static android.view.View createWatchAgainView​(android.content.Context context)  
      static int generateRandomInt()  
      static byte[] generateSHA1​(byte[] bytes)
      This function generates a SHA1 byte[] from another byte[].
      static java.lang.String generateSHA1​(java.lang.String exp)
      Generate SHA1 for string expression
      static java.lang.String generateUUIDTimeBased()
      Generate time-based UUID
      static java.lang.String getFileExtension​(java.lang.String url)  
      static long getMsFrom​(java.lang.String durationInString)  
      static long getMsFromSeconds​(long seconds)  
      static java.util.Map<java.lang.String,​java.lang.String> getQueryMap​(java.lang.String query)  
      static int getScreenHeight​(android.view.WindowManager windowManager)  
      static int getScreenWidth​(android.view.WindowManager windowManager)  
      static boolean hasScreenVisibilityChanged​(int oldVisibility, int newVisibility)  
      static boolean isBlank​(java.lang.CharSequence cs)
      Checks if a CharSequence is whitespace, empty ("") or null.
      static boolean isExternalStorageAvailable()
      Check the state that device external storage is available.
      static boolean isMraidActionUrl​(java.lang.String url)  
      static boolean isNotBlank​(java.lang.CharSequence cs)
      Checks if a CharSequence is not empty (""), not null and not whitespace only.
      static boolean isPermissionGranted​(android.content.Context context, java.lang.String permission)
      Checks if the permission was granted
      static boolean isScreenVisible​(int visibility)  
      static boolean isVast​(java.lang.String data)  
      static boolean isVideoContent​(java.lang.String type)  
      static java.lang.String loadStringFromFile​(android.content.res.Resources res, int file)
      Load JavaScript file from resources.
      static java.lang.String md5​(java.lang.String s)
      Md5.
      static BaseNetworkTask.GetUrlParams parseUrl​(java.lang.String url)  
      static org.json.JSONArray subJsonArray​(org.json.JSONArray array, int start, int length)
      Get subsection of JSONArray, starting from 'start' and has length 'length'
      static <E,​U>
      org.json.JSONObject
      toJson​(java.util.Map<E,​? extends java.util.Collection<U>> map)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DENSITY

        public static float DENSITY
    • Constructor Detail

      • Utils

        public Utils()
    • 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 path
        file - 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:
        true if 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:
        true if 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'
      • 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)
      • createCloseView

        public static android.view.View createCloseView​(android.content.Context context)
      • 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 context
        permission - - 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 create VAST with the help of AdResponseParserVast
        Returns:
        true if VAST creation 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)