use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class StartMenuController method drawStartMenu.
private void drawStartMenu(UIHost host) {
IconCache.getInstance(context).clearCache();
final SharedPreferences pref = U.getSharedPreferences(context);
boolean shouldShowSearchBox = shouldShowSearchBox(pref, hasHardwareKeyboard);
// Initialize layout params
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
// Determine where to show the start menu on screen
String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
int layoutId = getStartMenuLayoutId(taskbarPosition);
params.gravity = getStartMenuGravity(taskbarPosition);
// Initialize views
layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
layout.setAlpha(0);
startMenu = layout.findViewById(R.id.start_menu);
if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
layout.viewHandlesBackButton();
boolean scrollbar = pref.getBoolean(PREF_SCROLLBAR, false);
startMenu.setFastScrollEnabled(scrollbar);
startMenu.setFastScrollAlwaysVisible(scrollbar);
startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
startMenu.setBackgroundColor(0);
if (pref.getBoolean(PREF_VISUAL_FEEDBACK, true))
startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
int columns = context.getResources().getInteger(R.integer.tb_start_menu_columns);
boolean isGrid = pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid");
if (isGrid) {
ViewGroup.LayoutParams startMenuParams = startMenu.getLayoutParams();
startMenuParams.width = (int) (startMenuParams.width * (columns / 3f));
startMenu.setLayoutParams(startMenuParams);
}
searchView = layout.findViewById(R.id.search);
searchViewClicked = false;
int backgroundTint = U.getBackgroundTint(context);
FrameLayout startMenuFrame = layout.findViewById(R.id.start_menu_frame);
FrameLayout searchViewLayout = layout.findViewById(R.id.search_view_layout);
startMenuFrame.setBackgroundColor(backgroundTint);
searchViewLayout.setBackgroundColor(backgroundTint);
if (shouldShowSearchBox) {
if (!hasHardwareKeyboard)
searchView.setIconifiedByDefault(true);
searchView.setOnTouchListener((v, event) -> {
searchViewClicked = true;
return false;
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
if (!hasSubmittedQuery) {
ListAdapter adapter = startMenu.getAdapter();
if (adapter != null) {
hasSubmittedQuery = true;
if (adapter.getCount() > 0) {
View view = adapter.getView(0, null, startMenu);
LinearLayout layout = view.findViewById(R.id.entry);
layout.performClick();
} else {
if (U.shouldCollapse(context, true)) {
U.sendBroadcast(context, ACTION_HIDE_TASKBAR);
} else {
hideStartMenu(true);
}
Intent intent = generateQueryWebSearchIntent(query);
if (intent.resolveActivity(context.getPackageManager()) != null) {
context.startActivity(intent);
} else {
intent = generateQueryGoogleIntent(query);
try {
context.startActivity(intent);
} catch (ActivityNotFoundException ignored) {
}
}
}
}
}
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
searchView.setIconified(false);
View closeButton = searchView.findViewById(R.id.search_close_btn);
if (closeButton != null)
closeButton.setVisibility(View.GONE);
refreshApps(newText, false);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
U.newHandler().postDelayed(() -> {
EditText editText = searchView.findViewById(R.id.search_src_text);
if (editText != null) {
editText.requestFocus();
editText.setSelection(editText.getText().length());
}
}, 50);
}
return true;
}
});
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
LinearLayout powerButton = layout.findViewById(R.id.power_button);
powerButton.setOnClickListener(view -> {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
});
powerButton.setOnGenericMotionListener((view, motionEvent) -> {
if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
int[] location = new int[2];
view.getLocationOnScreen(location);
openContextMenu(location);
}
return false;
});
searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));
startMenu.setOnItemClickListener((viewParent, view, position, id) -> {
hideStartMenu(true);
AppEntry entry = (AppEntry) viewParent.getAdapter().getItem(position);
U.launchApp(context, entry, null, false, false, view);
});
View childLayout = layout.findViewById(R.id.search_view_child_layout);
if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
childLayout.setBackgroundColor(0);
if (isGrid) {
ViewGroup.LayoutParams childLayoutParams = childLayout.getLayoutParams();
childLayoutParams.width = (int) (childLayoutParams.width * (columns / 3f));
childLayout.setLayoutParams(childLayoutParams);
}
} else
searchViewLayout.setVisibility(View.GONE);
applyMarginFix(host, layout, params);
textView = layout.findViewById(R.id.no_apps_found);
U.registerReceiver(context, toggleReceiver, ACTION_TOGGLE_START_MENU);
U.registerReceiver(context, hideReceiver, ACTION_HIDE_START_MENU);
U.registerReceiver(context, hideReceiverNoReset, ACTION_HIDE_START_MENU_NO_RESET);
U.registerReceiver(context, showSpaceReceiver, ACTION_SHOW_START_MENU_SPACE);
U.registerReceiver(context, hideSpaceReceiver, ACTION_HIDE_START_MENU_SPACE);
U.registerReceiver(context, resetReceiver, ACTION_RESET_START_MENU);
handler = U.newHandler();
refreshApps(true);
host.addView(layout, params);
}
use of com.farmerbb.taskbar.util.AppEntry 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 com.farmerbb.taskbar.util.AppEntry 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.AppEntry 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());
}
use of com.farmerbb.taskbar.util.AppEntry in project Taskbar by farmerbb.
the class UninstallReceiver method onReceive.
@SuppressWarnings("Convert2streamapi")
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_PACKAGE_FULLY_REMOVED)) {
String packageName = intent.getData().getEncodedSchemeSpecificPart();
PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
List<AppEntry> pinnedApps = pba.getPinnedApps();
List<String> componentNames = new ArrayList<>();
for (AppEntry entry : pinnedApps) {
if (entry.getPackageName().equals(packageName)) {
componentNames.add(entry.getComponentName());
}
}
for (String componentName : componentNames) {
pba.removePinnedApp(context, componentName);
}
}
}
Aggregations