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.content.Intent;
25import android.graphics.Bitmap;
26import android.graphics.drawable.Drawable;
27import android.os.Build;
28import android.os.Bundle;
29
30import com.android.launcher3.IconCache;
31import com.android.launcher3.Utilities;
32
33import java.util.List;
34
35class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat {
36
37    AppWidgetManagerCompatV16(Context context) {
38        super(context);
39    }
40
41    @Override
42    public List<AppWidgetProviderInfo> getAllProviders() {
43        return mAppWidgetManager.getInstalledProviders();
44    }
45
46    @Override
47    public String loadLabel(AppWidgetProviderInfo info) {
48        return info.label.trim();
49    }
50
51    @Override
52    public boolean bindAppWidgetIdIfAllowed(int appWidgetId, AppWidgetProviderInfo info,
53            Bundle options) {
54        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
55            return mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.provider);
56        } else {
57            return mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.provider, options);
58        }
59    }
60
61    @Override
62    public UserHandleCompat getUser(AppWidgetProviderInfo info) {
63        return UserHandleCompat.myUserHandle();
64    }
65
66    @Override
67    public void startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity,
68            AppWidgetHost host, int requestCode) {
69        Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
70        intent.setComponent(info.configure);
71        intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, widgetId);
72        Utilities.startActivityForResultSafely(activity, intent, requestCode);
73    }
74
75    @Override
76    public Drawable loadPreview(AppWidgetProviderInfo info) {
77        return mContext.getPackageManager().getDrawable(
78                info.provider.getPackageName(), info.previewImage, null);
79    }
80
81    @Override
82    public Drawable loadIcon(AppWidgetProviderInfo info, IconCache cache) {
83        return cache.getFullResIcon(info.provider.getPackageName(), info.icon);
84    }
85
86    @Override
87    public Bitmap getBadgeBitmap(AppWidgetProviderInfo info, Bitmap bitmap) {
88        return bitmap;
89    }
90}
91