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.Context; 24 import android.content.Intent; 25 import android.graphics.Bitmap; 26 import android.graphics.drawable.Drawable; 27 import android.os.Build; 28 import android.os.Bundle; 29 30 import com.android.launcher3.IconCache; 31 import com.android.launcher3.Utilities; 32 33 import java.util.List; 34 35 class AppWidgetManagerCompatV16 extends AppWidgetManagerCompat { 36 AppWidgetManagerCompatV16(Context context)37 AppWidgetManagerCompatV16(Context context) { 38 super(context); 39 } 40 41 @Override getAllProviders()42 public List<AppWidgetProviderInfo> getAllProviders() { 43 return mAppWidgetManager.getInstalledProviders(); 44 } 45 46 @Override loadLabel(AppWidgetProviderInfo info)47 public String loadLabel(AppWidgetProviderInfo info) { 48 return info.label.trim(); 49 } 50 51 @Override bindAppWidgetIdIfAllowed(int appWidgetId, AppWidgetProviderInfo info, Bundle options)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 getUser(AppWidgetProviderInfo info)62 public UserHandleCompat getUser(AppWidgetProviderInfo info) { 63 return UserHandleCompat.myUserHandle(); 64 } 65 66 @Override startConfigActivity(AppWidgetProviderInfo info, int widgetId, Activity activity, AppWidgetHost host, int requestCode)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 loadPreview(AppWidgetProviderInfo info)76 public Drawable loadPreview(AppWidgetProviderInfo info) { 77 return mContext.getPackageManager().getDrawable( 78 info.provider.getPackageName(), info.previewImage, null); 79 } 80 81 @Override loadIcon(AppWidgetProviderInfo info, IconCache cache)82 public Drawable loadIcon(AppWidgetProviderInfo info, IconCache cache) { 83 return cache.getFullResIcon(info.provider.getPackageName(), info.icon); 84 } 85 86 @Override getBadgeBitmap(AppWidgetProviderInfo info, Bitmap bitmap)87 public Bitmap getBadgeBitmap(AppWidgetProviderInfo info, Bitmap bitmap) { 88 return bitmap; 89 } 90 } 91