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.content.Context; 20 import android.os.Bundle; 21 import android.provider.SearchIndexableResource; 22 23 import androidx.annotation.VisibleForTesting; 24 import androidx.preference.Preference; 25 import androidx.preference.PreferenceGroup; 26 import androidx.preference.PreferenceScreen; 27 28 import com.android.settings.R; 29 import com.android.settings.dashboard.DashboardFragment; 30 import com.android.settings.overlay.FeatureFactory; 31 import com.android.settings.search.BaseSearchIndexProvider; 32 import com.android.settingslib.search.SearchIndexable; 33 34 import java.util.Arrays; 35 import java.util.List; 36 37 @SearchIndexable 38 public class SystemDashboardFragment extends DashboardFragment { 39 40 private static final String TAG = "SystemDashboardFrag"; 41 42 public static final String EXTRA_SHOW_AWARE_DISABLED = "show_aware_dialog_disabled"; 43 44 @Override onCreate(Bundle icicle)45 public void onCreate(Bundle icicle) { 46 super.onCreate(icicle); 47 48 final PreferenceScreen screen = getPreferenceScreen(); 49 // We do not want to display an advanced button if only one setting is hidden 50 if (getVisiblePreferenceCount(screen) == screen.getInitialExpandedChildrenCount() + 1) { 51 screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE); 52 } 53 54 showRestrictionDialog(); 55 } 56 57 @VisibleForTesting showRestrictionDialog()58 public void showRestrictionDialog() { 59 final Bundle args = getArguments(); 60 if (args != null && args.getBoolean(EXTRA_SHOW_AWARE_DISABLED, false)) { 61 FeatureFactory.getFactory(getContext()).getAwareFeatureProvider() 62 .showRestrictionDialog(this); 63 } 64 } 65 66 @Override getMetricsCategory()67 public int getMetricsCategory() { 68 return SettingsEnums.SETTINGS_SYSTEM_CATEGORY; 69 } 70 71 @Override getLogTag()72 protected String getLogTag() { 73 return TAG; 74 } 75 76 @Override getPreferenceScreenResId()77 protected int getPreferenceScreenResId() { 78 return R.xml.system_dashboard_fragment; 79 } 80 81 @Override getHelpResource()82 public int getHelpResource() { 83 return R.string.help_url_system_dashboard; 84 } 85 getVisiblePreferenceCount(PreferenceGroup group)86 private int getVisiblePreferenceCount(PreferenceGroup group) { 87 int visibleCount = 0; 88 for (int i = 0; i < group.getPreferenceCount(); i++) { 89 final Preference preference = group.getPreference(i); 90 if (preference instanceof PreferenceGroup) { 91 visibleCount += getVisiblePreferenceCount((PreferenceGroup) preference); 92 } else if (preference.isVisible()) { 93 visibleCount++; 94 } 95 } 96 return visibleCount; 97 } 98 99 /** 100 * For Search. 101 */ 102 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 103 new BaseSearchIndexProvider() { 104 @Override 105 public List<SearchIndexableResource> getXmlResourcesToIndex( 106 Context context, boolean enabled) { 107 final SearchIndexableResource sir = new SearchIndexableResource(context); 108 sir.xmlResId = R.xml.system_dashboard_fragment; 109 return Arrays.asList(sir); 110 } 111 }; 112 }