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