Home | History | Annotate | Download | only in system
      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.content.Context;
     19 import android.os.Bundle;
     20 import android.provider.SearchIndexableResource;
     21 import android.support.v7.preference.Preference;
     22 import android.support.v7.preference.PreferenceGroup;
     23 import android.support.v7.preference.PreferenceScreen;
     24 
     25 import com.android.internal.logging.nano.MetricsProto;
     26 import com.android.settings.R;
     27 import com.android.settings.backup.BackupSettingsActivityPreferenceController;
     28 import com.android.settings.dashboard.DashboardFragment;
     29 import com.android.settings.search.BaseSearchIndexProvider;
     30 import com.android.settings.search.Indexable;
     31 
     32 import java.util.Arrays;
     33 import java.util.List;
     34 
     35 public class SystemDashboardFragment extends DashboardFragment {
     36 
     37     private static final String TAG = "SystemDashboardFrag";
     38 
     39     private static final String KEY_RESET = "reset_dashboard";
     40 
     41     @Override
     42     public void onCreate(Bundle icicle) {
     43         super.onCreate(icicle);
     44 
     45         final PreferenceScreen screen = getPreferenceScreen();
     46         // We do not want to display an advanced button if only one setting is hidden
     47         if (getVisiblePreferenceCount(screen) == screen.getInitialExpandedChildrenCount() + 1) {
     48             screen.setInitialExpandedChildrenCount(Integer.MAX_VALUE);
     49         }
     50     }
     51 
     52     @Override
     53     public int getMetricsCategory() {
     54         return MetricsProto.MetricsEvent.SETTINGS_SYSTEM_CATEGORY;
     55     }
     56 
     57     @Override
     58     protected String getLogTag() {
     59         return TAG;
     60     }
     61 
     62     @Override
     63     protected int getPreferenceScreenResId() {
     64         return R.xml.system_dashboard_fragment;
     65     }
     66 
     67     @Override
     68     public int getHelpResource() {
     69         return R.string.help_url_system_dashboard;
     70     }
     71 
     72     private int getVisiblePreferenceCount(PreferenceGroup group) {
     73         int visibleCount = 0;
     74         for (int i = 0; i < group.getPreferenceCount(); i++) {
     75             final Preference preference = group.getPreference(i);
     76             if (preference instanceof PreferenceGroup) {
     77                 visibleCount += getVisiblePreferenceCount((PreferenceGroup) preference);
     78             } else if (preference.isVisible()) {
     79                 visibleCount++;
     80             }
     81         }
     82         return visibleCount;
     83     }
     84 
     85     /**
     86      * For Search.
     87      */
     88     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
     89             new BaseSearchIndexProvider() {
     90                 @Override
     91                 public List<SearchIndexableResource> getXmlResourcesToIndex(
     92                         Context context, boolean enabled) {
     93                     final SearchIndexableResource sir = new SearchIndexableResource(context);
     94                     sir.xmlResId = R.xml.system_dashboard_fragment;
     95                     return Arrays.asList(sir);
     96                 }
     97 
     98                 @Override
     99                 public List<String> getNonIndexableKeys(Context context) {
    100                     List<String> keys = super.getNonIndexableKeys(context);
    101                     keys.add((new BackupSettingsActivityPreferenceController(
    102                             context).getPreferenceKey()));
    103                     keys.add(KEY_RESET);
    104                     return keys;
    105                 }
    106             };
    107 }