Search in sources :

Example 96 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by SudaMod.

the class DashboardFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(getCategoryKey());
    if (category == null) {
        return;
    }
    if (mSummaryLoader != null) {
        // SummaryLoader can be null when there is no dynamic tiles.
        mSummaryLoader.setListening(true);
    }
    final Activity activity = getActivity();
    if (activity instanceof SettingsBaseActivity) {
        mListeningToCategoryChange = true;
        ((SettingsBaseActivity) activity).addCategoryListener(this);
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) SettingsBaseActivity(com.android.settings.core.SettingsBaseActivity) SettingsBaseActivity(com.android.settings.core.SettingsBaseActivity) Activity(android.app.Activity)

Example 97 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by SudaMod.

the class SettingsActivity method onCreate.

@Override
protected void onCreate(Bundle savedState) {
    super.onCreate(savedState);
    Log.d(LOG_TAG, "Starting onCreate");
    long startTime = System.currentTimeMillis();
    final FeatureFactory factory = FeatureFactory.getFactory(this);
    mDashboardFeatureProvider = factory.getDashboardFeatureProvider(this);
    // Should happen before any call to getIntent()
    getMetaData();
    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_UI_OPTIONS)) {
        getWindow().setUiOptions(intent.getIntExtra(EXTRA_UI_OPTIONS, 0));
    }
    // Getting Intent properties can only be done after the super.onCreate(...)
    final String initialFragmentName = intent.getStringExtra(EXTRA_SHOW_FRAGMENT);
    // This is a "Sub Settings" when:
    // - this is a real SubSettings
    // - or :settings:show_fragment_as_subsetting is passed to the Intent
    final boolean isSubSettings = this instanceof SubSettings || intent.getBooleanExtra(EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, false);
    // in SettingsBaseActivity#onCreate().
    if (isSubSettings && !WizardManagerHelper.isAnySetupWizard(getIntent())) {
        setTheme(R.style.Theme_SubSettings);
    }
    setContentView(R.layout.settings_main_prefs);
    getSupportFragmentManager().addOnBackStackChangedListener(this);
    if (savedState != null) {
        // We are restarting from a previous saved state; used that to initialize, instead
        // of starting fresh.
        setTitleFromIntent(intent);
        ArrayList<DashboardCategory> categories = savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
        if (categories != null) {
            mCategories.clear();
            mCategories.addAll(categories);
            setTitleFromBackStack();
        }
    } else {
        launchSettingFragment(initialFragmentName, intent);
    }
    final boolean deviceProvisioned = Utils.isDeviceProvisioned(this);
    final ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(deviceProvisioned);
        actionBar.setHomeButtonEnabled(deviceProvisioned);
        actionBar.setDisplayShowTitleEnabled(true);
    }
    mSwitchBar = findViewById(R.id.switch_bar);
    if (mSwitchBar != null) {
        mSwitchBar.setMetricsTag(getMetricsTag());
    }
    // see if we should show Back/Next buttons
    if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, false)) {
        View buttonBar = findViewById(R.id.button_bar);
        if (buttonBar != null) {
            buttonBar.setVisibility(View.VISIBLE);
            Button backButton = findViewById(R.id.back_button);
            backButton.setOnClickListener(v -> {
                setResult(RESULT_CANCELED, null);
                finish();
            });
            Button skipButton = findViewById(R.id.skip_button);
            skipButton.setOnClickListener(v -> {
                setResult(RESULT_OK, null);
                finish();
            });
            mNextButton = findViewById(R.id.next_button);
            mNextButton.setOnClickListener(v -> {
                setResult(RESULT_OK, null);
                finish();
            });
            // set our various button parameters
            if (intent.hasExtra(EXTRA_PREFS_SET_NEXT_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_NEXT_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    mNextButton.setVisibility(View.GONE);
                } else {
                    mNextButton.setText(buttonText);
                }
            }
            if (intent.hasExtra(EXTRA_PREFS_SET_BACK_TEXT)) {
                String buttonText = intent.getStringExtra(EXTRA_PREFS_SET_BACK_TEXT);
                if (TextUtils.isEmpty(buttonText)) {
                    backButton.setVisibility(View.GONE);
                } else {
                    backButton.setText(buttonText);
                }
            }
            if (intent.getBooleanExtra(EXTRA_PREFS_SHOW_SKIP, false)) {
                skipButton.setVisibility(View.VISIBLE);
            }
        }
    }
    if (DEBUG_TIMING) {
        Log.d(LOG_TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Button(android.widget.Button) Intent(android.content.Intent) View(android.view.View) ActionBar(android.app.ActionBar) FeatureFactory(com.android.settings.overlay.FeatureFactory)

Example 98 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by SudaMod.

the class SettingsActivity method doUpdateTilesList.

private void doUpdateTilesList() {
    PackageManager pm = getPackageManager();
    final UserManager um = UserManager.get(this);
    final boolean isAdmin = um.isAdminUser();
    boolean somethingChanged = false;
    final String packageName = getPackageName();
    final StringBuilder changedList = new StringBuilder();
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, WifiSettingsActivity.class.getName()), pm.hasSystemFeature(PackageManager.FEATURE_WIFI), isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.BluetoothSettingsActivity.class.getName()), pm.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH), isAdmin) || somethingChanged;
    // Enable DataUsageSummaryActivity if the data plan feature flag is turned on otherwise
    // enable DataPlanUsageSummaryActivity.
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()), Utils.isBandwidthControlEnabled(), /* enabled */
    isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.ConnectedDeviceDashboardActivity.class.getName()), !UserManager.isDeviceInDemoMode(this), /* enabled */
    isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.PowerUsageSummaryActivity.class.getName()), mBatteryPresent, isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.DataUsageSummaryActivity.class.getName()), Utils.isBandwidthControlEnabled(), isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.UserSettingsActivity.class.getName()), UserHandle.MU_ENABLED && UserManager.supportsMultipleUsers() && !Utils.isMonkeyRunning(), isAdmin) || somethingChanged;
    final boolean showDev = DevelopmentSettingsEnabler.isDevelopmentSettingsEnabled(this) && !Utils.isMonkeyRunning();
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.DevelopmentSettingsDashboardActivity.class.getName()), showDev, isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, UserBackupSettingsActivity.class.getName()), true, isAdmin) || somethingChanged;
    somethingChanged = setTileEnabled(changedList, new ComponentName(packageName, Settings.WifiDisplaySettingsActivity.class.getName()), WifiDisplaySettings.isAvailable(this), isAdmin) || somethingChanged;
    if (UserHandle.MU_ENABLED && !isAdmin) {
        // When on restricted users, disable all extra categories (but only the settings ones).
        final List<DashboardCategory> categories = mDashboardFeatureProvider.getAllCategories();
        synchronized (categories) {
            for (DashboardCategory category : categories) {
                final int tileCount = category.getTilesCount();
                for (int i = 0; i < tileCount; i++) {
                    final ComponentName component = category.getTile(i).getIntent().getComponent();
                    final String name = component.getClassName();
                    final boolean isEnabledForRestricted = ArrayUtils.contains(SettingsGateway.SETTINGS_FOR_RESTRICTED, name);
                    if (packageName.equals(component.getPackageName()) && !isEnabledForRestricted) {
                        somethingChanged = setTileEnabled(changedList, component, false, isAdmin) || somethingChanged;
                    }
                }
            }
        }
    }
    // Final step, refresh categories.
    if (somethingChanged) {
        Log.d(LOG_TAG, "Enabled state changed for some tiles, reloading all categories " + changedList.toString());
        updateCategories();
    } else {
        Log.d(LOG_TAG, "No enabled state changed, skipping updateCategory call");
    }
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) PackageManager(android.content.pm.PackageManager) UserManager(android.os.UserManager) ComponentName(android.content.ComponentName) WifiDisplaySettings(com.android.settings.wfd.WifiDisplaySettings) TopLevelSettings(com.android.settings.homepage.TopLevelSettings)

Example 99 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by SudaMod.

the class CategoryManagerTest method sortCategories_singlePackage_shouldReorderBasedOnPriority.

@Test
public void sortCategories_singlePackage_shouldReorderBasedOnPriority() {
    // Create some fake tiles that are not sorted.
    final String testPackage = "com.android.test";
    final DashboardCategory category = new DashboardCategory(CATEGORY_HOMEPAGE);
    final ActivityInfo activityInfo1 = new ActivityInfo();
    activityInfo1.metaData = new Bundle();
    activityInfo1.metaData.putInt(META_DATA_KEY_ORDER, 100);
    activityInfo1.packageName = testPackage;
    activityInfo1.name = "class1";
    final ActivityInfo activityInfo2 = new ActivityInfo();
    activityInfo2.metaData = new Bundle();
    activityInfo2.metaData.putInt(META_DATA_KEY_ORDER, 50);
    activityInfo2.packageName = testPackage;
    activityInfo2.name = "class2";
    final ActivityInfo activityInfo3 = new ActivityInfo();
    activityInfo3.metaData = new Bundle();
    activityInfo3.metaData.putInt(META_DATA_KEY_ORDER, 200);
    activityInfo3.packageName = testPackage;
    activityInfo3.name = "class3";
    final Tile tile1 = new Tile(activityInfo1, category.key);
    final Tile tile2 = new Tile(activityInfo2, category.key);
    final Tile tile3 = new Tile(activityInfo3, category.key);
    category.addTile(tile1);
    category.addTile(tile2);
    category.addTile(tile3);
    mCategoryByKeyMap.put(CATEGORY_HOMEPAGE, category);
    // Sort their priorities
    mCategoryManager.sortCategories(RuntimeEnvironment.application, mCategoryByKeyMap);
    // Verify they are now sorted.
    assertThat(category.getTile(0)).isSameAs(tile3);
    assertThat(category.getTile(1)).isSameAs(tile1);
    assertThat(category.getTile(2)).isSameAs(tile2);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) ActivityInfo(android.content.pm.ActivityInfo) Bundle(android.os.Bundle) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Example 100 with DashboardCategory

use of com.android.settingslib.drawer.DashboardCategory in project android_packages_apps_Settings by SudaMod.

the class CategoryManagerTest method backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys.

@Test
public void backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys() {
    final String oldCategory = "com.android.settings.category.wireless";
    final Tile tile1 = new Tile(mActivityInfo, oldCategory);
    tile1.setCategory(oldCategory);
    final DashboardCategory category1 = new DashboardCategory(oldCategory);
    category1.addTile(tile1);
    mCategoryByKeyMap.put(oldCategory, category1);
    mTileByComponentCache.put(new Pair<>("PACKAGE", "CLASS1"), tile1);
    mCategoryManager.backwardCompatCleanupForCategory(mTileByComponentCache, mCategoryByKeyMap);
    // Added 1 more category to category map.
    assertThat(mCategoryByKeyMap.size()).isEqualTo(2);
    // The new category map has CATEGORY_NETWORK type now, which contains 1 tile.
    assertThat(mCategoryByKeyMap.get(CategoryKey.CATEGORY_NETWORK).getTilesCount()).isEqualTo(1);
    // Old category still exists.
    assertThat(mCategoryByKeyMap.get(oldCategory).getTilesCount()).isEqualTo(1);
}
Also used : DashboardCategory(com.android.settingslib.drawer.DashboardCategory) Tile(com.android.settingslib.drawer.Tile) Test(org.junit.Test)

Aggregations

DashboardCategory (com.android.settingslib.drawer.DashboardCategory)449 Tile (com.android.settingslib.drawer.Tile)302 Test (org.junit.Test)225 ProviderTile (com.android.settingslib.drawer.ProviderTile)184 ActivityTile (com.android.settingslib.drawer.ActivityTile)179 Bundle (android.os.Bundle)77 ArrayList (java.util.ArrayList)71 VisibleForTesting (androidx.annotation.VisibleForTesting)52 ActivityInfo (android.content.pm.ActivityInfo)41 Intent (android.content.Intent)32 ComponentName (android.content.ComponentName)31 Context (android.content.Context)31 Before (org.junit.Before)30 Activity (android.app.Activity)27 View (android.view.View)27 PreferenceScreen (android.support.v7.preference.PreferenceScreen)26 List (java.util.List)26 ProviderInfo (android.content.pm.ProviderInfo)23 HashMap (java.util.HashMap)20 TestConfig (com.android.settings.TestConfig)18