1/* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.launcher2; 18 19import android.appwidget.AppWidgetHost; 20import android.appwidget.AppWidgetHostView; 21import android.appwidget.AppWidgetProviderInfo; 22import android.content.Context; 23 24/** 25 * Specific {@link AppWidgetHost} that creates our {@link LauncherAppWidgetHostView} 26 * which correctly captures all long-press events. This ensures that users can 27 * always pick up and move widgets. 28 */ 29public class LauncherAppWidgetHost extends AppWidgetHost { 30 31 Launcher mLauncher; 32 33 public LauncherAppWidgetHost(Launcher launcher, int hostId) { 34 super(launcher, hostId); 35 mLauncher = launcher; 36 } 37 38 @Override 39 protected AppWidgetHostView onCreateView(Context context, int appWidgetId, 40 AppWidgetProviderInfo appWidget) { 41 return new LauncherAppWidgetHostView(context); 42 } 43 44 @Override 45 public void stopListening() { 46 super.stopListening(); 47 clearViews(); 48 } 49 50 protected void onProvidersChanged() { 51 // Once we get the message that widget packages are updated, we need to rebind items 52 // in AppsCustomize accordingly. 53 mLauncher.bindPackagesUpdated(LauncherModel.getSortedWidgetsAndShortcuts(mLauncher)); 54 } 55} 56