Commit e20555d4 authored by estade's avatar estade Committed by Commit bot

Make HyperlinkPreference optionally look like a link.

Use this option in AutofillWalletPreferences. We can also use this to simplify BandwidthReductionPreferences (which is where this code was mostly copied from), but that's in the internal repo, so is a different CL.

BUG=446700

Review URL: https://codereview.chromium.org/853863002

Cr-Commit-Position: refs/heads/master@{#311783}
parent 9b85b5bb
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
<declare-styleable name="HyperlinkPreference"> <declare-styleable name="HyperlinkPreference">
<!-- The URL to load when the preference is clicked --> <!-- The URL to load when the preference is clicked -->
<attr name="url" format="string" /> <attr name="url" format="string" />
<!-- True if the hyperlink should look like an <a> element. Default is false. -->
<attr name="imitateWebLink" format="boolean" />
</declare-styleable> </declare-styleable>
<declare-styleable name="ChromeSwitchPreference"> <declare-styleable name="ChromeSwitchPreference">
...@@ -18,4 +20,4 @@ ...@@ -18,4 +20,4 @@
case that the title is empty. --> case that the title is empty. -->
<attr name="dontUseSummaryAsTitle" format="boolean" /> <attr name="dontUseSummaryAsTitle" format="boolean" />
</declare-styleable> </declare-styleable>
</resources> </resources>
\ No newline at end of file
...@@ -17,12 +17,10 @@ ...@@ -17,12 +17,10 @@
<org.chromium.chrome.browser.preferences.TextMessagePreference <org.chromium.chrome.browser.preferences.TextMessagePreference
android:title="@string/autofill_wallet_description" /> android:title="@string/autofill_wallet_description" />
<!-- TODO(estade): Surprisingly, HyperlinkPreference does not actually look like a link.
We should either fix HyperlinkPreference or copy the technique used by
data_reduction_learn_more. -->
<org.chromium.chrome.browser.preferences.HyperlinkPreference <org.chromium.chrome.browser.preferences.HyperlinkPreference
android:title="@string/autofill_wallet_management_link_text" android:title="@string/autofill_wallet_management_link_text"
app:url="@string/autofill_manage_wallet_cards_url" /> app:url="@string/autofill_manage_wallet_cards_url"
app:imitateWebLink="true" />
<org.chromium.chrome.browser.preferences.TextMessagePreference <org.chromium.chrome.browser.preferences.TextMessagePreference
android:title="@string/autofill_wallet_cache_explanation" /> android:title="@string/autofill_wallet_cache_explanation" />
......
...@@ -9,6 +9,7 @@ import android.content.res.TypedArray; ...@@ -9,6 +9,7 @@ import android.content.res.TypedArray;
import android.preference.Preference; import android.preference.Preference;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView; import android.widget.TextView;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -20,12 +21,14 @@ public class HyperlinkPreference extends Preference { ...@@ -20,12 +21,14 @@ public class HyperlinkPreference extends Preference {
private final int mTitleResId; private final int mTitleResId;
private final int mUrlResId; private final int mUrlResId;
private final boolean mImitateWebLink;
public HyperlinkPreference(Context context, AttributeSet attrs) { public HyperlinkPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs, TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.HyperlinkPreference, 0, 0); R.styleable.HyperlinkPreference, 0, 0);
mUrlResId = a.getResourceId(R.styleable.HyperlinkPreference_url, 0); mUrlResId = a.getResourceId(R.styleable.HyperlinkPreference_url, 0);
mImitateWebLink = a.getBoolean(R.styleable.HyperlinkPreference_imitateWebLink, false);
a.recycle(); a.recycle();
mTitleResId = getTitleRes(); mTitleResId = getTitleRes();
} }
...@@ -40,5 +43,18 @@ public class HyperlinkPreference extends Preference { ...@@ -40,5 +43,18 @@ public class HyperlinkPreference extends Preference {
super.onBindView(view); super.onBindView(view);
TextView titleView = (TextView) view.findViewById(android.R.id.title); TextView titleView = (TextView) view.findViewById(android.R.id.title);
titleView.setSingleLine(false); titleView.setSingleLine(false);
if (mImitateWebLink) {
setSelectable(false);
titleView.setClickable(true);
titleView.setTextColor(titleView.getPaint().linkColor);
titleView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
HyperlinkPreference.this.onClick();
}
});
}
} }
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment