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.os.Bundle;
20 import android.os.Parcelable;
21 
22 import com.android.launcher3.Launcher;
23 import com.android.launcher3.LauncherAppWidgetProviderInfo;
24 import com.android.launcher3.LauncherSettings;
25 import com.android.launcher3.PendingAddItemInfo;
26 import com.android.launcher3.compat.AppWidgetManagerCompat;
27 
28 /**
29  * Meta data used for late binding of {@link LauncherAppWidgetProviderInfo}.
30  *
31  * @see {@link PendingAddItemInfo}
32  */
33 public class PendingAddWidgetInfo extends PendingAddItemInfo {
34     public int previewImage;
35     public int icon;
36     public LauncherAppWidgetProviderInfo info;
37     public AppWidgetHostView boundWidget;
38     public Bundle bindOptions = null;
39 
PendingAddWidgetInfo(Launcher launcher, LauncherAppWidgetProviderInfo i, Parcelable data)40     public PendingAddWidgetInfo(Launcher launcher, LauncherAppWidgetProviderInfo i, Parcelable data) {
41         if (i.isCustomWidget) {
42             itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
43         } else {
44             itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET;
45         }
46         this.info = i;
47         user = AppWidgetManagerCompat.getInstance(launcher).getUser(i);
48         componentName = i.provider;
49         previewImage = i.previewImage;
50         icon = i.icon;
51 
52         spanX = i.spanX;
53         spanY = i.spanY;
54         minSpanX = i.minSpanX;
55         minSpanY = i.minSpanY;
56     }
57 
isCustomWidget()58     public boolean isCustomWidget() {
59         return itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
60     }
61 
62     @Override
toString()63     public String toString() {
64         return String.format("PendingAddWidgetInfo package=%s, name=%s",
65                 componentName.getPackageName(), componentName.getShortClassName());
66     }
67 }
68