Merge "Refactoring due to removing some private APIs."
diff --git a/apps/Development/AndroidManifest.xml b/apps/Development/AndroidManifest.xml
index 32738dd..5847201 100644
--- a/apps/Development/AndroidManifest.xml
+++ b/apps/Development/AndroidManifest.xml
@@ -25,6 +25,7 @@
<uses-permission android:name="android.permission.DUMP" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.HARDWARE_TEST" />
+ <uses-permission android:name="android.permission.INTERACT_ACROSS_USERS_FULL" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.REBOOT" />
@@ -117,12 +118,14 @@
</intent-filter>
</activity>
+ <!--
<activity android:name="GLSTester" android:label="Google Login Service">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.TEST" />
</intent-filter>
</activity>
+ -->
<activity android:name="RunningProcesses" android:label="Running processes">
<intent-filter>
diff --git a/samples/WeatherListWidget/AndroidManifest.xml b/samples/WeatherListWidget/AndroidManifest.xml
index 7b1638f..878f110 100644
--- a/samples/WeatherListWidget/AndroidManifest.xml
+++ b/samples/WeatherListWidget/AndroidManifest.xml
@@ -36,7 +36,7 @@
</receiver>
<!-- The service serving the RemoteViews to the collection widget -->
- <service android:name="WeatherWidgetService"
+ <service android:name="android.support.v13.app.RemoteViewsServiceCompat"
android:permission="android.permission.BIND_REMOTEVIEWS"
android:exported="false" />
diff --git a/samples/WeatherListWidget/res/xml/widgetinfo.xml b/samples/WeatherListWidget/res/xml/widgetinfo.xml
index 2e41943..db64457 100644
--- a/samples/WeatherListWidget/res/xml/widgetinfo.xml
+++ b/samples/WeatherListWidget/res/xml/widgetinfo.xml
@@ -21,6 +21,6 @@
android:initialLayout="@layout/widget_layout"
android:resizeMode="vertical"
android:minResizeWidth="280dp"
- android:minResizeHeight="70dp"
+ android:minResizeHeight="40dp"
android:previewImage="@drawable/preview">
</appwidget-provider>
diff --git a/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetProvider.java b/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetProvider.java
index ea3f944..42f3e5f 100644
--- a/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetProvider.java
+++ b/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetProvider.java
@@ -19,21 +19,23 @@
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
-import android.content.Context;
-import android.content.Intent;
import android.content.ComponentName;
-import android.content.ContentValues;
import android.content.ContentResolver;
import android.content.ContentUris;
-import android.database.Cursor;
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
import android.database.ContentObserver;
+import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
+import android.util.Log;
import android.widget.RemoteViews;
import android.widget.Toast;
+import java.util.ArrayList;
import java.util.Random;
/**
@@ -73,7 +75,6 @@
private static final int sMaxDegrees = 96;
private boolean mIsLargeLayout = true;
- private int mHeaderWeatherState = 0;
public WeatherWidgetProvider() {
// Start the worker thread
@@ -116,6 +117,7 @@
final Cursor c = r.query(WeatherDataProvider.CONTENT_URI, null, null, null,
null);
final int count = c.getCount();
+ c.close();
// We disable the data changed observer temporarily since each of the updates
// will trigger an onChange() in our data observer.
@@ -131,12 +133,13 @@
final AppWidgetManager mgr = AppWidgetManager.getInstance(context);
final ComponentName cn = new ComponentName(context, WeatherWidgetProvider.class);
- mgr.notifyAppWidgetViewDataChanged(mgr.getAppWidgetIds(cn), R.id.weather_list);
+ int[] appWidgetIds = mgr.getAppWidgetIds(cn);
+ for (int i = 0; i < appWidgetIds.length; ++i) {
+ RemoteViews layout = buildLayout(context, appWidgetIds[i], mIsLargeLayout);
+ mgr.updateAppWidget(appWidgetIds[i], layout);
+ }
}
});
-
- final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
} else if (action.equals(CLICK_ACTION)) {
// Show a toast
final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
@@ -149,16 +152,46 @@
super.onReceive(ctx, intent);
}
+ private ArrayList<RemoteViews> getListOfCities(Context context) {
+ final String packageName = context.getPackageName();
+ ArrayList<RemoteViews> citiesList = new ArrayList<RemoteViews>();
+ Cursor c = context.getContentResolver().query(WeatherDataProvider.CONTENT_URI, null,
+ null, null, null);
+ final String itemFormatStr = context.getResources().getString(R.string.item_format_string);
+ while (c.moveToNext()) {
+ int tempColIndex = c.getColumnIndex(WeatherDataProvider.Columns.TEMPERATURE);
+ int temp = c.getInt(tempColIndex);
+ int dayColIndex = c.getColumnIndex(WeatherDataProvider.Columns.DAY);
+ String day = c.getString(dayColIndex);
+
+ RemoteViews rvRow = new RemoteViews(packageName, R.layout.widget_item);
+ rvRow.setTextViewText(R.id.widget_item, String.format(itemFormatStr, temp, day));
+
+ // Set the click intent so that we can handle it and show a toast message
+ final Intent fillInIntent = new Intent();
+ final Bundle extras = new Bundle();
+ extras.putString(WeatherWidgetProvider.EXTRA_DAY_ID, day);
+ fillInIntent.putExtras(extras);
+ rvRow.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
+
+ citiesList.add(rvRow);
+ }
+ c.close();
+ return citiesList;
+ }
+
private RemoteViews buildLayout(Context context, int appWidgetId, boolean largeLayout) {
+ final String packageName = context.getPackageName();
+
RemoteViews rv;
if (largeLayout) {
// Specify the service to provide data for the collection widget. Note that we need to
// embed the appWidgetId via the data otherwise it will be ignored.
- final Intent intent = new Intent(context, WeatherWidgetService.class);
- intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
- intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
- rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
- rv.setRemoteAdapter(appWidgetId, R.id.weather_list, intent);
+ rv = new RemoteViews(packageName, R.layout.widget_layout);
+
+ // Set the list of RemoteViews
+ ArrayList<RemoteViews> citiesList = getListOfCities(context);
+ rv.setRemoteAdapter(R.id.weather_list, citiesList, 1);
// Set the empty view to be displayed if the collection is empty. It must be a sibling
// view of the collection view.
diff --git a/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetService.java b/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetService.java
deleted file mode 100644
index 4780e80..0000000
--- a/samples/WeatherListWidget/src/com/example/android/weatherlistwidget/WeatherWidgetService.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.
- */
-
-package com.example.android.weatherlistwidget;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import android.appwidget.AppWidgetManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ContentUris;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Bundle;
-import android.widget.RemoteViews;
-import android.widget.RemoteViewsService;
-
-/**
- * This is the service that provides the factory to be bound to the collection service.
- */
-public class WeatherWidgetService extends RemoteViewsService {
- @Override
- public RemoteViewsFactory onGetViewFactory(Intent intent) {
- return new StackRemoteViewsFactory(this.getApplicationContext(), intent);
- }
-}
-
-/**
- * This is the factory that will provide data to the collection widget.
- */
-class StackRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
- private Context mContext;
- private Cursor mCursor;
- private int mAppWidgetId;
-
- public StackRemoteViewsFactory(Context context, Intent intent) {
- mContext = context;
- mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
- AppWidgetManager.INVALID_APPWIDGET_ID);
- }
-
- public void onCreate() {
- // Since we reload the cursor in onDataSetChanged() which gets called immediately after
- // onCreate(), we do nothing here.
- }
-
- public void onDestroy() {
- if (mCursor != null) {
- mCursor.close();
- }
- }
-
- public int getCount() {
- return mCursor.getCount();
- }
-
- public RemoteViews getViewAt(int position) {
- // Get the data for this position from the content provider
- String day = "Unknown Day";
- int temp = 0;
- if (mCursor.moveToPosition(position)) {
- final int dayColIndex = mCursor.getColumnIndex(WeatherDataProvider.Columns.DAY);
- final int tempColIndex = mCursor.getColumnIndex(
- WeatherDataProvider.Columns.TEMPERATURE);
- day = mCursor.getString(dayColIndex);
- temp = mCursor.getInt(tempColIndex);
- }
-
- // Return a proper item with the proper day and temperature
- final String formatStr = mContext.getResources().getString(R.string.item_format_string);
- final int itemId = R.layout.widget_item;
- RemoteViews rv = new RemoteViews(mContext.getPackageName(), itemId);
- rv.setTextViewText(R.id.widget_item, String.format(formatStr, temp, day));
-
- // Set the click intent so that we can handle it and show a toast message
- final Intent fillInIntent = new Intent();
- final Bundle extras = new Bundle();
- extras.putString(WeatherWidgetProvider.EXTRA_DAY_ID, day);
- fillInIntent.putExtras(extras);
- rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
-
- return rv;
- }
- public RemoteViews getLoadingView() {
- // We aren't going to return a default loading view in this sample
- return null;
- }
-
- public int getViewTypeCount() {
- // Technically, we have two types of views (the dark and light background views)
- return 2;
- }
-
- public long getItemId(int position) {
- return position;
- }
-
- public boolean hasStableIds() {
- return true;
- }
-
- public void onDataSetChanged() {
- // Refresh the cursor
- if (mCursor != null) {
- mCursor.close();
- }
- mCursor = mContext.getContentResolver().query(WeatherDataProvider.CONTENT_URI, null, null,
- null, null);
- }
-}