Search in sources :

Example 1 with BlacklistEntry

use of com.farmerbb.taskbar.util.BlacklistEntry 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) {
        }
}
Also used : SavedWindowSizes(com.farmerbb.taskbar.util.SavedWindowSizes) LauncherApps(android.content.pm.LauncherApps) Intent(android.content.Intent) IOException(java.io.IOException) AppEntry(com.farmerbb.taskbar.util.AppEntry) BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) UserManager(android.os.UserManager) FileOutputStream(java.io.FileOutputStream) TopApps(com.farmerbb.taskbar.util.TopApps) Blacklist(com.farmerbb.taskbar.util.Blacklist) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) File(java.io.File)

Example 2 with BlacklistEntry

use of com.farmerbb.taskbar.util.BlacklistEntry 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());
}
Also used : InputStreamReader(java.io.InputStreamReader) SavedWindowSizes(com.farmerbb.taskbar.util.SavedWindowSizes) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) AppEntry(com.farmerbb.taskbar.util.AppEntry) BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) SavedWindowSizesEntry(com.farmerbb.taskbar.util.SavedWindowSizesEntry) BufferedReader(java.io.BufferedReader) TopApps(com.farmerbb.taskbar.util.TopApps) Blacklist(com.farmerbb.taskbar.util.Blacklist) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) File(java.io.File)

Example 3 with BlacklistEntry

use of com.farmerbb.taskbar.util.BlacklistEntry in project Taskbar by farmerbb.

the class AppListAdapter method setupHidden.

private void setupHidden(int position, View convertView) {
    final BlacklistEntry entry = getItem(position);
    assert entry != null;
    final String componentName = entry.getPackageName();
    final String componentNameAlt = componentName.contains(":") ? componentName.split(":")[0] : componentName;
    final String componentNameAlt2 = componentNameAlt.contains("/") ? componentNameAlt.split("/")[1] : componentNameAlt;
    TextView textView = convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());
    final CheckBox checkBox = convertView.findViewById(R.id.checkbox);
    checkBox.setChecked(blacklist.isBlocked(componentName) || blacklist.isBlocked(componentNameAlt) || blacklist.isBlocked(componentNameAlt2));
    LinearLayout layout = convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        if (topApps.isTopApp(componentName) || topApps.isTopApp(componentNameAlt) || topApps.isTopApp(componentNameAlt2)) {
            U.showToast(getContext(), getContext().getString(R.string.tb_already_top_app, entry.getLabel()), Toast.LENGTH_LONG);
        } else if (blacklist.isBlocked(componentName)) {
            blacklist.removeBlockedApp(getContext(), componentName);
            checkBox.setChecked(false);
        } else if (blacklist.isBlocked(componentNameAlt)) {
            blacklist.removeBlockedApp(getContext(), componentNameAlt);
            checkBox.setChecked(false);
        } else if (blacklist.isBlocked(componentNameAlt2)) {
            blacklist.removeBlockedApp(getContext(), componentNameAlt2);
            checkBox.setChecked(false);
        } else {
            blacklist.addBlockedApp(getContext(), entry);
            checkBox.setChecked(true);
        }
    });
}
Also used : BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Example 4 with BlacklistEntry

use of com.farmerbb.taskbar.util.BlacklistEntry in project Taskbar by farmerbb.

the class AppListAdapter method setupTopApps.

private void setupTopApps(int position, View convertView) {
    final BlacklistEntry entry = getItem(position);
    assert entry != null;
    final String componentName = entry.getPackageName();
    final String componentNameAlt = componentName.contains(":") ? componentName.split(":")[0] : componentName;
    final String componentNameAlt2 = componentNameAlt.contains("/") ? componentNameAlt.split("/")[1] : componentNameAlt;
    TextView textView = convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());
    final CheckBox checkBox = convertView.findViewById(R.id.checkbox);
    checkBox.setChecked(topApps.isTopApp(componentName) || topApps.isTopApp(componentNameAlt) || topApps.isTopApp(componentNameAlt2));
    LinearLayout layout = convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        if (blacklist.isBlocked(componentName) || blacklist.isBlocked(componentNameAlt) || blacklist.isBlocked(componentNameAlt2)) {
            U.showToast(getContext(), getContext().getString(R.string.tb_already_blacklisted, entry.getLabel()), Toast.LENGTH_LONG);
        } else if (topApps.isTopApp(componentName)) {
            topApps.removeTopApp(getContext(), componentName);
            checkBox.setChecked(false);
        } else if (topApps.isTopApp(componentNameAlt)) {
            topApps.removeTopApp(getContext(), componentNameAlt);
            checkBox.setChecked(false);
        } else if (topApps.isTopApp(componentNameAlt2)) {
            topApps.removeTopApp(getContext(), componentNameAlt2);
            checkBox.setChecked(false);
        } else {
            topApps.addTopApp(getContext(), entry);
            checkBox.setChecked(true);
        }
    });
}
Also used : BlacklistEntry(com.farmerbb.taskbar.util.BlacklistEntry) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout)

Aggregations

BlacklistEntry (com.farmerbb.taskbar.util.BlacklistEntry)4 CheckBox (android.widget.CheckBox)2 LinearLayout (android.widget.LinearLayout)2 TextView (android.widget.TextView)2 AppEntry (com.farmerbb.taskbar.util.AppEntry)2 Blacklist (com.farmerbb.taskbar.util.Blacklist)2 PinnedBlockedApps (com.farmerbb.taskbar.util.PinnedBlockedApps)2 SavedWindowSizes (com.farmerbb.taskbar.util.SavedWindowSizes)2 TopApps (com.farmerbb.taskbar.util.TopApps)2 File (java.io.File)2 IOException (java.io.IOException)2 Intent (android.content.Intent)1 LauncherApps (android.content.pm.LauncherApps)1 UserManager (android.os.UserManager)1 SavedWindowSizesEntry (com.farmerbb.taskbar.util.SavedWindowSizesEntry)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStreamReader (java.io.InputStreamReader)1