1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.settings.system; 17 18 import android.app.settings.SettingsEnums; 19 import android.os.Bundle; 20 21 import androidx.preference.Preference; 22 import androidx.preference.PreferenceGroup; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settings.dashboard.DashboardFragment; 27 import com.android.settings.search.BaseSearchIndexProvider; 28 import com.android.settingslib.search.SearchIndexable; 29 30 @SearchIndexable 31 public class SystemDashboardFragment extends DashboardFragment { 32 33 private static final String TAG = "SystemDashboardFrag"; 34 35 @Override onCreate(Bundle icicle)36 public void onCreate(Bundle icicle) { 37 super.onCreate(icicle); 38 39 final PreferenceScreen screen = getPreferenceScreen(); 40 // We do not want to display an advanced button if only one setting is hidden 41 if (getVisiblePreferenceCount(screen) == screen.getInitialExpandedChildrenCount() + 1) { 42 screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE); 43 } 44 } 45 46 @Override getMetricsCategory()47 public int getMetricsCategory() { 48 return SettingsEnums.SETTINGS_SYSTEM_CATEGORY; 49 } 50 51 @Override getLogTag()52 protected String getLogTag() { 53 return TAG; 54 } 55 56 @Override getPreferenceScreenResId()57 protected int getPreferenceScreenResId() { 58 return R.xml.system_dashboard_fragment; 59 } 60 61 @Override getHelpResource()62 public int getHelpResource() { 63 return R.string.help_url_system_dashboard; 64 } 65 getVisiblePreferenceCount(PreferenceGroup group)66 private int getVisiblePreferenceCount(PreferenceGroup group) { 67 int visibleCount = 0; 68 for (int i = 0; i < group.getPreferenceCount(); i++) { 69 final Preference preference = group.getPreference(i); 70 if (preference instanceof PreferenceGroup) { 71 visibleCount += getVisiblePreferenceCount((PreferenceGroup) preference); 72 } else if (preference.isVisible()) { 73 visibleCount++; 74 } 75 } 76 return visibleCount; 77 } 78 79 /** 80 * For Search. 81 */ 82 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 83 new BaseSearchIndexProvider(R.xml.system_dashboard_fragment); 84 } 85