Merge "Add GlobalActionsColumnLayout to replace HardwareUILayout." into qt-dev am: dc22284752
am: d57ce8a73c
Change-Id: I14fb71a7d3f53e0449567e6418c00684271a0dc5
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.systemui.globalactions;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.util.leak.RotationUtils;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* Tests for {@link ListGridLayout}.
|
||||
*/
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class GlobalActionsColumnLayoutTest extends SysuiTestCase {
|
||||
|
||||
private GlobalActionsColumnLayout mColumnLayout;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mColumnLayout = spy((GlobalActionsColumnLayout)
|
||||
LayoutInflater.from(mContext).inflate(R.layout.global_actions_column, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldReverseListItems() {
|
||||
doReturn(View.LAYOUT_DIRECTION_LTR).when(mColumnLayout).getCurrentLayoutDirection();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(false, mColumnLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(false, mColumnLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(RotationUtils.ROTATION_SEASCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(true, mColumnLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(View.LAYOUT_DIRECTION_RTL).when(mColumnLayout).getCurrentLayoutDirection();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(true, mColumnLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(false, mColumnLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(RotationUtils.ROTATION_SEASCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(false, mColumnLayout.shouldReverseListItems());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAnimationOffsetX() {
|
||||
doReturn(50f).when(mColumnLayout).getAnimationDistance();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(50f, mColumnLayout.getAnimationOffsetX(), .01);
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(0, mColumnLayout.getAnimationOffsetX(), .01);
|
||||
|
||||
doReturn(RotationUtils.ROTATION_SEASCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(0, mColumnLayout.getAnimationOffsetX(), .01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAnimationOffsetY() {
|
||||
doReturn(50f).when(mColumnLayout).getAnimationDistance();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(0, mColumnLayout.getAnimationOffsetY(), .01);
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(-50f, mColumnLayout.getAnimationOffsetY(), .01);
|
||||
|
||||
doReturn(RotationUtils.ROTATION_SEASCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
assertEquals(50f, mColumnLayout.getAnimationOffsetY(), .01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSnapToPowerButton_portrait() {
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
doReturn(50).when(mColumnLayout).getPowerButtonOffsetDistance();
|
||||
|
||||
mColumnLayout.snapToPowerButton();
|
||||
assertEquals(Gravity.TOP | Gravity.RIGHT, mColumnLayout.getGravity());
|
||||
assertEquals(50, mColumnLayout.getPaddingTop(), .01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCenterAlongEdge_portrait() {
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
|
||||
mColumnLayout.centerAlongEdge();
|
||||
assertEquals(Gravity.CENTER_VERTICAL | Gravity.RIGHT, mColumnLayout.getGravity());
|
||||
assertEquals(0, mColumnLayout.getPaddingTop(), .01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSnap_initialState() {
|
||||
doReturn(false).when(mColumnLayout).shouldSnapToPowerButton();
|
||||
|
||||
mColumnLayout.updateSnap(); // should do nothing, since snap has not changed from init state
|
||||
|
||||
verify(mColumnLayout, times(0)).snapToPowerButton();
|
||||
verify(mColumnLayout, times(0)).centerAlongEdge();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSnap_snapThenSnap() {
|
||||
doReturn(true).when(mColumnLayout).shouldSnapToPowerButton();
|
||||
|
||||
mColumnLayout.updateSnap(); // should snap to power button
|
||||
|
||||
verify(mColumnLayout, times(1)).snapToPowerButton();
|
||||
verify(mColumnLayout, times(0)).centerAlongEdge();
|
||||
|
||||
mColumnLayout.updateSnap(); // should do nothing, since this is the same state as last time
|
||||
|
||||
verify(mColumnLayout, times(1)).snapToPowerButton();
|
||||
verify(mColumnLayout, times(0)).centerAlongEdge();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSnap_snapThenCenter() {
|
||||
doReturn(true).when(mColumnLayout).shouldSnapToPowerButton();
|
||||
|
||||
mColumnLayout.updateSnap(); // should snap to power button
|
||||
|
||||
verify(mColumnLayout, times(1)).snapToPowerButton();
|
||||
verify(mColumnLayout, times(0)).centerAlongEdge();
|
||||
|
||||
doReturn(false).when(mColumnLayout).shouldSnapToPowerButton();
|
||||
|
||||
mColumnLayout.updateSnap(); // should center to edge
|
||||
|
||||
verify(mColumnLayout, times(1)).snapToPowerButton();
|
||||
verify(mColumnLayout, times(1)).centerAlongEdge();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSnapToPowerButton_vertical() {
|
||||
doReturn(RotationUtils.ROTATION_NONE).when(mColumnLayout).getCurrentRotation();
|
||||
doReturn(300).when(mColumnLayout).getPowerButtonOffsetDistance();
|
||||
doReturn(1000).when(mColumnLayout).getMeasuredHeight();
|
||||
View wrapper = spy(new View(mContext, null));
|
||||
doReturn(wrapper).when(mColumnLayout).getWrapper();
|
||||
doReturn(500).when(wrapper).getMeasuredHeight();
|
||||
|
||||
assertEquals(true, mColumnLayout.shouldSnapToPowerButton());
|
||||
|
||||
doReturn(600).when(mColumnLayout).getMeasuredHeight();
|
||||
|
||||
assertEquals(false, mColumnLayout.shouldSnapToPowerButton());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShouldSnapToPowerButton_horizontal() {
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mColumnLayout).getCurrentRotation();
|
||||
doReturn(300).when(mColumnLayout).getPowerButtonOffsetDistance();
|
||||
doReturn(1000).when(mColumnLayout).getMeasuredWidth();
|
||||
View wrapper = spy(new View(mContext, null));
|
||||
doReturn(wrapper).when(mColumnLayout).getWrapper();
|
||||
doReturn(500).when(wrapper).getMeasuredWidth();
|
||||
|
||||
assertEquals(true, mColumnLayout.shouldSnapToPowerButton());
|
||||
|
||||
doReturn(600).when(mColumnLayout).getMeasuredWidth();
|
||||
|
||||
assertEquals(false, mColumnLayout.shouldSnapToPowerButton());
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,8 @@ package com.android.systemui.globalactions;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -32,7 +28,6 @@ import android.view.ViewGroup;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.MultiListLayout;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
import com.android.systemui.util.leak.RotationUtils;
|
||||
@@ -49,61 +44,12 @@ import org.junit.runner.RunWith;
|
||||
public class GlobalActionsGridLayoutTest extends SysuiTestCase {
|
||||
|
||||
private GlobalActionsGridLayout mGridLayout;
|
||||
private TestAdapter mAdapter;
|
||||
private ListGridLayout mListGrid;
|
||||
|
||||
private class TestAdapter extends MultiListLayout.MultiListAdapter {
|
||||
@Override
|
||||
public void onClickItem(int index) { }
|
||||
|
||||
@Override
|
||||
public boolean onLongClickItem(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countSeparatedItems() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countListItems() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeSeparated(int position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return countSeparatedItems() + countListItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mGridLayout = spy((GlobalActionsGridLayout)
|
||||
LayoutInflater.from(mContext).inflate(R.layout.global_actions_grid, null));
|
||||
mAdapter = spy(new TestAdapter());
|
||||
mGridLayout.setAdapter(mAdapter);
|
||||
mListGrid = spy(mGridLayout.getListView());
|
||||
doReturn(mListGrid).when(mGridLayout).getListView();
|
||||
}
|
||||
@@ -122,7 +68,7 @@ public class GlobalActionsGridLayoutTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void testShouldReverseListItems() {
|
||||
doReturn(View.LAYOUT_DIRECTION_LTR).when(mGridLayout).getLayoutDirection();
|
||||
doReturn(View.LAYOUT_DIRECTION_LTR).when(mGridLayout).getCurrentLayoutDirection();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mGridLayout).getCurrentRotation();
|
||||
assertEquals(false, mGridLayout.shouldReverseListItems());
|
||||
@@ -133,7 +79,7 @@ public class GlobalActionsGridLayoutTest extends SysuiTestCase {
|
||||
doReturn(RotationUtils.ROTATION_SEASCAPE).when(mGridLayout).getCurrentRotation();
|
||||
assertEquals(true, mGridLayout.shouldReverseListItems());
|
||||
|
||||
doReturn(View.LAYOUT_DIRECTION_RTL).when(mGridLayout).getLayoutDirection();
|
||||
doReturn(View.LAYOUT_DIRECTION_RTL).when(mGridLayout).getCurrentLayoutDirection();
|
||||
|
||||
doReturn(RotationUtils.ROTATION_LANDSCAPE).when(mGridLayout).getCurrentRotation();
|
||||
assertEquals(true, mGridLayout.shouldReverseListItems());
|
||||
@@ -185,123 +131,26 @@ public class GlobalActionsGridLayoutTest extends SysuiTestCase {
|
||||
assertEquals(0f, mGridLayout.getAnimationOffsetY(), .01);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testOnUpdateList_noAdapter() {
|
||||
mGridLayout.setAdapter(null);
|
||||
mGridLayout.updateList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_noItems() {
|
||||
doReturn(0).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
mGridLayout.updateList();
|
||||
|
||||
ViewGroup separatedView = mGridLayout.getSeparatedView();
|
||||
ListGridLayout listView = mGridLayout.getListView();
|
||||
|
||||
assertEquals(0, separatedView.getChildCount());
|
||||
assertEquals(View.GONE, separatedView.getVisibility());
|
||||
|
||||
verify(mListGrid, times(0)).addItem(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_resizesFirstSeparatedItem() {
|
||||
doReturn(1).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
public void testUpdateSeparatedItemSize() {
|
||||
View firstView = new View(mContext, null);
|
||||
View secondView = new View(mContext, null);
|
||||
|
||||
doReturn(firstView).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
ViewGroup separatedView = mGridLayout.getSeparatedView();
|
||||
separatedView.addView(firstView);
|
||||
|
||||
mGridLayout.updateList();
|
||||
mGridLayout.updateSeparatedItemSize();
|
||||
|
||||
ViewGroup.LayoutParams childParams = firstView.getLayoutParams();
|
||||
assertEquals(ViewGroup.LayoutParams.MATCH_PARENT, childParams.width);
|
||||
assertEquals(ViewGroup.LayoutParams.MATCH_PARENT, childParams.height);
|
||||
|
||||
doReturn(2).when(mAdapter).countSeparatedItems();
|
||||
doReturn(secondView).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(1);
|
||||
separatedView.addView(secondView);
|
||||
|
||||
mGridLayout.updateList();
|
||||
mGridLayout.updateSeparatedItemSize();
|
||||
|
||||
childParams = firstView.getLayoutParams();
|
||||
assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, childParams.width);
|
||||
assertEquals(ViewGroup.LayoutParams.WRAP_CONTENT, childParams.height);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_onlySeparatedItems() {
|
||||
doReturn(1).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
View testView = new View(mContext, null);
|
||||
doReturn(testView).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
mGridLayout.updateList();
|
||||
|
||||
verify(mListGrid, times(0)).addItem(any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_oneSeparatedOneList() {
|
||||
doReturn(1).when(mAdapter).countSeparatedItems();
|
||||
doReturn(1).when(mAdapter).countListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
mGridLayout.updateList();
|
||||
|
||||
ViewGroup separatedView = mGridLayout.getSeparatedView();
|
||||
|
||||
assertEquals(1, separatedView.getChildCount());
|
||||
assertEquals(View.VISIBLE, separatedView.getVisibility());
|
||||
assertEquals(view1, separatedView.getChildAt(0));
|
||||
|
||||
verify(mListGrid, times(1)).addItem(view2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_fourInList() {
|
||||
doReturn(0).when(mAdapter).countSeparatedItems();
|
||||
doReturn(4).when(mAdapter).countListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
View view3 = new View(mContext, null);
|
||||
View view4 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
doReturn(view3).when(mAdapter).getView(eq(2), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(2);
|
||||
|
||||
doReturn(view4).when(mAdapter).getView(eq(3), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(3);
|
||||
|
||||
mGridLayout.updateList();
|
||||
|
||||
ViewGroup separatedView = mGridLayout.getSeparatedView();
|
||||
assertEquals(0, separatedView.getChildCount());
|
||||
assertEquals(View.GONE, separatedView.getVisibility());
|
||||
|
||||
verify(mListGrid, times(1)).addItem(view1);
|
||||
verify(mListGrid, times(1)).addItem(view2);
|
||||
verify(mListGrid, times(1)).addItem(view3);
|
||||
verify(mListGrid, times(1)).addItem(view4);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,303 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.systemui.globalactions;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.testing.AndroidTestingRunner;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
|
||||
import com.android.systemui.MultiListLayout;
|
||||
import com.android.systemui.SysuiTestCase;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Tests for {@link ListGridLayout}.
|
||||
*/
|
||||
@SmallTest
|
||||
@RunWith(AndroidTestingRunner.class)
|
||||
public class GlobalActionsLayoutTest extends SysuiTestCase {
|
||||
|
||||
private TestLayout mLayout;
|
||||
private TestAdapter mAdapter;
|
||||
|
||||
private class TestAdapter extends MultiListLayout.MultiListAdapter {
|
||||
@Override
|
||||
public void onClickItem(int index) { }
|
||||
|
||||
@Override
|
||||
public boolean onLongClickItem(int index) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countSeparatedItems() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int countListItems() {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldBeSeparated(int position) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return countSeparatedItems() + countListItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private class TestLayout extends GlobalActionsLayout {
|
||||
ArrayList<View> mSeparatedViews = new ArrayList<>();
|
||||
ArrayList<View> mListViews = new ArrayList<>();
|
||||
boolean mSeparatedViewVisible = false;
|
||||
|
||||
TestLayout(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldReverseListItems() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnimationOffsetX() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAnimationOffsetY() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToListView(View v, boolean reverse) {
|
||||
if (reverse) {
|
||||
mListViews.add(0, v);
|
||||
} else {
|
||||
mListViews.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addToSeparatedView(View v, boolean reverse) {
|
||||
if (reverse) {
|
||||
mSeparatedViews.add(0, v);
|
||||
} else {
|
||||
mSeparatedViews.add(v);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setSeparatedViewVisibility(boolean visible) {
|
||||
mSeparatedViewVisible = visible;
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mLayout = spy(new TestLayout(mContext, null));
|
||||
mAdapter = spy(new TestAdapter());
|
||||
mLayout.setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testOnUpdateList_noAdapter() {
|
||||
mLayout.setAdapter(null);
|
||||
mLayout.updateList();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_noItems() {
|
||||
doReturn(0).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(0, mLayout.mSeparatedViews.size());
|
||||
assertEquals(0, mLayout.mListViews.size());
|
||||
|
||||
assertEquals(false, mLayout.mSeparatedViewVisible);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_oneSeparatedOneList() {
|
||||
doReturn(1).when(mAdapter).countSeparatedItems();
|
||||
doReturn(1).when(mAdapter).countListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(1, mLayout.mSeparatedViews.size());
|
||||
assertEquals(1, mLayout.mListViews.size());
|
||||
assertEquals(view1, mLayout.mSeparatedViews.get(0));
|
||||
assertEquals(view2, mLayout.mListViews.get(0));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_twoSeparatedItems() {
|
||||
doReturn(2).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(2, mLayout.mSeparatedViews.size());
|
||||
assertEquals(0, mLayout.mListViews.size());
|
||||
|
||||
assertEquals(view1, mLayout.mSeparatedViews.get(0));
|
||||
assertEquals(view2, mLayout.mSeparatedViews.get(1));
|
||||
|
||||
// if separated view has items in it, should be made visible
|
||||
assertEquals(true, mLayout.mSeparatedViewVisible);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_twoSeparatedItems_reverse() {
|
||||
doReturn(2).when(mAdapter).countSeparatedItems();
|
||||
doReturn(0).when(mAdapter).countListItems();
|
||||
doReturn(true).when(mLayout).shouldReverseListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(true).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(2, mLayout.mSeparatedViews.size());
|
||||
assertEquals(0, mLayout.mListViews.size());
|
||||
|
||||
// separated view items are not reversed in current implementation, and this is intentional!
|
||||
assertEquals(view1, mLayout.mSeparatedViews.get(0));
|
||||
assertEquals(view2, mLayout.mSeparatedViews.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_fourInList() {
|
||||
doReturn(0).when(mAdapter).countSeparatedItems();
|
||||
doReturn(4).when(mAdapter).countListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
View view3 = new View(mContext, null);
|
||||
View view4 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
doReturn(view3).when(mAdapter).getView(eq(2), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(2);
|
||||
|
||||
doReturn(view4).when(mAdapter).getView(eq(3), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(3);
|
||||
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(0, mLayout.mSeparatedViews.size());
|
||||
assertEquals(4, mLayout.mListViews.size());
|
||||
assertEquals(view1, mLayout.mListViews.get(0));
|
||||
assertEquals(view2, mLayout.mListViews.get(1));
|
||||
assertEquals(view3, mLayout.mListViews.get(2));
|
||||
assertEquals(view4, mLayout.mListViews.get(3));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnUpdateList_fourInList_reverse() {
|
||||
doReturn(0).when(mAdapter).countSeparatedItems();
|
||||
doReturn(4).when(mAdapter).countListItems();
|
||||
doReturn(true).when(mLayout).shouldReverseListItems();
|
||||
View view1 = new View(mContext, null);
|
||||
View view2 = new View(mContext, null);
|
||||
View view3 = new View(mContext, null);
|
||||
View view4 = new View(mContext, null);
|
||||
|
||||
doReturn(view1).when(mAdapter).getView(eq(0), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(0);
|
||||
|
||||
doReturn(view2).when(mAdapter).getView(eq(1), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(1);
|
||||
|
||||
doReturn(view3).when(mAdapter).getView(eq(2), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(2);
|
||||
|
||||
doReturn(view4).when(mAdapter).getView(eq(3), any(), any());
|
||||
doReturn(false).when(mAdapter).shouldBeSeparated(3);
|
||||
|
||||
mLayout.updateList();
|
||||
|
||||
assertEquals(0, mLayout.mSeparatedViews.size());
|
||||
assertEquals(4, mLayout.mListViews.size());
|
||||
assertEquals(view1, mLayout.mListViews.get(3));
|
||||
assertEquals(view2, mLayout.mListViews.get(2));
|
||||
assertEquals(view3, mLayout.mListViews.get(1));
|
||||
assertEquals(view4, mLayout.mListViews.get(0));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user