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