public class SdkUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
protected static int[] |
THUMB_COLORS |
static long |
TOAST_MIN_REPEAT_DELAY |
| Constructor and Description |
|---|
SdkUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
Utility method to calculate the best sample size for downscaling Bitmap preserving aspect ratio.
|
static <T> T |
cloneSerializable(T source)
Helper method to clone a serializable object.
|
static void |
closeQuietly(java.io.Closeable... closeables)
Helper method to close one or more closeables while ignoring exceptions.
|
static java.lang.String |
concatStringWithDelimiter(java.lang.String[] strings,
java.lang.String delimiter)
Utility method to create a large String with the given delimiter.
|
static java.lang.String |
convertSerializableToString(java.io.Serializable obj)
Helper method to write a serializable object into a String.
|
static void |
copyStream(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
Utility method to write given inputStream to given outputStream.
|
static java.io.OutputStream |
createArrayOutputStream(java.io.OutputStream[] outputStreams)
Helper method that wraps given arrays inside of a single outputstream.
|
static java.util.concurrent.ThreadPoolExecutor |
createDefaultThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit)
Utility method to create a new StringMappedThreadPoolExecutor (which can be used to inspect runnables).
|
static android.graphics.Bitmap |
decodeSampledBitmapFromFile(java.io.File file,
int reqWidth,
int reqHeight)
Utility method to create a downsampled bitmap from a given image file preserving aspect ratio.
|
static android.graphics.Bitmap |
decodeSampledBitmapFromFile(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight)
Utility method to create a downsampled bitmap from a given image file preserving aspect ratio.
|
static boolean |
deleteFolderRecursive(java.io.File f)
Recursively delete a folder and all its subfolders and files.
|
static java.lang.String |
generateStateToken()
Per OAuth2 specs, auth code exchange should include a state token for CSRF validation
|
static java.lang.String |
getAssetFile(android.content.Context context,
java.lang.String assetName)
Helper method for reading an asset file into a string.
|
static java.lang.String |
getAsStringSafely(java.lang.Object object)
Helper method to return String form of an object that null checks.
|
static boolean |
isBlank(java.lang.String str)
Utility method to check if given string is blank.
|
static boolean |
isEmptyString(java.lang.String str)
Utility method to check if given string is empty.
|
static boolean |
isInternetAvailable(android.content.Context context)
Check for an internet connection.
|
static long |
parseJsonValueToInteger(com.eclipsesource.json.JsonValue value)
Parse a given JsonValue to an int regardless of whether that value is a String or an int.
|
static long |
parseJsonValueToLong(com.eclipsesource.json.JsonValue value)
Parse a given JsonValue to a long regardless of whether that value is a String or a long.
|
static void |
setColorsThumb(android.widget.TextView initialsView,
int position)
Sets the the background thumb color for the account view to one of the material colors
|
static void |
setInitialsThumb(android.content.Context context,
android.widget.TextView initialsView,
java.lang.String fullName)
Helper method used to display initials into a given textview.
|
static java.lang.String |
sha1(java.io.InputStream inputStream)
Utilitiy method to calculate sha1 based on given inputStream.
|
static void |
toastSafely(android.content.Context context,
int resId,
int duration)
Helper method for showing a toast message checking to see if user is on ui thread, and not showing the
same toast if it has already been shown within TOAST_MIN_REPEAT_DELAY time.
|
protected static final int[] THUMB_COLORS
public static long TOAST_MIN_REPEAT_DELAY
public static java.lang.String generateStateToken()
public static void copyStream(java.io.InputStream inputStream,
java.io.OutputStream outputStream)
throws java.io.IOException,
java.lang.InterruptedException
inputStream - the inputStream to copy from.outputStream - the outputStream to write to.java.io.IOException - thrown if there was a problem reading from inputStream or writing to outputStream.java.lang.InterruptedException - thrown if the thread is interrupted which indicates cancelling.public static java.io.OutputStream createArrayOutputStream(java.io.OutputStream[] outputStreams)
outputStreams - an array of multiple outputstreams.public static java.lang.String getAsStringSafely(java.lang.Object object)
object - an object to get string from.public static boolean isEmptyString(java.lang.String str)
str - string to check.public static boolean isBlank(java.lang.String str)
str - string to check.public static java.lang.String sha1(java.io.InputStream inputStream)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
inputStream - InputStream of file to calculate sha1 for.java.io.IOException - thrown if there was issue getting stream content.java.security.NoSuchAlgorithmException - thrown if Sha-1 algorithm implementation is not supported by OS.public static long parseJsonValueToLong(com.eclipsesource.json.JsonValue value)
value - a JsonValue to parse to a long.public static long parseJsonValueToInteger(com.eclipsesource.json.JsonValue value)
value - a JsonValue to parse to an int.public static java.lang.String concatStringWithDelimiter(java.lang.String[] strings,
java.lang.String delimiter)
strings - Strings to concatenate.delimiter - The delimiter to use to put between each string item.public static java.util.concurrent.ThreadPoolExecutor createDefaultThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,
java.util.concurrent.TimeUnit unit)
corePoolSize - the number of threads to keep in the pool, even if they are idle, unless allowCoreThreadTimeOut is setmaximumPoolSize - the maximum number of threads to allow in the poolkeepAliveTime - when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating.unit - the time unit for the keepAliveTime argumentpublic static <T> T cloneSerializable(T source)
T - The class of the serializable object.source - the serializable object to clone.public static java.lang.String convertSerializableToString(java.io.Serializable obj)
obj - the Serializable objectpublic static void closeQuietly(java.io.Closeable... closeables)
closeables - one or more closeables to close while swallowing exceptions.public static boolean deleteFolderRecursive(java.io.File f)
f - directory to be deleted.public static boolean isInternetAvailable(android.content.Context context)
context - current context.public static java.lang.String getAssetFile(android.content.Context context,
java.lang.String assetName)
context - current context.assetName - the asset namepublic static void toastSafely(android.content.Context context,
int resId,
int duration)
context - current context.resId - string resource id to display.duration - Toast.LENGTH_LONG or Toast.LENGTH_SHORT.public static void setInitialsThumb(android.content.Context context,
android.widget.TextView initialsView,
java.lang.String fullName)
context - current contextinitialsView - TextView used to set initials into.fullName - The user's full name to create initials for.public static void setColorsThumb(android.widget.TextView initialsView,
int position)
initialsView - view where the thumbs will be shownposition - index position of itempublic static android.graphics.Bitmap decodeSampledBitmapFromFile(android.content.res.Resources res,
int resId,
int reqWidth,
int reqHeight)
res - Resource to get asset from.resId - the id of the image asset.reqWidth - the required width for the bitmapreqHeight - the required height for the bitmap.public static android.graphics.Bitmap decodeSampledBitmapFromFile(java.io.File file,
int reqWidth,
int reqHeight)
file - image filereqWidth - the required width for the bitmapreqHeight - the required height for the bitmap.public static int calculateInSampleSize(android.graphics.BitmapFactory.Options options,
int reqWidth,
int reqHeight)
options - BitmapFactory options of a Bitmap used to check dimensions.reqWidth - the required width for displaying bitmap.reqHeight - the required height for displaying the bitmap.