ShortcutInfoCompat.java revision 70a7c9b70003ae87e2b2968bc6ceded0fe0f0e8b
1/* 2 * Copyright (C) 2016 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 17package com.android.launcher3.shortcuts; 18 19import android.annotation.TargetApi; 20import android.content.ComponentName; 21import android.content.Context; 22import android.content.Intent; 23import android.content.pm.ShortcutInfo; 24import android.os.Build; 25 26import com.android.launcher3.ItemInfo; 27import com.android.launcher3.compat.UserHandleCompat; 28import com.android.launcher3.compat.UserManagerCompat; 29import com.android.launcher3.util.ComponentKey; 30 31/** 32 * Wrapper class for {@link android.content.pm.ShortcutInfo}, representing deep shortcuts into apps. 33 * 34 * Not to be confused with {@link com.android.launcher3.ShortcutInfo}. 35 */ 36@TargetApi(Build.VERSION_CODES.N) 37public class ShortcutInfoCompat { 38 private static final String INTENT_CATEGORY = "com.android.launcher3.DEEP_SHORTCUT"; 39 public static final String EXTRA_SHORTCUT_ID = "shortcut_id"; 40 41 private ShortcutInfo mShortcutInfo; 42 43 public ShortcutInfoCompat(ShortcutInfo shortcutInfo) { 44 mShortcutInfo = shortcutInfo; 45 } 46 47 @TargetApi(Build.VERSION_CODES.N) 48 public Intent makeIntent(Context context) { 49 long serialNumber = UserManagerCompat.getInstance(context) 50 .getSerialNumberForUser(getUserHandle()); 51 return new Intent(Intent.ACTION_MAIN) 52 .addCategory(INTENT_CATEGORY) 53 .setComponent(getActivity()) 54 .setPackage(getPackage()) 55 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) 56 .putExtra(ItemInfo.EXTRA_PROFILE, serialNumber) 57 .putExtra(EXTRA_SHORTCUT_ID, getId()); 58 } 59 60 public ShortcutInfo getShortcutInfo() { 61 return mShortcutInfo; 62 } 63 64 public String getPackage() { 65 return mShortcutInfo.getPackage(); 66 } 67 68 public String getId() { 69 return mShortcutInfo.getId(); 70 } 71 72 public CharSequence getShortLabel() { 73 return mShortcutInfo.getShortLabel(); 74 } 75 76 public CharSequence getLongLabel() { 77 return mShortcutInfo.getLongLabel(); 78 } 79 80 public long getLastChangedTimestamp() { 81 return mShortcutInfo.getLastChangedTimestamp(); 82 } 83 84 public ComponentName getActivity() { 85 return mShortcutInfo.getActivity(); 86 } 87 88 public UserHandleCompat getUserHandle() { 89 return UserHandleCompat.fromUser(mShortcutInfo.getUserHandle()); 90 } 91 92 public boolean hasKeyFieldsOnly() { 93 return mShortcutInfo.hasKeyFieldsOnly(); 94 } 95 96 public boolean isPinned() { 97 return mShortcutInfo.isPinned(); 98 } 99 100 public boolean isDeclaredInManifest() { 101 return mShortcutInfo.isDeclaredInManifest(); 102 } 103 104 public boolean isEnabled() { 105 return mShortcutInfo.isEnabled(); 106 } 107 108 public int getRank() { 109 return mShortcutInfo.getRank(); 110 } 111 112 @Override 113 public String toString() { 114 return mShortcutInfo.toString(); 115 } 116} 117