This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding sample for collection widgets backed by content providers.
Change-Id: If0005d88a19dfa05ddd7c60aba1a1d7d742158be
- Loading branch information
Winson Chung
committed
Feb 11, 2011
1 parent
f8da117
commit e412a0f
Showing
38 changed files
with
707 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<!-- Declare the contents of this Android application. The namespace | ||
attribute brings in the Android platform namespace, and the package | ||
supplies a unique name for the application. When writing your | ||
own application, the package name must be changed from "com.example.*" | ||
to come from a domain that you own or have control over. --> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.example.android.weatherlistwidget"> | ||
<uses-sdk android:minSdkVersion="11" /> | ||
<application android:label="Weather Widget Sample"> | ||
<!-- The widget provider --> | ||
<receiver android:name="WeatherWidgetProvider"> | ||
<intent-filter> | ||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" /> | ||
</intent-filter> | ||
<!-- This specifies the widget provider info --> | ||
<meta-data android:name="android.appwidget.provider" | ||
android:resource="@xml/widgetinfo" /> | ||
</receiver> | ||
|
||
<!-- The service serving the RemoteViews to the collection widget --> | ||
<service android:name="WeatherWidgetService" | ||
android:permission="android.permission.BIND_REMOTEVIEWS" | ||
android:exported="false" /> | ||
|
||
<!-- The content provider serving the (fake) weather data --> | ||
<provider android:name="WeatherDataProvider" | ||
android:authorities="com.example.android.weatherlistwidget.provider" /> | ||
</application> | ||
</manifest> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<p>This sample demonstrates how to create a list-based widget specifically backed by a content provider.<br/> | ||
<em>Please make sure that you understand the earlier stack widget sample code before delving into this example | ||
(see <a href="../StackWidget/index.html">StackWidget</a>).</em></p> | ||
|
||
<p>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.</p> | ||
|
||
<p>This sample uses the following classes: | ||
<ul> | ||
<li><a href="src/com/example/android/weatherlistwidget/WeatherDataProvider.html"><code>WeatherDataProvider</code></a> — | ||
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. | ||
</li> | ||
<li><a href="src/com/example/android/weatherlistwidget/WeatherWidgetProvider.html"><code>WeatherWidgetProvider</code></a> — | ||
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. | ||
</li> | ||
<li><a href="src/com/example/android/weatherlistwidget/WeatherWidgetService.html"><code>WeatherWidgetService</code></a> — | ||
Our RemoteViewsService which manages the creation of new factories, which return the RemoteViews | ||
for each item in the ListView. | ||
</li> | ||
</ul> | ||
</p> | ||
|
||
<p>If you are writing collection-based widgets, remember that the feature is | ||
supported only on Android 3.0 (API level 11) and higher versions of the platform. | ||
Remember to add the following to the application's manifest publishing to Android Market:</p> | ||
|
||
<ul> | ||
<li><code><uses-sdk android:minSdkVersion="11" /></code>, which indicates | ||
to Android Market and the platform that your application requires Android 3.0 or | ||
higher. For more information, see the <a href="../../../guide/appendix/api-levels.html">API Levels</a> | ||
and the documentation for the | ||
<a href="../../../guide/topics/manifest/uses-sdk-element.html"><code><uses-sdk></code></a> | ||
element.</li> | ||
</ul> | ||
|
||
<img alt="Screenshot" src="../images/WeatherListWidget.png" /> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item android:state_pressed="true" | ||
android:drawable="@drawable/refresh_pressed" /> <!-- pressed --> | ||
<item android:drawable="@drawable/refresh" /> <!-- default --> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/widget_item" | ||
android:layout_width="match_parent" | ||
android:layout_height="46dp" | ||
android:paddingLeft="25dp" | ||
android:gravity="center_vertical" | ||
android:background="@drawable/item_bg_dark" | ||
android:textColor="#e5e5e1" | ||
android:textSize="24sp" /> |
24 changes: 24 additions & 0 deletions
24
samples/WeatherListWidget/res/layout/light_widget_item.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<TextView xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/widget_item" | ||
android:layout_width="match_parent" | ||
android:layout_height="46dp" | ||
android:paddingLeft="25dp" | ||
android:gravity="center_vertical" | ||
android:background="@drawable/item_bg_light" | ||
android:textColor="#e5e5e1" | ||
android:textSize="24sp" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="294dp" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
<FrameLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
<ImageView | ||
android:id="@+id/header" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/header" /> | ||
<ImageButton | ||
android:id="@+id/refresh" | ||
android:layout_width="56dp" | ||
android:layout_height="39dp" | ||
android:layout_marginLeft="222dp" | ||
android:layout_marginTop="20dp" | ||
android:background="@drawable/refresh_button" /> | ||
</FrameLayout> | ||
<FrameLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:layout_gravity="center" | ||
android:background="@drawable/body"> | ||
<ListView | ||
android:id="@+id/weather_list" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" /> | ||
<TextView | ||
android:id="@+id/empty_view" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:visibility="gone" | ||
android:textColor="#ffffff" | ||
android:text="@string/empty_view_text" | ||
android:textSize="20sp" /> | ||
</FrameLayout> | ||
<ImageView | ||
android:id="@+id/footer" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:src="@drawable/footer" /> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<resources> | ||
<string name="empty_view_text">No cities found...</string> | ||
<string name="toast_format_string">%1$s says Hi!</string> | ||
<string name="item_format_string">%1$d\u00B0 in %2$s</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2011 The Android Open Source Project | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<appwidget-provider | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:minWidth="222dip" | ||
android:minHeight="222dip" | ||
android:updatePeriodMillis="1800000" | ||
android:initialLayout="@layout/widget_layout" | ||
android:previewImage="@drawable/preview"> | ||
</appwidget-provider> |
Oops, something went wrong.