1 /*
2  * Copyright (C) 2010 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;
18 
19 import android.content.ComponentName;
20 
21 import androidx.annotation.NonNull;
22 import androidx.annotation.Nullable;
23 
24 import com.android.launcher3.model.data.ItemInfoWithIcon;
25 
26 import java.util.Optional;
27 
28 /**
29  * Meta data that is used for deferred binding. e.g., this object is used to pass information on
30  * draggable targets when they are dropped onto the workspace from another container.
31  */
32 public class PendingAddItemInfo extends ItemInfoWithIcon {
33 
34     /**
35      * The component that will be created.
36      */
37     public ComponentName componentName;
38 
PendingAddItemInfo()39     public PendingAddItemInfo() { }
40 
PendingAddItemInfo(PendingAddItemInfo info)41     public PendingAddItemInfo(PendingAddItemInfo info) {
42         super(info);
43         componentName = info.componentName;
44     }
45 
46     @Override
dumpProperties()47     protected String dumpProperties() {
48         return super.dumpProperties() + " componentName=" + componentName;
49     }
50 
51     /**
52      * Returns shallow copy of the object.
53      */
54     @NonNull
55     @Override
makeShallowCopy()56     public PendingAddItemInfo makeShallowCopy() {
57         PendingAddItemInfo itemInfo = new PendingAddItemInfo();
58         itemInfo.copyFrom(this);
59         itemInfo.componentName = this.componentName;
60         return itemInfo;
61     }
62 
63     @Override
clone()64     public PendingAddItemInfo clone() {
65         return makeShallowCopy();
66     }
67 
68     @Nullable
69     @Override
getTargetComponent()70     public ComponentName getTargetComponent() {
71         return Optional.ofNullable(super.getTargetComponent()).orElse(componentName);
72     }
73 
74 }
75