Search in sources :

Example 1 with SavedWindowSizesEntry

use of com.farmerbb.taskbar.util.SavedWindowSizesEntry 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)

Aggregations

AppEntry (com.farmerbb.taskbar.util.AppEntry)1 Blacklist (com.farmerbb.taskbar.util.Blacklist)1 BlacklistEntry (com.farmerbb.taskbar.util.BlacklistEntry)1 PinnedBlockedApps (com.farmerbb.taskbar.util.PinnedBlockedApps)1 SavedWindowSizes (com.farmerbb.taskbar.util.SavedWindowSizes)1 SavedWindowSizesEntry (com.farmerbb.taskbar.util.SavedWindowSizesEntry)1 TopApps (com.farmerbb.taskbar.util.TopApps)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1