public class

CommonUtils

extends Object
java.lang.Object
   ↳ chan.util.CommonUtils

Class Overview

Provides some utilities to work with JSON objects, bitmaps and logging.

Summary

Public Methods
static String getJsonString(JSONObject jsonObject, String name)

Returns the value mapped by name if exists, coercing it if necessary, or throws if no such mapping exists.

static String optJsonString(JSONObject jsonObject, String name)

Returns the value mapped by name if exists, coercing it if necessary, or null value if no such mapping exists.

static String optJsonString(JSONObject jsonObject, String name, String fallback)

Returns the value mapped by name if exists, coercing it if necessary, or fallback value if no such mapping exists.

static String restoreCloudFlareProtectedEmails(String string)

Restores emails from HTML string protected by CloudFlare.

static boolean sleepMaxTime(long startTime, long interval)

Wait time = interval - (current time - startTime).

static Bitmap trimBitmap(Bitmap bitmap, int backgroundColor)

Trims bitmap removing empty lines on the edges of image.

static void writeLog(Object... data)

Convenient method to write all objects to log file with client tag.

[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String getJsonString (JSONObject jsonObject, String name)

Returns the value mapped by name if exists, coercing it if necessary, or throws if no such mapping exists. This method may handle null values.

Parameters
jsonObject JSONObject: JSONObject from which the value will be taken.
name String: Field name.
Returns
String Value mapped by name.
Throws
JSONException If no such mapping exists.

public static String optJsonString (JSONObject jsonObject, String name)

Returns the value mapped by name if exists, coercing it if necessary, or null value if no such mapping exists. This method may handle null values.

Parameters
jsonObject JSONObject: JSONObject from which the value will be taken.
name String: Field name.
Returns
String Value mapped by name.

public static String optJsonString (JSONObject jsonObject, String name, String fallback)

Returns the value mapped by name if exists, coercing it if necessary, or fallback value if no such mapping exists. This method may handle null values.

Parameters
jsonObject JSONObject: JSONObject from which the value will be taken.
name String: Field name.
fallback String
Returns
String Value mapped by name.

public static String restoreCloudFlareProtectedEmails (String string)

Restores emails from HTML string protected by CloudFlare.

Parameters
string String: HTML string.
Returns
String HTML string with restored emails.

public static boolean sleepMaxTime (long startTime, long interval)

Wait time = interval - (current time - startTime). Returns whether thread was interrupted during sleep.

Parameters
startTime long: Time when operation was started.
interval long: Minimum time for operation.
Returns
boolean True if thread was interrupted.

public static Bitmap trimBitmap (Bitmap bitmap, int backgroundColor)

Trims bitmap removing empty lines on the edges of image. May return null bitmap. If bitmap wasn't trimmed, this method will return original bitmap.

Parameters
bitmap Bitmap: Bitmap to trim.
backgroundColor int: Background color.
Returns
Bitmap Trimmed bitmap.

public static void writeLog (Object... data)

Convenient method to write all objects to log file with client tag.

Parameters
data Object: Array of objects to write.