Commit e428ad32 authored by Christian Dullweber's avatar Christian Dullweber Committed by Commit Bot

Remove ClearBrowsingDataTabCheckbox

Move code from CBDTabCheckbox to CBDCheckbox.
Replace View.OnTouchListener with lambda.
Fully remove ClearBrowsingDataPreferencesTab.java.

Bug: 777842
Change-Id: I57c668b5a82de74605d57b01647c6b7376cabe21
Reviewed-on: https://chromium-review.googlesource.com/758678
Commit-Queue: Christian Dullweber <dullweber@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515534}
parent 5f1936b1
......@@ -3,7 +3,7 @@
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. -->
<!-- Used by ClearBrowsingDataPreferencesTab to replace the default layout
<!-- Used by ClearBrowsingDataPreferences to replace the default layout
of a PreferenceFragment and add a footer button. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
......
......@@ -417,7 +417,6 @@
<dimen name="psl_info_tooltip_margin">8dp</dimen>
<!-- Clear browsing data preferences dimensions -->
<dimen name="clear_browsing_data_checkbox_height">56dp</dimen>
<dimen name="clear_browsing_data_button_margin">8dp</dimen>
<!-- Payments UI
......
......@@ -17,39 +17,39 @@
android:layout="@layout/divider_preference_with_bottom_padding"
android:selectable="false"/>
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_history_checkbox"
android:persistent="false"
android:title="@string/clear_history_title"
android:summary="@string/clear_browsing_history_summary" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_cookies_checkbox"
android:persistent="false"
android:title="@string/clear_cookies_and_site_data_title"
android:summary="@string/clear_cookies_and_site_data_summary_basic" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_cache_checkbox"
android:persistent="false"
android:title="@string/clear_cache_title" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_passwords_checkbox"
android:persistent="false"
android:title="@string/clear_passwords_title" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_form_data_checkbox"
android:persistent="false"
android:title="@string/clear_form_data_title" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_site_settings_checkbox"
android:persistent="false"
android:title="@string/prefs_site_settings" />
<org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference
<org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference
android:key="clear_media_licenses_checkbox"
android:persistent="false"
android:title="@string/clear_media_licenses_title" />
......
......@@ -4,20 +4,32 @@
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.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ImageView;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.AccessibilityUtil;
import org.chromium.ui.text.NoUnderlineClickableSpan;
import org.chromium.ui.text.SpanApplier;
/**
* A preference representing one browsing data type in ClearBrowsingDataPreferences.
* This class allows clickable links inside the checkbox summary.
*/
public class ClearBrowsingDataCheckBoxPreference extends ChromeBaseCheckBoxPreference {
private LinearLayout mView;
private View mView;
private Runnable mLinkClickDelegate;
private boolean mHasClickableSpans;
/**
* Constructor for inflating from XML.
......@@ -26,13 +38,47 @@ public class ClearBrowsingDataCheckBoxPreference extends ChromeBaseCheckBoxPrefe
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;
}
@SuppressLint("ClickableViewAccessibility")
@Override
public View onCreateView(ViewGroup parent) {
if (mView != null) return mView;
mView = (LinearLayout) super.onCreateView(parent);
mView = super.onCreateView(parent);
setupLayout(mView);
final TextView textView = (TextView) mView.findViewById(android.R.id.summary);
// Create custom onTouch listener to be able to respond to click events inside the summary.
textView.setOnTouchListener((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 mView;
}
......@@ -40,26 +86,43 @@ public class ClearBrowsingDataCheckBoxPreference extends ChromeBaseCheckBoxPrefe
* This method modifies the default CheckBoxPreference layout.
* @param view The view of this preference.
*/
protected void setupLayout(LinearLayout view) {
// Checkboxes in the Clear Browsing Data dialog will show and hide the results of
// BrowsingDataCounter. It is important that they will not change height when doing so.
// We will therefore set a fixed height.
int height = getContext().getResources().getDimensionPixelSize(
R.dimen.clear_browsing_data_checkbox_height);
view.setMinimumHeight(height);
// The title and summary are enclosed in a common RelativeLayout. We must remove
// its vertical padding for it to be correctly vertically centered in the fixed-height view.
View textLayout = (View) view.findViewById(android.R.id.title).getParent();
private void setupLayout(View view) {
// Adjust icon padding.
int padding = getContext().getResources().getDimensionPixelSize(R.dimen.pref_icon_padding);
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
ApiCompatibilityUtils.setPaddingRelative(
textLayout,
ApiCompatibilityUtils.getPaddingStart(textLayout),
0,
ApiCompatibilityUtils.getPaddingEnd(textLayout),
0);
icon, padding, icon.getPaddingTop(), 0, icon.getPaddingBottom());
}
public void announceForAccessibility(CharSequence announcement) {
if (mView != null) mView.announceForAccessibility(announcement);
}
@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;
}
// Talkback users can't select links inside the summary because it is already a target
// that toggles the checkbox. Links will still be read out and users can manually
// navigate to them.
if (AccessibilityUtil.isAccessibilityEnabled()) {
super.setSummary(summaryString.replaceAll("</?link>", ""));
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);
}
}
// 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.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.util.AccessibilityUtil;
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.
textView.setOnTouchListener(new View.OnTouchListener() {
@Override
@SuppressLint("ClickableViewAccessibility")
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) {
// Override to remove layout customizations from super class.
// Adjust icon padding.
int padding = getContext().getResources().getDimensionPixelSize(R.dimen.pref_icon_padding);
ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
ApiCompatibilityUtils.setPaddingRelative(
icon, padding, icon.getPaddingTop(), 0, icon.getPaddingBottom());
}
@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;
}
// Talkback users can't select links inside the summary because it is already a target
// that toggles the checkbox. Links will still be read out and users can manually
// navigate to them.
if (AccessibilityUtil.isAccessibilityEnabled()) {
super.setSummary(summaryString.replaceAll("</?link>", ""));
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);
}
}
......@@ -11,7 +11,7 @@ import org.chromium.base.metrics.RecordUserAction;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.UrlConstants;
import org.chromium.chrome.browser.browsing_data.ClearBrowsingDataTab;
import org.chromium.chrome.browser.preferences.ClearBrowsingDataTabCheckBoxPreference;
import org.chromium.chrome.browser.preferences.ClearBrowsingDataCheckBoxPreference;
import org.chromium.chrome.browser.sync.ProfileSyncService;
import org.chromium.chrome.browser.tabmodel.TabModel;
import org.chromium.chrome.browser.tabmodel.document.TabDelegate;
......@@ -28,10 +28,10 @@ public class ClearBrowsingDataPreferencesBasic extends ClearBrowsingDataPreferen
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ClearBrowsingDataTabCheckBoxPreference historyCheckbox =
(ClearBrowsingDataTabCheckBoxPreference) findPreference(PREF_HISTORY);
ClearBrowsingDataTabCheckBoxPreference cookiesCheckbox =
(ClearBrowsingDataTabCheckBoxPreference) findPreference(PREF_COOKIES);
ClearBrowsingDataCheckBoxPreference historyCheckbox =
(ClearBrowsingDataCheckBoxPreference) findPreference(PREF_HISTORY);
ClearBrowsingDataCheckBoxPreference cookiesCheckbox =
(ClearBrowsingDataCheckBoxPreference) findPreference(PREF_COOKIES);
historyCheckbox.setLinkClickDelegate(() -> {
new TabDelegate(false /* incognito */)
......
// 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.privacy;
/**
* TODO(crbug.com/782631): Remove when java_checker.py is fixed.
*/
public class ClearBrowsingDataPreferencesTab {}
......@@ -893,7 +893,6 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/preferences/ChromePreferenceManager.java",
"java/src/org/chromium/chrome/browser/preferences/ChromeSwitchPreference.java",
"java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataCheckBoxPreference.java",
"java/src/org/chromium/chrome/browser/preferences/ClearBrowsingDataTabCheckBoxPreference.java",
"java/src/org/chromium/chrome/browser/preferences/ExpandablePreferenceGroup.java",
"java/src/org/chromium/chrome/browser/preferences/HomepageEditor.java",
"java/src/org/chromium/chrome/browser/preferences/HomepagePreferences.java",
......
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