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