use of android.content.pm.LauncherActivityInfo in project robolectric by robolectric.
the class ShadowLauncherAppsTest method getShortcutConfigActivityList_packageNull_getsShortcutFromAllPackagesForUser.
@Test
@Config(minSdk = O, maxSdk = R)
public void getShortcutConfigActivityList_packageNull_getsShortcutFromAllPackagesForUser() {
LauncherActivityInfo launcherActivityInfo1 = createLauncherActivityInfoPostN(TEST_PACKAGE_NAME, USER_HANDLE);
LauncherActivityInfo launcherActivityInfo2 = createLauncherActivityInfoPostN(TEST_PACKAGE_NAME_2, USER_HANDLE);
LauncherActivityInfo launcherActivityInfo3 = createLauncherActivityInfoPostN(TEST_PACKAGE_NAME_3, UserHandle.of(10));
shadowOf(launcherApps).addShortcutConfigActivity(USER_HANDLE, launcherActivityInfo1);
shadowOf(launcherApps).addShortcutConfigActivity(USER_HANDLE, launcherActivityInfo2);
shadowOf(launcherApps).addShortcutConfigActivity(UserHandle.of(10), launcherActivityInfo3);
assertThat(launcherApps.getShortcutConfigActivityList(null, USER_HANDLE)).containsExactly(launcherActivityInfo1, launcherActivityInfo2);
}
use of android.content.pm.LauncherActivityInfo in project robolectric by robolectric.
the class ShadowLauncherAppsTest method getShortcutConfigActivityListS_packageNull_getsShortcutFromAllPackagesForUser.
@Test
@Config(minSdk = S)
public void getShortcutConfigActivityListS_packageNull_getsShortcutFromAllPackagesForUser() {
LauncherActivityInfo launcherActivityInfo1 = createLauncherActivityInfoS(TEST_PACKAGE_NAME, USER_HANDLE);
LauncherActivityInfo launcherActivityInfo2 = createLauncherActivityInfoS(TEST_PACKAGE_NAME_2, USER_HANDLE);
LauncherActivityInfo launcherActivityInfo3 = createLauncherActivityInfoS(TEST_PACKAGE_NAME_3, UserHandle.of(10));
shadowOf(launcherApps).addShortcutConfigActivity(USER_HANDLE, launcherActivityInfo1);
shadowOf(launcherApps).addShortcutConfigActivity(USER_HANDLE, launcherActivityInfo2);
shadowOf(launcherApps).addShortcutConfigActivity(UserHandle.of(10), launcherActivityInfo3);
assertThat(launcherApps.getShortcutConfigActivityList(null, USER_HANDLE)).containsExactly(launcherActivityInfo1, launcherActivityInfo2);
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class StartMenuController method generateAppEntries.
@VisibleForTesting
List<AppEntry> generateAppEntries(Context context, UserManager userManager, PackageManager pm, List<LauncherActivityInfo> queryList) {
final List<AppEntry> entries = new ArrayList<>();
Drawable defaultIcon = pm.getDefaultActivityIcon();
for (LauncherActivityInfo appInfo : queryList) {
// Attempt to work around frequently reported OutOfMemoryErrors
String label;
Drawable icon;
try {
label = appInfo.getLabel().toString();
icon = IconCache.getInstance(context).getIcon(context, pm, appInfo);
} catch (OutOfMemoryError e) {
System.gc();
label = appInfo.getApplicationInfo().packageName;
icon = defaultIcon;
}
String packageName = appInfo.getApplicationInfo().packageName;
ComponentName componentName = new ComponentName(packageName, appInfo.getName());
AppEntry newEntry = new AppEntry(packageName, componentName.flattenToString(), label, icon, false);
newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
entries.add(newEntry);
}
return entries;
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class StartMenuController method refreshApps.
private void refreshApps(final String query, final boolean firstDraw) {
if (thread != null)
thread.interrupt();
handler = U.newHandler();
thread = new Thread(() -> {
if (pm == null)
pm = context.getPackageManager();
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
final List<UserHandle> userHandles = userManager.getUserProfiles();
final List<LauncherActivityInfo> unfilteredList = new ArrayList<>();
for (UserHandle handle : userHandles) {
unfilteredList.addAll(launcherApps.getActivityList(null, handle));
}
final List<LauncherActivityInfo> topAppsList = new ArrayList<>();
final List<LauncherActivityInfo> allAppsList = new ArrayList<>();
final List<LauncherActivityInfo> list = new ArrayList<>();
TopApps topApps = TopApps.getInstance(context);
for (LauncherActivityInfo appInfo : unfilteredList) {
String userSuffix = ":" + userManager.getSerialNumberForUser(appInfo.getUser());
if (topApps.isTopApp(appInfo.getComponentName().flattenToString() + userSuffix) || topApps.isTopApp(appInfo.getComponentName().flattenToString()) || topApps.isTopApp(appInfo.getName()))
topAppsList.add(appInfo);
}
Blacklist blacklist = Blacklist.getInstance(context);
for (LauncherActivityInfo appInfo : unfilteredList) {
String userSuffix = ":" + userManager.getSerialNumberForUser(appInfo.getUser());
if (!(blacklist.isBlocked(appInfo.getComponentName().flattenToString() + userSuffix) || blacklist.isBlocked(appInfo.getComponentName().flattenToString()) || blacklist.isBlocked(appInfo.getName())) && !(topApps.isTopApp(appInfo.getComponentName().flattenToString() + userSuffix) || topApps.isTopApp(appInfo.getComponentName().flattenToString()) || topApps.isTopApp(appInfo.getName())))
allAppsList.add(appInfo);
}
Collections.sort(topAppsList, comparator);
Collections.sort(allAppsList, comparator);
list.addAll(topAppsList);
list.addAll(allAppsList);
topAppsList.clear();
allAppsList.clear();
List<LauncherActivityInfo> queryList;
if (query == null)
queryList = list;
else {
queryList = new ArrayList<>();
for (LauncherActivityInfo appInfo : list) {
if (appInfo.getLabel().toString().toLowerCase().contains(query.toLowerCase()))
queryList.add(appInfo);
}
}
// Now that we've generated the list of apps,
// we need to determine if we need to redraw the start menu or not
boolean shouldRedrawStartMenu = false;
List<String> finalApplicationIds = new ArrayList<>();
if (query == null && !firstDraw) {
for (LauncherActivityInfo appInfo : queryList) {
finalApplicationIds.add(appInfo.getApplicationInfo().packageName);
}
if (finalApplicationIds.size() != currentStartMenuIds.size())
shouldRedrawStartMenu = true;
else {
for (int i = 0; i < finalApplicationIds.size(); i++) {
if (!finalApplicationIds.get(i).equals(currentStartMenuIds.get(i))) {
shouldRedrawStartMenu = true;
break;
}
}
}
} else
shouldRedrawStartMenu = true;
if (shouldRedrawStartMenu) {
if (query == null)
currentStartMenuIds = finalApplicationIds;
final List<AppEntry> entries = generateAppEntries(context, userManager, pm, queryList);
handler.post(() -> {
String queryText = searchView.getQuery().toString();
if (query == null && queryText.length() == 0 || query != null && query.equals(queryText)) {
if (firstDraw) {
SharedPreferences pref = U.getSharedPreferences(context);
if (pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid")) {
startMenu.setNumColumns(context.getResources().getInteger(R.integer.tb_start_menu_columns));
adapter = new StartMenuAdapter(context, R.layout.tb_row_alt, entries);
} else
adapter = new StartMenuAdapter(context, R.layout.tb_row, entries);
startMenu.setAdapter(adapter);
}
int position = startMenu.getFirstVisiblePosition();
if (!firstDraw && adapter != null)
adapter.updateList(entries);
startMenu.setSelection(position);
if (adapter != null && adapter.getCount() > 0)
textView.setText(null);
else if (query != null)
textView.setText(context.getString(Patterns.WEB_URL.matcher(query).matches() ? R.string.tb_press_enter_alt : R.string.tb_press_enter));
else
textView.setText(context.getString(R.string.tb_nothing_to_see_here));
}
});
}
});
thread.start();
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class ContextMenuActivity method onPreferenceClick.
@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.N_MR1)
@Override
public boolean onPreferenceClick(Preference p) {
UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
boolean appIsValid = isStartButton || isOverflowMenu || desktopIcon != null || (entry != null && !launcherApps.getActivityList(entry.getPackageName(), userManager.getUserForSerialNumber(entry.getUserId(this))).isEmpty());
secondaryMenu = false;
if (appIsValid)
switch(p.getKey()) {
case PREF_APP_INFO:
U.launchApp(this, () -> launcherApps.startAppDetailsActivity(ComponentName.unflattenFromString(entry.getComponentName()), userManager.getUserForSerialNumber(entry.getUserId(this)), null, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder()))));
prepareToClose();
break;
case PREF_UNINSTALL:
if (U.hasFreeformSupport(this) && isInMultiWindowMode()) {
Intent intent2 = new Intent(this, DummyActivity.class);
intent2.putExtra("uninstall", entry.getPackageName());
intent2.putExtra("user_id", entry.getUserId(this));
try {
startActivity(intent2);
} catch (IllegalArgumentException ignored) {
}
} else {
Intent intent2 = new Intent(Intent.ACTION_DELETE, Uri.parse("package:" + entry.getPackageName()));
intent2.putExtra(Intent.EXTRA_USER, userManager.getUserForSerialNumber(entry.getUserId(this)));
try {
startActivity(intent2);
} catch (ActivityNotFoundException | IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_OPEN_TASKBAR_SETTINGS:
U.launchApp(this, () -> {
Intent intent2 = new Intent(this, MainActivity.class);
intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
LauncherHelper helper = LauncherHelper.getInstance();
if (helper.isOnHomeScreen(this) || helper.isOnSecondaryHomeScreen(this))
U.applyOpenInNewWindow(this, intent2);
try {
startActivity(intent2, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_QUIT_TASKBAR:
Intent quitIntent = new Intent(ACTION_QUIT);
quitIntent.setPackage(getPackageName());
sendBroadcast(quitIntent);
prepareToClose();
break;
case PREF_PIN_APP:
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(this);
if (pba.isPinned(entry.getComponentName()))
pba.removePinnedApp(this, entry.getComponentName());
else {
Intent intent = new Intent();
intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
LauncherActivityInfo appInfo = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(entry.getUserId(this)));
if (appInfo != null) {
AppEntry newEntry = new AppEntry(entry.getPackageName(), entry.getComponentName(), entry.getLabel(), IconCache.getInstance(this).getIcon(this, appInfo), true);
newEntry.setUserId(entry.getUserId(this));
pba.addPinnedApp(this, newEntry);
}
}
break;
case PREF_BLOCK_APP:
PinnedBlockedApps pba2 = PinnedBlockedApps.getInstance(this);
if (pba2.isBlocked(entry.getComponentName()))
pba2.removeBlockedApp(this, entry.getComponentName());
else
pba2.addBlockedApp(this, entry);
break;
case PREF_SHOW_WINDOW_SIZES:
generateWindowSizes();
if (U.hasBrokenSetLaunchBoundsApi())
U.showToastLong(this, R.string.tb_window_sizes_not_available);
getListView().setOnItemLongClickListener((parent, view, position, id) -> {
String[] windowSizes = getResources().getStringArray(R.array.tb_pref_window_size_list_values);
SavedWindowSizes.getInstance(this).setWindowSize(this, entry.getPackageName(), windowSizes[position]);
generateWindowSizes();
return true;
});
secondaryMenu = true;
break;
case PREF_WINDOW_SIZE_STANDARD:
case PREF_WINDOW_SIZE_LARGE:
case PREF_WINDOW_SIZE_FULLSCREEN:
case PREF_WINDOW_SIZE_HALF_LEFT:
case PREF_WINDOW_SIZE_HALF_RIGHT:
case PREF_WINDOW_SIZE_PHONE_SIZE:
String windowSize = p.getKey().replace("window_size_", "");
SharedPreferences pref2 = U.getSharedPreferences(this);
if (pref2.getBoolean(PREF_SAVE_WINDOW_SIZES, true)) {
SavedWindowSizes.getInstance(this).setWindowSize(this, entry.getPackageName(), windowSize);
}
U.launchApp(U.getDisplayContext(this), entry, windowSize, false, true, getListView().getChildAt(p.getOrder()));
if (U.hasBrokenSetLaunchBoundsApi())
U.cancelToast();
prepareToClose();
break;
case PREF_APP_SHORTCUTS:
getPreferenceScreen().removeAll();
generateShortcuts();
secondaryMenu = true;
break;
case PREF_SHORTCUT_1:
case PREF_SHORTCUT_2:
case PREF_SHORTCUT_3:
case PREF_SHORTCUT_4:
case PREF_SHORTCUT_5:
U.startShortcut(U.getDisplayContext(this), entry, shortcuts.get(Integer.parseInt(p.getKey().replace("shortcut_", "")) - 1), getListView().getChildAt(p.getOrder()));
prepareToClose();
break;
case PREF_START_MENU_APPS:
Intent intent = U.getThemedIntent(this, SelectAppActivity.class);
if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && isInMultiWindowMode()) {
intent.putExtra("no_shadow", true);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
U.startActivityMaximized(U.getDisplayContext(this), intent);
} else {
try {
startActivity(intent);
} catch (IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_VOLUME:
AudioManager audio = (AudioManager) getSystemService(AUDIO_SERVICE);
audio.adjustSuggestedStreamVolume(AudioManager.ADJUST_SAME, AudioManager.USE_DEFAULT_STREAM_TYPE, AudioManager.FLAG_SHOW_UI);
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
U.showToast(this, R.string.tb_opening_volume_control);
U.sendBroadcast(this, ACTION_UNDIM_SCREEN);
}
prepareToClose();
break;
case PREF_FILE_MANAGER:
U.launchApp(this, () -> {
Intent fileManagerIntent;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
fileManagerIntent = new Intent(Intent.ACTION_VIEW);
else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
fileManagerIntent = new Intent("android.provider.action.BROWSE");
else {
fileManagerIntent = new Intent("android.provider.action.BROWSE_DOCUMENT_ROOT");
fileManagerIntent.setComponent(ComponentName.unflattenFromString("com.android.documentsui/.DocumentsActivity"));
}
fileManagerIntent.addCategory(Intent.CATEGORY_DEFAULT);
fileManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
fileManagerIntent.setData(Uri.parse("content://com.android.externalstorage.documents/root/primary"));
try {
startActivity(fileManagerIntent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (ActivityNotFoundException e) {
U.showToast(this, R.string.tb_lock_device_not_supported);
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_SYSTEM_SETTINGS:
U.launchApp(this, () -> {
Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS);
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(settingsIntent, U.getActivityOptionsBundle(this, ApplicationType.APP_PORTRAIT, getListView().getChildAt(p.getOrder())));
} catch (ActivityNotFoundException e) {
U.showToast(this, R.string.tb_lock_device_not_supported);
} catch (IllegalArgumentException ignored) {
}
});
prepareToClose();
break;
case PREF_LOCK_DEVICE:
U.lockDevice(this);
prepareToClose();
break;
case PREF_POWER_MENU:
U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG, () -> {
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
U.showToast(this, R.string.tb_opening_power_menu);
U.sendBroadcast(this, ACTION_UNDIM_SCREEN);
}
});
prepareToClose();
break;
case PREF_ADD_ICON_TO_DESKTOP:
Intent intent2 = U.getThemedIntent(this, DesktopIconSelectAppActivity.class);
intent2.putExtra("desktop_icon", desktopIcon);
if (U.hasFreeformSupport(this) && U.isFreeformModeEnabled(this) && isInMultiWindowMode()) {
intent2.putExtra("no_shadow", true);
intent2.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
U.startActivityMaximized(U.getDisplayContext(this), intent2);
} else {
try {
startActivity(intent2);
} catch (IllegalArgumentException ignored) {
}
}
prepareToClose();
break;
case PREF_ARRANGE_ICONS:
U.sendBroadcast(this, ACTION_ENTER_ICON_ARRANGE_MODE);
break;
case PREF_SORT_BY_NAME:
U.sendBroadcast(this, ACTION_SORT_DESKTOP_ICONS);
break;
case PREF_CHANGE_WALLPAPER:
if (LauncherHelper.getInstance().isOnSecondaryHomeScreen(this)) {
generateWallpaperOptions();
secondaryMenu = true;
} else if (U.isChromeOs(this)) {
U.sendBroadcast(this, ACTION_WALLPAPER_CHANGE_REQUESTED);
} else {
changeWallpaper();
prepareToClose();
}
break;
case PREF_REMOVE_DESKTOP_ICON:
try {
SharedPreferences pref5 = U.getSharedPreferences(this);
JSONArray jsonIcons = new JSONArray(pref5.getString(PREF_DESKTOP_ICONS, "[]"));
int iconToRemove = -1;
for (int i = 0; i < jsonIcons.length(); i++) {
DesktopIconInfo info = DesktopIconInfo.fromJson(jsonIcons.getJSONObject(i));
if (info != null && info.column == desktopIcon.column && info.row == desktopIcon.row) {
iconToRemove = i;
break;
}
}
if (iconToRemove > -1) {
jsonIcons.remove(iconToRemove);
pref5.edit().putString(PREF_DESKTOP_ICONS, jsonIcons.toString()).apply();
U.sendBroadcast(this, ACTION_REFRESH_DESKTOP_ICONS);
}
} catch (JSONException ignored) {
}
break;
case PREF_CHANGE_WALLPAPER_GLOBAL:
changeWallpaper();
prepareToClose();
break;
case PREF_CHANGE_WALLPAPER_DESKTOP:
U.sendBroadcast(this, ACTION_WALLPAPER_CHANGE_REQUESTED);
break;
case PREF_REMOVE_DESKTOP_WALLPAPER:
U.sendBroadcast(this, ACTION_REMOVE_DESKTOP_WALLPAPER);
break;
}
if (!secondaryMenu)
finish();
return true;
}
Aggregations