1 /* 2 * Copyright (C) 2015 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 package com.android.launcher3.widget; 17 18 import android.appwidget.AppWidgetHostView; 19 import android.content.Context; 20 import android.os.Bundle; 21 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 25 import com.android.launcher3.LauncherSettings; 26 import com.android.launcher3.PendingAddItemInfo; 27 import com.android.launcher3.logger.LauncherAtom; 28 import com.android.launcher3.model.data.FolderInfo; 29 import com.android.launcher3.model.data.LauncherAppWidgetInfo; 30 import com.android.launcher3.widget.util.WidgetSizes; 31 32 /** 33 * Meta data used for late binding of {@link LauncherAppWidgetProviderInfo}. 34 * 35 * @see {@link PendingAddItemInfo} 36 */ 37 public class PendingAddWidgetInfo extends PendingAddItemInfo { 38 public int previewImage; 39 public int icon; 40 public LauncherAppWidgetProviderInfo info; 41 public AppWidgetHostView boundWidget; 42 public Bundle bindOptions = null; 43 public int sourceContainer; 44 PendingAddWidgetInfo(LauncherAppWidgetProviderInfo i, int container)45 public PendingAddWidgetInfo(LauncherAppWidgetProviderInfo i, int container) { 46 if (i.isCustomWidget()) { 47 itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; 48 } else { 49 itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; 50 } 51 this.info = i; 52 user = i.getProfile(); 53 componentName = i.provider; 54 previewImage = i.previewImage; 55 icon = i.icon; 56 57 spanX = i.spanX; 58 spanY = i.spanY; 59 minSpanX = i.minSpanX; 60 minSpanY = i.minSpanY; 61 this.sourceContainer = this.container = container; 62 } 63 getHandler()64 public WidgetAddFlowHandler getHandler() { 65 return new WidgetAddFlowHandler(info); 66 } 67 getDefaultSizeOptions(Context context)68 public Bundle getDefaultSizeOptions(Context context) { 69 return WidgetSizes.getWidgetSizeOptions(context, componentName, spanX, spanY); 70 } 71 72 @NonNull 73 @Override buildProto(@ullable FolderInfo folderInfo)74 public LauncherAtom.ItemInfo buildProto(@Nullable FolderInfo folderInfo) { 75 LauncherAtom.ItemInfo info = super.buildProto(folderInfo); 76 return info.toBuilder() 77 .addItemAttributes(LauncherAppWidgetInfo.getAttribute(sourceContainer)) 78 .build(); 79 } 80 } 81