java.lang.Objectandroid.content.Context
android.content.ContextWrapper
android.app.Service
com.google.android.apps.dashclock.api.DashClockExtension
public abstract class DashClockExtension
Base class for a DashClock extension. Extensions are a way for other apps to show additional
status information within DashClock widgets that the user may add to the lockscreen or home
screen. A limited amount of status information is supported. See the ExtensionData class
for the types of information that can be displayed.
DashClockExtensiononUpdateData(int) method, which will be called
when DashClock requests updated data to show for this extension. Once the extension has new
data to show, call publishUpdate(ExtensionData) to pass the data to the main DashClock
process. onUpdateData(int) will by default be called roughly once per hour, but
extensions can use methods such as setUpdateWhenScreenOn(boolean) and
addWatchContentUris(String[]) to request more frequent updates.
Subclasses can also override the onInitialize(boolean) method to perform basic
initialization each time a connection to DashClock is established or re-established.
DashClockExtension class should thus be declared as <service>
components in the application's AndroidManifest.xml file.
The main DashClock app discovers available extensions using Android's Intent mechanism.
Ensure that your service definition includes an <intent-filter>
with an action of ACTION_EXTENSION. Also make sure to require the
PERMISSION_READ_EXTENSION_DATA permission so that only DashClock can bind to your
service and request updates. Lastly, there are a few <meta-data> elements that
you should add to your service definition:
protocolVersion (required): should be 1.description (required): should be a one- or two-sentence description
of the extension, as a string.settingsActivity (optional): if present, should be the qualified
component name for a configuration activity in the extension's package that DashClock can offer
to the user for customizing the extension.worldReadable (optional): if present and true (default is false), will allow
other apps besides DashClock to read data for this extension.
<service android:name=".ExampleExtension"
android:icon="@drawable/ic_extension_example"
android:label="@string/extension_title"
android:permission="com.google.android.apps.dashclock.permission.READ_EXTENSION_DATA">
<intent-filter>
<action android:name="com.google.android.apps.dashclock.Extension" />
</intent-filter>
<meta-data android:name="protocolVersion" android:value="2" />
<meta-data android:name="worldReadable" android:value="true" />
<meta-data android:name="description"
android:value="@string/extension_description" />
<!-- A settings activity is optional -->
<meta-data android:name="settingsActivity"
android:value=".ExampleSettingsActivity" />
</service>
If a settingsActivity meta-data element is present, an activity with the given
component name should be defined and exported in the application's manifest as well. DashClock
will set the EXTRA_FROM_DASHCLOCK_SETTINGS extra to true in the launch intent for this
activity. An example is shown below:
<activity android:name=".ExampleSettingsActivity"
android:label="@string/title_settings"
android:exported="true" />
Finally, below is a simple example DashClockExtension subclass that shows static data in
DashClock:
public class ExampleExtension extends DashClockExtension {
protected void onUpdateData(int reason) {
publishUpdate(new ExtensionData()
.visible(true)
.icon(R.drawable.ic_extension_example)
.status("Hello")
.expandedTitle("Hello, world!")
.expandedBody("This is an example.")
.clickIntent(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.google.com"))));
}
}
| Field Summary | |
|---|---|
static String |
ACTION_EXTENSION
The Intent action representing a DashClock extension. |
static String |
EXTRA_FROM_DASHCLOCK_SETTINGS
Boolean extra that will be set to true when DashClock starts extension settings activities. |
static String |
PERMISSION_READ_EXTENSION_DATA
The permission that DashClock extensions should require callers to have before providing any status updates. |
static int |
UPDATE_REASON_CONTENT_CHANGED
Indicates that onUpdateData(int) was triggered because content changed on a content
URI previously registered with addWatchContentUris(String[]). |
static int |
UPDATE_REASON_INITIAL
Indicates that this is the first call to onUpdateData(int) since the connection to
the main DashClock app was established. |
static int |
UPDATE_REASON_MANUAL
Indicates that onUpdateData(int) was triggered because the user explicitly requested
that the extension be updated. |
static int |
UPDATE_REASON_PERIODIC
Indicates that onUpdateData(int) was triggered due to a normal perioidic refresh
of extension data. |
static int |
UPDATE_REASON_SCREEN_ON
Indicates that onUpdateData(int) was triggered because the device screen turned on
and the extension has called
setUpdateWhenScreenOn(true). |
static int |
UPDATE_REASON_SETTINGS_CHANGED
Indicates that onUpdateData(int) was triggered because settings for this extension
may have changed. |
static int |
UPDATE_REASON_UNKNOWN
Indicates that onUpdateData(int) was triggered for an unknown reason. |
| Fields inherited from class android.app.Service |
|---|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY |
| Fields inherited from interface android.content.ComponentCallbacks2 |
|---|
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN |
| Constructor Summary | |
|---|---|
protected |
DashClockExtension()
|
| Method Summary | |
|---|---|
protected void |
addWatchContentUris(String[] uris)
Requests that the main DashClock app watch the given content URIs (using ContentResolver.registerContentObserver)
and call this extension's onUpdateData(int) method when changes are observed. |
IBinder |
onBind(Intent intent)
|
void |
onCreate()
|
void |
onDestroy()
|
protected void |
onInitialize(boolean isReconnect)
Called when a connection with the main DashClock app has been established or re-established after a previous one was lost. |
protected abstract void |
onUpdateData(int reason)
Called when the DashClock app process is requesting that the extension provide updated information to show to the user. |
protected void |
publishUpdate(ExtensionData data)
Notifies the main DashClock app that new data is available for the extension and should potentially be shown to the user. |
protected void |
removeAllWatchContentUris()
Requests that the main DashClock app stop watching all content URIs previously registered with addWatchContentUris(String[]) for this extension. |
protected void |
setUpdateWhenScreenOn(boolean updateWhenScreenOn)
Requests that the main DashClock app call (or not call) this extension's onUpdateData(int) method when the screen turns on (the phone resumes from idle). |
| Methods inherited from class android.app.Service |
|---|
dump, getApplication, onConfigurationChanged, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult |
| Methods inherited from class android.content.Context |
|---|
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String ACTION_EXTENSION
Intent action representing a DashClock extension. This service should
declare an <intent-filter> for this action in order to register with
DashClock.
public static final String EXTRA_FROM_DASHCLOCK_SETTINGS
public static final String PERMISSION_READ_EXTENSION_DATA
public static final int UPDATE_REASON_CONTENT_CHANGED
onUpdateData(int) was triggered because content changed on a content
URI previously registered with addWatchContentUris(String[]).
public static final int UPDATE_REASON_INITIAL
onUpdateData(int) since the connection to
the main DashClock app was established. Note that updates aren't requested in response to
reconnections after a connection is lost.
public static final int UPDATE_REASON_MANUAL
onUpdateData(int) was triggered because the user explicitly requested
that the extension be updated.
public static final int UPDATE_REASON_PERIODIC
onUpdateData(int) was triggered due to a normal perioidic refresh
of extension data.
public static final int UPDATE_REASON_SCREEN_ON
onUpdateData(int) was triggered because the device screen turned on
and the extension has called
setUpdateWhenScreenOn(true).
public static final int UPDATE_REASON_SETTINGS_CHANGED
onUpdateData(int) was triggered because settings for this extension
may have changed.
public static final int UPDATE_REASON_UNKNOWN
onUpdateData(int) was triggered for an unknown reason. This should
be treated as a generic update (similar to UPDATE_REASON_PERIODIC.
| Constructor Detail |
|---|
protected DashClockExtension()
| Method Detail |
|---|
protected final void addWatchContentUris(String[] uris)
ContentResolver.registerContentObserver)
and call this extension's onUpdateData(int) method when changes are observed.
This should generally be called in the onInitialize(boolean) method.
uris - The URIs to watch.public final IBinder onBind(Intent intent)
onBind in class Servicepublic void onCreate()
onCreate in class Servicepublic void onDestroy()
onDestroy in class Serviceprotected void onInitialize(boolean isReconnect)
isReconnect
will be true. Override this method to perform basic extension initialization before calls
to onUpdateData(int) are made.
isReconnect - Whether or not this call is being made after a connection was dropped and
a new connection has been established.protected abstract void onUpdateData(int reason)
publishUpdate(ExtensionData) method. Note that doing
nothing doesn't clear existing data. To clear any existing data, call
publishUpdate(ExtensionData) with null data.
reason - The reason for the update. See UPDATE_REASON_PERIODIC and related
constants for more details.protected final void publishUpdate(ExtensionData data)
onUpdateData(int) method, but can be made only after
onInitialize(boolean) has been called. If you only call this from within
onUpdateData(int) this is already ensured.
data - The data to show, or null if existing data should be cleared (hiding
the extension from view).protected final void removeAllWatchContentUris()
addWatchContentUris(String[]) for this extension.
uris - The URIs to watch.protected final void setUpdateWhenScreenOn(boolean updateWhenScreenOn)
onUpdateData(int) method when the screen turns on (the phone resumes from idle).
This should generally be called in the onInitialize(boolean) method. By default,
extensions do not get updated when the screen turns on.
updateWhenScreenOn - Whether or not a call to onUpdateData(int) method when
the screen turns on.Intent.ACTION_SCREEN_ON