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