Date: Thu, 10 Feb 2011 19:10:20 -0800
Subject: [PATCH] Adding sample for collection widgets backed by content
providers.
Change-Id: If0005d88a19dfa05ddd7c60aba1a1d7d742158be
---
build/sdk.atree | 1 +
samples/WeatherListWidget/Android.mk | 16 ++
samples/WeatherListWidget/AndroidManifest.xml | 45 +++++
samples/WeatherListWidget/_index.html | 43 +++++
.../res/drawable-hdpi/body.png | Bin 0 -> 6286 bytes
.../res/drawable-hdpi/footer.png | Bin 0 -> 332 bytes
.../res/drawable-hdpi/header.png | Bin 0 -> 11739 bytes
.../res/drawable-hdpi/icon.png | Bin 0 -> 4147 bytes
.../res/drawable-hdpi/item_bg_dark.png | Bin 0 -> 558 bytes
.../res/drawable-hdpi/item_bg_light.png | Bin 0 -> 567 bytes
.../res/drawable-hdpi/refresh.png | Bin 0 -> 4020 bytes
.../res/drawable-hdpi/refresh_pressed.png | Bin 0 -> 3943 bytes
.../res/drawable-ldpi/body.png | Bin 0 -> 4068 bytes
.../res/drawable-ldpi/footer.png | Bin 0 -> 3032 bytes
.../res/drawable-ldpi/header.png | Bin 0 -> 14518 bytes
.../res/drawable-ldpi/icon.png | Bin 0 -> 1723 bytes
.../res/drawable-ldpi/item_bg_dark.png | Bin 0 -> 6883 bytes
.../res/drawable-ldpi/item_bg_light.png | Bin 0 -> 6076 bytes
.../res/drawable-ldpi/refresh.png | Bin 0 -> 1665 bytes
.../res/drawable-ldpi/refresh_pressed.png | Bin 0 -> 1614 bytes
.../res/drawable-mdpi/body.png | Bin 0 -> 3602 bytes
.../res/drawable-mdpi/footer.png | Bin 0 -> 247 bytes
.../res/drawable-mdpi/header.png | Bin 0 -> 7443 bytes
.../res/drawable-mdpi/icon.png | Bin 0 -> 2574 bytes
.../res/drawable-mdpi/item_bg_dark.png | Bin 0 -> 399 bytes
.../res/drawable-mdpi/item_bg_light.png | Bin 0 -> 438 bytes
.../res/drawable-mdpi/refresh.png | Bin 0 -> 1735 bytes
.../res/drawable-mdpi/refresh_pressed.png | Bin 0 -> 1735 bytes
.../res/drawable-nodpi/preview.png | Bin 0 -> 28360 bytes
.../res/drawable/refresh_button.xml | 6 +
.../res/layout/dark_widget_item.xml | 24 +++
.../res/layout/light_widget_item.xml | 24 +++
.../res/layout/widget_layout.xml | 61 ++++++
.../WeatherListWidget/res/values/strings.xml | 20 ++
.../WeatherListWidget/res/xml/widgetinfo.xml | 23 +++
.../WeatherDataProvider.java | 137 +++++++++++++
.../WeatherWidgetProvider.java | 181 ++++++++++++++++++
.../WeatherWidgetService.java | 126 ++++++++++++
38 files changed, 707 insertions(+)
create mode 100644 samples/WeatherListWidget/Android.mk
create mode 100644 samples/WeatherListWidget/AndroidManifest.xml
create mode 100644 samples/WeatherListWidget/_index.html
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/body.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/footer.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/header.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/icon.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/item_bg_dark.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/item_bg_light.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/refresh.png
create mode 100644 samples/WeatherListWidget/res/drawable-hdpi/refresh_pressed.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/body.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/footer.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/header.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/icon.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/item_bg_dark.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/item_bg_light.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/refresh.png
create mode 100644 samples/WeatherListWidget/res/drawable-ldpi/refresh_pressed.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/body.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/footer.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/header.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/icon.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/item_bg_dark.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/item_bg_light.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/refresh.png
create mode 100644 samples/WeatherListWidget/res/drawable-mdpi/refresh_pressed.png
create mode 100644 samples/WeatherListWidget/res/drawable-nodpi/preview.png
create mode 100644 samples/WeatherListWidget/res/drawable/refresh_button.xml
create mode 100644 samples/WeatherListWidget/res/layout/dark_widget_item.xml
create mode 100644 samples/WeatherListWidget/res/layout/light_widget_item.xml
create mode 100644 samples/WeatherListWidget/res/layout/widget_layout.xml
create mode 100644 samples/WeatherListWidget/res/values/strings.xml
create mode 100644 samples/WeatherListWidget/res/xml/widgetinfo.xml
create mode 100644 samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherDataProvider.java
create mode 100644 samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetProvider.java
create mode 100644 samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetService.java
diff --git a/build/sdk.atree b/build/sdk.atree
index e0689091736..641862640d5 100644
--- a/build/sdk.atree
+++ b/build/sdk.atree
@@ -178,6 +178,7 @@ development/samples/SpinnerTest samples/${PLATFORM_NAME}/SpinnerTes
development/samples/TicTacToeLib samples/${PLATFORM_NAME}/TicTacToeLib
development/samples/TicTacToeMain samples/${PLATFORM_NAME}/TicTacToeMain
development/samples/VoiceRecognitionService samples/${PLATFORM_NAME}/VoiceRecognitionService
+development/samples/WeatherListWidget samples/${PLATFORM_NAME}/WeatherListWidget
development/apps/WidgetPreview samples/${PLATFORM_NAME}/WidgetPreview
development/samples/Wiktionary samples/${PLATFORM_NAME}/Wiktionary
development/samples/WiktionarySimple samples/${PLATFORM_NAME}/WiktionarySimple
diff --git a/samples/WeatherListWidget/Android.mk b/samples/WeatherListWidget/Android.mk
new file mode 100644
index 00000000000..95d233fa80c
--- /dev/null
+++ b/samples/WeatherListWidget/Android.mk
@@ -0,0 +1,16 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := tests
+
+# Only compile source java files in this apk.
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_PACKAGE_NAME := WeatherListWidget
+
+LOCAL_SDK_VERSION := current
+
+include $(BUILD_PACKAGE)
+
+# Use the following include to make our test apk.
+include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/samples/WeatherListWidget/AndroidManifest.xml b/samples/WeatherListWidget/AndroidManifest.xml
new file mode 100644
index 00000000000..cfb23722cc7
--- /dev/null
+++ b/samples/WeatherListWidget/AndroidManifest.xml
@@ -0,0 +1,45 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/samples/WeatherListWidget/_index.html b/samples/WeatherListWidget/_index.html
new file mode 100644
index 00000000000..730f27caa7a
--- /dev/null
+++ b/samples/WeatherListWidget/_index.html
@@ -0,0 +1,43 @@
+This sample demonstrates how to create a list-based widget specifically backed by a content provider.
+Please make sure that you understand the earlier stack widget sample code before delving into this example
+ (see StackWidget).
+
+As in the StackWidget example, we will be using a collection view (the ListView in this case) to
+present some mock weather data in a widget. In particular, we will be using a content provider to
+demonstrate how the widget can retrieve data and update itself when you are using more complex data
+sources. When working with external data, or data which must be fetched over high latency, it is
+important to keep the data cached in a persistent location so that the widget feels responsive.
+
+This sample uses the following classes:
+
+ WeatherDataProvider
—
+ Our ContentProvider which stores the weather data for this sample. Note that for simplicity,
+ it currently stores the data in memory as opposed to an external and persistent storage such
+ as a file, network location, database, or shared preference.
+
+ WeatherWidgetProvider
—
+ Our AppWidgetProvider which handles specific intent actions (such as when an item is clicked,
+ or the refresh button is pressed). It also sets up the RemoteViews for the widget and binds
+ the service to the collection view in the widget.
+
+ WeatherWidgetService
—
+ Our RemoteViewsService which manages the creation of new factories, which return the RemoteViews
+ for each item in the ListView.
+
+
+