@Test public void testShortcutWithIdenticalIdGetsUpdated() throws Exception { ShortcutInfo shortcut1 = createShortcut("id1"); when(shortcut1.getLongLabel()).thenReturn("original"); ShortcutInfo shortcut2 = createShortcut("id1"); when(shortcut2.getLongLabel()).thenReturn("updated"); shortcutManager.addDynamicShortcuts(ImmutableList.of(shortcut1)); assertThat(shortcutManager.getDynamicShortcuts()).hasSize(1); shortcutManager.addDynamicShortcuts(ImmutableList.of(shortcut2)); assertThat(shortcutManager.getDynamicShortcuts()).hasSize(1); assertThat(shortcutManager.getDynamicShortcuts().get(0).getLongLabel()).isEqualTo("updated"); }
@Test public void testDynamicShortcuts_immutableShortcutDoesntGetUpdated() throws Exception { ShortcutInfo shortcut1 = createShortcut("id1", true /* isImmutable */); when(shortcut1.getLongLabel()).thenReturn("original"); ShortcutInfo shortcut2 = createShortcut("id1", true /* isImmutable */); when(shortcut2.getLongLabel()).thenReturn("updated"); shortcutManager.addDynamicShortcuts(ImmutableList.of(shortcut1)); assertThat(shortcutManager.getDynamicShortcuts()).hasSize(1); shortcutManager.addDynamicShortcuts(ImmutableList.of(shortcut2)); assertThat(shortcutManager.getDynamicShortcuts()).hasSize(1); assertThat(shortcutManager.getDynamicShortcuts().get(0).getLongLabel()).isEqualTo("original"); }
@Test @Config(minSdk = Build.VERSION_CODES.O) public void testUpdateShortcut_pinned() throws Exception { ShortcutInfo shortcut1 = createShortcut("id1"); when(shortcut1.getLongLabel()).thenReturn("original"); ShortcutInfo shortcutUpdated = createShortcut("id1"); when(shortcutUpdated.getLongLabel()).thenReturn("updated"); shortcutManager.requestPinShortcut( shortcut1, null /* resultIntent */); assertThat(shortcutManager.getPinnedShortcuts()).containsExactly(shortcut1); shortcutManager.updateShortcuts(ImmutableList.of(shortcutUpdated)); assertThat(shortcutManager.getPinnedShortcuts()).containsExactly(shortcutUpdated); }
@Test public void testUpdateShortcut_dynamic() throws Exception { ShortcutInfo shortcut1 = createShortcut("id1"); when(shortcut1.getLongLabel()).thenReturn("original"); ShortcutInfo shortcutUpdated = createShortcut("id1"); when(shortcutUpdated.getLongLabel()).thenReturn("updated"); shortcutManager.addDynamicShortcuts( ImmutableList.of(shortcut1)); assertThat(shortcutManager.getDynamicShortcuts()).containsExactly(shortcut1); shortcutManager.updateShortcuts(ImmutableList.of(shortcutUpdated)); assertThat(shortcutManager.getDynamicShortcuts()).containsExactly(shortcutUpdated); }
@Test public void testUpdateShortcutsOnlyUpdatesExistingShortcuts() throws Exception { ShortcutInfo shortcut1 = createShortcut("id1"); when(shortcut1.getLongLabel()).thenReturn("original"); ShortcutInfo shortcutUpdated = createShortcut("id1"); when(shortcutUpdated.getLongLabel()).thenReturn("updated"); ShortcutInfo shortcut2 = createShortcut("id2"); shortcutManager.addDynamicShortcuts(ImmutableList.of(shortcut1)); assertThat(shortcutManager.getDynamicShortcuts()).containsExactly(shortcut1); shortcutManager.updateShortcuts(ImmutableList.of(shortcutUpdated, shortcut2)); assertThat(shortcutManager.getDynamicShortcuts()).containsExactly(shortcutUpdated); assertThat(shortcutManager.getDynamicShortcuts().get(0).getLongLabel()).isEqualTo("updated"); }
} else if (shortcutInfo.getLongLabel() != null) { pojo.setName(shortcutInfo.getLongLabel().toString()); } else { Log.d(TAG, "Invalid shortcut " + pojo.id + ", ignoring");
public CharSequence getLongLabel() { return mShortcutInfo.getLongLabel(); }
public CharSequence getLongLabel() { return mShortcutInfo.getLongLabel(); }
public CharSequence getLongLabel() { return mShortcutInfo.getLongLabel(); }
private void addShortcutToActionPopup(final LauncherApps launcherApps, final ShortcutInfo shortcutInfo) { if (Build.VERSION.SDK_INT>=25) { if (shortcutInfo != null && shortcutInfo.getActivity() != null) { //Log.d(TAG, shortcutInfo.getShortLabel() + " " + shortcutInfo.getActivity().getClassName()); if (shortcutInfo.isEnabled()) { String label = ""; if (shortcutInfo.getShortLabel() != null) label += shortcutInfo.getShortLabel(); if (shortcutInfo.getLongLabel() != null && !label.contentEquals(shortcutInfo.getLongLabel())) label = shortcutInfo.getLongLabel() + ""; Drawable icon = launcherApps.getShortcutIconDrawable(shortcutInfo, DisplayMetrics.DENSITY_DEFAULT); addActionMenuItem(label.trim(), icon, new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT >= 25) { try { launcherApps.startShortcut(shortcutInfo, null, null); } catch (Exception e) { Log.e(TAG, "Couldn't Launch shortcut", e); } } dismissActionPopup(); } }); } } } }
@TargetApi(Build.VERSION_CODES.O) private void acceptShortcut(LauncherApps launcherApps, LauncherApps.PinItemRequest request) { ShortcutReceiver shrecv = GlobState.getShortcutReceiver(this); if (shrecv == null) { return; } ShortcutInfo si = request.getShortcutInfo(); if (si == null) { return; } Drawable iconDrawable = launcherApps.getShortcutIconDrawable(si, 0); Bitmap icon = null; if (iconDrawable != null) { icon = IconsHandler.drawableToBitmap(iconDrawable); } String label = null; if (si.getShortLabel() != null) { label = si.getShortLabel().toString(); CharSequence longlabel = si.getLongLabel(); if (longlabel != null) { if (longlabel.toString().startsWith(label)) { label = longlabel.toString(); } else { label += " " + longlabel; } } } shrecv.addOreoLink(this, si.getId(), si.getPackage(), label, icon); request.accept(); }
.setLongLabel(prevShortcut.getLongLabel()) .setIntent(shortcutIntent) .setIcon(Icon.createWithResource(context, R.drawable.circle))