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 17package com.android.launcher3.compat; 18 19import android.app.Activity; 20import android.appwidget.AppWidgetHost; 21import android.appwidget.AppWidgetManager; 22import android.appwidget.AppWidgetProviderInfo; 23import android.content.Context; 24import android.graphics.Bitmap; 25import android.graphics.drawable.Drawable; 26import android.os.Bundle; 27 28import com.android.launcher3.IconCache; 29import com.android.launcher3.Utilities; 30 31import java.util.List; 32 33public abstract class AppWidgetManagerCompat { 34 35 private static final Object sInstanceLock = new Object(); 36 private static AppWidgetManagerCompat sInstance; 37 38 39 public static AppWidgetManagerCompat getInstance(Context context) { 40 synchronized (sInstanceLock) { 41 if (sInstance == null) { 42 if (Utilities.isLmpOrAbove()) { 43 sInstance = new AppWidgetManagerCompatVL(context.getApplicationContext()); 44 } else { 45 sInstance = new AppWidgetManagerCompatV16(context.getApplicationContext()); 46 } 47 } 48 return sInstance; 49 } 50 } 51 52 final AppWidgetManager mAppWidgetManager; 53 final Context mContext; 54 55 AppWidgetManagerCompat(Context context) { 56 mContext = context; 57 mAppWidgetManager = AppWidgetManager.getInstance(context); 58 } 59 60 public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) { 61 return mAppWidgetManager.getAppWidgetInfo(appWidgetId); 62 } 63 64 public abstract List<AppWidgetProviderInfo> getAllProviders(); 65 66 public abstract String loadLabel(AppWidgetProviderInfo info); 67 68 public abstract boolean bindAppWidgetIdIfAllowed( 69 int appWidgetId, AppWidgetProviderInfo info, Bundle options); 70 71 public abstract UserHandleCompat getUser(AppWidgetProviderInfo info); 72 73 public abstract void startConfigActivity(AppWidgetProviderInfo info, int widgetId, 74 Activity activity, AppWidgetHost host, int requestCode); 75 76 public abstract Drawable loadPreview(AppWidgetProviderInfo info); 77 78 public abstract Drawable loadIcon(AppWidgetProviderInfo info, IconCache cache); 79 80 public abstract Bitmap getBadgeBitmap(AppWidgetProviderInfo info, Bitmap bitmap); 81 82} 83