use of com.farmerbb.taskbar.util.Blacklist 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();
}
use of com.farmerbb.taskbar.util.Blacklist 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 com.farmerbb.taskbar.util.Blacklist in project Taskbar by farmerbb.
the class BackupUtils method restore.
public static void restore(Context context, BackupAgent agent) {
// Get pinned and blocked apps
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
pba.clear(context);
String[] pinnedAppsPackageNames = agent.getStringArray(BACKUP_KEY_PINNED_APPS_PACKAGE_NAMES);
String[] pinnedAppsComponentNames = agent.getStringArray(BACKUP_KEY_PINNED_APPS_COMPONENT_NAMES);
String[] pinnedAppsLabels = agent.getStringArray(BACKUP_KEY_PINNED_APPS_LABELS);
long[] pinnedAppsUserIds = agent.getLongArray(BACKUP_KEY_PINNED_APPS_USER_IDS);
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE);
if (pinnedAppsPackageNames != null && pinnedAppsComponentNames != null && pinnedAppsLabels != null)
for (int i = 0; i < pinnedAppsPackageNames.length; i++) {
Intent throwaway = new Intent();
throwaway.setComponent(ComponentName.unflattenFromString(pinnedAppsComponentNames[i]));
long userId;
if (pinnedAppsUserIds != null)
userId = pinnedAppsUserIds[i];
else
userId = userManager.getSerialNumberForUser(Process.myUserHandle());
AppEntry newEntry = new AppEntry(pinnedAppsPackageNames[i], pinnedAppsComponentNames[i], pinnedAppsLabels[i], IconCache.getInstance(context).getIcon(context, launcherApps.resolveActivity(throwaway, userManager.getUserForSerialNumber(userId))), true);
newEntry.setUserId(userId);
pba.addPinnedApp(context, newEntry);
}
String[] blockedAppsPackageNames = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_PACKAGE_NAMES);
String[] blockedAppsComponentNames = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_COMPONENT_NAMES);
String[] blockedAppsLabels = agent.getStringArray(BACKUP_KEY_BLOCKED_APPS_LABELS);
if (blockedAppsPackageNames != null && blockedAppsComponentNames != null && blockedAppsLabels != null)
for (int i = 0; i < blockedAppsPackageNames.length; i++) {
pba.addBlockedApp(context, new AppEntry(blockedAppsPackageNames[i], blockedAppsComponentNames[i], blockedAppsLabels[i], null, false));
}
// Get blacklist
Blacklist blacklist = Blacklist.getInstance(context);
blacklist.clear(context);
String[] blacklistPackageNames = agent.getStringArray(BACKUP_KEY_BLACKLIST_PACKAGE_NAMES);
String[] blacklistLabels = agent.getStringArray(BACKUP_KEY_BLACKLIST_LABELS);
if (blacklistPackageNames != null && blacklistLabels != null)
for (int i = 0; i < blacklistPackageNames.length; i++) {
blacklist.addBlockedApp(context, new BlacklistEntry(blacklistPackageNames[i], blacklistLabels[i]));
}
// Get top apps
TopApps topApps = TopApps.getInstance(context);
topApps.clear(context);
String[] topAppsPackageNames = agent.getStringArray(BACKUP_KEY_TOP_APPS_PACKAGE_NAMES);
String[] topAppsLabels = agent.getStringArray(BACKUP_KEY_TOP_APPS_LABELS);
if (topAppsPackageNames != null && topAppsLabels != null)
for (int i = 0; i < topAppsPackageNames.length; i++) {
topApps.addTopApp(context, new BlacklistEntry(topAppsPackageNames[i], topAppsLabels[i]));
}
// Get saved window sizes
if (U.canEnableFreeform(context)) {
SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context);
savedWindowSizes.clear(context);
String[] savedWindowSizesComponentNames = agent.getStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_COMPONENT_NAMES);
String[] savedWindowSizesWindowSizes = agent.getStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_WINDOW_SIZES);
if (savedWindowSizesComponentNames != null && savedWindowSizesWindowSizes != null)
for (int i = 0; i < savedWindowSizesComponentNames.length; i++) {
savedWindowSizes.setWindowSize(context, savedWindowSizesComponentNames[i], savedWindowSizesWindowSizes[i]);
}
}
// Get shared preferences
String contents = agent.getString(BACKUP_KEY_PREFERENCE);
if (contents.length() > 0)
try {
File file = new File(getSharedPreferencePath(context));
FileOutputStream output = new FileOutputStream(file);
output.write(contents.getBytes());
output.close();
} catch (IOException ignored) {
}
}
use of com.farmerbb.taskbar.util.Blacklist in project Taskbar by farmerbb.
the class BackupUtils method backup.
public static void backup(Context context, BackupAgent agent) {
// Get pinned and blocked apps
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
List<AppEntry> pinnedAppsList = pba.getPinnedApps();
String[] pinnedAppsPackageNames = new String[pinnedAppsList.size()];
String[] pinnedAppsComponentNames = new String[pinnedAppsList.size()];
String[] pinnedAppsLabels = new String[pinnedAppsList.size()];
long[] pinnedAppsUserIds = new long[pinnedAppsList.size()];
for (int i = 0; i < pinnedAppsList.size(); i++) {
AppEntry entry = pinnedAppsList.get(i);
pinnedAppsPackageNames[i] = entry.getPackageName();
pinnedAppsComponentNames[i] = entry.getComponentName();
pinnedAppsLabels[i] = entry.getLabel();
pinnedAppsUserIds[i] = entry.getUserId(context);
}
agent.putStringArray(BACKUP_KEY_PINNED_APPS_PACKAGE_NAMES, pinnedAppsPackageNames);
agent.putStringArray(BACKUP_KEY_PINNED_APPS_COMPONENT_NAMES, pinnedAppsComponentNames);
agent.putStringArray(BACKUP_KEY_PINNED_APPS_LABELS, pinnedAppsLabels);
agent.putLongArray(BACKUP_KEY_PINNED_APPS_USER_IDS, pinnedAppsUserIds);
List<AppEntry> blockedAppsList = pba.getBlockedApps();
String[] blockedAppsPackageNames = new String[blockedAppsList.size()];
String[] blockedAppsComponentNames = new String[blockedAppsList.size()];
String[] blockedAppsLabels = new String[blockedAppsList.size()];
for (int i = 0; i < blockedAppsList.size(); i++) {
AppEntry entry = blockedAppsList.get(i);
blockedAppsPackageNames[i] = entry.getPackageName();
blockedAppsComponentNames[i] = entry.getComponentName();
blockedAppsLabels[i] = entry.getLabel();
}
agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_PACKAGE_NAMES, blockedAppsPackageNames);
agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_COMPONENT_NAMES, blockedAppsComponentNames);
agent.putStringArray(BACKUP_KEY_BLOCKED_APPS_LABELS, blockedAppsLabels);
// Get blacklist
Blacklist blacklist = Blacklist.getInstance(context);
List<BlacklistEntry> blacklistList = blacklist.getBlockedApps();
String[] blacklistPackageNames = new String[blacklistList.size()];
String[] blacklistLabels = new String[blacklistList.size()];
for (int i = 0; i < blacklistList.size(); i++) {
BlacklistEntry entry = blacklistList.get(i);
blacklistPackageNames[i] = entry.getPackageName();
blacklistLabels[i] = entry.getLabel();
}
agent.putStringArray(BACKUP_KEY_BLACKLIST_PACKAGE_NAMES, blacklistPackageNames);
agent.putStringArray(BACKUP_KEY_BLACKLIST_LABELS, blacklistLabels);
// Get top apps
TopApps topApps = TopApps.getInstance(context);
List<BlacklistEntry> topAppsList = topApps.getTopApps();
String[] topAppsPackageNames = new String[topAppsList.size()];
String[] topAppsLabels = new String[topAppsList.size()];
for (int i = 0; i < topAppsList.size(); i++) {
BlacklistEntry entry = topAppsList.get(i);
topAppsPackageNames[i] = entry.getPackageName();
topAppsLabels[i] = entry.getLabel();
}
agent.putStringArray(BACKUP_KEY_TOP_APPS_PACKAGE_NAMES, topAppsPackageNames);
agent.putStringArray(BACKUP_KEY_TOP_APPS_LABELS, topAppsLabels);
// Get saved window sizes
if (U.canEnableFreeform(context)) {
SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context);
List<SavedWindowSizesEntry> savedWindowSizesList = savedWindowSizes.getSavedWindowSizes();
String[] savedWindowSizesComponentNames = new String[savedWindowSizesList.size()];
String[] savedWindowSizesWindowSizes = new String[savedWindowSizesList.size()];
for (int i = 0; i < savedWindowSizesList.size(); i++) {
SavedWindowSizesEntry entry = savedWindowSizesList.get(i);
savedWindowSizesComponentNames[i] = entry.getComponentName();
savedWindowSizesWindowSizes[i] = entry.getWindowSize();
}
agent.putStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_COMPONENT_NAMES, savedWindowSizesComponentNames);
agent.putStringArray(BACKUP_KEY_SAVED_WINDOW_SIZES_WINDOW_SIZES, savedWindowSizesWindowSizes);
}
// Get shared preferences
StringBuilder preferences = new StringBuilder();
try {
File file = new File(getSharedPreferencePath(context));
FileInputStream input = new FileInputStream(file);
InputStreamReader reader = new InputStreamReader(input);
BufferedReader buffer = new BufferedReader(reader);
String line = buffer.readLine();
while (line != null) {
preferences.append(line);
line = buffer.readLine();
if (line != null)
preferences.append("\n");
}
reader.close();
} catch (IOException ignored) {
}
agent.putString(BACKUP_KEY_PREFERENCE, preferences.toString());
}
Aggregations