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