【Android源码 栏目提醒】:网学会员Android源码 为您提供WeatherWidgetProvider java android源码 - 开发文档参考,解决您在WeatherWidgetProvider java android源码 - 开发文档学习中工作中的难题,参考学习。
/ 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 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.database.ContentObserver import android.net.Uri import android.os.Handler import android.os.HandlerThread import android.widget.RemoteViews import android.widget.Toast import java.util.Random / Our data observer just notifies an update for all weather widgets when it detects a change. / class WeatherDataProviderObserver extends ContentObserver private AppWidgetManager mAppWidgetManager private ComponentName mComponentName WeatherDataProviderObserverAppWidgetManager mgr ComponentName cn Handler h superh mAppWidgetManager mgr mComponentName cn Override public void onChangeboolean selfChange // The data has changed so notify the widget that the collection view needs to be updated. // In response the factorys onDataSetChanged will be called which will requery the // cursor for the new data. mAppWidgetManager.notifyAppWidgetViewDataChanged mAppWidgetManager.getAppWidgetIdsmComponentName R.id.weather_list / The weather widgets AppWidgetProvider. / public class WeatherWidgetProvider extends AppWidgetProvider public static String CLICK_ACTION com.example.android.weatherlistwidget.CLICK public static String REFRESH_ACTION com.example.android.weatherlistwidget.REFRESH public static String EXTRA_CITY_ID com.example.android.weatherlistwidget.city private static HandlerThread sWorkerThread private static Handler sWorkerQueue private static WeatherDataProviderObserver sDataObserver public WeatherWidgetProvider // Start the worker thread sWorkerThread new HandlerThreadWeatherWidgetProvider-worker sWorkerThread.start sWorkerQueue new HandlersWorkerThread.getLooper Override public void onEnabledContext context // Register for external updates to the data to trigger an update of the widget. When using // content providers the data is often updated via a background service or in response to // user interaction in the main app. To ensure that the widget always reflects the current // state of the data we must listen for changes and update ourselves accordingly. final ContentResolver r context.getContentResolver if sDataObserver null final AppWidgetManage