android.content.pm.ShortcutInfo Java Examples

The following examples show how to use android.content.pm.ShortcutInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AegisApplication.java    From Aegis with GNU General Public License v3.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void initAppShortcuts() {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("action", "scan");
    intent.setAction(Intent.ACTION_MAIN);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_new")
            .setShortLabel(getString(R.string.new_entry))
            .setLongLabel(getString(R.string.add_new_entry))
            .setIcon(Icon.createWithResource(this, R.drawable.ic_qr_code))
            .setIntent(intent)
            .build();

    shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
 
Example #2
Source File: MainActivity.java    From SecondScreen with Apache License 2.0 6 votes vote down vote up
private void setLauncherShortcuts() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        if(shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName());
            intent.putExtra("launched-from-app", true);

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions")
                    .setShortLabel(getString(R.string.label_quick_actions))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon))
                    .setIntent(intent)
                    .build();

            shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
        }
    }
}
 
Example #3
Source File: ResourcesShortcutActivityGenerated.java    From shortbread with Apache License 2.0 6 votes vote down vote up
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
Example #4
Source File: AppUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fetch and return shortcuts for a specific app.
 *
 * @param launcherApps  LauncherApps service from an activity.
 * @param componentName The component name to flatten to package name.
 *
 * @return A list of shortcut. Null if nonexistent.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
public static List<ShortcutInfo> getShortcuts(LauncherApps launcherApps, String componentName) {
    // Return nothing if we don't have permission to retrieve shortcuts.
    if (launcherApps == null || !launcherApps.hasShortcutHostPermission()) {
        return new ArrayList<>(0);
    }

    LauncherApps.ShortcutQuery shortcutQuery = new LauncherApps.ShortcutQuery();
    shortcutQuery.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
            | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
            | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);
    shortcutQuery.setPackage(getPackageName(componentName));

    return launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle());
}
 
Example #5
Source File: ShortcutHelper.java    From zapp with MIT License 6 votes vote down vote up
/**
 * Adds the given channel as shortcut to the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context to access system services
 * @param channel channel to create a shortcut for
 * @return true if the channel could be added
 */
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
	ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

	if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
		return false;
	}

	ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
		.setShortLabel(channel.getName())
		.setLongLabel(channel.getName())
		.setIcon(Icon.createWithResource(context, channel.getDrawableId()))
		.setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
		.build();

	try {
		return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
	} catch (IllegalArgumentException e) {
		// too many shortcuts
		return false;
	}
}
 
Example #6
Source File: Helper.java    From AppOpsX with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static void updataShortcuts(Context context, List<AppInfo> items) {
  ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
  List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
  int max = shortcutManager.getMaxShortcutCountPerActivity();
  for (int i = 0; i < max && i < items.size(); i++) {
    AppInfo appInfo = items.get(i);
    ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName);
    shortcut.setShortLabel(appInfo.appName);
    shortcut.setLongLabel(appInfo.appName);

    shortcut.setIcon(
        Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo))));

    Intent intent = new Intent(context, AppPermissionActivity.class);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName);
    intent.setAction(Intent.ACTION_DEFAULT);
    shortcut.setIntent(intent);

    shortcutInfoList.add(shortcut.build());
  }
  shortcutManager.setDynamicShortcuts(shortcutInfoList);
}
 
Example #7
Source File: UIUtils.java    From rebootmenu with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 启动器添加快捷方式
 *
 * @param context     上下文
 * @param titleRes    标题资源id
 * @param iconRes     图标资源id
 * @param shortcutAct Shortcut额外
 * @param isForce     是否是root强制模式
 * @see com.ryuunoakaihitomi.rebootmenu.activity.Shortcut
 */
public static void addLauncherShortcut(@NonNull Context context, @StringRes int titleRes, @DrawableRes int iconRes, int shortcutAct, boolean isForce) {
    new DebugLog("addLauncherShortcut", DebugLog.LogLevel.V);
    String forceToken = isForce ? "*" : "";
    String title = forceToken + context.getString(titleRes);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        context.sendBroadcast(new Intent("com.android.launcher.action.INSTALL_SHORTCUT")
                .putExtra("duplicate", false)
                .putExtra(Intent.EXTRA_SHORTCUT_NAME, title)
                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, iconRes))
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(context, Shortcut.class)
                        .putExtra(Shortcut.extraTag, shortcutAct)));
    else {
        ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, "o_launcher_shortcut:" + shortcutAct)
                .setShortLabel(title)
                .setIcon(Icon.createWithResource(context, iconRes))
                .setIntent(new Intent(context, Shortcut.class)
                        .putExtra(Shortcut.extraTag, shortcutAct)
                        .setAction(Intent.ACTION_VIEW))
                .build();
        new DebugLog("addLauncherShortcut: requestPinShortcut:"
                + context.getSystemService(ShortcutManager.class).requestPinShortcut(shortcutInfo, null));
    }
}
 
Example #8
Source File: App.java    From hash-checker with Apache License 2.0 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
@SuppressLint("ResourceType")
@NonNull
private ShortcutInfo getShortcut(
        @NonNull String id,
        @IdRes int labelResId,
        @IdRes int iconResId,
        @NonNull String intentAction
) {
    Intent intent = new Intent(
            this,
            MainActivity.class
    );
    intent.setAction(intentAction);
    return new ShortcutInfo.Builder(this, id)
            .setShortLabel(getString(labelResId))
            .setIcon(
                    Icon.createWithResource(
                            this,
                            iconResId
                    )
            )
            .setIntent(intent)
            .build();
}
 
Example #9
Source File: MainActivity.java    From Android7_Shortcuts_Demo with Apache License 2.0 6 votes vote down vote up
private void setupShortcuts() {
        mShortcutManager = getSystemService(ShortcutManager.class);

        List<ShortcutInfo> infos = new ArrayList<>();
        for (int i = 0; i < mShortcutManager.getMaxShortcutCountPerActivity(); i++) {
            Intent intent = new Intent(this, MessageActivity.class);
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra("msg", "我和" + mAdapter.getItem(i) + "的对话");

            ShortcutInfo info = new ShortcutInfo.Builder(this, "id" + i)
                    .setShortLabel(mAdapter.getItem(i))
                    .setLongLabel("联系人:" + mAdapter.getItem(i))
                    .setIcon(Icon.createWithResource(this, R.drawable.icon))
                    .setIntent(intent)
                    .build();
            infos.add(info);
//            manager.addDynamicShortcuts(Arrays.asList(info));
        }

        mShortcutManager.setDynamicShortcuts(infos);
    }
 
Example #10
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 6 votes vote down vote up
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addRemoteToAppShortcuts(Context context, RemoteItem remoteItem, String id) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName());

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id)
            .setShortLabel(remoteItem.getName())
            .setIcon(Icon.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
            .setIntent(intent)
            .build();

    shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
 
Example #11
Source File: ShortcutHelper.java    From android-proguards with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
 
Example #12
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Build a list of shortcuts for each target activity and return as a map. The result won't
 * contain "floating" shortcuts because they don't belong on any activities.
 */
private ArrayMap<ComponentName, ArrayList<ShortcutInfo>> sortShortcutsToActivities() {
    final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> activitiesToShortcuts
            = new ArrayMap<>();
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.isFloating()) {
            continue; // Ignore floating shortcuts, which are not tied to any activities.
        }

        final ComponentName activity = si.getActivity();
        if (activity == null) {
            mShortcutUser.mService.wtf("null activity detected.");
            continue;
        }

        ArrayList<ShortcutInfo> list = activitiesToShortcuts.get(activity);
        if (list == null) {
            list = new ArrayList<>();
            activitiesToShortcuts.put(activity, list);
        }
        list.add(si);
    }
    return activitiesToShortcuts;
}
 
Example #13
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isPinnedByCaller(int launcherUserId, @NonNull String callingPackage,
        @NonNull String packageName, @NonNull String shortcutId, int userId) {
    Preconditions.checkStringNotEmpty(packageName, "packageName");
    Preconditions.checkStringNotEmpty(shortcutId, "shortcutId");

    synchronized (mLock) {
        throwIfUserLockedL(userId);
        throwIfUserLockedL(launcherUserId);

        getLauncherShortcutsLocked(callingPackage, userId, launcherUserId)
                .attemptToRestoreIfNeededAndSave();

        final ShortcutInfo si = getShortcutInfoLocked(
                launcherUserId, callingPackage, packageName, shortcutId, userId,
                /*getPinnedByAnyLauncher=*/ false);
        return si != null && si.isPinned();
    }
}
 
Example #14
Source File: ShortcutsUtils.java    From shortrain with MIT License 6 votes vote down vote up
public static int getNextRailNumber(ShortcutManager shortcutManager) {
    List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts();

    int newRailId = -1;

    for (ShortcutInfo shortcutInfo : shortcuts) {
        String id = shortcutInfo.getId();
        if (isRailShortcut(id)) {
            int railId = getRailNumber(id);
            if (railId > newRailId) {
                newRailId = railId;
            }
        }
    }

    newRailId++;

    return newRailId;
}
 
Example #15
Source File: AppUtils.java    From HgLauncher with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fetch and return shortcuts for a specific app.
 *
 * @param launcherApps  LauncherApps service from an activity.
 * @param componentName The component name to flatten to package name.
 *
 * @return A list of shortcut. Null if nonexistent.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
public static List<ShortcutInfo> getShortcuts(LauncherApps launcherApps, String componentName) {
    // Return nothing if we don't have permission to retrieve shortcuts.
    if (launcherApps == null || !launcherApps.hasShortcutHostPermission()) {
        return new ArrayList<>(0);
    }

    LauncherApps.ShortcutQuery shortcutQuery = new LauncherApps.ShortcutQuery();
    shortcutQuery.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
            | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
            | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);
    shortcutQuery.setPackage(getPackageName(componentName));

    return launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle());
}
 
Example #16
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void disableShortcuts(String packageName, List shortcutIds,
        CharSequence disabledMessage, int disabledMessageResId, @UserIdInt int userId) {
    verifyCaller(packageName, userId);
    Preconditions.checkNotNull(shortcutIds, "shortcutIds must be provided");

    synchronized (mLock) {
        throwIfUserLockedL(userId);

        final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(packageName, userId);

        ps.ensureImmutableShortcutsNotIncludedWithIds((List<String>) shortcutIds,
                /*ignoreInvisible=*/ true);

        final String disabledMessageString =
                (disabledMessage == null) ? null : disabledMessage.toString();

        for (int i = shortcutIds.size() - 1; i >= 0; i--) {
            final String id = Preconditions.checkStringNotEmpty((String) shortcutIds.get(i));
            if (!ps.isShortcutExistsAndVisibleToPublisher(id)) {
                continue;
            }
            ps.disableWithId(id,
                    disabledMessageString, disabledMessageResId,
                    /* overrideImmutable=*/ false, /*ignoreInvisible=*/ true,
                    ShortcutInfo.DISABLED_REASON_BY_APP);
        }

        // We may have removed dynamic shortcuts which may have left a gap, so adjust the ranks.
        ps.adjustRanks();
    }
    packageShortcutsChanged(packageName, userId);

    verifyStates();
}
 
Example #17
Source File: DynamicShortcutManager.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
    return new ShortcutInfo.Builder(context, id)
            .setShortLabel(shortLabel)
            .setLongLabel(longLabel)
            .setIcon(icon)
            .setIntent(intent)
            .build();
}
 
Example #18
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 5 votes vote down vote up
public static void removeAppShortcut(Context context, String remoteName) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
        return;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Set<String> appShortcutIds = sharedPreferences.getStringSet(context.getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>());
    String id = getUniqueIdFromString(remoteName);

    if (!appShortcutIds.contains(id)) {
        return;
    }

    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    List<ShortcutInfo> shortcutInfoList = shortcutManager.getDynamicShortcuts();
    for (ShortcutInfo shortcutInfo : shortcutInfoList) {
        if (shortcutInfo.getId().equals(id)) {
            shortcutManager.removeDynamicShortcuts(Collections.singletonList(shortcutInfo.getId()));
            return;
        }
    }

    SharedPreferences.Editor editor = sharedPreferences.edit();
    appShortcutIds.remove(id);
    Set<String> updateAppShortcutIds = new HashSet<>(appShortcutIds);
    editor.putStringSet(context.getString(R.string.shared_preferences_app_shortcuts), updateAppShortcutIds);
    editor.apply();
}
 
Example #19
Source File: LauncherActivity.java    From paper-launcher with MIT License 5 votes vote down vote up
public void showShortcutsBottomSheet(String packageName, List<ShortcutInfo> shortcutsArrayList) {
    if (isExpandingAppDrawer()) {
        return;
    }

    mShortcutsRecyclerView.setAdapter(new ShortcutsRecyclerViewAdapter(shortcutsArrayList == null
            ? new ArrayList<>()
            : shortcutsArrayList));

    ApplicationInfo applicationInfo;
    try {
        applicationInfo = getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();

        return;
    }

    IconUtil.setIconOnImageView(this, mBottomSheetAppImageView, applicationInfo);

    mBottomSheetAppTextView.setText(applicationInfo.loadLabel(getPackageManager()));

    mBottomSheetAppInfoImageView.setOnClickListener(view -> {
        Intent intent = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
        intent.addCategory(Intent.CATEGORY_DEFAULT);
        intent.setData(Uri.parse("package:" + packageName));
        startActivity(intent);
    });

    BottomSheetBehaviorRecyclerManager manager =
            new BottomSheetBehaviorRecyclerManager(mParentCoordinatorLayout, mBottomSheetBehavior, mBottomSheetView);
    manager.addControl(mShortcutsRecyclerView);
    manager.create();

    mBottomSheetBehavior.setState(BottomSheetBehaviorV2.STATE_EXPANDED);
}
 
Example #20
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
ShortcutInfo getPackageShortcutForTest(String packageName, String shortcutId, int userId) {
    synchronized (mLock) {
        final ShortcutPackage pkg = getPackageShortcutForTest(packageName, userId);
        if (pkg == null) return null;

        return pkg.findShortcutById(shortcutId);
    }
}
 
Example #21
Source File: LastAddedShortcutType.java    From Orin with GNU General Public License v3.0 5 votes vote down vote up
public ShortcutInfo getShortcutInfo() {
    return new ShortcutInfo.Builder(context, getId())
            .setShortLabel(context.getString(R.string.app_shortcut_last_added_short))
            .setLongLabel(context.getString(R.string.app_shortcut_last_added_long))
            .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_last_added))
            .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_LAST_ADDED))
            .build();
}
 
Example #22
Source File: U.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
private static void launchApp(final Context context,
                              final AppEntry entry,
                              final String windowSize,
                              final boolean launchedFromTaskbar,
                              final boolean isPersistentShortcut,
                              final boolean openInNewWindow,
                              final ShortcutInfo shortcut,
                              final View view,
                              final Runnable onError) {
    launchApp(context, launchedFromTaskbar, isPersistentShortcut, () ->
            continueLaunchingApp(context, entry, windowSize, openInNewWindow, shortcut, view, onError)
    );
}
 
Example #23
Source File: ShortcutService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Handles {@link #requestPinShortcut} and {@link ShortcutServiceInternal#requestPinAppWidget}.
 * After validating the caller, it passes the request to {@link #mShortcutRequestPinProcessor}.
 * Either {@param shortcut} or {@param appWidget} should be non-null.
 */
private boolean requestPinItem(String packageName, int userId, ShortcutInfo shortcut,
        AppWidgetProviderInfo appWidget, Bundle extras, IntentSender resultIntent) {
    verifyCaller(packageName, userId);
    verifyShortcutInfoPackage(packageName, shortcut);

    final boolean ret;
    synchronized (mLock) {
        throwIfUserLockedL(userId);

        Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()),
                "Calling application must have a foreground activity or a foreground service");

        // If it's a pin shortcut request, and there's already a shortcut with the same ID
        // that's not visible to the caller (i.e. restore-blocked; meaning it's pinned by
        // someone already), then we just replace the existing one with this new one,
        // and then proceed the rest of the process.
        if (shortcut != null) {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(
                    packageName, userId);
            final String id = shortcut.getId();
            if (ps.isShortcutExistsAndInvisibleToPublisher(id)) {

                ps.updateInvisibleShortcutForPinRequestWith(shortcut);

                packageShortcutsChanged(packageName, userId);
            }
        }

        // Send request to the launcher, if supported.
        ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, extras,
                userId, resultIntent);
    }

    verifyStates();

    return ret;
}
 
Example #24
Source File: LinphoneShortcutManager.java    From linphone-android with GNU General Public License v3.0 5 votes vote down vote up
public ShortcutInfo createContactShortcutInfo(LinphoneContact contact) {
    if (contact == null) return null;

    Bitmap bm = null;
    if (contact.getThumbnailUri() != null) {
        bm = ImageUtils.getRoundBitmapFromUri(mContext, contact.getThumbnailUri());
    }
    Icon icon =
            bm == null
                    ? Icon.createWithResource(mContext, R.drawable.avatar)
                    : Icon.createWithBitmap(bm);

    try {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(mContext, ContactsActivity.class);
        intent.addFlags(
                Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.putExtra("ContactId", contact.getContactId());

        return new ShortcutInfo.Builder(mContext, contact.getContactId())
                .setShortLabel(contact.getFullName())
                .setIcon(icon)
                .setCategories(mCategories)
                .setIntent(intent)
                .build();
    } catch (Exception e) {
        Log.e("[Shortcuts Manager] ShortcutInfo.Builder exception: " + e);
    }

    return null;
}
 
Example #25
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static Intent parseIntent(XmlPullParser parser)
        throws IOException, XmlPullParserException {

    Intent intent = ShortcutService.parseIntentAttribute(parser,
            ATTR_INTENT_NO_EXTRA);

    final int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }
        final int depth = parser.getDepth();
        final String tag = parser.getName();
        if (ShortcutService.DEBUG_LOAD) {
            Slog.d(TAG, String.format("  depth=%d type=%d name=%s",
                    depth, type, tag));
        }
        switch (tag) {
            case TAG_EXTRAS:
                ShortcutInfo.setIntentExtras(intent,
                        PersistableBundle.restoreFromXml(parser));
                continue;
        }
        throw ShortcutService.throwForInvalidTag(depth, tag);
    }
    return intent;
}
 
Example #26
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** @return true if there's any shortcuts that are not manifest shortcuts. */
public boolean hasNonManifestShortcuts() {
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (!si.isDeclaredInManifest()) {
            return true;
        }
    }
    return false;
}
 
Example #27
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/** Clears the implicit ranks for all shortcuts. */
public void clearAllImplicitRanks() {
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        si.clearImplicitRankAndRankChangedFlag();
    }
}
 
Example #28
Source File: TopTracksShortcutType.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public ShortcutInfo getShortcutInfo() {
    return new ShortcutInfo.Builder(context, getId())
            .setShortLabel(context.getString(R.string.app_shortcut_top_tracks_short))
            .setLongLabel(context.getString(R.string.my_top_tracks))
            .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_top_tracks))
            .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_TOP_TRACKS))
            .build();
}
 
Example #29
Source File: DynamicShortcutManager.java    From VinylMusicPlayer with GNU General Public License v3.0 5 votes vote down vote up
public static ShortcutInfo createShortcut(Context context, String id, String shortLabel, String longLabel, Icon icon, Intent intent) {
    return new ShortcutInfo.Builder(context, id)
            .setShortLabel(shortLabel)
            .setLongLabel(longLabel)
            .setIcon(icon)
            .setIntent(intent)
            .build();
}
 
Example #30
Source File: ShortcutPackage.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the filenames (excluding path names) of icon bitmap files from this package.
 */
public ArraySet<String> getUsedBitmapFiles() {
    final ArraySet<String> usedFiles = new ArraySet<>(mShortcuts.size());

    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.getBitmapPath() != null) {
            usedFiles.add(getFileName(si.getBitmapPath()));
        }
    }
    return usedFiles;
}