Merge "Fix unexpected highlight" am: e763da5884
am: 6e347e61ca
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1490657 Change-Id: Iee515a52a2bd470e2587202427a76826f8ba5f32
This commit is contained in:
@@ -23,7 +23,6 @@ import android.animation.AnimatorListenerAdapter;
|
|||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@@ -114,7 +113,9 @@ 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) {
|
if (position == mHighlightPosition
|
||||||
|
&& (mHighlightKey != null
|
||||||
|
&& TextUtils.equals(mHighlightKey, getItem(position).getKey()))) {
|
||||||
// This position should be highlighted. If it's highlighted before - skip animation.
|
// This position should be highlighted. If it's highlighted before - skip animation.
|
||||||
addHighlightBackground(v, !mFadeInAnimated);
|
addHighlightBackground(v, !mFadeInAnimated);
|
||||||
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
|
} else if (Boolean.TRUE.equals(v.getTag(R.id.preference_highlighted))) {
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.widget;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
@@ -32,6 +33,7 @@ import android.graphics.drawable.ColorDrawable;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceCategory;
|
import androidx.preference.PreferenceCategory;
|
||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
import androidx.preference.PreferenceViewHolder;
|
import androidx.preference.PreferenceViewHolder;
|
||||||
@@ -65,14 +67,18 @@ public class HighlightablePreferenceGroupAdapterTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
private HighlightablePreferenceGroupAdapter mAdapter;
|
private HighlightablePreferenceGroupAdapter mAdapter;
|
||||||
private PreferenceViewHolder mViewHolder;
|
private PreferenceViewHolder mViewHolder;
|
||||||
|
private Preference mPreference;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mContext = RuntimeEnvironment.application;
|
mContext = RuntimeEnvironment.application;
|
||||||
|
mPreference = new Preference(mContext);
|
||||||
|
mPreference.setKey(TEST_KEY);
|
||||||
when(mPreferenceCatetory.getContext()).thenReturn(mContext);
|
when(mPreferenceCatetory.getContext()).thenReturn(mContext);
|
||||||
mAdapter = spy(new HighlightablePreferenceGroupAdapter(mPreferenceCatetory, TEST_KEY,
|
mAdapter = spy(new HighlightablePreferenceGroupAdapter(mPreferenceCatetory, TEST_KEY,
|
||||||
false /* highlighted*/));
|
false /* highlighted*/));
|
||||||
|
when(mAdapter.getItem(anyInt())).thenReturn(mPreference);
|
||||||
mViewHolder = PreferenceViewHolder.createInstanceForTests(
|
mViewHolder = PreferenceViewHolder.createInstanceForTests(
|
||||||
View.inflate(mContext, R.layout.app_preference_item, null));
|
View.inflate(mContext, R.layout.app_preference_item, null));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user