com.todoroo.andlib.utility
Class AndroidUtilities

java.lang.Object
  extended by com.todoroo.andlib.utility.AndroidUtilities

public class AndroidUtilities
extends java.lang.Object

Android Utility Classes

Author:
Tim Su

Nested Class Summary
static interface AndroidUtilities.SerializedPut<T>
           
 
Field Summary
static java.lang.String SEPARATOR_ESCAPE
           
static java.lang.String SERIALIZATION_SEPARATOR
           
 
Constructor Summary
AndroidUtilities()
           
 
Method Summary
static Property<?>[] addToArray(Property<?>[] list, Property<?>... newItems)
          Join items to a list
static android.os.Bundle bundleFromSerializedString(java.lang.String string)
          Turn Bundle into a string
static java.lang.String bundleToSerializedString(android.os.Bundle source)
          Serializes a Bundle into a string
static java.lang.Object callApiMethod(int minSdk, java.lang.Object receiver, java.lang.String methodName, java.lang.Class<?>[] params, java.lang.Object... args)
          Call a method via reflection if API level is at least minSdk
static java.lang.String capitalize(java.lang.String string)
          Capitalize the first character
static
<TYPE> TYPE[]
concat(TYPE[] dest, TYPE[] source, TYPE... additional)
          Concatenate additional stuff to the end of the array
static android.content.ContentValues contentValuesFromSerializedString(java.lang.String string)
          Turn ContentValues into a string
static android.content.ContentValues contentValuesFromString(java.lang.String string)
          Turn ContentValues into a string
static java.lang.String contentValuesToSerializedString(android.content.ContentValues source)
          Serializes a content value into a string
static java.lang.String[][] contentValuesToStringArrays(android.content.ContentValues source)
          Rips apart a content value into two string arrays, keys and value
static void copyDatabases(android.content.Context context, java.lang.String folder)
          Copy databases to a given folder.
static void copyFile(java.io.File in, java.io.File out)
          Copy a file from one place to another
static void copyStream(java.io.InputStream source, java.io.OutputStream dest)
          Copy stream from source to destination
static boolean equals(java.lang.Object a, java.lang.Object b)
          Returns true if a and b or null or a.equals(b)
static android.graphics.Bitmap fetchImage(java.net.URL url)
          Fetch the image specified by the given url
static
<KEY,VALUE>
KEY
findKeyInMap(java.util.Map<KEY,VALUE> map, VALUE value)
          Search for the given value in the map, returning key if found
static
<TYPE> TYPE
findViewByType(android.view.View view, java.lang.Class<TYPE> type)
          Find a child view of a certain type
static int getSdkVersion()
           
static java.lang.String getSignature(android.content.Context context, java.lang.String packageName)
          Gets application signature
static
<TYPE> int
indexOf(TYPE[] array, TYPE value)
          Return index of value in array
static boolean isConnected(android.content.Context context)
           
static java.lang.String md5(java.lang.String input)
          Performs an md5 hash on the input string
static void putInto(android.content.ContentValues target, java.lang.String key, java.lang.Object value)
          Put an arbitrary object into a ContentValues
static java.lang.CharSequence readFile(android.content.Context activity, int id)
          From Android MyTracks project (http://mytracks.googlecode.com/).
static android.content.Intent remoteIntent(java.lang.String appPackage, java.lang.String activityClass)
          Create an intent to a remote activity
static void sleepDeep(long l)
          Sleep, ignoring interruption.
static void sortFilesByDateDesc(java.io.File[] files)
          Sort files by date so the newest file is on top
static void startExternalIntent(android.content.Context context, android.content.Intent intent, int request)
          Start the given intent, handling security exceptions if they arise
static void startExternalIntentForResult(android.app.Activity activity, android.content.Intent intent, int requestCode)
          Start the given intent, handling security exceptions if they arise
static void suppressVirtualKeyboard(android.widget.TextView editor)
          Suppress virtual keyboard until user's first tap
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR_ESCAPE

public static final java.lang.String SEPARATOR_ESCAPE
See Also:
Constant Field Values

SERIALIZATION_SEPARATOR

public static final java.lang.String SERIALIZATION_SEPARATOR
See Also:
Constant Field Values
Constructor Detail

AndroidUtilities

public AndroidUtilities()
Method Detail

suppressVirtualKeyboard

public static void suppressVirtualKeyboard(android.widget.TextView editor)
Suppress virtual keyboard until user's first tap


isConnected

public static boolean isConnected(android.content.Context context)
Returns:
true if we're connected to the internet

fetchImage

public static android.graphics.Bitmap fetchImage(java.net.URL url)
                                          throws java.io.IOException
Fetch the image specified by the given url

Throws:
java.io.IOException

startExternalIntent

public static void startExternalIntent(android.content.Context context,
                                       android.content.Intent intent,
                                       int request)
Start the given intent, handling security exceptions if they arise

Parameters:
context -
intent -
request - request code. if negative, no request.

startExternalIntentForResult

public static void startExternalIntentForResult(android.app.Activity activity,
                                                android.content.Intent intent,
                                                int requestCode)
Start the given intent, handling security exceptions if they arise

Parameters:
activity -
intent -
requestCode -

putInto

public static void putInto(android.content.ContentValues target,
                           java.lang.String key,
                           java.lang.Object value)
Put an arbitrary object into a ContentValues

Parameters:
target -
key -
value -

contentValuesToStringArrays

public static java.lang.String[][] contentValuesToStringArrays(android.content.ContentValues source)
Rips apart a content value into two string arrays, keys and value


indexOf

public static <TYPE> int indexOf(TYPE[] array,
                                 TYPE value)
Return index of value in array

Parameters:
array - array to search
value - value to look for
Returns:

contentValuesToSerializedString

public static java.lang.String contentValuesToSerializedString(android.content.ContentValues source)
Serializes a content value into a string


bundleToSerializedString

public static java.lang.String bundleToSerializedString(android.os.Bundle source)
Serializes a Bundle into a string


contentValuesFromSerializedString

public static android.content.ContentValues contentValuesFromSerializedString(java.lang.String string)
Turn ContentValues into a string

Parameters:
string -
Returns:

bundleFromSerializedString

public static android.os.Bundle bundleFromSerializedString(java.lang.String string)
Turn Bundle into a string

Parameters:
string -
Returns:

contentValuesFromString

public static android.content.ContentValues contentValuesFromString(java.lang.String string)
Turn ContentValues into a string

Parameters:
string -
Returns:

equals

public static boolean equals(java.lang.Object a,
                             java.lang.Object b)
Returns true if a and b or null or a.equals(b)

Parameters:
a -
b -
Returns:

copyFile

public static void copyFile(java.io.File in,
                            java.io.File out)
                     throws java.lang.Exception
Copy a file from one place to another

Parameters:
in -
out -
Throws:
java.lang.Exception

copyStream

public static void copyStream(java.io.InputStream source,
                              java.io.OutputStream dest)
                       throws java.io.IOException
Copy stream from source to destination

Parameters:
source -
dest -
Throws:
java.io.IOException

findViewByType

public static <TYPE> TYPE findViewByType(android.view.View view,
                                         java.lang.Class<TYPE> type)
Find a child view of a certain type

Parameters:
view -
type -
Returns:
first view (by DFS) if found, or null if none

getSdkVersion

public static int getSdkVersion()
Returns:
Android SDK version as an integer. Works on all versions

copyDatabases

public static void copyDatabases(android.content.Context context,
                                 java.lang.String folder)
Copy databases to a given folder. Useful for debugging

Parameters:
folder -

sortFilesByDateDesc

public static void sortFilesByDateDesc(java.io.File[] files)
Sort files by date so the newest file is on top

Parameters:
files -

findKeyInMap

public static <KEY,VALUE> KEY findKeyInMap(java.util.Map<KEY,VALUE> map,
                                           VALUE value)
Search for the given value in the map, returning key if found

Parameters:
map -
value -
Returns:
null if not found, otherwise key

sleepDeep

public static void sleepDeep(long l)
Sleep, ignoring interruption. Before using this method, think carefully about why you are ignoring interruptions.

Parameters:
l -

callApiMethod

public static java.lang.Object callApiMethod(int minSdk,
                                             java.lang.Object receiver,
                                             java.lang.String methodName,
                                             java.lang.Class<?>[] params,
                                             java.lang.Object... args)
Call a method via reflection if API level is at least minSdk

Parameters:
minSdk - minimum sdk number (i.e. 8)
receiver - object to call method on
methodName - method name to call
params - method parameter types
args - arguments
Returns:
method return value, or null if nothing was called or exception

readFile

public static java.lang.CharSequence readFile(android.content.Context activity,
                                              int id)
From Android MyTracks project (http://mytracks.googlecode.com/). Licensed under the Apache Public License v2

Parameters:
activity -
id -
Returns:

md5

public static java.lang.String md5(java.lang.String input)
Performs an md5 hash on the input string

Parameters:
input -
Returns:

remoteIntent

public static android.content.Intent remoteIntent(java.lang.String appPackage,
                                                  java.lang.String activityClass)
Create an intent to a remote activity

Parameters:
appPackage -
activityClass -
Returns:

getSignature

public static java.lang.String getSignature(android.content.Context context,
                                            java.lang.String packageName)
Gets application signature

Returns:
application signature, or null if an error was encountered

addToArray

public static Property<?>[] addToArray(Property<?>[] list,
                                       Property<?>... newItems)
Join items to a list

Type Parameters:
TYPE -
Parameters:
list -
newList -
newItems -
Returns:

concat

public static <TYPE> TYPE[] concat(TYPE[] dest,
                                   TYPE[] source,
                                   TYPE... additional)
Concatenate additional stuff to the end of the array

Parameters:
params -
additional -
Returns:

capitalize

public static java.lang.String capitalize(java.lang.String string)
Capitalize the first character

Parameters:
string -
Returns: