From 506c0cfab42ff7e212a7cae530324d23cc88ae20 Mon Sep 17 00:00:00 2001 From: Edgar Wang Date: Sat, 13 Feb 2021 12:28:26 +0800 Subject: Create SettingsLibTwoTargetPreference Bug: 180156703 Test: robotest Change-Id: I4a9958efa47ac24f88e06c8fdb1c9d0a5542e360 --- packages/SettingsLib/Android.bp | 10 +- .../SettingsLib/TwoTargetPreference/Android.bp | 13 ++ .../TwoTargetPreference/AndroidManifest.xml | 23 ++++ .../res/layout/preference_two_target.xml | 97 +++++++++++++++ .../res/layout/preference_two_target_divider.xml | 31 +++++ .../TwoTargetPreference/res/values/dimens.xml | 21 ++++ .../settingslib/widget/TwoTargetPreference.java | 119 +++++++++++++++++++ .../res/layout/preference_two_target.xml | 97 --------------- .../res/layout/preference_two_target_divider.xml | 31 ----- packages/SettingsLib/res/values/dimens.xml | 3 - .../android/settingslib/RestrictedPreference.java | 2 + .../android/settingslib/TwoTargetPreference.java | 116 ------------------ .../settingslib/TwoTargetPreferenceTest.java | 129 -------------------- .../widget/TwoTargetPreferenceTest.java | 131 +++++++++++++++++++++ 14 files changed, 444 insertions(+), 379 deletions(-) create mode 100644 packages/SettingsLib/TwoTargetPreference/Android.bp create mode 100644 packages/SettingsLib/TwoTargetPreference/AndroidManifest.xml create mode 100644 packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target.xml create mode 100644 packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target_divider.xml create mode 100644 packages/SettingsLib/TwoTargetPreference/res/values/dimens.xml create mode 100644 packages/SettingsLib/TwoTargetPreference/src/com/android/settingslib/widget/TwoTargetPreference.java delete mode 100644 packages/SettingsLib/res/layout/preference_two_target.xml delete mode 100644 packages/SettingsLib/res/layout/preference_two_target_divider.xml delete mode 100644 packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java delete mode 100644 packages/SettingsLib/tests/robotests/src/com/android/settingslib/TwoTargetPreferenceTest.java create mode 100644 packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/TwoTargetPreferenceTest.java diff --git a/packages/SettingsLib/Android.bp b/packages/SettingsLib/Android.bp index f2a0e1cb83bd..68ce7d963242 100644 --- a/packages/SettingsLib/Android.bp +++ b/packages/SettingsLib/Android.bp @@ -17,8 +17,8 @@ android_library { // TODO(b/149540986): revert this change. static_libs: [ - // All other dependent components should be put in - // "SettingsLibDependenciesWithoutWifiTracker". + // All other dependent components should be put in + // "SettingsLibDependenciesWithoutWifiTracker". "WifiTrackerLib", ], @@ -27,7 +27,10 @@ android_library { resource_dirs: ["res"], - srcs: ["src/**/*.java", "src/**/*.kt"], + srcs: [ + "src/**/*.java", + "src/**/*.kt", + ], min_sdk_version: "21", @@ -67,6 +70,7 @@ java_defaults { "SettingsLibFooterPreference", "SettingsLibUsageProgressBarPreference", "SettingsLibCollapsingToolbarBaseActivity", + "SettingsLibTwoTargetPreference", ], } diff --git a/packages/SettingsLib/TwoTargetPreference/Android.bp b/packages/SettingsLib/TwoTargetPreference/Android.bp new file mode 100644 index 000000000000..f2e79b9ab53b --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/Android.bp @@ -0,0 +1,13 @@ +android_library { + name: "SettingsLibTwoTargetPreference", + + srcs: ["src/**/*.java"], + resource_dirs: ["res"], + + static_libs: [ + "androidx.annotation_annotation", + "androidx.preference_preference", + ], + sdk_version: "system_current", + min_sdk_version: "21", +} diff --git a/packages/SettingsLib/TwoTargetPreference/AndroidManifest.xml b/packages/SettingsLib/TwoTargetPreference/AndroidManifest.xml new file mode 100644 index 000000000000..120b0859a70a --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/AndroidManifest.xml @@ -0,0 +1,23 @@ + + + + + + + + diff --git a/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target.xml b/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target.xml new file mode 100644 index 000000000000..21fcedcc01b6 --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target_divider.xml b/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target_divider.xml new file mode 100644 index 000000000000..bd477f8068ff --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/res/layout/preference_two_target_divider.xml @@ -0,0 +1,31 @@ + + + + + + \ No newline at end of file diff --git a/packages/SettingsLib/TwoTargetPreference/res/values/dimens.xml b/packages/SettingsLib/TwoTargetPreference/res/values/dimens.xml new file mode 100644 index 000000000000..32a865905267 --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/res/values/dimens.xml @@ -0,0 +1,21 @@ + + + + + 24dp + 32dp + diff --git a/packages/SettingsLib/TwoTargetPreference/src/com/android/settingslib/widget/TwoTargetPreference.java b/packages/SettingsLib/TwoTargetPreference/src/com/android/settingslib/widget/TwoTargetPreference.java new file mode 100644 index 000000000000..9130662021d5 --- /dev/null +++ b/packages/SettingsLib/TwoTargetPreference/src/com/android/settingslib/widget/TwoTargetPreference.java @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settingslib.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.ImageView; +import android.widget.LinearLayout; + +import androidx.annotation.IntDef; +import androidx.preference.Preference; +import androidx.preference.PreferenceViewHolder; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/** + * The Base preference with two target areas divided by a vertical divider + */ +public class TwoTargetPreference extends Preference { + + @IntDef({ICON_SIZE_DEFAULT, ICON_SIZE_MEDIUM, ICON_SIZE_SMALL}) + @Retention(RetentionPolicy.SOURCE) + public @interface IconSize { + } + + public static final int ICON_SIZE_DEFAULT = 0; + public static final int ICON_SIZE_MEDIUM = 1; + public static final int ICON_SIZE_SMALL = 2; + + @IconSize + private int mIconSize; + private int mSmallIconSize; + private int mMediumIconSize; + + public TwoTargetPreference(Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(context); + } + + public TwoTargetPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(context); + } + + public TwoTargetPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(context); + } + + public TwoTargetPreference(Context context) { + super(context); + init(context); + } + + private void init(Context context) { + setLayoutResource(R.layout.preference_two_target); + mSmallIconSize = context.getResources().getDimensionPixelSize( + R.dimen.two_target_pref_small_icon_size); + mMediumIconSize = context.getResources().getDimensionPixelSize( + R.dimen.two_target_pref_medium_icon_size); + final int secondTargetResId = getSecondTargetResId(); + if (secondTargetResId != 0) { + setWidgetLayoutResource(secondTargetResId); + } + } + + public void setIconSize(@IconSize int iconSize) { + mIconSize = iconSize; + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + final ImageView icon = holder.itemView.findViewById(android.R.id.icon); + switch (mIconSize) { + case ICON_SIZE_SMALL: + icon.setLayoutParams(new LinearLayout.LayoutParams(mSmallIconSize, mSmallIconSize)); + break; + case ICON_SIZE_MEDIUM: + icon.setLayoutParams( + new LinearLayout.LayoutParams(mMediumIconSize, mMediumIconSize)); + break; + } + final View divider = holder.findViewById(R.id.two_target_divider); + final View widgetFrame = holder.findViewById(android.R.id.widget_frame); + final boolean shouldHideSecondTarget = shouldHideSecondTarget(); + if (divider != null) { + divider.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE); + } + if (widgetFrame != null) { + widgetFrame.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE); + } + } + + protected boolean shouldHideSecondTarget() { + return getSecondTargetResId() == 0; + } + + protected int getSecondTargetResId() { + return 0; + } +} diff --git a/packages/SettingsLib/res/layout/preference_two_target.xml b/packages/SettingsLib/res/layout/preference_two_target.xml deleted file mode 100644 index ff6a22d5523c..000000000000 --- a/packages/SettingsLib/res/layout/preference_two_target.xml +++ /dev/null @@ -1,97 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/packages/SettingsLib/res/layout/preference_two_target_divider.xml b/packages/SettingsLib/res/layout/preference_two_target_divider.xml deleted file mode 100644 index b81dd83d2586..000000000000 --- a/packages/SettingsLib/res/layout/preference_two_target_divider.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/packages/SettingsLib/res/values/dimens.xml b/packages/SettingsLib/res/values/dimens.xml index ef4b97f7743f..9d5b23166190 100644 --- a/packages/SettingsLib/res/values/dimens.xml +++ b/packages/SettingsLib/res/values/dimens.xml @@ -32,9 +32,6 @@ 20dp 56dp - 24dp - 32dp - 4dp diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java index ad7e995412aa..fc8b5879c5fa 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedPreference.java @@ -27,6 +27,8 @@ import androidx.core.content.res.TypedArrayUtils; import androidx.preference.PreferenceManager; import androidx.preference.PreferenceViewHolder; +import com.android.settingslib.widget.TwoTargetPreference; + /** * Preference class that supports being disabled by a user restriction * set by a device admin. diff --git a/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java b/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java deleted file mode 100644 index 02895a479352..000000000000 --- a/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settingslib; - -import android.annotation.IntDef; -import android.content.Context; -import android.util.AttributeSet; -import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; - -import androidx.preference.Preference; -import androidx.preference.PreferenceViewHolder; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -public class TwoTargetPreference extends Preference { - - @IntDef({ICON_SIZE_DEFAULT, ICON_SIZE_MEDIUM, ICON_SIZE_SMALL}) - @Retention(RetentionPolicy.SOURCE) - public @interface IconSize { - } - - public static final int ICON_SIZE_DEFAULT = 0; - public static final int ICON_SIZE_MEDIUM = 1; - public static final int ICON_SIZE_SMALL = 2; - - @IconSize - private int mIconSize; - private int mSmallIconSize; - private int mMediumIconSize; - - public TwoTargetPreference(Context context, AttributeSet attrs, - int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - init(context); - } - - public TwoTargetPreference(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - init(context); - } - - public TwoTargetPreference(Context context, AttributeSet attrs) { - super(context, attrs); - init(context); - } - - public TwoTargetPreference(Context context) { - super(context); - init(context); - } - - private void init(Context context) { - setLayoutResource(R.layout.preference_two_target); - mSmallIconSize = context.getResources().getDimensionPixelSize( - R.dimen.two_target_pref_small_icon_size); - mMediumIconSize = context.getResources().getDimensionPixelSize( - R.dimen.two_target_pref_medium_icon_size); - final int secondTargetResId = getSecondTargetResId(); - if (secondTargetResId != 0) { - setWidgetLayoutResource(secondTargetResId); - } - } - - public void setIconSize(@IconSize int iconSize) { - mIconSize = iconSize; - } - - @Override - public void onBindViewHolder(PreferenceViewHolder holder) { - super.onBindViewHolder(holder); - final ImageView icon = holder.itemView.findViewById(android.R.id.icon); - switch (mIconSize) { - case ICON_SIZE_SMALL: - icon.setLayoutParams(new LinearLayout.LayoutParams(mSmallIconSize, mSmallIconSize)); - break; - case ICON_SIZE_MEDIUM: - icon.setLayoutParams( - new LinearLayout.LayoutParams(mMediumIconSize, mMediumIconSize)); - break; - } - final View divider = holder.findViewById(R.id.two_target_divider); - final View widgetFrame = holder.findViewById(android.R.id.widget_frame); - final boolean shouldHideSecondTarget = shouldHideSecondTarget(); - if (divider != null) { - divider.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE); - } - if (widgetFrame != null) { - widgetFrame.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE); - } - } - - protected boolean shouldHideSecondTarget() { - return getSecondTargetResId() == 0; - } - - protected int getSecondTargetResId() { - return 0; - } -} diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/TwoTargetPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/TwoTargetPreferenceTest.java deleted file mode 100644 index 3f0ba13ce50a..000000000000 --- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/TwoTargetPreferenceTest.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settingslib; - -import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_DEFAULT; -import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_MEDIUM; -import static com.android.settingslib.TwoTargetPreference.ICON_SIZE_SMALL; - -import static com.google.common.truth.Truth.assertThat; - -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; - -import android.content.Context; -import android.view.View; -import android.view.ViewGroup; -import android.widget.LinearLayout; - -import androidx.preference.PreferenceViewHolder; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.MockitoAnnotations; -import org.robolectric.RobolectricTestRunner; -import org.robolectric.RuntimeEnvironment; - -@RunWith(RobolectricTestRunner.class) -public class TwoTargetPreferenceTest { - - private PreferenceViewHolder mViewHolder; - private View mDivider; - private View mWidgetFrame; - private View mRootView; - private TwoTargetPreference mPreference; - private Context mContext; - - @Before - public void setUp() { - MockitoAnnotations.initMocks(this); - mContext = RuntimeEnvironment.application; - mPreference = spy(new TwoTargetPreference(mContext)); - mRootView = View.inflate(mContext, R.layout.preference_two_target, null /* parent */); - mViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView); - - mDivider = mViewHolder.findViewById(R.id.two_target_divider); - mWidgetFrame = mViewHolder.findViewById(android.R.id.widget_frame); - } - - @Test - public void bind_noSecondTarget_shouldNotDrawDivider() { - assertThat(mPreference.shouldHideSecondTarget()).isTrue(); - - mPreference.onBindViewHolder(mViewHolder); - - assertThat(mDivider.getVisibility()).isEqualTo(View.GONE); - assertThat(mWidgetFrame.getVisibility()).isEqualTo(View.GONE); - } - - @Test - public void bind_hasSecondTarget_shouldNotDrawDivider() { - doReturn(false).when(mPreference).shouldHideSecondTarget(); - - mPreference.onBindViewHolder(mViewHolder); - - assertThat(mDivider.getVisibility()).isEqualTo(View.VISIBLE); - assertThat(mWidgetFrame.getVisibility()).isEqualTo(View.VISIBLE); - } - - @Test - public void bind_smallIcon_shouldUseSmallIconSize() { - mPreference.setIconSize(ICON_SIZE_SMALL); - - mPreference.onBindViewHolder(mViewHolder); - - final int smallIconSize = mContext.getResources().getDimensionPixelSize( - R.dimen.two_target_pref_small_icon_size); - final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder - .findViewById(android.R.id.icon) - .getLayoutParams(); - - assertThat(layoutParams.width).isEqualTo(smallIconSize); - assertThat(layoutParams.height).isEqualTo(smallIconSize); - } - - @Test - public void bind_mediumIcon_shouldUseMediumIconSize() { - mPreference.setIconSize(ICON_SIZE_MEDIUM); - - mPreference.onBindViewHolder(mViewHolder); - - final int size = mContext.getResources().getDimensionPixelSize( - R.dimen.two_target_pref_medium_icon_size); - final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder - .findViewById(android.R.id.icon) - .getLayoutParams(); - - assertThat(layoutParams.width).isEqualTo(size); - assertThat(layoutParams.height).isEqualTo(size); - } - - @Test - public void bind_defaultIcon_shouldUseDefaultIconSize() { - mPreference.setIconSize(ICON_SIZE_DEFAULT); - - mPreference.onBindViewHolder(mViewHolder); - - final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder - .findViewById(android.R.id.icon) - .getLayoutParams(); - - assertThat(layoutParams.width).isEqualTo(ViewGroup.LayoutParams.WRAP_CONTENT); - assertThat(layoutParams.height).isEqualTo(ViewGroup.LayoutParams.WRAP_CONTENT); - } -} diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/TwoTargetPreferenceTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/TwoTargetPreferenceTest.java new file mode 100644 index 000000000000..aaec909aa335 --- /dev/null +++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/widget/TwoTargetPreferenceTest.java @@ -0,0 +1,131 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settingslib.widget; + +import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_DEFAULT; +import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_MEDIUM; +import static com.android.settingslib.widget.TwoTargetPreference.ICON_SIZE_SMALL; + +import static com.google.common.truth.Truth.assertThat; + +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; + +import android.content.Context; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +import androidx.preference.PreferenceViewHolder; + +import com.android.settingslib.R; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; + +@RunWith(RobolectricTestRunner.class) +public class TwoTargetPreferenceTest { + + private PreferenceViewHolder mViewHolder; + private View mDivider; + private View mWidgetFrame; + private View mRootView; + private TwoTargetPreference mPreference; + private Context mContext; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mContext = RuntimeEnvironment.application; + mPreference = spy(new TwoTargetPreference(mContext)); + mRootView = View.inflate(mContext, R.layout.preference_two_target, null /* parent */); + mViewHolder = PreferenceViewHolder.createInstanceForTests(mRootView); + + mDivider = mViewHolder.findViewById(R.id.two_target_divider); + mWidgetFrame = mViewHolder.findViewById(android.R.id.widget_frame); + } + + @Test + public void bind_noSecondTarget_shouldNotDrawDivider() { + assertThat(mPreference.shouldHideSecondTarget()).isTrue(); + + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mDivider.getVisibility()).isEqualTo(View.GONE); + assertThat(mWidgetFrame.getVisibility()).isEqualTo(View.GONE); + } + + @Test + public void bind_hasSecondTarget_shouldNotDrawDivider() { + doReturn(false).when(mPreference).shouldHideSecondTarget(); + + mPreference.onBindViewHolder(mViewHolder); + + assertThat(mDivider.getVisibility()).isEqualTo(View.VISIBLE); + assertThat(mWidgetFrame.getVisibility()).isEqualTo(View.VISIBLE); + } + + @Test + public void bind_smallIcon_shouldUseSmallIconSize() { + mPreference.setIconSize(ICON_SIZE_SMALL); + + mPreference.onBindViewHolder(mViewHolder); + + final int smallIconSize = mContext.getResources().getDimensionPixelSize( + R.dimen.two_target_pref_small_icon_size); + final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder + .findViewById(android.R.id.icon) + .getLayoutParams(); + + assertThat(layoutParams.width).isEqualTo(smallIconSize); + assertThat(layoutParams.height).isEqualTo(smallIconSize); + } + + @Test + public void bind_mediumIcon_shouldUseMediumIconSize() { + mPreference.setIconSize(ICON_SIZE_MEDIUM); + + mPreference.onBindViewHolder(mViewHolder); + + final int size = mContext.getResources().getDimensionPixelSize( + R.dimen.two_target_pref_medium_icon_size); + final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder + .findViewById(android.R.id.icon) + .getLayoutParams(); + + assertThat(layoutParams.width).isEqualTo(size); + assertThat(layoutParams.height).isEqualTo(size); + } + + @Test + public void bind_defaultIcon_shouldUseDefaultIconSize() { + mPreference.setIconSize(ICON_SIZE_DEFAULT); + + mPreference.onBindViewHolder(mViewHolder); + + final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mViewHolder + .findViewById(android.R.id.icon) + .getLayoutParams(); + + assertThat(layoutParams.width).isEqualTo(ViewGroup.LayoutParams.WRAP_CONTENT); + assertThat(layoutParams.height).isEqualTo(ViewGroup.LayoutParams.WRAP_CONTENT); + } +} -- cgit v1.2.3-59-g8ed1b