Class POBUtils
-
- All Implemented Interfaces:
public class POBUtilsThis is common utility class
-
-
Constructor Summary
Constructors Constructor Description POBUtils()
-
Method Summary
Modifier and Type Method Description static booleanisDebugBuild(@NonNull() Context context)Method to check if the app is running in debug mode. static booleanhasPermission(@NonNull() Context appContext, @NonNull() String permission)Method is used to check app has user permission static intgetRandomNumber(int lowerBound, int upperBound)Returns the random number between lowerBound and upperBound static booleanopenExternalBrowser(Context context, String url)Opens url in external app of browser static booleanisNullOrEmpty(@Nullable() String str)Method to check String isNull or isEmpty static booleanisNull(@Nullable() Array<Object> obj)Method to check Object array is Null/Empty or one of the object inside the object array is null static POBLocationgetLocation(@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 static intgetScreenWidth()Method to get screen width in DP static intconvertPixelToDp(int value)Method is used to convert Pixel into DP static intgetScreenHeight()Method to get screen height in DP static Array<int>getViewXYPosition(View view)Method is used get x, y position of View static intconvertDpToPixel(int value)Method is used to covert DP into pixel static floatconvertDpToPixelWithFloatPrecession(int value)Method is used to covert DP into pixel with float precession static POBAdSizegetInterstitialAdSize(@NonNull() Context context)static intgetDeviceOrientation(@NonNull() Context appContext)Returns the device current orientation static booleanisTablet(Context context)Method to check whether the device is Phone or Tablet. static StringreadFromAssets(@NonNull() Context context, @NonNull() String file)Utility method to read file from assets static intgetTimeOffsetInMinutes()Returns local time as the number +/- of minutes from UTC. static doubleconvertToSeconds(@Nullable() String duration, @Nullable() String skipOffset)Calculates time in seconds whether skip offset is in time format or percentage static doublegetSeconds(@Nullable() String time)Utility method to convert time string to seconds static intgetIntegerValue(@Nullable() String data)static booleangetBooleanValue(@Nullable() String data)static floatgetVisiblePercent(@Nullable() View view)To get visibility percent of view, if view is null it will always returns 0 as visibility percent static booleanisViewVisible(@Nullable() View view, int visibilityCriteriaInPixel)To get visibility of view. static intgetViewVisiblePixel(@Nullable() View view)To get visible pixel of view. static voidrunOnMainThread(Runnable action)Runs the specified action on the Main/UI thread. static booleanisMainThread()Method to check whether the current thread is Main thread or not. static voidrunOnBackgroundThread(Runnable action)Runs the specified action on the non main thread. static intgetValidRefreshInterval(int refreshInterval, int minRefreshInterval)Validates and returns time interval in seconds to refresh the banner ad. static ContextresolveWebViewContext(@NonNull() Context context)Used to get resolved context for WebView. static voidlogBidWinningStatus(boolean hasWon, @Nullable() String partnerName)Log the statement based on the winning status static StringbuildUrlWithQueryParam(@NonNull() String serverUrl, @NonNull() String key, @NonNull() String value)Util method to add query param to a url static StringbuildUriWithQueryParams(@NonNull() Uri uri, @NonNull() Map<String, String> queryParams)Util method to build a url with given map of query params static booleanisJsonObjectNullOrEmpty(@Nullable() JSONObject jsonObject)Checks if the json object is null or not empty. static booleanisJsonArrayNullOrEmpty(@Nullable() JSONArray jsonArray)Checks if the json array is null or not empty. static List<String>convertStringJsonArrayToList(@Nullable() JSONArray jsonArray)Converts the JSONArray to List static StringparseJsTracker(@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 static booleanisListNullOrEmpty(@Nullable() List<out Object> list)Function used to check whether the list is null or empty static booleanisValidPlayStoreUrl(@Nullable() String urlString)Method to check if url is valid play store url and contains bundle id static List<String>filterListOfStrings(@Nullable() List<String> listOfStrings, @NonNull() String filter)Filters out the strings which contains the filter string in it. static Set<String>parseJsonArrayToSet(@Nullable() JSONArray jsonArray)Parse the json array to static booleanisStringValueNullOrEmpty(@Nullable() String string)Function return true if the string passed is null or empty or is "null" static StringgetMappingKey(int profileId, @Nullable() Integer versionId)MappingKey is the key used to search the requested profile in the CacheManager. static voidstartActivity(@NonNull() Context context, @NonNull() Intent intent)Used to start activity with intent. static StringdecodeUrl(@NonNull() String encodedUrl)Decodes a URL encoded string using UTF-8 encoding. -
-
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 contextpermission- 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 numberupperBound- 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 contexturl- 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
-
getInterstitialAdSize
static POBAdSize getInterstitialAdSize(@NonNull() Context context)
-
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]
-
readFromAssets
@Nullable()@WorkerThread() static String readFromAssets(@NonNull() Context context, @NonNull() String file)
Utility method to read file from assets
- Parameters:
context- instance of Contextfile- name of file- Returns:
String content of file
-
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
-
getIntegerValue
static int getIntegerValue(@Nullable() String data)
-
getBooleanValue
static boolean getBooleanValue(@Nullable() String data)
-
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 checkedvisibilityCriteriaInPixel- 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 statuspartnerName- Name of the winning partner
-
buildUrlWithQueryParam
@NonNull() static String buildUrlWithQueryParam(@NonNull() String serverUrl, @NonNull() String key, @NonNull() String value)
Util method to add query param to a url
- Parameters:
serverUrl- url in which the param needs to be addedkey- key of query paramvalue- value of query param- Returns:
returns url with added query param
-
buildUriWithQueryParams
@NonNull() static String buildUriWithQueryParams(@NonNull() Uri uri, @NonNull() Map<String, String> queryParams)
Util method to build a url with given map of query params
- Parameters:
uri- url stringqueryParams- map of query params- Returns:
generated url string with query params
-
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
-
convertStringJsonArrayToList
@Nullable() static List<String> convertStringJsonArrayToList(@Nullable() JSONArray jsonArray)
Converts the JSONArray to List
- Parameters:
jsonArray- JSONArray- Returns:
List of
-
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.
-
parseJsonArrayToSet
@NonNull() static Set<String> parseJsonArrayToSet(@Nullable() JSONArray jsonArray)
- Parameters:
jsonArray- the json array of String- Returns:
the parsed country set of type <
-
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 userversionId- 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- Contextintent- Intent with all the details and flags
-
-
-
-