Commit 8442f938 authored by Peter Kotwicz's avatar Peter Kotwicz Committed by Chromium LUCI CQ

Fix UseSwitchCompatOrMaterialXml lint errors

This CL replaces android.widget.Switch with
androidx.appcompat.widget.SwitchCompat in the keyboard accessory to
silence a UseSwitchCompatOrMaterialXml lint error. This is in preparation
for rolling the androidx.appcompat to version 1.3.0

Replacing android.widget.Switch with
androidx.appcompat.widget.SwitchCompat for the keyboard accessoory does
cause very minor visual changes. (I only noticed them by comparing
screenshots using an image editor)

This CL also suppresses the UseSwitchCompatOrMaterialXml lint error for
R.id.incognito_switch The lint error is suppressed because using
androidx.appcompat.widget.SwitchCompat causes noticeable visual changes.

BUG=1064277

Change-Id: I976c675b057451aa4b9895cb06b9d665223ca0f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569962
Commit-Queue: Peter Kotwicz <pkotwicz@chromium.org>
Reviewed-by: default avatarFriedrich [CET] <fhorschig@chromium.org>
Reviewed-by: default avatarIoana Pandele <ioanap@chromium.org>
Reviewed-by: default avatarYusuf Ozuysal <yusufo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833637}
parent 5e1bf5af
......@@ -80,6 +80,7 @@ android_library("test_java") {
"//content/public/test/android:content_java_test_support",
"//net/android:net_java_test_support",
"//third_party/android_deps:androidx_annotation_annotation_java",
"//third_party/android_deps:androidx_appcompat_appcompat_java",
"//third_party/android_deps:androidx_recyclerview_recyclerview_java",
"//third_party/android_deps:androidx_test_runner_java",
"//third_party/android_deps:espresso_java",
......
......@@ -37,7 +37,7 @@
android:textAppearance="@style/TextAppearance.TextMedium.Secondary" />
</LinearLayout>
<android.widget.Switch
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/option_toggle_switch"
android:layout_marginStart="16dp"
android:layout_width="48dp"
......
......@@ -8,11 +8,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Switch;
import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
......@@ -119,7 +119,7 @@ class AccessorySheetTabViewBinder {
TextView subtitleText = view.findViewById(R.id.option_toggle_subtitle);
subtitleText.setText(optionToggle.isEnabled() ? R.string.text_on : R.string.text_off);
Switch switchView = view.findViewById(R.id.option_toggle_switch);
SwitchCompat switchView = view.findViewById(R.id.option_toggle_switch);
switchView.setChecked(optionToggle.isEnabled());
switchView.setBackground(null);
}
......
......@@ -19,9 +19,9 @@ import static org.junit.Assert.assertTrue;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Switch;
import android.widget.TextView;
import androidx.appcompat.widget.SwitchCompat;
import androidx.recyclerview.widget.RecyclerView;
import androidx.test.filters.MediumTest;
......@@ -198,8 +198,8 @@ public class PasswordAccessorySheetModernViewTest {
View switchView = mView.get().findViewById(R.id.option_toggle_switch);
assertThat(switchView, is(not(nullValue())));
assertThat(switchView, instanceOf(Switch.class));
assertFalse(((Switch) switchView).isChecked());
assertThat(switchView, instanceOf(SwitchCompat.class));
assertFalse(((SwitchCompat) switchView).isChecked());
}
@Test
......
......@@ -14,6 +14,7 @@
android:visibility="gone">
<Switch
tools:ignore="UseSwitchCompatOrMaterialXml"
android:id="@+id/incognito_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
......
......@@ -6,6 +6,7 @@
<org.chromium.chrome.browser.toolbar.top.TabSwitcherModeTTPhone
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/tab_switcher_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height_no_shadow"
......@@ -89,7 +90,8 @@
android:paddingEnd="16dp"
android:thumb="@drawable/incognito_switch"
android:track="@drawable/incognito_switch_track"
android:visibility="gone"/>
android:visibility="gone"
tools:ignore="UseSwitchCompatOrMaterialXml"/>
<include layout="@layout/menu_button" />
......
......@@ -31,6 +31,7 @@ class IncognitoSwitchCoordinator {
private TabModelSelector mTabModelSelector;
private TabModelSelectorObserver mTabModelSelectorObserver;
@SuppressWarnings({"UseSwitchCompatOrMaterialCode"})
public IncognitoSwitchCoordinator(ViewGroup root, TabModelSelector tabModelSelector) {
assert tabModelSelector != null;
mTabModelSelector = tabModelSelector;
......
......@@ -24,6 +24,7 @@ class IncognitoSwitchViewBinder {
* Build a binder that handles interaction between the model and the view that make up the
* incognito switch.
*/
@SuppressWarnings({"UseSwitchCompatOrMaterialCode"})
public static void bind(PropertyModel model, Switch incognitoSwitch, PropertyKey propertyKey) {
if (IncognitoSwitchProperties.ON_CHECKED_CHANGE_LISTENER == propertyKey) {
incognitoSwitch.setOnCheckedChangeListener(
......
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