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