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