Home | History | Annotate | Download | only in compat
      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 
     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 
     59     AppWidgetManagerCompat(Context context) {
     60         mContext = context;
     61         mAppWidgetManager = AppWidgetManager.getInstance(context);
     62     }
     63 
     64     public AppWidgetProviderInfo getAppWidgetInfo(int appWidgetId) {
     65         return mAppWidgetManager.getAppWidgetInfo(appWidgetId);
     66     }
     67 
     68     public LauncherAppWidgetProviderInfo getLauncherAppWidgetInfo(int appWidgetId) {
     69         AppWidgetProviderInfo info = getAppWidgetInfo(appWidgetId);
     70         return info == null ? null : LauncherAppWidgetProviderInfo.fromProviderInfo(mContext, info);
     71     }
     72 
     73     public abstract List<AppWidgetProviderInfo> getAllProviders();
     74 
     75     public abstract String loadLabel(LauncherAppWidgetProviderInfo info);
     76 
     77     public abstract boolean bindAppWidgetIdIfAllowed(
     78             int appWidgetId, AppWidgetProviderInfo info, Bundle options);
     79 
     80     public abstract UserHandleCompat getUser(LauncherAppWidgetProviderInfo info);
     81 
     82     public abstract void startConfigActivity(AppWidgetProviderInfo info, int widgetId,
     83             Activity activity, AppWidgetHost host, int requestCode);
     84 
     85     public abstract Drawable loadPreview(AppWidgetProviderInfo info);
     86 
     87     public abstract Drawable loadIcon(LauncherAppWidgetProviderInfo info, IconCache cache);
     88 
     89     public abstract Bitmap getBadgeBitmap(LauncherAppWidgetProviderInfo info, Bitmap bitmap,
     90             int imageWidth, int imageHeight);
     91 
     92     public abstract LauncherAppWidgetProviderInfo findProvider(
     93             ComponentName provider, UserHandleCompat user);
     94 
     95     public abstract HashMap<ComponentKey, AppWidgetProviderInfo> getAllProvidersMap();
     96 }
     97