Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e4a5c47f authored by Jason Monk's avatar Jason Monk Committed by android-build-merger
Browse files

Merge \\\"Settings: Better handling for disabled tiles\\\" into nyc-dev am:...

Merge \\\"Settings: Better handling for disabled tiles\\\" into nyc-dev am: 27eadb6f am: a62da523
am: 739f8958

Change-Id: I943edc13cc7e7bec50eb28204cd005e9aa005972
parents f7590b87 739f8958
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@@ -20,14 +20,17 @@ import android.annotation.Nullable;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.os.AsyncTask;
import android.os.Bundle;
import android.provider.Settings;
import android.support.v4.widget.DrawerLayout;
import android.util.ArraySet;
import android.util.Log;
import android.util.Pair;
import android.view.Gravity;
@@ -58,6 +61,9 @@ public class SettingsDrawerActivity extends Activity {

    private static List<DashboardCategory> sDashboardCategories;
    private static HashMap<Pair<String, String>, Tile> sTileCache;
    // Serves as a temporary list of tiles to ignore until we heard back from the PM that they
    // are disabled.
    private static ArraySet<ComponentName> sTileBlacklist = new ArraySet<>();
    private static InterestingConfigChanges sConfigTracker;

    private final PackageReceiver mPackageReceiver = new PackageReceiver();
@@ -288,6 +294,24 @@ public class SettingsDrawerActivity extends Activity {
        finish();
    }

    public void setTileEnabled(ComponentName component, boolean enabled) {
        PackageManager pm = getPackageManager();
        int state = pm.getComponentEnabledSetting(component);
        boolean isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED;
        if (isEnabled != enabled || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
            if (enabled) {
                sTileBlacklist.remove(component);
            } else {
                sTileBlacklist.add(component);
            }
            pm.setComponentEnabledSetting(component, enabled
                    ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                    : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                    PackageManager.DONT_KILL_APP);
            new CategoriesUpdater().execute();
        }
    }

    public interface CategoryListener {
        void onCategoriesChanged();
    }
@@ -303,6 +327,15 @@ public class SettingsDrawerActivity extends Activity {

        @Override
        protected void onPostExecute(List<DashboardCategory> dashboardCategories) {
            for (int i = 0; i < dashboardCategories.size(); i++) {
                DashboardCategory category = dashboardCategories.get(i);
                for (int j = 0; j < category.tiles.size(); j++) {
                    Tile tile = category.tiles.get(j);
                    if (sTileBlacklist.contains(tile.intent.getComponent())) {
                        category.tiles.remove(j--);
                    }
                }
            }
            sDashboardCategories = dashboardCategories;
            onCategoriesChanged();
        }