Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3617)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java

Issue 2730703003: Change CBD layout and texts (Closed)
Patch Set: cleanup test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java
new file mode 100644
index 0000000000000000000000000000000000000000..aa3398a87a994e6f4806b85f023072b07bb376f6
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java
@@ -0,0 +1,127 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+package org.chromium.chrome.browser.preferences;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.style.ClickableSpan;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.ListView;
+import android.widget.RelativeLayout;
+import android.widget.TextView;
+
+import org.chromium.base.ApiCompatibilityUtils;
+import org.chromium.ui.text.NoUnderlineClickableSpan;
+import org.chromium.ui.text.SpanApplier;
+
+/**
+ * A preference representing one browsing data type in ClearBrowsingDataPreferencesTab.
+ * This class allows clickable links inside the checkbox summary.
+ */
+public class ClearBrowsingDataTabCheckBoxPreference extends ClearBrowsingDataCheckBoxPreference {
+ private Runnable mLinkClickDelegate;
+ private boolean mHasClickableSpans;
+
+ /**
+ * Constructor for inflating from XML.
+ */
+ public ClearBrowsingDataTabCheckBoxPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ /**
+ * @param linkClickDelegate A Runnable that is executed when a link inside the summary is
+ * clicked.
+ */
+ public void setLinkClickDelegate(Runnable linkClickDelegate) {
+ mLinkClickDelegate = linkClickDelegate;
+ }
+
+ @Override
+ public View onCreateView(ViewGroup parent) {
+ View view = super.onCreateView(parent);
+
+ final TextView textView = (TextView) view.findViewById(android.R.id.summary);
+
+ // Create custom onTouch listener to be able to respond to click events inside the summary.
Theresa 2017/03/24 17:15:37 Is the desired UX that when you click anywhere bes
dullweber 2017/03/27 14:11:04 My goal was that clicking the text should check or
Theresa 2017/03/27 15:24:52 I don't think that is acceptable behavior, but we
+ textView.setOnTouchListener(new View.OnTouchListener() {
+ @Override
+ @SuppressLint("ClickableViewAccessibility")
Theresa 2017/03/24 17:15:37 We need to test this with TalkBack on to make sur
+ public boolean onTouch(View v, MotionEvent event) {
+ if (!mHasClickableSpans) {
+ return false;
+ }
+ // Find out which character was touched.
+ int offset = textView.getOffsetForPosition(event.getX(), event.getY());
+ // Check if this character contains a span.
+ Spanned text = (Spanned) textView.getText();
+ ClickableSpan[] types = text.getSpans(offset, offset, ClickableSpan.class);
+
+ if (types.length > 0) {
+ if (event.getAction() == MotionEvent.ACTION_UP) {
+ for (ClickableSpan type : types) {
+ type.onClick(textView);
+ }
+ }
+ return true;
+ } else {
+ return false;
+ }
+ }
+ });
+
+ return view;
+ }
+
+ @Override
+ protected void setupLayout(LinearLayout view) {
+ float density = view.getResources().getDisplayMetrics().density;
+ // Use a custom layout to improve the design with large summary texts.
+ view.setGravity(Gravity.TOP);
+ ListView.LayoutParams lp = (ListView.LayoutParams) view.getLayoutParams();
+ ApiCompatibilityUtils.setPaddingRelative(view, ApiCompatibilityUtils.getPaddingStart(view),
+ (int) (6 * density), ApiCompatibilityUtils.getPaddingEnd(view),
Theresa 2017/03/24 17:15:36 You should define a dimension with a value of "6"
dullweber 2017/03/27 14:11:04 Done, I also improved the documentation of why I c
+ (int) (6 * density));
+ view.setLayoutParams(lp);
+
+ RelativeLayout textLayout =
+ (RelativeLayout) view.findViewById(android.R.id.title).getParent();
+ ApiCompatibilityUtils.setPaddingRelative(textLayout,
+ ApiCompatibilityUtils.getPaddingStart(textLayout), 0,
+ ApiCompatibilityUtils.getPaddingEnd(textLayout), 0);
Theresa 2017/03/24 17:15:37 If possible, it is highly preferable to avoid this
dullweber 2017/03/27 14:11:04 I made these layout changes to align the checkbox
Theresa 2017/03/27 15:24:52 The UX decision either needs to be consistent with
dullweber 2017/03/30 09:11:58 I removed the custom gravity on the checkbox. This
+
+ LinearLayout widgetFrame = (LinearLayout) view.findViewById(android.R.id.widget_frame);
+ widgetFrame.setGravity(Gravity.TOP);
+ }
+
+ @Override
+ public void setSummary(CharSequence summary) {
+ // If there is no link in the summary, invoke the default behavior.
+ String summaryString = summary.toString();
+ if (!summaryString.contains("<link>") || !summaryString.contains("</link>")) {
+ super.setSummary(summary);
+ return;
+ }
+
+ // Linkify <link></link> span.
+ final SpannableString summaryWithLink = SpanApplier.applySpans(summaryString,
+ new SpanApplier.SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
+ @Override
+ public void onClick(View widget) {
+ if (mLinkClickDelegate != null) mLinkClickDelegate.run();
+ }
+ }));
+
+ mHasClickableSpans = true;
+ super.setSummary(summaryWithLink);
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698