1 /* 2 * Copyright (C) 2014 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.batterysaver; 18 19 import android.app.settings.SettingsEnums; 20 import android.text.TextUtils; 21 22 import androidx.annotation.VisibleForTesting; 23 24 import com.android.settings.R; 25 import com.android.settings.dashboard.DashboardFragment; 26 import com.android.settings.search.BaseSearchIndexProvider; 27 import com.android.settingslib.HelpUtils; 28 import com.android.settingslib.search.SearchIndexable; 29 import com.android.settingslib.widget.FooterPreference; 30 31 /** 32 * Battery saver settings page 33 */ 34 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 35 public class BatterySaverSettings extends DashboardFragment { 36 private static final String TAG = "BatterySaverSettings"; 37 private static final String KEY_FOOTER_PREFERENCE = "battery_saver_footer_preference"; 38 private String mHelpUri; 39 40 @Override onStart()41 public void onStart() { 42 super.onStart(); 43 setupFooter(); 44 } 45 46 @Override getMetricsCategory()47 public int getMetricsCategory() { 48 return SettingsEnums.OPEN_BATTERY_SAVER; 49 } 50 51 @Override getPreferenceScreenResId()52 protected int getPreferenceScreenResId() { 53 return R.xml.battery_saver_settings; 54 } 55 56 @Override getLogTag()57 protected String getLogTag() { 58 return TAG; 59 } 60 61 @Override getHelpResource()62 public int getHelpResource() { 63 return R.string.help_url_battery_saver_settings; 64 } 65 66 /** 67 * For Search. 68 */ 69 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 70 new BaseSearchIndexProvider(R.xml.battery_saver_settings); 71 72 // Updates the footer for this page. 73 @VisibleForTesting setupFooter()74 void setupFooter() { 75 mHelpUri = getString(R.string.help_url_battery_saver_settings); 76 if (!TextUtils.isEmpty(mHelpUri)) { 77 addHelpLink(); 78 } 79 } 80 81 // Changes the text to include a learn more link if possible. 82 @VisibleForTesting addHelpLink()83 void addHelpLink() { 84 FooterPreference pref = getPreferenceScreen().findPreference(KEY_FOOTER_PREFERENCE); 85 if (pref != null) { 86 pref.setSelectable(false); 87 pref.setLearnMoreAction(v -> { 88 mMetricsFeatureProvider.action(getContext(), 89 SettingsEnums.ACTION_APP_BATTERY_LEARN_MORE); 90 startActivityForResult(HelpUtils.getHelpIntent(getContext(), 91 getString(R.string.help_url_battery_saver_settings), 92 /*backupContext=*/ ""), /*requestCode=*/ 0); 93 }); 94 pref.setLearnMoreContentDescription(getString(R.string.battery_saver_link_a11y)); 95 } 96 } 97 } 98