Search in sources :

Example 6 with PinnedBlockedApps

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

PinnedBlockedApps (com.farmerbb.taskbar.util.PinnedBlockedApps)6 Intent (android.content.Intent)5 AppEntry (com.farmerbb.taskbar.util.AppEntry)5 SuppressLint (android.annotation.SuppressLint)3 SharedPreferences (android.content.SharedPreferences)3 LauncherApps (android.content.pm.LauncherApps)3 PackageManager (android.content.pm.PackageManager)3 ResolveInfo (android.content.pm.ResolveInfo)3 UserManager (android.os.UserManager)3 TargetApi (android.annotation.TargetApi)2 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)2 Handler (android.os.Handler)2 DisplayMetrics (android.util.DisplayMetrics)2 MainActivity (com.farmerbb.taskbar.MainActivity)2 Blacklist (com.farmerbb.taskbar.util.Blacklist)2 BlacklistEntry (com.farmerbb.taskbar.util.BlacklistEntry)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