Merge changes from topic "fix-expressive-design-preference-group" into main
* changes: [Expressive design] preference group - fix preference highlight Fix expressive design preference group
This commit is contained in:
24
res/drawable/preference_background_highlighted.xml
Normal file
24
res/drawable/preference_background_highlighted.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?><!-- Copyright (C) 2014 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:color="?android:colorControlHighlight">
|
||||||
|
<item>
|
||||||
|
<shape
|
||||||
|
android:shape="rectangle"
|
||||||
|
android:tint="@color/preference_highlight_color">
|
||||||
|
</shape>
|
||||||
|
</item>
|
||||||
|
</ripple>
|
@@ -29,11 +29,12 @@ import android.util.Log;
|
|||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.DrawableRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceGroup;
|
import androidx.preference.PreferenceGroup;
|
||||||
import androidx.preference.PreferenceGroupAdapter;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
@@ -42,40 +43,35 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
import com.android.settings.accessibility.AccessibilityUtil;
|
import com.android.settings.accessibility.AccessibilityUtil;
|
||||||
|
import com.android.settingslib.widget.SettingsPreferenceGroupAdapter;
|
||||||
|
import com.android.settingslib.widget.SettingsThemeHelper;
|
||||||
|
|
||||||
import com.google.android.material.appbar.AppBarLayout;
|
import com.google.android.material.appbar.AppBarLayout;
|
||||||
|
|
||||||
public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter {
|
public class HighlightablePreferenceGroupAdapter extends SettingsPreferenceGroupAdapter {
|
||||||
|
|
||||||
private static final String TAG = "HighlightableAdapter";
|
private static final String TAG = "HighlightableAdapter";
|
||||||
@VisibleForTesting
|
@VisibleForTesting static final long DELAY_COLLAPSE_DURATION_MILLIS = 300L;
|
||||||
static final long DELAY_COLLAPSE_DURATION_MILLIS = 300L;
|
@VisibleForTesting static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 600L;
|
||||||
@VisibleForTesting
|
@VisibleForTesting static final long DELAY_HIGHLIGHT_DURATION_MILLIS_A11Y = 300L;
|
||||||
static final long DELAY_HIGHLIGHT_DURATION_MILLIS = 600L;
|
|
||||||
@VisibleForTesting
|
|
||||||
static final long DELAY_HIGHLIGHT_DURATION_MILLIS_A11Y = 300L;
|
|
||||||
private static final long HIGHLIGHT_DURATION = 15000L;
|
private static final long HIGHLIGHT_DURATION = 15000L;
|
||||||
private static final long HIGHLIGHT_FADE_OUT_DURATION = 500L;
|
private static final long HIGHLIGHT_FADE_OUT_DURATION = 500L;
|
||||||
private static final long HIGHLIGHT_FADE_IN_DURATION = 200L;
|
private static final long HIGHLIGHT_FADE_IN_DURATION = 200L;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting @DrawableRes final int mHighlightBackgroundRes;
|
||||||
final int mHighlightColor;
|
@VisibleForTesting boolean mFadeInAnimated;
|
||||||
@VisibleForTesting
|
|
||||||
boolean mFadeInAnimated;
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final int mNormalBackgroundRes;
|
private final @DrawableRes int mNormalBackgroundRes;
|
||||||
private final @Nullable String mHighlightKey;
|
private final @Nullable String mHighlightKey;
|
||||||
private boolean mHighlightRequested;
|
private boolean mHighlightRequested;
|
||||||
private int mHighlightPosition = RecyclerView.NO_POSITION;
|
private int mHighlightPosition = RecyclerView.NO_POSITION;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to override initial expanded child count.
|
* Tries to override initial expanded child count.
|
||||||
* <p/>
|
*
|
||||||
* Initial expanded child count will be ignored if:
|
* <p>Initial expanded child count will be ignored if: 1. fragment contains request to highlight
|
||||||
* 1. fragment contains request to highlight a particular row.
|
* a particular row. 2. count value is invalid.
|
||||||
* 2. count value is invalid.
|
|
||||||
*/
|
*/
|
||||||
public static void adjustInitialExpandedChildCount(SettingsPreferenceFragment host) {
|
public static void adjustInitialExpandedChildCount(SettingsPreferenceFragment host) {
|
||||||
if (host == null) {
|
if (host == null) {
|
||||||
@@ -102,7 +98,8 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
screen.setInitialExpandedChildrenCount(initialCount);
|
screen.setInitialExpandedChildrenCount(initialCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup,
|
public HighlightablePreferenceGroupAdapter(
|
||||||
|
@NonNull PreferenceGroup preferenceGroup,
|
||||||
@Nullable String key,
|
@Nullable String key,
|
||||||
boolean highlightRequested) {
|
boolean highlightRequested) {
|
||||||
super(preferenceGroup);
|
super(preferenceGroup);
|
||||||
@@ -110,14 +107,12 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
mHighlightRequested = highlightRequested;
|
mHighlightRequested = highlightRequested;
|
||||||
mContext = preferenceGroup.getContext();
|
mContext = preferenceGroup.getContext();
|
||||||
final TypedValue outValue = new TypedValue();
|
final TypedValue outValue = new TypedValue();
|
||||||
mContext.getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
|
mNormalBackgroundRes = R.drawable.preference_background;
|
||||||
outValue, true /* resolveRefs */);
|
mHighlightBackgroundRes = R.drawable.preference_background_highlighted;
|
||||||
mNormalBackgroundRes = outValue.resourceId;
|
|
||||||
mHighlightColor = mContext.getColor(R.color.preference_highlight_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(PreferenceViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull PreferenceViewHolder holder, int position) {
|
||||||
super.onBindViewHolder(holder, position);
|
super.onBindViewHolder(holder, position);
|
||||||
updateBackground(holder, position);
|
updateBackground(holder, position);
|
||||||
}
|
}
|
||||||
@@ -125,22 +120,23 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void updateBackground(PreferenceViewHolder holder, int position) {
|
void updateBackground(PreferenceViewHolder holder, int position) {
|
||||||
View v = holder.itemView;
|
View v = holder.itemView;
|
||||||
if (position == mHighlightPosition
|
Preference preference = getItem(position);
|
||||||
&& (mHighlightKey != null
|
if (preference != null
|
||||||
&& TextUtils.equals(mHighlightKey, getItem(position).getKey()))
|
&& position == mHighlightPosition
|
||||||
|
&& (mHighlightKey != null && TextUtils.equals(mHighlightKey, preference.getKey()))
|
||||||
&& v.isShown()) {
|
&& v.isShown()) {
|
||||||
// This position should be highlighted. If it's highlighted before - skip animation.
|
// This position should be highlighted. If it's highlighted before - skip animation.
|
||||||
v.requestAccessibilityFocus();
|
v.requestAccessibilityFocus();
|
||||||
addHighlightBackground(holder, !mFadeInAnimated);
|
addHighlightBackground(holder, !mFadeInAnimated, position);
|
||||||
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
|
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
|
||||||
// View with highlight is reused for a view that should not have highlight
|
// View with highlight is reused for a view that should not have highlight
|
||||||
removeHighlightBackground(holder, false /* animate */);
|
removeHighlightBackground(holder, false /* animate */, position);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function can highlight a specific setting in recycler view.
|
* A function can highlight a specific setting in recycler view. note: Before highlighting a
|
||||||
* note: Before highlighting a setting, screen collapses tool bar with an animation.
|
* setting, screen collapses tool bar with an animation.
|
||||||
*/
|
*/
|
||||||
public void requestHighlight(View root, RecyclerView recyclerView, AppBarLayout appBarLayout) {
|
public void requestHighlight(View root, RecyclerView recyclerView, AppBarLayout appBarLayout) {
|
||||||
if (mHighlightRequested || recyclerView == null || TextUtils.isEmpty(mHighlightKey)) {
|
if (mHighlightRequested || recyclerView == null || TextUtils.isEmpty(mHighlightKey)) {
|
||||||
@@ -155,21 +151,24 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
mHighlightRequested = true;
|
mHighlightRequested = true;
|
||||||
// Collapse app bar after 300 milliseconds.
|
// Collapse app bar after 300 milliseconds.
|
||||||
if (appBarLayout != null) {
|
if (appBarLayout != null) {
|
||||||
root.postDelayed(() -> {
|
root.postDelayed(
|
||||||
appBarLayout.setExpanded(false, true);
|
() -> appBarLayout.setExpanded(false, true),
|
||||||
}, DELAY_COLLAPSE_DURATION_MILLIS);
|
DELAY_COLLAPSE_DURATION_MILLIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the animator as early as possible to avoid a RecyclerView crash.
|
// Remove the animator as early as possible to avoid a RecyclerView crash.
|
||||||
recyclerView.setItemAnimator(null);
|
recyclerView.setItemAnimator(null);
|
||||||
// Scroll to correct position after a short delay.
|
// Scroll to correct position after a short delay.
|
||||||
root.postDelayed(() -> {
|
root.postDelayed(
|
||||||
if (ensureHighlightPosition()) {
|
() -> {
|
||||||
recyclerView.smoothScrollToPosition(mHighlightPosition);
|
if (ensureHighlightPosition()) {
|
||||||
highlightAndFocusTargetItem(recyclerView, mHighlightPosition);
|
recyclerView.smoothScrollToPosition(mHighlightPosition);
|
||||||
}
|
highlightAndFocusTargetItem(recyclerView, mHighlightPosition);
|
||||||
}, AccessibilityUtil.isTouchExploreEnabled(mContext)
|
}
|
||||||
? DELAY_HIGHLIGHT_DURATION_MILLIS_A11Y : DELAY_HIGHLIGHT_DURATION_MILLIS);
|
},
|
||||||
|
AccessibilityUtil.isTouchExploreEnabled(mContext)
|
||||||
|
? DELAY_HIGHLIGHT_DURATION_MILLIS_A11Y
|
||||||
|
: DELAY_HIGHLIGHT_DURATION_MILLIS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void highlightAndFocusTargetItem(RecyclerView recyclerView, int highlightPosition) {
|
private void highlightAndFocusTargetItem(RecyclerView recyclerView, int highlightPosition) {
|
||||||
@@ -178,20 +177,23 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
notifyItemChanged(mHighlightPosition);
|
notifyItemChanged(mHighlightPosition);
|
||||||
target.itemView.requestFocus();
|
target.itemView.requestFocus();
|
||||||
} else { // otherwise we're about to scroll to that view (but we might not be scrolling yet)
|
} else { // otherwise we're about to scroll to that view (but we might not be scrolling yet)
|
||||||
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
recyclerView.addOnScrollListener(
|
||||||
@Override
|
new RecyclerView.OnScrollListener() {
|
||||||
public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
|
@Override
|
||||||
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
public void onScrollStateChanged(
|
||||||
notifyItemChanged(mHighlightPosition);
|
@NonNull RecyclerView recyclerView, int newState) {
|
||||||
ViewHolder target = recyclerView
|
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
|
||||||
.findViewHolderForAdapterPosition(highlightPosition);
|
notifyItemChanged(mHighlightPosition);
|
||||||
if (target != null) {
|
ViewHolder target =
|
||||||
target.itemView.requestFocus();
|
recyclerView.findViewHolderForAdapterPosition(
|
||||||
|
highlightPosition);
|
||||||
|
if (target != null) {
|
||||||
|
target.itemView.requestFocus();
|
||||||
|
}
|
||||||
|
recyclerView.removeOnScrollListener(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
recyclerView.removeOnScrollListener(this);
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,44 +220,54 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void requestRemoveHighlightDelayed(PreferenceViewHolder holder) {
|
void requestRemoveHighlightDelayed(PreferenceViewHolder holder, int position) {
|
||||||
final View v = holder.itemView;
|
final View v = holder.itemView;
|
||||||
v.postDelayed(() -> {
|
v.postDelayed(
|
||||||
mHighlightPosition = RecyclerView.NO_POSITION;
|
() -> {
|
||||||
removeHighlightBackground(holder, true /* animate */);
|
mHighlightPosition = RecyclerView.NO_POSITION;
|
||||||
}, HIGHLIGHT_DURATION);
|
removeHighlightBackground(holder, true /* animate */, position);
|
||||||
|
},
|
||||||
|
HIGHLIGHT_DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addHighlightBackground(PreferenceViewHolder holder, boolean animate) {
|
private void addHighlightBackground(
|
||||||
|
PreferenceViewHolder holder, boolean animate, int position) {
|
||||||
final View v = holder.itemView;
|
final View v = holder.itemView;
|
||||||
v.setTag(R.id.preference_highlighted, true);
|
v.setTag(R.id.preference_highlighted, true);
|
||||||
|
final int backgroundFrom = getBackgroundRes(position, false);
|
||||||
|
final int backgroundTo = getBackgroundRes(position, true);
|
||||||
|
|
||||||
if (!animate) {
|
if (!animate) {
|
||||||
v.setBackgroundColor(mHighlightColor);
|
v.setBackgroundResource(backgroundTo);
|
||||||
Log.d(TAG, "AddHighlight: Not animation requested - setting highlight background");
|
Log.d(TAG, "AddHighlight: Not animation requested - setting highlight background");
|
||||||
requestRemoveHighlightDelayed(holder);
|
requestRemoveHighlightDelayed(holder, position);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mFadeInAnimated = true;
|
mFadeInAnimated = true;
|
||||||
final int colorFrom = mNormalBackgroundRes;
|
|
||||||
final int colorTo = mHighlightColor;
|
// TODO(b/377561018): Fix fade-in animation
|
||||||
final ValueAnimator fadeInLoop = ValueAnimator.ofObject(
|
final ValueAnimator fadeInLoop =
|
||||||
new ArgbEvaluator(), colorFrom, colorTo);
|
ValueAnimator.ofObject(new ArgbEvaluator(), backgroundFrom, backgroundTo);
|
||||||
fadeInLoop.setDuration(HIGHLIGHT_FADE_IN_DURATION);
|
fadeInLoop.setDuration(HIGHLIGHT_FADE_IN_DURATION);
|
||||||
fadeInLoop.addUpdateListener(
|
fadeInLoop.addUpdateListener(
|
||||||
animator -> v.setBackgroundColor((int) animator.getAnimatedValue()));
|
animator -> v.setBackgroundResource((int) animator.getAnimatedValue()));
|
||||||
fadeInLoop.setRepeatMode(ValueAnimator.REVERSE);
|
fadeInLoop.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
fadeInLoop.setRepeatCount(4);
|
fadeInLoop.setRepeatCount(4);
|
||||||
fadeInLoop.start();
|
fadeInLoop.start();
|
||||||
Log.d(TAG, "AddHighlight: starting fade in animation");
|
Log.d(TAG, "AddHighlight: starting fade in animation");
|
||||||
holder.setIsRecyclable(false);
|
holder.setIsRecyclable(false);
|
||||||
requestRemoveHighlightDelayed(holder);
|
requestRemoveHighlightDelayed(holder, position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeHighlightBackground(PreferenceViewHolder holder, boolean animate) {
|
private void removeHighlightBackground(
|
||||||
|
PreferenceViewHolder holder, boolean animate, int position) {
|
||||||
final View v = holder.itemView;
|
final View v = holder.itemView;
|
||||||
|
int backgroundFrom = getBackgroundRes(position, true);
|
||||||
|
int backgroundTo = getBackgroundRes(position, false);
|
||||||
|
|
||||||
if (!animate) {
|
if (!animate) {
|
||||||
v.setTag(R.id.preference_highlighted, false);
|
v.setTag(R.id.preference_highlighted, false);
|
||||||
v.setBackgroundResource(mNormalBackgroundRes);
|
v.setBackgroundResource(backgroundTo);
|
||||||
Log.d(TAG, "RemoveHighlight: No animation requested - setting normal background");
|
Log.d(TAG, "RemoveHighlight: No animation requested - setting normal background");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -265,25 +277,33 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
|||||||
Log.d(TAG, "RemoveHighlight: Not highlighted - skipping");
|
Log.d(TAG, "RemoveHighlight: Not highlighted - skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int colorFrom = mHighlightColor;
|
|
||||||
int colorTo = mNormalBackgroundRes;
|
|
||||||
|
|
||||||
v.setTag(R.id.preference_highlighted, false);
|
v.setTag(R.id.preference_highlighted, false);
|
||||||
final ValueAnimator colorAnimation = ValueAnimator.ofObject(
|
// TODO(b/377561018): Fix fade-out animation
|
||||||
new ArgbEvaluator(), colorFrom, colorTo);
|
final ValueAnimator colorAnimation =
|
||||||
|
ValueAnimator.ofObject(new ArgbEvaluator(), backgroundFrom, backgroundTo);
|
||||||
colorAnimation.setDuration(HIGHLIGHT_FADE_OUT_DURATION);
|
colorAnimation.setDuration(HIGHLIGHT_FADE_OUT_DURATION);
|
||||||
colorAnimation.addUpdateListener(
|
colorAnimation.addUpdateListener(
|
||||||
animator -> v.setBackgroundColor((int) animator.getAnimatedValue()));
|
animator -> v.setBackgroundResource((int) animator.getAnimatedValue()));
|
||||||
colorAnimation.addListener(new AnimatorListenerAdapter() {
|
colorAnimation.addListener(
|
||||||
@Override
|
new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator animation) {
|
@Override
|
||||||
// Animation complete - the background is now white. Change to mNormalBackgroundRes
|
public void onAnimationEnd(@NonNull Animator animation) {
|
||||||
// so it is white and has ripple on touch.
|
// Animation complete - the background needs to be the target background.
|
||||||
v.setBackgroundResource(mNormalBackgroundRes);
|
v.setBackgroundResource(backgroundTo);
|
||||||
holder.setIsRecyclable(true);
|
holder.setIsRecyclable(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
colorAnimation.start();
|
colorAnimation.start();
|
||||||
Log.d(TAG, "Starting fade out animation");
|
Log.d(TAG, "Starting fade out animation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @DrawableRes int getBackgroundRes(int position, boolean isHighlighted) {
|
||||||
|
if (SettingsThemeHelper.isExpressiveTheme(mContext)) {
|
||||||
|
Log.d(TAG, "[Expressive Theme] get rounded background, highlight = " + isHighlighted);
|
||||||
|
return getRoundCornerDrawableRes(position, false, isHighlighted);
|
||||||
|
} else {
|
||||||
|
return (isHighlighted) ? mHighlightBackgroundRes : mNormalBackgroundRes;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -231,7 +231,7 @@ public class HighlightablePreferenceGroupAdapterTest {
|
|||||||
assertThat(mAdapter.mFadeInAnimated).isTrue();
|
assertThat(mAdapter.mFadeInAnimated).isTrue();
|
||||||
assertThat(mViewHolder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
assertThat(mViewHolder.itemView.getBackground()).isInstanceOf(ColorDrawable.class);
|
||||||
assertThat(mViewHolder.itemView.getTag(R.id.preference_highlighted)).isEqualTo(true);
|
assertThat(mViewHolder.itemView.getTag(R.id.preference_highlighted)).isEqualTo(true);
|
||||||
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder);
|
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -256,14 +256,14 @@ public class HighlightablePreferenceGroupAdapterTest {
|
|||||||
// through animation.
|
// through animation.
|
||||||
assertThat(mAdapter.mFadeInAnimated).isTrue();
|
assertThat(mAdapter.mFadeInAnimated).isTrue();
|
||||||
// remove highlight should be requested.
|
// remove highlight should be requested.
|
||||||
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder);
|
verify(mAdapter).requestRemoveHighlightDelayed(mViewHolder, 10);
|
||||||
|
|
||||||
ReflectionHelpers.setField(mAdapter, "mHighlightPosition", 10);
|
ReflectionHelpers.setField(mAdapter, "mHighlightPosition", 10);
|
||||||
mAdapter.updateBackground(mViewHolder, 10);
|
mAdapter.updateBackground(mViewHolder, 10);
|
||||||
// only sets background color once - if it's animation this would be called many times
|
// only sets background color once - if it's animation this would be called many times
|
||||||
verify(mViewHolder.itemView).setBackgroundColor(mAdapter.mHighlightColor);
|
verify(mViewHolder.itemView).setBackgroundResource(mAdapter.mHighlightBackgroundRes);
|
||||||
// remove highlight should be requested.
|
// remove highlight should be requested.
|
||||||
verify(mAdapter, times(2)).requestRemoveHighlightDelayed(mViewHolder);
|
verify(mAdapter, times(2)).requestRemoveHighlightDelayed(mViewHolder, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -273,7 +273,8 @@ public class HighlightablePreferenceGroupAdapterTest {
|
|||||||
|
|
||||||
mAdapter.updateBackground(mViewHolder, 0);
|
mAdapter.updateBackground(mViewHolder, 0);
|
||||||
|
|
||||||
assertThat(mViewHolder.itemView.getBackground()).isNotInstanceOf(ColorDrawable.class);
|
assertThat(mViewHolder.itemView.getBackground())
|
||||||
|
.isNotEqualTo(mAdapter.mHighlightBackgroundRes);
|
||||||
assertThat(mViewHolder.itemView.getTag(R.id.preference_highlighted)).isEqualTo(false);
|
assertThat(mViewHolder.itemView.getTag(R.id.preference_highlighted)).isEqualTo(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user