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.discovery;
18 
19 import android.content.ComponentName;
20 import android.content.Intent;
21 import android.support.annotation.NonNull;
22 import android.support.annotation.Nullable;
23 
24 import com.android.launcher3.AppInfo;
25 import com.android.launcher3.LauncherSettings;
26 import com.android.launcher3.ShortcutInfo;
27 
28 public class AppDiscoveryAppInfo extends AppInfo {
29 
30     public final boolean showAsDiscoveryItem;
31     public final boolean isInstantApp;
32     public final boolean isRecent;
33     public final float rating;
34     public final long reviewCount;
35     public final @NonNull String publisher;
36     public final @NonNull Intent installIntent;
37     public final @NonNull Intent launchIntent;
38     public final @Nullable String priceFormatted;
39 
AppDiscoveryAppInfo(AppDiscoveryItem item)40     public AppDiscoveryAppInfo(AppDiscoveryItem item) {
41         this.intent = item.isInstantApp ? item.launchIntent : item.installIntent;
42         this.title = item.title;
43         this.iconBitmap = item.bitmap;
44         this.isDisabled = ShortcutInfo.DEFAULT;
45         this.usingLowResIcon = false;
46         this.isInstantApp = item.isInstantApp;
47         this.isRecent = item.isRecent;
48         this.rating = item.starRating;
49         this.showAsDiscoveryItem = true;
50         this.publisher = item.publisher != null ? item.publisher : "";
51         this.priceFormatted = item.price;
52         this.componentName = new ComponentName(item.packageName, "");
53         this.installIntent = item.installIntent;
54         this.launchIntent = item.launchIntent;
55         this.reviewCount = item.reviewCount;
56         this.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
57     }
58 
59     @Override
makeShortcut()60     public ShortcutInfo makeShortcut() {
61         if (!isDragAndDropSupported()) {
62             throw new RuntimeException("DnD is currently not supported for discovered store apps");
63         }
64         return super.makeShortcut();
65     }
66 
isDragAndDropSupported()67     public boolean isDragAndDropSupported() {
68         return isInstantApp;
69     }
70 
71 }
72