1 /* 2 * Copyright (C) 2014 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 17 package android.appwidget.cts.provider; 18 19 import android.appwidget.AppWidgetManager; 20 import android.appwidget.AppWidgetProvider; 21 import android.content.Context; 22 import android.os.Bundle; 23 24 public abstract class StubbableAppWidgetProvider extends AppWidgetProvider { 25 @Override onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)26 public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 27 AppWidgetProviderCallbacks callbacks = getCallbacks(); 28 if (callbacks != null) { 29 callbacks.onUpdate(context, appWidgetManager, appWidgetIds); 30 } 31 } 32 33 @Override onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions)34 public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, 35 int appWidgetId, Bundle newOptions) { 36 AppWidgetProviderCallbacks callbacks = getCallbacks(); 37 if (callbacks != null) { 38 callbacks.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); 39 } 40 } 41 42 @Override onDeleted(Context context, int[] appWidgetIds)43 public void onDeleted(Context context, int[] appWidgetIds) { 44 AppWidgetProviderCallbacks callbacks = getCallbacks(); 45 if (callbacks != null) { 46 callbacks.onDeleted(context, appWidgetIds); 47 } 48 } 49 50 @Override onEnabled(Context context)51 public void onEnabled(Context context) { 52 AppWidgetProviderCallbacks callbacks = getCallbacks(); 53 if (callbacks != null) { 54 callbacks.onEnabled(context); 55 } 56 } 57 58 @Override onDisabled(Context context)59 public void onDisabled(Context context) { 60 AppWidgetProviderCallbacks callbacks = getCallbacks(); 61 if (callbacks != null) { 62 callbacks.onDisabled(context); 63 } 64 } 65 66 @Override onRestored(Context context, int[] oldWidgetIds, int[] newWidgetIds)67 public void onRestored(Context context, int[] oldWidgetIds, int[] newWidgetIds) { 68 AppWidgetProviderCallbacks callbacks = getCallbacks(); 69 if (callbacks != null) { 70 super.onRestored(context, oldWidgetIds, newWidgetIds); 71 } 72 } 73 getCallbacks()74 protected abstract AppWidgetProviderCallbacks getCallbacks(); 75 } 76