• 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.app.Activity;
21 import android.content.ComponentName;
22 import android.content.Context;
23 import android.content.pm.LauncherApps;
24 import android.content.pm.ShortcutInfo;
25 import android.graphics.drawable.Drawable;
26 import android.os.Build;
27 
28 import com.android.launcher3.IconCache;
29 import com.android.launcher3.Launcher;
30 import com.android.launcher3.LauncherAppState;
31 import com.android.launcher3.LauncherSettings;
32 import com.android.launcher3.R;
33 import com.android.launcher3.compat.LauncherAppsCompat;
34 import com.android.launcher3.compat.PinItemRequestCompat;
35 import com.android.launcher3.compat.ShortcutConfigActivityInfo;
36 
37 /**
38  * Extension of ShortcutConfigActivityInfo to be used in the confirmation prompt for pin item
39  * request.
40  */
41 @TargetApi(Build.VERSION_CODES.N_MR1)
42 class PinShortcutRequestActivityInfo extends ShortcutConfigActivityInfo {
43 
44     // Class name used in the target component, such that it will never represent an
45     // actual existing class.
46     private static final String DUMMY_COMPONENT_CLASS = "pinned-shortcut";
47 
48     private final PinItemRequestCompat mRequest;
49     private final ShortcutInfo mInfo;
50     private final Context mContext;
51 
PinShortcutRequestActivityInfo(PinItemRequestCompat request, Context context)52     public PinShortcutRequestActivityInfo(PinItemRequestCompat request, Context context) {
53         super(new ComponentName(request.getShortcutInfo().getPackage(), DUMMY_COMPONENT_CLASS),
54                 request.getShortcutInfo().getUserHandle());
55         mRequest = request;
56         mInfo = request.getShortcutInfo();
57         mContext = context;
58     }
59 
60     @Override
getItemType()61     public int getItemType() {
62         return LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT;
63     }
64 
65     @Override
getLabel()66     public CharSequence getLabel() {
67         return mInfo.getShortLabel();
68     }
69 
70     @Override
getFullResIcon(IconCache cache)71     public Drawable getFullResIcon(IconCache cache) {
72         return mContext.getSystemService(LauncherApps.class)
73                 .getShortcutIconDrawable(mInfo, LauncherAppState.getIDP(mContext).fillResIconDpi);
74     }
75 
76     @Override
createShortcutInfo()77     public com.android.launcher3.ShortcutInfo createShortcutInfo() {
78         // Total duration for the drop animation to complete.
79         long duration = mContext.getResources().getInteger(R.integer.config_dropAnimMaxDuration) +
80                 Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT +
81                 mContext.getResources().getInteger(R.integer.config_overlayTransitionTime) / 2;
82         // Delay the actual accept() call until the drop animation is complete.
83         return LauncherAppsCompat.createShortcutInfoFromPinItemRequest(
84                 mContext, mRequest, duration);
85     }
86 
87     @Override
startConfigActivity(Activity activity, int requestCode)88     public boolean startConfigActivity(Activity activity, int requestCode) {
89         return false;
90     }
91 
92     @Override
isPersistable()93     public boolean isPersistable() {
94         return false;
95     }
96 }
97