Class POBUtils

  • All Implemented Interfaces:

    
    public class POBUtils
    
                        

    This is common utility class

    • Constructor Detail

      • POBUtils

        POBUtils()
    • Method Detail

      • isDebugBuild

         static boolean isDebugBuild(@NonNull() Context context)

        Method to check if the app is running in debug mode.

        Parameters:
        context - context to fetch ApplicationInfo
        Returns:

        true if app is running in debug mode else false

      • hasPermission

         static boolean hasPermission(@NonNull() Context appContext, @NonNull() String permission)

        Method is used to check app has user permission

        Parameters:
        appContext - android app context
        permission - string of app permission
        Returns:

        true if user provides the permission else return false

      • getRandomNumber

         static int getRandomNumber(int lowerBound, int upperBound)

        Returns the random number between lowerBound and upperBound

        Parameters:
        lowerBound - Minimum value for random number
        upperBound - Maximum value for random number
        Returns:

        random number between lowerBound and upperBound

      • openExternalBrowser

         static boolean openExternalBrowser(Context context, String url)

        Opens url in external app of browser

        Parameters:
        context - android app context
        url - which is going to be opened in external browser/application
        Returns:

        returns true if intent opens url else return false

      • isNullOrEmpty

         static boolean isNullOrEmpty(@Nullable() String str)

        Method to check String isNull or isEmpty

        Parameters:
        str - which is going to checked
        Returns:

        true if passed string is Null or Empty else return false

      • isNull

         static boolean isNull(@Nullable() Array<Object> obj)

        Method to check Object array is Null/Empty or one of the object inside the object array is null

        Parameters:
        obj - accepts array of object
        Returns:

        true if Object array is Null/Empty or one of the object inside the object array is null else false

      • getLocation

        @Nullable() static POBLocation getLocation(@Nullable() POBLocationDetector locationDetector)

        Method identifies isLocationDetectionEnabled if enabled then fetch last known location of the device if disabled then get location provided by the publisher

        Parameters:
        locationDetector - instance of POBLocationDetector
        Returns:

        value of POBLocation

      • getScreenWidth

         static int getScreenWidth()

        Method to get screen width in DP

        Returns:

        int value of screen width

      • convertPixelToDp

         static int convertPixelToDp(int value)

        Method is used to convert Pixel into DP

        Parameters:
        value - in Pixel
        Returns:

        int value in DP

      • getScreenHeight

         static int getScreenHeight()

        Method to get screen height in DP

        Returns:

        int value of screen height

      • getViewXYPosition

         static Array<int> getViewXYPosition(View view)

        Method is used get x, y position of View

        Parameters:
        view - on which operation to be performed
        Returns:

        array of int include 0=x, 1=y position which is in DP

      • convertDpToPixel

         static int convertDpToPixel(int value)

        Method is used to covert DP into pixel

        Parameters:
        value - of DP
        Returns:

        int pixel value for respective DP

      • convertDpToPixelWithFloatPrecession

         static float convertDpToPixelWithFloatPrecession(int value)

        Method is used to covert DP into pixel with float precession

        Parameters:
        value - of DP
        Returns:

        float pixel value for respective DP

      • getDeviceOrientation

         static int getDeviceOrientation(@NonNull() Context appContext)

        Returns the device current orientation

        Parameters:
        appContext - application context
        Returns:

        device current orientation

      • isTablet

         static boolean isTablet(Context context)

        Method to check whether the device is Phone or Tablet.

        Parameters:
        context - provide screenLayout and screenLayout size mask
        Returns:

        boolean value [true, if device is Tablet else is false]

      • getTimeOffsetInMinutes

         static int getTimeOffsetInMinutes()

        Returns local time as the number +/- of minutes from UTC.

        Returns:

        Local time in minutes

      • convertToSeconds

         static double convertToSeconds(@Nullable() String duration, @Nullable() String skipOffset)

        Calculates time in seconds whether skip offset is in time format or percentage

        Parameters:
        duration - should be in format HH:MM:SS.
        skipOffset - should be in format HH:MM:SS.
        Returns:

        offset time

      • getSeconds

         static double getSeconds(@Nullable() String time)

        Utility method to convert time string to seconds

        Parameters:
        time - time can be in format HH:MM:SS.
        Returns:

        seconds

      • getVisiblePercent

         static float getVisiblePercent(@Nullable() View view)

        To get visibility percent of view, if view is null it will always returns 0 as visibility percent

        Parameters:
        view - on which visibility percent is calculated
        Returns:

        visibility percent of view in float

      • isViewVisible

         static boolean isViewVisible(@Nullable() View view, int visibilityCriteriaInPixel)

        To get visibility of view. Returns true if visibility criteria in pixel is met.

        Parameters:
        view - on which visibility should be checked
        visibilityCriteriaInPixel - number of pixel needed to meet visibility criteria
        Returns:

        true if visibility criteria in pixel is met.

      • getViewVisiblePixel

         static int getViewVisiblePixel(@Nullable() View view)

        To get visible pixel of view. Returns count of visible pixel.

        Parameters:
        view - on which visibility should be checked
        Returns:

        0 if view is not visible.

      • runOnMainThread

         static void runOnMainThread(Runnable action)

        Runs the specified action on the Main/UI thread. If the current thread is the Main/UI thread, then the action is executed immediately. If the current thread is not the Main/UI thread, the action is posted to the event queue of the Main/UI thread.

        Parameters:
        action - the action to run on the Main/UI thread
      • isMainThread

         static boolean isMainThread()

        Method to check whether the current thread is Main thread or not.

        Returns:

        true if current thread is Main thread else false.

      • runOnBackgroundThread

         static void runOnBackgroundThread(Runnable action)

        Runs the specified action on the non main thread.

        Parameters:
        action - the action to run on the Main/UI thread
      • getValidRefreshInterval

         static int getValidRefreshInterval(int refreshInterval, int minRefreshInterval)

        Validates and returns time interval in seconds to refresh the banner ad. By default Banner Ad view does not auto-refresh, to enable auto refresh set refreshInterval to a non zero value. Expected value should be greater than minRefreshInterval seconds. Ad refresh behaviour when refreshInterval=X: - X<=0 :: Ad will not refresh - X >0 and X <= minRefreshInterval :: Ad will refresh after every minRefreshInterval seconds - X >minRefreshInterval :: Ad will refresh after every X seconds

        Parameters:
        refreshInterval - time interval in seconds
      • resolveWebViewContext

        @NonNull() static Context resolveWebViewContext(@NonNull() Context context)

        Used to get resolved context for WebView. Checks for api levels to avoid app crashes through appcompat library version 1.1.0 Crash only happens on Lollipop devices and android 6, 8,9 where devices does not have play services for more details refer Google-IssueTracker: 141132133

        Note: Must be used with WebView FIXME: Remove this method onces new appcompat library available with above mentioned fix.

        Parameters:
        context - the instance of context
        Returns:

        resolved/fixed context

      • logBidWinningStatus

         static void logBidWinningStatus(boolean hasWon, @Nullable() String partnerName)

        Log the statement based on the winning status

        Parameters:
        hasWon - Winning status
        partnerName - Name of the winning partner
      • isJsonObjectNullOrEmpty

         static boolean isJsonObjectNullOrEmpty(@Nullable() JSONObject jsonObject)

        Checks if the json object is null or not empty.

        Parameters:
        jsonObject - JSONObject
        Returns:

        true if the json object is null or empty else false

      • isJsonArrayNullOrEmpty

         static boolean isJsonArrayNullOrEmpty(@Nullable() JSONArray jsonArray)

        Checks if the json array is null or not empty.

        Parameters:
        jsonArray - JSONArray
        Returns:

        true if the json array is null or empty else false

      • parseJsTracker

        @NonNull() static String parseJsTracker(@NonNull() List<String> jsTrackers)

        Function takes List of script tags can convert it into a single string which can directly be embedded in head tag for execution

        Parameters:
        jsTrackers - List of script tags string or the url of .js files.
        Returns:

        String which can directly be embedded in head tag of html

      • isListNullOrEmpty

         static boolean isListNullOrEmpty(@Nullable() List<out Object> list)

        Function used to check whether the list is null or empty

        Parameters:
        list - List of any data type
        Returns:

        boolean true is list is empty or null else false

      • isValidPlayStoreUrl

         static boolean isValidPlayStoreUrl(@Nullable() String urlString)

        Method to check if url is valid play store url and contains bundle id

        Parameters:
        urlString - url string
        Returns:

        true if valid play store url else false

      • filterListOfStrings

        @NonNull() static List<String> filterListOfStrings(@Nullable() List<String> listOfStrings, @NonNull() String filter)

        Filters out the strings which contains the filter string in it.

        Parameters:
        listOfStrings - List of strings to be used to filtering.
        filter - Filter string used to filter out the string.
        Returns:

        List of strings which contains the filter string in it.

      • isStringValueNullOrEmpty

         static boolean isStringValueNullOrEmpty(@Nullable() String string)

        Function return true if the string passed is null or empty or is "null"

        Parameters:
        string - String to perform check on
        Returns:

        true for null, empty or "null" else false

      • getMappingKey

         static String getMappingKey(int profileId, @Nullable() Integer versionId)

        MappingKey is the key used to search the requested profile in the CacheManager. Formation of key :- Example :- profileInfoKey = "1165" (If version id is not specified) profileInfoKey = "1165:2" (If version id is specified) because multiple version of the same profile may exists

        Parameters:
        profileId - The profile ID of the user
        versionId - The version of the profile
        Returns:

        A combination of profile ID and version ID

      • startActivity

         static void startActivity(@NonNull() Context context, @NonNull() Intent intent)

        Used to start activity with intent. It will catch the exception if any and log the error.

        Parameters:
        context - Context
        intent - Intent with all the details and flags
      • decodeUrl

        @Nullable() static String decodeUrl(@NonNull() String encodedUrl)

        Decodes a URL encoded string using UTF-8 encoding.

        Parameters:
        encodedUrl - The URL encoded string to decode.
        Returns:

        The decoded URL string, or null if decoding fails.