Merge "Mutate the drawable when updating QS icon." into sc-qpr1-dev am: 590dc710e8
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15668772 Change-Id: I19dc60bd67390bf94fbb15cc4a9cded33c16f63a
This commit is contained in:
committed by
Automerger Merge Worker
commit
acabbde4aa
@@ -116,6 +116,9 @@ public class QSIconViewImpl extends QSIconView {
|
|||||||
: icon.getInvisibleDrawable(mContext) : null;
|
: icon.getInvisibleDrawable(mContext) : null;
|
||||||
int padding = icon != null ? icon.getPadding() : 0;
|
int padding = icon != null ? icon.getPadding() : 0;
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
|
if (d.getConstantState() != null) {
|
||||||
|
d = d.getConstantState().newDrawable();
|
||||||
|
}
|
||||||
d.setAutoMirrored(false);
|
d.setAutoMirrored(false);
|
||||||
d.setLayoutDirection(getLayoutDirection());
|
d.setLayoutDirection(getLayoutDirection());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.ArgumentMatchers.argThat;
|
import static org.mockito.ArgumentMatchers.argThat;
|
||||||
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -73,6 +74,24 @@ public class QSIconViewImplTest extends SysuiTestCase {
|
|||||||
verify(s.icon, never()).getInvisibleDrawable(any());
|
verify(s.icon, never()).getInvisibleDrawable(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testMutateIconDrawable() {
|
||||||
|
SlashImageView iv = mock(SlashImageView.class);
|
||||||
|
Drawable originalDrawable = mock(Drawable.class);
|
||||||
|
Drawable otherDrawable = mock(Drawable.class);
|
||||||
|
State s = new State();
|
||||||
|
s.icon = mock(Icon.class);
|
||||||
|
when(s.icon.getInvisibleDrawable(eq(mContext))).thenReturn(originalDrawable);
|
||||||
|
when(s.icon.getDrawable(eq(mContext))).thenReturn(originalDrawable);
|
||||||
|
when(iv.isShown()).thenReturn(true);
|
||||||
|
when(originalDrawable.getConstantState()).thenReturn(fakeConstantState(otherDrawable));
|
||||||
|
|
||||||
|
|
||||||
|
mIconView.updateIcon(iv, s, /* allowAnimations= */true);
|
||||||
|
|
||||||
|
verify(iv).setState(any(), eq(otherDrawable));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoFirstFade() {
|
public void testNoFirstFade() {
|
||||||
ImageView iv = mock(ImageView.class);
|
ImageView iv = mock(ImageView.class);
|
||||||
@@ -104,4 +123,18 @@ public class QSIconViewImplTest extends SysuiTestCase {
|
|||||||
public void testIconNotSet_toString() {
|
public void testIconNotSet_toString() {
|
||||||
assertFalse(mIconView.toString().contains("lastIcon"));
|
assertFalse(mIconView.toString().contains("lastIcon"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Drawable.ConstantState fakeConstantState(Drawable otherDrawable) {
|
||||||
|
return new Drawable.ConstantState() {
|
||||||
|
@Override
|
||||||
|
public Drawable newDrawable() {
|
||||||
|
return otherDrawable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getChangingConfigurations() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user