Commit d85b1cf5 authored by Wenyu Fu's avatar Wenyu Fu Committed by Commit Bot

Add selectable background into RadioButtonWithDescription

Seems every RadioButtonWithDescription has the xml attribute of
android:background="?attr/selectalbeItemBackground". Adding this
attributed into widget constructor for simplicity.

Bug: 1048863
Change-Id: Ia335afe12cd5130bdddccf0e083db1b35e28a572
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067279
Commit-Queue: Theresa  <twellington@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747090}
parent 49df5045
...@@ -28,14 +28,12 @@ ...@@ -28,14 +28,12 @@
android:id="@+id/sync_confirm_import_choice" android:id="@+id/sync_confirm_import_choice"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
app:primaryText="@string/sync_import_existing_data" /> app:primaryText="@string/sync_import_existing_data" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription <org.chromium.components.browser_ui.widget.RadioButtonWithDescription
android:id="@+id/sync_keep_separate_choice" android:id="@+id/sync_keep_separate_choice"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
app:primaryText="@string/sync_keep_existing_data_separate" /> app:primaryText="@string/sync_keep_existing_data_separate" />
</LinearLayout> </LinearLayout>
......
...@@ -33,14 +33,12 @@ ...@@ -33,14 +33,12 @@
android:id="@+id/radio_button_chrome_ntp" android:id="@+id/radio_button_chrome_ntp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/options_homepage_chrome_homepage" /> app:primaryText="@string/options_homepage_chrome_homepage" />
<org.chromium.components.browser_ui.widget.RadioButtonWithEditText <org.chromium.components.browser_ui.widget.RadioButtonWithEditText
android:id="@+id/radio_button_uri_edit" android:id="@+id/radio_button_uri_edit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:hint="@string/options_homepage_edit_hint" android:hint="@string/options_homepage_edit_hint"
android:inputType="textUri" /> android:inputType="textUri" />
......
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
android:id="@+id/system_default" android:id="@+id/system_default"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/themes_system_default_title" app:primaryText="@string/themes_system_default_title"
app:descriptionText="@string/themes_system_default_summary" /> app:descriptionText="@string/themes_system_default_summary" />
...@@ -31,7 +30,6 @@ ...@@ -31,7 +30,6 @@
android:minHeight="@dimen/min_touch_target_size" android:minHeight="@dimen/min_touch_target_size"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/light_mode" /> app:primaryText="@string/light_mode" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription <org.chromium.components.browser_ui.widget.RadioButtonWithDescription
...@@ -41,7 +39,6 @@ ...@@ -41,7 +39,6 @@
android:minHeight="@dimen/min_touch_target_size" android:minHeight="@dimen/min_touch_target_size"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/dark_mode" /> app:primaryText="@string/dark_mode" />
</org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout> </org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout>
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?android:attr/selectableItemBackground"
app:primaryText="@string/website_settings_category_allowed" /> app:primaryText="@string/website_settings_category_allowed" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription <org.chromium.components.browser_ui.widget.RadioButtonWithDescription
...@@ -32,7 +31,6 @@ ...@@ -32,7 +31,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?android:attr/selectableItemBackground"
app:primaryText="@string/website_settings_category_ask" /> app:primaryText="@string/website_settings_category_ask" />
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription <org.chromium.components.browser_ui.widget.RadioButtonWithDescription
...@@ -40,7 +38,6 @@ ...@@ -40,7 +38,6 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingStart="?android:attr/listPreferredItemPaddingStart" android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:background="?android:attr/selectableItemBackground"
app:primaryText="@string/website_settings_category_blocked" /> app:primaryText="@string/website_settings_category_blocked" />
</org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout> </org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout>
......
...@@ -48,6 +48,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase { ...@@ -48,6 +48,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase {
private RadioButtonWithDescription mRadioButtonWithDescription1; private RadioButtonWithDescription mRadioButtonWithDescription1;
private RadioButtonWithDescription mRadioButtonWithDescription2; private RadioButtonWithDescription mRadioButtonWithDescription2;
private RadioButtonWithDescription mRadioButtonWithDescription3;
private RadioButtonWithEditText mRadioButtonWithEditText1; private RadioButtonWithEditText mRadioButtonWithEditText1;
private RadioButtonWithEditText mRadioButtonWithEditText2; private RadioButtonWithEditText mRadioButtonWithEditText2;
...@@ -76,6 +77,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase { ...@@ -76,6 +77,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase {
mRadioButtonWithDescription1 = content.findViewById(R.id.test_radio_description_1); mRadioButtonWithDescription1 = content.findViewById(R.id.test_radio_description_1);
mRadioButtonWithDescription2 = content.findViewById(R.id.test_radio_description_2); mRadioButtonWithDescription2 = content.findViewById(R.id.test_radio_description_2);
mRadioButtonWithDescription3 = content.findViewById(R.id.test_radio_description_3);
mRadioButtonWithEditText1 = content.findViewById(R.id.test_radio_edit_text_1); mRadioButtonWithEditText1 = content.findViewById(R.id.test_radio_edit_text_1);
mRadioButtonWithEditText2 = content.findViewById(R.id.test_radio_edit_text_2); mRadioButtonWithEditText2 = content.findViewById(R.id.test_radio_edit_text_2);
mRadioButtonWithEditText3 = content.findViewById(R.id.test_radio_edit_text_3); mRadioButtonWithEditText3 = content.findViewById(R.id.test_radio_edit_text_3);
...@@ -85,6 +87,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase { ...@@ -85,6 +87,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase {
Assert.assertNotNull(mLayout); Assert.assertNotNull(mLayout);
Assert.assertNotNull(mRadioButtonWithDescription1); Assert.assertNotNull(mRadioButtonWithDescription1);
Assert.assertNotNull(mRadioButtonWithDescription2); Assert.assertNotNull(mRadioButtonWithDescription2);
Assert.assertNotNull(mRadioButtonWithDescription3);
Assert.assertNotNull(mRadioButtonWithEditText1); Assert.assertNotNull(mRadioButtonWithEditText1);
Assert.assertNotNull(mRadioButtonWithEditText2); Assert.assertNotNull(mRadioButtonWithEditText2);
Assert.assertNotNull(mRadioButtonWithEditText3); Assert.assertNotNull(mRadioButtonWithEditText3);
...@@ -97,6 +100,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase { ...@@ -97,6 +100,7 @@ public class RadioButtonRenderTest extends DummyUiActivityTestCase {
public void testRadioButtonWithDescriptionLayout() throws Exception { public void testRadioButtonWithDescriptionLayout() throws Exception {
mRenderTestRule.render(mRadioButtonWithDescription1, "test_radio_description_1"); mRenderTestRule.render(mRadioButtonWithDescription1, "test_radio_description_1");
mRenderTestRule.render(mRadioButtonWithDescription2, "test_radio_description_2"); mRenderTestRule.render(mRadioButtonWithDescription2, "test_radio_description_2");
mRenderTestRule.render(mRadioButtonWithDescription3, "test_radio_description_3");
mRenderTestRule.render(mRadioButtonWithEditText1, "test_radio_edit_text_1"); mRenderTestRule.render(mRadioButtonWithEditText1, "test_radio_edit_text_1");
mRenderTestRule.render(mRadioButtonWithEditText2, "test_radio_edit_text_2"); mRenderTestRule.render(mRadioButtonWithEditText2, "test_radio_edit_text_2");
mRenderTestRule.render(mRadioButtonWithEditText3, "test_radio_edit_text_3"); mRenderTestRule.render(mRadioButtonWithEditText3, "test_radio_edit_text_3");
......
...@@ -11,6 +11,7 @@ import android.os.Parcelable; ...@@ -11,6 +11,7 @@ import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.SparseArray; import android.util.SparseArray;
import android.util.TypedValue;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
...@@ -88,6 +89,14 @@ public class RadioButtonWithDescription extends RelativeLayout implements OnClic ...@@ -88,6 +89,14 @@ public class RadioButtonWithDescription extends RelativeLayout implements OnClic
getPaddingEnd() == 0 ? lateralPadding : getPaddingEnd(), getPaddingEnd() == 0 ? lateralPadding : getPaddingEnd(),
getPaddingBottom() == 0 ? verticalPadding : getPaddingBottom()); getPaddingBottom() == 0 ? verticalPadding : getPaddingBottom());
// Set the background if not specified in xml
if (getBackground() == null) {
TypedValue background = new TypedValue();
getContext().getTheme().resolveAttribute(
android.R.attr.selectableItemBackground, background, true);
setBackgroundResource(background.resourceId);
}
// We want RadioButtonWithDescription to handle the clicks itself. // We want RadioButtonWithDescription to handle the clicks itself.
setOnClickListener(this); setOnClickListener(this);
// Make it focusable for navigation via key events (tab/up/down keys) // Make it focusable for navigation via key events (tab/up/down keys)
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
android:id="@+id/test_radio_description_1" android:id="@+id/test_radio_description_1"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/test_string" /> app:primaryText="@string/test_string" />
<!-- RadioButtonWithDescription - With primary and description. --> <!-- RadioButtonWithDescription - With primary and description. -->
...@@ -26,7 +25,15 @@ ...@@ -26,7 +25,15 @@
android:id="@+id/test_radio_description_2" android:id="@+id/test_radio_description_2"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" app:primaryText="@string/test_string"
app:descriptionText="@string/test_string" />
<!-- RadioButtonWithDescription - With background override. -->
<org.chromium.components.browser_ui.widget.RadioButtonWithDescription
android:id="@+id/test_radio_description_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/background_color_non_empty"
app:primaryText="@string/test_string" app:primaryText="@string/test_string"
app:descriptionText="@string/test_string" /> app:descriptionText="@string/test_string" />
...@@ -40,7 +47,6 @@ ...@@ -40,7 +47,6 @@
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:inputType="text" android:inputType="text"
android:hint="@string/test_uri" android:hint="@string/test_uri"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/test_string" app:primaryText="@string/test_string"
app:descriptionText="@string/test_string" /> app:descriptionText="@string/test_string" />
...@@ -54,7 +60,6 @@ ...@@ -54,7 +60,6 @@
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:inputType="text" android:inputType="text"
android:hint="@string/test_uri" android:hint="@string/test_uri"
android:background="?attr/selectableItemBackground"
app:primaryText="@string/test_string" /> app:primaryText="@string/test_string" />
<!-- RadioButtonWithDescription - Without primary, with hint, with description. --> <!-- RadioButtonWithDescription - Without primary, with hint, with description. -->
...@@ -67,7 +72,6 @@ ...@@ -67,7 +72,6 @@
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:inputType="text" android:inputType="text"
android:hint="@string/test_uri" android:hint="@string/test_uri"
android:background="?attr/selectableItemBackground"
app:descriptionText="@string/test_string" /> app:descriptionText="@string/test_string" />
<!-- RadioButtonWithDescription - Without primary, without description. --> <!-- RadioButtonWithDescription - Without primary, without description. -->
...@@ -79,7 +83,6 @@ ...@@ -79,7 +83,6 @@
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:inputType="text" android:inputType="text"
android:hint="@string/test_uri" android:hint="@string/test_uri" />
android:background="?attr/selectableItemBackground" />
</org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout> </org.chromium.components.browser_ui.widget.RadioButtonWithDescriptionLayout>
</FrameLayout> </FrameLayout>
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