home widgets
satya - Friday, September 11, 2009 10:20:00 AM
android home widgets sample code
android home widgets sample code
Search Google for: android home widgets sample code
Search Android Developers Group for: android home widgets sample code
Search Android Beginers Group for: android home widgets sample code
Search Google Code for: android home widgets sample code
Search Android Issues Database for: android home widgets sample code
satya - Friday, September 11, 2009 10:20:33 AM
search 1.5 samples if there are any examples
search 1.5 samples if there are any examples
satya - Friday, September 11, 2009 10:21:35 AM
blog: introducing home screen widgets
satya - Friday, September 11, 2009 10:25:46 AM
Here is an article:Creating a Home Screen App Widget on Android
Here is an article:Creating a Home Screen App Widget on Android
satya - Friday, September 11, 2009 10:26:48 AM
Take a look at this as well
titled: 'Introducing Home Screen Widgets'
satya - Friday, September 11, 2009 10:27:51 AM
Read this widget design guidelines
satya - Friday, September 11, 2009 10:28:29 AM
Here is a formal topic on app widgets
satya - Friday, September 11, 2009 1:20:40 PM
Android RemoteViews
Android RemoteViews
Search Google for: Android RemoteViews
Search Android Developers Group for: Android RemoteViews
Search Android Beginers Group for: Android RemoteViews
satya - Friday, September 11, 2009 1:21:17 PM
Class overview of RemoteViews
satya - Friday, September 11, 2009 1:22:22 PM
lifecycle of a broadcast receiver
satya - Friday, September 11, 2009 2:13:12 PM
Sample code for word of the day
satya - Friday, September 11, 2009 2:16:42 PM
Here is a weblog to go with it
satya - Saturday, September 12, 2009 8:06:54 AM
scope of widgets: Jeff Sharkey
Users can also interact with your app through the widget, for example pausing or switching music tracks. If you have a background service, you can push widget updates on your own schedule, or the AppWidget framework provides an automatic update mechanism.
satya - Saturday, September 12, 2009 8:11:21 AM
why a service
when a timer goes off, you may not want to perform a lengthy operation as part of the timer. Instead let the timer start a service. This service can take 10 minutes. Then the service has the ability to broadcast out the values to the widgets.
satya - Saturday, September 12, 2009 8:13:39 AM
Here is a way to start a service
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
// To prevent any ANR timeouts, we perform the update in a service
context.startService(new Intent(context, UpdateService.class));
}
Notice how similar it is to start a service as to start an activity. Both use an intent and gets invoked in a similar manner.
satya - Saturday, September 12, 2009 8:31:45 AM
read this blog post as well:what-the-docs-dont-tell-you
satya - Saturday, September 12, 2009 8:37:31 AM
Here is a forecast app widget from Jeff Sharkey
satya - Saturday, September 12, 2009 9:35:12 AM
AppWidgetManager API reference
satya - Saturday, September 12, 2009 9:43:13 AM
Android app widgets edit controls
Android app widgets edit controls
Search Google for: Android app widgets edit controls
Search Android Developers Group for: Android app widgets edit controls
Search Android Beginers Group for: Android app widgets edit controls
Search Google Code for: Android app widgets edit controls
Search Android Issues Database for: Android app widgets edit controls
satya - Saturday, September 12, 2009 1:37:49 PM
onUpdate(Context, AppWidgetManager, int[])
This is called to update the App Widget at intervals defined by the updatePeriodMillis attribute in the AppWidgetProviderInfo. This method is also called when the user adds the App Widget, so it should perform the essential setup, such as define event handlers for Views and start a temporary Service, if necessary.
However, if you have declared a configuration Activity, this method is not called when the user adds the App Widget, but is called for the subsequent updates. It is the responsibility of the configuration Activity to perform the first update when configuration is done.
satya - Saturday, September 12, 2009 1:38:14 PM
onDeleted(Context, int[])
This is called every time an App Widget is deleted from the App Widget host.
satya - Saturday, September 12, 2009 1:39:27 PM
onEnabled(Context)
This is called when an instance the App Widget is created for the first time. For example, if the user adds two instances of your App Widget, this is only called the first time. If you need to open a new database or perform other setup that only needs to occur once for all App Widget instances, then this is a good place to do it.
satya - Saturday, September 12, 2009 1:39:50 PM
onDisabled(Context)
This is called when the last instance of your App Widget is deleted from the App Widget host. This is where you should clean up any work done in onEnabled(Context), such as delete a temporary database.
satya - Saturday, September 12, 2009 1:41:51 PM
onReceive(Context, Intent)
This is called for every broadcast and before each of the above callback methods. You normally don't need to implement this method because the default AppWidgetProvider implementation filters all App Widget broadcasts and calls the above methods as appropriate.
satya - Saturday, September 12, 2009 1:42:51 PM
Here is the "ondeleted" bug thread
satya - Saturday, September 12, 2009 1:44:34 PM
Here is the suggested patch for onreceive
@Override
public void onReceive(Context context, Intent intent) {
final String action = intent.getAction();
if (AppWidgetManager.ACTION_APPWIDGET_DELETED.equals(action)) {
final int appWidgetId = extras.getInt
(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
if (appWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID) {
this.onDeleted(context, new int[] { appWidgetId });
}
} else {
super.onReceive(context, intent);
}
}
satya - Saturday, September 12, 2009 7:57:28 PM
The name of the metadata must be the following in the receiver
<meta-data android:name="android.appwidget.provider"
android:resource="@xml/appwidget_provider" />
satya - Tuesday, September 15, 2009 12:13:48 PM
Updating an appwidget explicitly
//Look for your widget provider class name
ComponentName thisWidget = new ComponentName(this, WordWidget.class);
//get the app widget manager
AppWidgetManager manager = AppWidgetManager.getInstance(this);
//update all instances of this widget
manager.updateAppWidget(thisWidget, updateViews);
//or
int widgetId = 12;
manager.updateAppWidget(12, updateViews);
//Where updateviews are the remoteviews
satya - Tuesday, September 15, 2009 12:15:23 PM
One more thing to remember: app widget provider is stateless
This means if you want to manage state of a widget between two calls to update, you will need to manage that state using either static variables, registries, or preferences, or a combination of these techniques.
satya - Tuesday, September 15, 2009 12:32:30 PM
Here is how you find the widget id for which your config activity is invoked
// Find the widget id from the intent.
Intent intent = getIntent();
Bundle extras = intent.getExtras();
if (extras != null) {
mAppWidgetId = extras.getInt(
AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
}
satya - Tuesday, September 15, 2009 1:35:28 PM
You have to define your activity this way
<activity android:name=".ExampleAppWidgetConfigure">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_CONFIGURE" />
</intent-filter>
</activity>
satya - Tuesday, September 15, 2009 1:35:56 PM
The provider info should have this
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
...
android:configure="com.example.android.ExampleAppWidgetConfigure"
... >
</appwidget-provider>
satya - Tuesday, September 15, 2009 1:36:25 PM
and ...
It is the responsibility of the configuration Activity to request an update from the AppWidgetManager when the App Widget is first created.
satya - Tuesday, September 15, 2009 1:37:14 PM
The reply need...
The App Widget host calls the configuration Activity and the configuration Activity should always return a result. The result should include the App Widget ID passed by the Intent that launched the Activity (saved in the Intent extras as EXTRA_APPWIDGET_ID).
satya - Tuesday, September 15, 2009 1:37:36 PM
Finishing the activity...
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
finish();
satya - Tuesday, September 15, 2009 6:24:05 PM
how does android app widget work if there is no time interval
how does android app widget work if there is no time interval
Search for: how does android app widget work if there is no time interval
satya - Tuesday, September 15, 2009 6:50:11 PM
How can I clean up previous instances of android app widgets
How can I clean up previous instances of android app widgets
Search Google for: How can I clean up previous instances of android app widgets
Search Android Developers Group for: How can I clean up previous instances of android app widgets
Search Android Beginers Group for: How can I clean up previous instances of android app widgets
Search Google Code for: How can I clean up previous instances of android app widgets
Search Android Issues Database for: How can I clean up previous instances of android app widgets
satya - Tuesday, September 15, 2009 6:55:20 PM
is there an android widget manager UI?
is there an android widget manager UI?
satya - Tuesday, September 15, 2009 7:14:27 PM
finish receiver called but none active
finish receiver called but none active
Search Google for: finish receiver called but none active
Search Android Developers Group for: finish receiver called but none active
Search Android Beginers Group for: finish receiver called but none active
Search Google Code for: finish receiver called but none active
Search Android Issues Database for: finish receiver called but none active
satya - Wednesday, September 16, 2009 9:34:15 AM
android widgets custom scheduling
android widgets custom scheduling
satya - Wednesday, September 16, 2009 9:43:33 AM
See this note on uninstalling app widgets
satya - Wednesday, September 16, 2009 9:43:59 AM
in summary...
User is expected to clean up the widgets before uninstalling.
satya - Wednesday, September 16, 2009 9:45:07 AM
uninstall android app widgets
uninstall android app widgets
Search for: uninstall android app widgets
This is a better search
satya - Wednesday, September 16, 2009 9:46:18 AM
Read this to see more of uninstall
satya - Wednesday, September 16, 2009 10:39:43 AM
Another oddity: update may still be fired while the configurator is up
when a configuration activity is invoked on behalf of an instance, it may still be emitting update events. You may want to check for this fact.
satya - Wednesday, September 16, 2009 1:14:40 PM
are static variables retained between two android appwidget invocations?
are static variables retained between two android appwidget invocations?
Search for: are static variables retained between two android appwidget invocations?
satya - Wednesday, September 16, 2009 1:21:10 PM
android static variables
android static variables
satya - Wednesday, September 16, 2009 1:31:07 PM
what is the lifecycle of an android broadcast receiver
what is the lifecycle of an android broadcast receiver
Search for: what is the lifecycle of an android broadcast receiver
satya - Wednesday, September 16, 2009 10:35:29 PM
Read up on the lifecycle of services
satya - Thursday, September 17, 2009 12:48:29 PM
android broadcast receiver local service
android broadcast receiver local service
satya - Thursday, September 17, 2009 1:32:19 PM
Understand SharedPreferences
Understand SharedPreferences
satya - Thursday, September 17, 2009 1:36:46 PM
Here is the API for the SharedPreferences editor
satya - Thursday, September 17, 2009 1:43:14 PM
Here is an interesting app with preferences and passwords
satya - Thursday, September 17, 2009 1:44:08 PM
android SharedPreferences: better search
satya - Thursday, September 17, 2009 2:14:29 PM
Do you need to set something for persisting shared preferences?
Do you need to set something for persisting shared preferences?
The post seem to suggest to set android:persistent=true.
satya - Thursday, September 17, 2009 2:16:18 PM
Here is a longer discussion on the topic
satya - Friday, September 18, 2009 10:22:26 AM
where are android shared preferences stored?
where are android shared preferences stored?
satya - Friday, September 18, 2009 10:22:43 AM
file location of android shared preferences
file location of android shared preferences
satya - Friday, September 18, 2009 2:28:01 PM
Can I have two app widgets in one android apk file or package?
Can I have two app widgets in one android apk file or package?
Search for: Can I have two app widgets in one android apk file or package?
satya - Friday, September 18, 2009 4:57:04 PM
Allowed controls for a widget
FrameLayout
LinearLayout
RelativeLayout
AnalogClock
Button
Chronometer
ImageButton
ImageView
ProgressBar
TextView
satya - Wednesday, September 23, 2009 9:04:53 AM
figuring out widget sizes
The values for the minWidth and minHeight attributes specify the minimum area required by the App Widget's layout.
The default Home screen positions App Widgets in its window based on a grid of cells that have a defined height and width. If the values for an App Widget's minimum width or height don't match the dimensions of the cells, then the App Widget dimensions round up to the nearest cell size. (See the App Widget Design Guidelines for more information on the Home screen cell sizes.)
Because the Home screen's layout orientation (and thus, the cell sizes) can change, as a rule of thumb, you should assume the worst-case cell size of 74 pixels for the height and width of a cell.
However, you must subtract 2 from the final dimension to account for any integer rounding errors that occur in the pixel count. To find your minimum width and height in density-independent pixels (dp), use this formula:
(number of cells * 74) - 2
Following this formula, you should use 72 dp for a height of one cell, 294 dp and for a width of four cells.
satya - Wednesday, September 23, 2009 9:19:58 AM
widgets are **not naturally** suited for quick updates....see the note
If the device is asleep when it is time for an update (as defined by updatePeriodMillis), then the device will wake up in order to perform the update. If you don't update more than once per hour, this probably won't cause significant problems for the battery life.
If, however, you need to update more frequently and/or you do not need to update while the device is asleep, then you can instead perform updates based on an alarm that will not wake the device.
To do so, set an alarm with an Intent that your AppWidgetProvider receives, using the AlarmManager. Set the alarm type to either ELAPSED_REALTIME or RTC, which will only deliver the alarm when the device is awake. Then set updatePeriodMillis to zero ("0").
satya - Saturday, February 26, 2011 9:45:58 AM
See a follow up notes as we move on to honeycomb