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