use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class TaskbarController method generateAppEntries.
@VisibleForTesting
void generateAppEntries(Context context, int number, List<AppEntry> usageStatsList6, List<AppEntry> entries, List<LauncherActivityInfo> launcherAppCache) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
final List<UserHandle> userHandles = userManager.getUserProfiles();
final String googleSearchBoxPackage = "com.google.android.googlequicksearchbox";
final String googleSearchBoxActivity = "com.google.android.googlequicksearchbox.SearchActivity";
for (int i = 0; i < number; i++) {
for (UserHandle handle : userHandles) {
String packageName = usageStatsList6.get(i).getPackageName();
long lastTimeUsed = usageStatsList6.get(i).getLastTimeUsed();
List<LauncherActivityInfo> list = launcherApps.getActivityList(packageName, handle);
if (!list.isEmpty()) {
// Google App workaround
if (!packageName.equals(googleSearchBoxPackage)) {
launcherAppCache.add(list.get(0));
} else {
boolean added = false;
for (LauncherActivityInfo info : list) {
if (info.getName().equals(googleSearchBoxActivity)) {
launcherAppCache.add(info);
added = true;
}
}
if (!added) {
launcherAppCache.add(list.get(0));
}
}
AppEntry newEntry = new AppEntry(packageName, null, null, null, false);
newEntry.setUserId(userManager.getSerialNumberForUser(handle));
newEntry.setLastTimeUsed(lastTimeUsed);
entries.add(newEntry);
break;
}
}
}
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class TaskbarController method populateAppEntries.
@SuppressWarnings("SuspiciousListRemoveInLoop")
@VisibleForTesting
void populateAppEntries(Context context, PackageManager pm, List<AppEntry> entries, List<LauncherActivityInfo> launcherAppCache) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
int launcherAppCachePos = -1;
for (int i = 0; i < entries.size(); i++) {
if (entries.get(i).getComponentName() == null) {
launcherAppCachePos++;
LauncherActivityInfo appInfo = launcherAppCache.get(launcherAppCachePos);
String packageName = entries.get(i).getPackageName();
long lastTimeUsed = entries.get(i).getLastTimeUsed();
entries.remove(i);
AppEntry newEntry = new AppEntry(packageName, appInfo.getComponentName().flattenToString(), appInfo.getLabel().toString(), IconCache.getInstance(context).getIcon(context, pm, appInfo), false);
newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
newEntry.setLastTimeUsed(lastTimeUsed);
entries.add(i, newEntry);
}
}
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class U method refreshPinnedIcons.
public static void refreshPinnedIcons(Context context) {
IconCache.getInstance(context).clearCache();
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
List<AppEntry> pinnedAppsList = new ArrayList<>(pba.getPinnedApps());
List<AppEntry> blockedAppsList = new ArrayList<>(pba.getBlockedApps());
PackageManager pm = context.getPackageManager();
pba.clear(context);
for (AppEntry entry : pinnedAppsList) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
final List<UserHandle> userHandles = userManager.getUserProfiles();
LauncherActivityInfo appInfo = null;
for (UserHandle handle : userHandles) {
List<LauncherActivityInfo> list = launcherApps.getActivityList(entry.getPackageName(), handle);
if (!list.isEmpty()) {
// Google App workaround
if (!entry.getPackageName().equals("com.google.android.googlequicksearchbox"))
appInfo = list.get(0);
else {
boolean added = false;
for (LauncherActivityInfo info : list) {
if (info.getName().equals("com.google.android.googlequicksearchbox.SearchActivity")) {
appInfo = info;
added = true;
}
}
if (!added)
appInfo = list.get(0);
}
break;
}
}
if (appInfo != null) {
AppEntry newEntry = new AppEntry(entry.getPackageName(), entry.getComponentName(), entry.getLabel(), IconCache.getInstance(context).getIcon(context, pm, appInfo), true);
newEntry.setUserId(entry.getUserId(context));
pba.addPinnedApp(context, newEntry);
}
}
for (AppEntry entry : blockedAppsList) {
pba.addBlockedApp(context, entry);
}
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class FavoriteAppTileService method updateState.
private void updateState() {
Tile tile = getQsTile();
if (tile == null)
return;
SharedPreferences pref = U.getSharedPreferences(this);
if (pref.getBoolean(prefix + PREF_ADDED_SUFFIX, false)) {
tile.setState(Tile.STATE_ACTIVE);
tile.setLabel(pref.getString(prefix + PREF_LABEL_SUFFIX, getString(R.string.tb_new_shortcut)));
String componentName = pref.getString(prefix + PREF_COMPONENT_NAME_SUFFIX, null);
float threshold = pref.getFloat(prefix + PREF_ICON_THRESHOLD_SUFFIX, -1);
if (componentName != null && threshold >= 0) {
UserManager userManager = (UserManager) getSystemService(USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE);
long userId = pref.getLong(prefix + PREF_USER_ID_SUFFIX, userManager.getSerialNumberForUser(Process.myUserHandle()));
Intent intent = new Intent();
intent.setComponent(ComponentName.unflattenFromString(componentName));
LauncherActivityInfo info = launcherApps.resolveActivity(intent, userManager.getUserForSerialNumber(userId));
IconCache cache = IconCache.getInstance(this);
BitmapDrawable icon = U.convertToMonochrome(this, cache.getIcon(this, info), threshold);
tile.setIcon(Icon.createWithBitmap(icon.getBitmap()));
} else {
tile.setIcon(Icon.createWithResource(this, R.drawable.tb_favorite_app_tile));
}
} else {
tile.setState(Tile.STATE_INACTIVE);
tile.setLabel(getString(R.string.tb_new_shortcut));
tile.setIcon(Icon.createWithResource(this, R.drawable.tb_favorite_app_tile));
}
tile.updateTile();
}
use of android.content.pm.LauncherActivityInfo in project Taskbar by farmerbb.
the class StartMenuService method refreshApps.
private void refreshApps(final String query, final boolean firstDraw) {
if (thread != null)
thread.interrupt();
handler = new Handler();
thread = new Thread(() -> {
if (pm == null)
pm = getPackageManager();
UserManager userManager = (UserManager) getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) 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(StartMenuService.this);
for (LauncherActivityInfo appInfo : unfilteredList) {
if (topApps.isTopApp(appInfo.getComponentName().flattenToString()) || topApps.isTopApp(appInfo.getName()))
topAppsList.add(appInfo);
}
Blacklist blacklist = Blacklist.getInstance(StartMenuService.this);
for (LauncherActivityInfo appInfo : unfilteredList) {
if (!(blacklist.isBlocked(appInfo.getComponentName().flattenToString()) || blacklist.isBlocked(appInfo.getName())) && !(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;
Drawable defaultIcon = pm.getDefaultActivityIcon();
final List<AppEntry> entries = new ArrayList<>();
for (LauncherActivityInfo appInfo : queryList) {
// Attempt to work around frequently reported OutOfMemoryErrors
String label;
Drawable icon;
try {
label = appInfo.getLabel().toString();
icon = IconCache.getInstance(StartMenuService.this).getIcon(StartMenuService.this, pm, appInfo);
} catch (OutOfMemoryError e) {
System.gc();
label = appInfo.getApplicationInfo().packageName;
icon = defaultIcon;
}
AppEntry newEntry = new AppEntry(appInfo.getApplicationInfo().packageName, new ComponentName(appInfo.getApplicationInfo().packageName, appInfo.getName()).flattenToString(), label, icon, false);
newEntry.setUserId(userManager.getSerialNumberForUser(appInfo.getUser()));
entries.add(newEntry);
}
handler.post(() -> {
String queryText = searchView.getQuery().toString();
if (query == null && queryText.length() == 0 || query != null && query.equals(queryText)) {
StartMenuAdapter adapter;
SharedPreferences pref = U.getSharedPreferences(StartMenuService.this);
if (pref.getString("start_menu_layout", "list").equals("grid")) {
startMenu.setNumColumns(3);
adapter = new StartMenuAdapter(StartMenuService.this, R.layout.row_alt, entries);
} else
adapter = new StartMenuAdapter(StartMenuService.this, R.layout.row, entries);
int position = startMenu.getFirstVisiblePosition();
startMenu.setAdapter(adapter);
startMenu.setSelection(position);
if (adapter.getCount() > 0)
textView.setText(null);
else if (query != null)
textView.setText(getString(Patterns.WEB_URL.matcher(query).matches() ? R.string.press_enter_alt : R.string.press_enter));
else
textView.setText(getString(R.string.nothing_to_see_here));
}
});
}
});
thread.start();
}
Aggregations