com.google.android.apps.dashclock.api
Class ExtensionData

java.lang.Object
  extended by com.google.android.apps.dashclock.api.ExtensionData
All Implemented Interfaces:
Parcelable

public class ExtensionData
extends Object
implements Parcelable

A parcelable, serializable object representing data related to a DashClockExtension that should be shown to the user.

This class follows the fluent interface style, using method chaining to provide for more readable code. For example, to set the status and visibility of this data, use status(String) and visible(boolean) methods like so:

 ExtensionData data = new ExtensionData();
 data.visible(true).status("hello");
Conversely, to get the status, use status(). Setters and getters are thus overloads (or overlords?) of the same method.

Required fields

While no fields are required, if the data is 'visible' (i.e. visible(boolean) has been called with true, at least the following fields should be populated: Really awesome extensions will also set these fields:

See Also:
DashClockExtension.publishUpdate(ExtensionData)

Nested Class Summary
 
Nested classes/interfaces inherited from interface android.os.Parcelable
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
 
Field Summary
static Parcelable.Creator<ExtensionData> CREATOR
           
static int MAX_CONTENT_DESCRIPTION_LENGTH
          The maximum length for contentDescription(String).
static int MAX_EXPANDED_BODY_LENGTH
          The maximum length for expandedBody(String).
static int MAX_EXPANDED_TITLE_LENGTH
          The maximum length for expandedTitle(String).
static int MAX_STATUS_LENGTH
          The maximum length for status(String).
static int PARCELABLE_VERSION
          Since there might be a case where new versions of DashClock use extensions running old versions of the protocol (and thus old versions of this class), we need a versioning system for the parcels sent between the core app and its extensions.
 
Fields inherited from interface android.os.Parcelable
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
 
Constructor Summary
ExtensionData()
           
 
Method Summary
 void clean()
          Cleans up this object's data according to the size limits described by MAX_STATUS_LENGTH, MAX_EXPANDED_TITLE_LENGTH, etc.
 Intent clickIntent()
          Returns the click intent to start (using Context.startActivity(android.content.Intent)) when the user clicks the status in DashClock.
 ExtensionData clickIntent(Intent clickIntent)
          Sets the click intent to start (using Context.startActivity(android.content.Intent)) when the user clicks the status in DashClock.
 String contentDescription()
          Returns the content description for this data, used for accessibility purposes.
 ExtensionData contentDescription(String contentDescription)
          Sets the content description for this data.
 int describeContents()
           
 void deserialize(JSONObject data)
          Deserializes the given JSON representation of extension data, populating this object.
static boolean equals(ExtensionData x, ExtensionData y)
          Returns true if the two provided data objects are equal (or both null).
 boolean equals(Object o)
           
 String expandedBody()
          Returns the expanded body text representing this data.
 ExtensionData expandedBody(String expandedBody)
          Sets the expanded body text (below the expanded title), representing this data.
 String expandedTitle()
          Returns the expanded title representing this data.
 ExtensionData expandedTitle(String expandedTitle)
          Sets the expanded title representing this data.
 void fromBundle(Bundle src)
          Deserializes the given Bundle representation of extension data, populating this object.
 int hashCode()
           
 int icon()
          Returns the ID of the drawable resource within the extension's package that represents this data.
 ExtensionData icon(int icon)
          Sets the ID of the drawable resource within the extension's package that represents this data.
 Uri iconUri()
          Returns the content:// URI of a bitmap representing this data.
 ExtensionData iconUri(Uri iconUri)
          Sets the content:// URI of the bitmap representing this data.
 JSONObject serialize()
          Serializes the contents of this object to JSON.
 String status()
          Returns the short string representing this data, to be shown in DashClock's collapsed form.
 ExtensionData status(String status)
          Sets the short string representing this data, to be shown in DashClock's collapsed form.
 Bundle toBundle()
          Serializes the contents of this object to a Bundle.
 boolean visible()
          Returns whether or not the relevant extension should be visible (whether or not there is relevant information to show to the user about the extension).
 ExtensionData visible(boolean visible)
          Sets whether or not the relevant extension should be visible (whether or not there is relevant information to show to the user about the extension).
 void writeToParcel(Parcel parcel, int i)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CREATOR

public static final Parcelable.Creator<ExtensionData> CREATOR
See Also:
Parcelable

MAX_CONTENT_DESCRIPTION_LENGTH

public static final int MAX_CONTENT_DESCRIPTION_LENGTH
The maximum length for contentDescription(String). Enforced by clean().

See Also:
Constant Field Values

MAX_EXPANDED_BODY_LENGTH

public static final int MAX_EXPANDED_BODY_LENGTH
The maximum length for expandedBody(String). Enforced by clean().

See Also:
Constant Field Values

MAX_EXPANDED_TITLE_LENGTH

public static final int MAX_EXPANDED_TITLE_LENGTH
The maximum length for expandedTitle(String). Enforced by clean().

See Also:
Constant Field Values

MAX_STATUS_LENGTH

public static final int MAX_STATUS_LENGTH
The maximum length for status(String). Enforced by clean().

See Also:
Constant Field Values

PARCELABLE_VERSION

public static final int PARCELABLE_VERSION
Since there might be a case where new versions of DashClock use extensions running old versions of the protocol (and thus old versions of this class), we need a versioning system for the parcels sent between the core app and its extensions.

See Also:
Constant Field Values
Constructor Detail

ExtensionData

public ExtensionData()
Method Detail

clean

public void clean()
Cleans up this object's data according to the size limits described by MAX_STATUS_LENGTH, MAX_EXPANDED_TITLE_LENGTH, etc.


clickIntent

public Intent clickIntent()
Returns the click intent to start (using Context.startActivity(android.content.Intent)) when the user clicks the status in DashClock. Default null.


clickIntent

public ExtensionData clickIntent(Intent clickIntent)
Sets the click intent to start (using Context.startActivity(android.content.Intent)) when the user clicks the status in DashClock. The activity represented by this intent will be started in a new task and should be exported. Default null.


contentDescription

public String contentDescription()
Returns the content description for this data, used for accessibility purposes.

Since:
Protocol Version 2 (API r2.x)

contentDescription

public ExtensionData contentDescription(String contentDescription)
Sets the content description for this data. This content description will replace the status(), expandedTitle() and expandedBody() for accessibility purposes.

Since:
Protocol Version 2 (API v2.x)
See Also:
View

describeContents

public int describeContents()
Specified by:
describeContents in interface Parcelable

deserialize

public void deserialize(JSONObject data)
                 throws JSONException
Deserializes the given JSON representation of extension data, populating this object.

Throws:
JSONException

equals

public static boolean equals(ExtensionData x,
                             ExtensionData y)
Returns true if the two provided data objects are equal (or both null).


equals

public boolean equals(Object o)
Overrides:
equals in class Object

expandedBody

public String expandedBody()
Returns the expanded body text representing this data. Default null.


expandedBody

public ExtensionData expandedBody(String expandedBody)
Sets the expanded body text (below the expanded title), representing this data. Can span multiple lines, although DashClock will cap the number of lines shown. Default null.


expandedTitle

public String expandedTitle()
Returns the expanded title representing this data. Generally a longer form of status(). Default null.


expandedTitle

public ExtensionData expandedTitle(String expandedTitle)
Sets the expanded title representing this data. Generally a longer form of status(). Can be multiple lines, although DashClock will cap the number of lines shown. If this is not set, DashClock will just use the status(). Default null.


fromBundle

public void fromBundle(Bundle src)
Deserializes the given Bundle representation of extension data, populating this object.


hashCode

public int hashCode()
Overrides:
hashCode in class Object

icon

public int icon()
Returns the ID of the drawable resource within the extension's package that represents this data. Default 0.


icon

public ExtensionData icon(int icon)
Sets the ID of the drawable resource within the extension's package that represents this data. The icon should be entirely white, with alpha, and about 48x48 dp. It will be scaled down as needed. If there is no contextual icon representation of the data, simply use the extension or app icon. If an iconUri is provided, it will take precedence over this value. Default 0.

See Also:
iconUri(Uri)

iconUri

public Uri iconUri()
Returns the content:// URI of a bitmap representing this data. Default null.

Since:
Protocol Version 2 (API r2.x)

iconUri

public ExtensionData iconUri(Uri iconUri)
Sets the content:// URI of the bitmap representing this data. This takes precedence over the regular icon resource ID if set. This resource will be loaded using ContentResolver.openFileDescriptor(android.net.Uri, String) and BitmapFactory. See the icon method for guidelines on the styling of this bitmap.

Since:
Protocol Version 2 (API r2.x)

serialize

public JSONObject serialize()
                     throws JSONException
Serializes the contents of this object to JSON.

Throws:
JSONException

status

public String status()
Returns the short string representing this data, to be shown in DashClock's collapsed form. Default null.


status

public ExtensionData status(String status)
Sets the short string representing this data, to be shown in DashClock's collapsed form. Should be no longer than a few characters. For example, if your expandedTitle() is "45°, Sunny", your status could simply be "45°". Alternatively, if the status contains a single newline, DashClock may break it up over two lines and use a smaller font. This should be avoided where possible in favor of an expandedTitle(String). Default null.


toBundle

public Bundle toBundle()
Serializes the contents of this object to a Bundle.


visible

public boolean visible()
Returns whether or not the relevant extension should be visible (whether or not there is relevant information to show to the user about the extension). Default false.


visible

public ExtensionData visible(boolean visible)
Sets whether or not the relevant extension should be visible (whether or not there is relevant information to show to the user about the extension). Default false.


writeToParcel

public void writeToParcel(Parcel parcel,
                          int i)
Specified by:
writeToParcel in interface Parcelable