Search in sources :

Example 1 with SavedWindowSizes

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

the class ReceiveSettingsReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    // Ignore this broadcast if this is the free version
    if (BuildConfig.APPLICATION_ID.equals(BuildConfig.PAID_APPLICATION_ID)) {
        // Get pinned and blocked apps
        PinnedBlockedApps pba = PinnedBlockedApps.getInstance(context);
        pba.clear(context);
        String[] pinnedAppsPackageNames = intent.getStringArrayExtra("pinned_apps_package_names");
        String[] pinnedAppsComponentNames = intent.getStringArrayExtra("pinned_apps_component_names");
        String[] pinnedAppsLabels = intent.getStringArrayExtra("pinned_apps_labels");
        long[] pinnedAppsUserIds = intent.getLongArrayExtra("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, context.getPackageManager(), launcherApps.resolveActivity(throwaway, userManager.getUserForSerialNumber(userId))), true);
                newEntry.setUserId(userId);
                pba.addPinnedApp(context, newEntry);
            }
        String[] blockedAppsPackageNames = intent.getStringArrayExtra("blocked_apps_package_names");
        String[] blockedAppsComponentNames = intent.getStringArrayExtra("blocked_apps_component_names");
        String[] blockedAppsLabels = intent.getStringArrayExtra("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 = intent.getStringArrayExtra("blacklist_package_names");
        String[] blacklistLabels = intent.getStringArrayExtra("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 = intent.getStringArrayExtra("top_apps_package_names");
        String[] topAppsLabels = intent.getStringArrayExtra("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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            SavedWindowSizes savedWindowSizes = SavedWindowSizes.getInstance(context);
            savedWindowSizes.clear(context);
            String[] savedWindowSizesComponentNames = intent.getStringArrayExtra("saved_window_sizes_component_names");
            String[] savedWindowSizesWindowSizes = intent.getStringArrayExtra("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 = intent.getStringExtra("preferences");
        if (contents.length() > 0)
            try {
                File file = new File(context.getFilesDir().getParent() + "/shared_prefs/" + BuildConfig.APPLICATION_ID + "_preferences.xml");
                FileOutputStream output = new FileOutputStream(file);
                output.write(contents.getBytes());
                output.close();
            } catch (IOException e) {
            /* Gracefully fail */
            }
        try {
            File file = new File(context.getFilesDir() + File.separator + "imported_successfully");
            if (file.createNewFile())
                LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.IMPORT_FINISHED"));
        } catch (IOException e) {
        /* Gracefully fail */
        }
    }
}
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 SavedWindowSizes

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

the class SendSettingsReceiver method onReceive.

@Override
public void onReceive(Context context, Intent intent) {
    // Ignore this broadcast if this is the paid version
    if (BuildConfig.APPLICATION_ID.equals(BuildConfig.BASE_APPLICATION_ID)) {
        Intent sendSettingsIntent = new Intent("com.farmerbb.taskbar.SEND_SETTINGS");
        sendSettingsIntent.setPackage(BuildConfig.PAID_APPLICATION_ID);
        // 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);
        }
        sendSettingsIntent.putExtra("pinned_apps_package_names", pinnedAppsPackageNames);
        sendSettingsIntent.putExtra("pinned_apps_component_names", pinnedAppsComponentNames);
        sendSettingsIntent.putExtra("pinned_apps_labels", pinnedAppsLabels);
        sendSettingsIntent.putExtra("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();
        }
        sendSettingsIntent.putExtra("blocked_apps_package_names", blockedAppsPackageNames);
        sendSettingsIntent.putExtra("blocked_apps_component_names", blockedAppsComponentNames);
        sendSettingsIntent.putExtra("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();
        }
        sendSettingsIntent.putExtra("blacklist_package_names", blacklistPackageNames);
        sendSettingsIntent.putExtra("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();
        }
        sendSettingsIntent.putExtra("top_apps_package_names", topAppsPackageNames);
        sendSettingsIntent.putExtra("top_apps_labels", topAppsLabels);
        // Get saved window sizes
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            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();
            }
            sendSettingsIntent.putExtra("saved_window_sizes_component_names", savedWindowSizesComponentNames);
            sendSettingsIntent.putExtra("saved_window_sizes_window_sizes", savedWindowSizesWindowSizes);
        }
        // Get shared preferences
        StringBuilder preferences = new StringBuilder("");
        try {
            File file = new File(context.getFilesDir().getParent() + "/shared_prefs/" + BuildConfig.APPLICATION_ID + "_preferences.xml");
            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 e) {
        /* Gracefully fail */
        }
        sendSettingsIntent.putExtra("preferences", preferences.toString());
        // Finally, send the broadcast
        context.sendBroadcast(sendSettingsIntent);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SavedWindowSizes(com.farmerbb.taskbar.util.SavedWindowSizes) Intent(android.content.Intent) 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

Intent (android.content.Intent)2 AppEntry (com.farmerbb.taskbar.util.AppEntry)2 Blacklist (com.farmerbb.taskbar.util.Blacklist)2 BlacklistEntry (com.farmerbb.taskbar.util.BlacklistEntry)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 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