• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.dragndrop;
18 
19 import android.annotation.TargetApi;
20 import android.appwidget.AppWidgetManager;
21 import android.appwidget.AppWidgetProviderInfo;
22 import android.content.pm.LauncherApps.PinItemRequest;
23 import android.os.Build;
24 import android.os.Bundle;
25 import android.os.Parcel;
26 import android.os.Parcelable;
27 
28 import com.android.launcher3.Launcher;
29 import com.android.launcher3.model.data.ItemInfo;
30 import com.android.launcher3.widget.WidgetAddFlowHandler;
31 
32 /**
33  * Extension of WidgetAddFlowHandler to handle pin item request behavior.
34  *
35  * No config activity is shown even if it is defined in widget config. And a callback is sent when
36  * the widget is bound.
37  */
38 @TargetApi(Build.VERSION_CODES.O)
39 public class PinWidgetFlowHandler extends WidgetAddFlowHandler implements Parcelable {
40 
41     private final PinItemRequest mRequest;
42 
PinWidgetFlowHandler(AppWidgetProviderInfo providerInfo, PinItemRequest request)43     public PinWidgetFlowHandler(AppWidgetProviderInfo providerInfo, PinItemRequest request) {
44         super(providerInfo);
45         mRequest = request;
46     }
47 
PinWidgetFlowHandler(Parcel parcel)48     protected PinWidgetFlowHandler(Parcel parcel) {
49         super(parcel);
50         mRequest = PinItemRequest.CREATOR.createFromParcel(parcel);
51     }
52 
53     @Override
writeToParcel(Parcel parcel, int i)54     public void writeToParcel(Parcel parcel, int i) {
55         super.writeToParcel(parcel, i);
56         mRequest.writeToParcel(parcel, i);
57     }
58 
59     @Override
startConfigActivity(Launcher launcher, int appWidgetId, ItemInfo info, int requestCode)60     public boolean startConfigActivity(Launcher launcher, int appWidgetId, ItemInfo info,
61             int requestCode) {
62         Bundle extras = new Bundle();
63         extras.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
64         mRequest.accept(extras);
65         return false;
66     }
67 
68     @Override
needsConfigure()69     public boolean needsConfigure() {
70         return false;
71     }
72 
73     public static final Parcelable.Creator<PinWidgetFlowHandler> CREATOR =
74             new Parcelable.Creator<PinWidgetFlowHandler>() {
75                 public PinWidgetFlowHandler createFromParcel(Parcel source) {
76                     return new PinWidgetFlowHandler(source);
77                 }
78 
79                 public PinWidgetFlowHandler[] newArray(int size) {
80                     return new PinWidgetFlowHandler[size];
81                 }
82             };
83 }
84