Add description to battery settings footer link (2/3)

- Update battery saver footer learn more link description
 - Update app usage footer learn more link description

Bug: 187812487
Bug: 187135286
Test: make RunSettingsRoboTests
Change-Id: Iee496cf615f2f9e0e61be69d6b3a1d6c1c859013
This commit is contained in:
Wesley.CW Wang
2021-05-26 18:58:07 +08:00
parent 029edb7c48
commit 256636055b
4 changed files with 28 additions and 68 deletions

View File

@@ -5999,6 +5999,8 @@
<string name="manager_battery_usage_unrestricted_only">unrestricted</string>
<!-- The state when app is limited to optimized option only (e.g This app requires optimized battery usage) [CHAR_LIMIT=40] -->
<string name="manager_battery_usage_optimized_only">optimized</string>
<!-- Accessibility description for battery usage learn more link [CHAR LIMIT=NONE] -->
<string name="manager_battery_usage_link_a11y">Learn more about battery usage options</string>
<!-- Title for the screen usage in power use UI [CHAR_LIMIT=60] -->
<string name="device_screen_usage">Screen usage since full charge</string>
@@ -6087,6 +6089,8 @@
<string name="battery_tip_early_heads_up_summary">Battery may run out earlier than usual</string>
<!-- Title when early heads up is solved [CHAR LIMIT=NONE] -->
<string name="battery_tip_early_heads_up_done_title">Battery Saver on</string>
<!-- Accessibility description for battery saver learn more link [CHAR LIMIT=NONE] -->
<string name="battery_saver_link_a11y">Learn more about Battery saver</string>
<!-- Summary when early heads up is solved [CHAR LIMIT=NONE] -->
<string name="battery_tip_early_heads_up_done_summary">Some features may be limited</string>
<!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
@@ -12152,6 +12156,9 @@
<!-- Help URI, battery saver page [DO NOT TRANSLATE] -->
<string name="help_url_battery_saver_settings" translatable="false"></string>
<!-- Help URI, app usage page [DO NOT TRANSLATE] -->
<string name="help_url_app_usage_settings" translatable="false"></string>
<!-- Help URI, smart battery page [DO NOT TRANSLATE] -->
<string name="help_uri_smart_battery_settings" translatable="false"></string>

View File

@@ -25,7 +25,6 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.UserHandle;
import android.text.Html;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
@@ -47,10 +46,12 @@ import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.utils.StringUtil;
import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.RadioButtonPreference;
@@ -104,7 +105,7 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
@VisibleForTesting
Preference mBackgroundPreference;
@VisibleForTesting
Preference mFooterPreference;
FooterPreference mFooterPreference;
@VisibleForTesting
RadioButtonPreference mRestrictedPreference;
@VisibleForTesting
@@ -351,7 +352,13 @@ public class AdvancedPowerUsageDetail extends DashboardFragment implements
//Present default string to normal app.
footerString = context.getString(R.string.manager_battery_usage_footer);
}
mFooterPreference.setTitle(Html.fromHtml(footerString, Html.FROM_HTML_MODE_COMPACT));
mFooterPreference.setTitle(footerString);
mFooterPreference.setLearnMoreAction(v ->
startActivityForResult(HelpUtils.getHelpIntent(context,
context.getString(R.string.help_url_app_usage_settings),
/*backupContext=*/ ""), /*requestCode=*/ 0));
mFooterPreference.setLearnMoreContentDescription(
context.getString(R.string.manager_battery_usage_link_a11y));
}
@Override

View File

@@ -17,17 +17,10 @@
package com.android.settings.fuelgauge.batterysaver;
import android.app.settings.SettingsEnums;
import android.text.Annotation;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.URLSpan;
import android.view.View;
import androidx.annotation.VisibleForTesting;
import androidx.fragment.app.Fragment;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
@@ -94,64 +87,16 @@ public class BatterySaverSettings extends DashboardFragment {
void addHelpLink() {
FooterPreference pref = getPreferenceScreen().findPreference(KEY_FOOTER_PREFERENCE);
if (pref != null) {
SupportPageLearnMoreSpan.linkify(mFooterText, this, mHelpUri);
pref.setTitle(mFooterText);
pref.setSelectable(false);
}
}
/**
* A {@link URLSpan} that opens a support page when clicked
*/
public static class SupportPageLearnMoreSpan extends URLSpan {
private static final String ANNOTATION_URL = "url";
private final Fragment mFragment;
private final String mUriString;
public SupportPageLearnMoreSpan(Fragment fragment, String uriString) {
// sets the url to empty string so we can prevent any other span processing from
// from clearing things we need in this string.
super("");
mFragment = fragment;
mUriString = uriString;
}
@Override
public void onClick(View widget) {
if (mFragment != null) {
// launch the support page
mFragment.startActivityForResult(HelpUtils.getHelpIntent(mFragment.getContext(),
mUriString, ""), 0);
}
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
}
/**
* This method takes a string and turns it into a url span that will launch a support page
* @param msg The text to turn into a link
* @param fragment The fragment which contains this span
* @param uriString The URI string of the help article to open when clicked
* @return A CharSequence containing the original text content as a url
*/
public static CharSequence linkify(Spannable msg, Fragment fragment, String uriString) {
Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
for (Annotation annotation : spans) {
int start = msg.getSpanStart(annotation);
int end = msg.getSpanEnd(annotation);
if (ANNOTATION_URL.equals(annotation.getValue())) {
SupportPageLearnMoreSpan link =
new SupportPageLearnMoreSpan(fragment, uriString);
msg.removeSpan(annotation);
msg.setSpan(link, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return msg;
pref.setLearnMoreAction(v -> {
mMetricsFeatureProvider.action(getContext(),
SettingsEnums.ACTION_APP_BATTERY_LEARN_MORE);
startActivityForResult(HelpUtils.getHelpIntent(getContext(),
getString(R.string.help_url_battery_saver_settings),
/*backupContext=*/ ""), /*requestCode=*/ 0);
});
pref.setLearnMoreContentDescription(getString(R.string.battery_saver_link_a11y));
}
}
}

View File

@@ -60,6 +60,7 @@ import com.android.settingslib.applications.ApplicationsState;
import com.android.settingslib.applications.instantapps.InstantAppDataProvider;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.widget.RadioButtonPreference;
@@ -125,7 +126,7 @@ public class AdvancedPowerUsageDetailTest {
private Context mContext;
private Preference mForegroundPreference;
private Preference mBackgroundPreference;
private Preference mFooterPreference;
private FooterPreference mFooterPreference;
private RadioButtonPreference mRestrictedPreference;
private RadioButtonPreference mOptimizePreference;
private RadioButtonPreference mUnrestrictedPreference;
@@ -206,7 +207,7 @@ public class AdvancedPowerUsageDetailTest {
mForegroundPreference = new Preference(mContext);
mBackgroundPreference = new Preference(mContext);
mFooterPreference = new Preference(mContext);
mFooterPreference = new FooterPreference(mContext);
mRestrictedPreference = new RadioButtonPreference(mContext);
mOptimizePreference = new RadioButtonPreference(mContext);
mUnrestrictedPreference = new RadioButtonPreference(mContext);