• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 
17 package com.android.settings.fuelgauge;
18 
19 import android.app.settings.SettingsEnums;
20 import android.content.Context;
21 import android.os.Bundle;
22 import android.provider.SearchIndexableResource;
23 
24 import com.android.settings.R;
25 import com.android.settings.SettingsActivity;
26 import com.android.settings.core.InstrumentedPreferenceFragment;
27 import com.android.settings.dashboard.DashboardFragment;
28 import com.android.settings.search.BaseSearchIndexProvider;
29 import com.android.settingslib.core.AbstractPreferenceController;
30 import com.android.settingslib.search.SearchIndexable;
31 
32 import java.util.ArrayList;
33 import java.util.Arrays;
34 import java.util.List;
35 
36 /**
37  * Fragment to show smart battery and restricted app controls
38  */
39 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
40 public class SmartBatterySettings extends DashboardFragment {
41     public static final String TAG = "SmartBatterySettings";
42 
43     @Override
onCreate(Bundle icicle)44     public void onCreate(Bundle icicle) {
45         super.onCreate(icicle);
46         mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.smart_battery_footer);
47     }
48 
49     @Override
getMetricsCategory()50     public int getMetricsCategory() {
51         return SettingsEnums.FUELGAUGE_SMART_BATTERY;
52     }
53 
54     @Override
getLogTag()55     protected String getLogTag() {
56         return TAG;
57     }
58 
59     @Override
getPreferenceScreenResId()60     protected int getPreferenceScreenResId() {
61         return R.xml.smart_battery_detail;
62     }
63 
64     @Override
getHelpResource()65     public int getHelpResource() {
66         return R.string.help_uri_smart_battery_settings;
67     }
68 
69     @Override
createPreferenceControllers(Context context)70     protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
71         return buildPreferenceControllers(context, (SettingsActivity) getActivity(), this);
72     }
73 
buildPreferenceControllers( Context context, SettingsActivity settingsActivity, InstrumentedPreferenceFragment fragment)74     private static List<AbstractPreferenceController> buildPreferenceControllers(
75             Context context, SettingsActivity settingsActivity,
76             InstrumentedPreferenceFragment fragment) {
77         final List<AbstractPreferenceController> controllers = new ArrayList<>();
78         controllers.add(new SmartBatteryPreferenceController(context));
79         if (settingsActivity != null && fragment != null) {
80             controllers.add(
81                     new RestrictAppPreferenceController(fragment));
82         } else {
83             controllers.add(new RestrictAppPreferenceController(context));
84         }
85 
86         return controllers;
87     }
88 
89     public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
90             new BaseSearchIndexProvider() {
91                 @Override
92                 public List<SearchIndexableResource> getXmlResourcesToIndex(
93                         Context context, boolean enabled) {
94                     final SearchIndexableResource sir = new SearchIndexableResource(context);
95                     sir.xmlResId = R.xml.smart_battery_detail;
96                     return Arrays.asList(sir);
97                 }
98 
99                 @Override
100                 public List<AbstractPreferenceController> createPreferenceControllers(
101                         Context context) {
102                     return buildPreferenceControllers(context, null, null);
103                 }
104             };
105 }
106