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