Merge "Make "Learn more" string translatable and set URL to be non-translatable"

This commit is contained in:
Eun-Jeong Shin
2023-02-01 04:58:06 +00:00
committed by Android (Google) Code Review
5 changed files with 34 additions and 27 deletions

View File

@@ -46,4 +46,7 @@
<!-- Whether to tint the icon of the sensor hardware privacy toggle unblock dialog.
Set to false if using a custom icon. -->
<bool name="config_unblockHwSensorIconEnableTint">true</bool>
<!-- Configuration to set Learn more in device logs as URL link -->
<bool name="log_access_confirmation_learn_more_as_link">false</bool>
</resources>

View File

@@ -17,11 +17,6 @@
*/
-->
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<!-- Content for the log access confirmation dialog. [CHAR LIMIT=NONE]-->
<string name="log_access_confirmation_body">Device logs record what happens on your device. Apps can use these logs to find and fix issues.\n\nSome logs may contain sensitive info, so only allow apps you trust to access all device logs.
\n\nIf you don’t allow this app to access all device logs, it can still access its own logs. Your device manufacturer may still be able to access some logs or info on your device.\n\nLearn more at g.co/android/devicelogs.
</string>
<!-- Learn more URL for the log access confirmation dialog. [DO NOT TRANSLATE]-->
<string name="log_access_confirmation_learn_more" translatable="false"></string>
<string name="log_access_confirmation_learn_more_url" translatable="false"></string>
</resources>

View File

@@ -835,4 +835,7 @@
<!-- Whether the floating rotation button should be on the left/right in the device's natural
orientation -->
<bool name="floating_rotation_button_position_left">true</bool>
<!-- Configuration to set Learn more in device logs as URL link -->
<bool name="log_access_confirmation_learn_more_as_link">true</bool>
</resources>

View File

@@ -2846,7 +2846,9 @@
</string>
<!-- Learn more URL for the log access confirmation dialog. [DO NOT TRANSLATE]-->
<string name="log_access_confirmation_learn_more" translatable="false">&lt;a href="https://support.google.com/android?p=system_logs#topic=7313011"&gt;Learn more&lt;/a&gt;</string>
<string name="log_access_confirmation_learn_more_url" translatable="false">https://support.google.com/android?p=system_logs#topic=7313011</string>
<string name="log_access_confirmation_learn_more">Learn more</string>
<string name="log_access_confirmation_learn_more_at">Learn more at <xliff:g id="url" example="g.co/android/devicelogs">%s</xliff:g></string>
<!--
Template for an action that opens a specific app. [CHAR LIMIT=16]

View File

@@ -28,11 +28,10 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.text.Html;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.TypefaceSpan;
import android.text.style.URLSpan;
import android.util.Slog;
import android.view.ContextThemeWrapper;
@@ -64,7 +63,10 @@ public class LogAccessDialogActivity extends Activity implements
private String mAlertTitle;
private String mAlertBody;
private String mAlertLearnMore;
private boolean mAlertLearnMoreLink;
private SpannableString mAlertLearnMore;
private AlertDialog.Builder mAlertDialog;
private AlertDialog mAlert;
private View mAlertView;
@@ -90,8 +92,20 @@ public class LogAccessDialogActivity extends Activity implements
return;
}
mAlertBody = getResources().getString(R.string.log_access_confirmation_body);
mAlertLearnMore = getResources().getString(R.string.log_access_confirmation_learn_more);
mAlertBody = getString(R.string.log_access_confirmation_body);
mAlertLearnMoreLink = this.getResources()
.getBoolean(R.bool.log_access_confirmation_learn_more_as_link);
if (mAlertLearnMoreLink) {
mAlertLearnMore = new SpannableString(
getString(R.string.log_access_confirmation_learn_more));
mAlertLearnMore.setSpan(new URLSpan(
getString(R.string.log_access_confirmation_learn_more_url)),
0, mAlertLearnMore.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
mAlertLearnMore = new SpannableString(
getString(R.string.log_access_confirmation_learn_more_at,
getString(R.string.log_access_confirmation_learn_more_url)));
}
// create View
int themeId = R.style.LogAccessDialogTheme;
@@ -180,15 +194,6 @@ public class LogAccessDialogActivity extends Activity implements
return titleString;
}
private Spannable styleFont(String text) {
Spannable s = (Spannable) Html.fromHtml(text);
for (URLSpan span : s.getSpans(0, s.length(), URLSpan.class)) {
TypefaceSpan typefaceSpan = new TypefaceSpan("google-sans");
s.setSpan(typefaceSpan, s.getSpanStart(span), s.getSpanEnd(span), 0);
}
return s;
}
/**
* Returns the dialog view.
* If we cannot retrieve the package name, it returns null and we decline the full device log
@@ -207,13 +212,12 @@ public class LogAccessDialogActivity extends Activity implements
.setText(mAlertTitle);
if (!TextUtils.isEmpty(mAlertLearnMore)) {
Spannable mSpannableLearnMore = styleFont(mAlertLearnMore);
((TextView) view.findViewById(R.id.log_access_dialog_body))
.setText(TextUtils.concat(mAlertBody, "\n\n", mSpannableLearnMore));
((TextView) view.findViewById(R.id.log_access_dialog_body))
.setText(TextUtils.concat(mAlertBody, "\n\n", mAlertLearnMore));
if (mAlertLearnMoreLink) {
((TextView) view.findViewById(R.id.log_access_dialog_body))
.setMovementMethod(LinkMovementMethod.getInstance());
}
} else {
((TextView) view.findViewById(R.id.log_access_dialog_body))
.setText(mAlertBody);