1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 15package com.android.systemui.qs.tileimpl; 16 17import static org.mockito.ArgumentMatchers.any; 18import static org.mockito.ArgumentMatchers.argThat; 19import static org.mockito.Mockito.mock; 20import static org.mockito.Mockito.never; 21import static org.mockito.Mockito.verify; 22import static org.mockito.Mockito.when; 23 24import android.content.res.ColorStateList; 25import android.graphics.drawable.Drawable; 26import android.service.quicksettings.Tile; 27import android.support.test.filters.SmallTest; 28import android.testing.AndroidTestingRunner; 29import android.testing.UiThreadTest; 30import android.widget.ImageView; 31 32import com.android.systemui.SysuiTestCase; 33import com.android.systemui.plugins.qs.QSTile.Icon; 34import com.android.systemui.plugins.qs.QSTile.State; 35 36import org.junit.Before; 37import org.junit.Test; 38import org.junit.runner.RunWith; 39import org.mockito.ArgumentMatcher; 40 41@RunWith(AndroidTestingRunner.class) 42@UiThreadTest 43@SmallTest 44public class QSIconViewImplTest extends SysuiTestCase { 45 46 private QSIconViewImpl mIconView; 47 48 @Before 49 public void setup() { 50 mIconView = new QSIconViewImpl(mContext); 51 } 52 53 @Test 54 public void testNoFirstAnimation() { 55 ImageView iv = mock(ImageView.class); 56 State s = new State(); 57 when(iv.isShown()).thenReturn(true); 58 59 // No current icon, only the static drawable should be used. 60 s.icon = mock(Icon.class); 61 when(iv.getDrawable()).thenReturn(null); 62 mIconView.updateIcon(iv, s); 63 verify(s.icon, never()).getDrawable(any()); 64 verify(s.icon).getInvisibleDrawable(any()); 65 66 // Has icon, should use the standard (animated) form. 67 s.icon = mock(Icon.class); 68 when(iv.getDrawable()).thenReturn(mock(Drawable.class)); 69 mIconView.updateIcon(iv, s); 70 verify(s.icon).getDrawable(any()); 71 verify(s.icon, never()).getInvisibleDrawable(any()); 72 } 73 74 @Test 75 public void testNoFirstFade() { 76 ImageView iv = mock(ImageView.class); 77 State s = new State(); 78 s.state = Tile.STATE_ACTIVE; 79 int desiredColor = mIconView.getColor(s.state); 80 when(iv.isShown()).thenReturn(true); 81 82 mIconView.setIcon(iv, s); 83 verify(iv).setImageTintList(argThat(stateList -> stateList.getColors()[0] == desiredColor)); 84 } 85} 86