Merge "Removing magic constants from TAPL/Widgets" into ub-launcher3-qt-qpr1-dev

am: 77f045b607

Change-Id: I8ea519aca0ef3830f506c91c2086e1eb31b4b6f2
This commit is contained in:
Vadim Tryshev 2019-09-26 14:40:40 -07:00 committed by android-build-merger
commit 12db478e46
3 changed files with 49 additions and 26 deletions

View File

@ -41,7 +41,6 @@ import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -53,7 +52,8 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class AddConfigWidgetTest extends AbstractLauncherUiTest {
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
@Rule
public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
private LauncherAppWidgetProviderInfo mWidgetInfo;
private AppWidgetManager mAppWidgetManager;
@ -70,14 +70,12 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
@Test
@PortraitLandscape
@org.junit.Ignore
public void testWidgetConfig() throws Throwable {
runTest(true);
}
@Test
@PortraitLandscape
@org.junit.Ignore
public void testConfigCancelled() throws Throwable {
runTest(false);
}

View File

@ -30,7 +30,6 @@ import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.rule.ShellCommandRule;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -42,11 +41,11 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class AddWidgetTest extends AbstractLauncherUiTest {
@Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
@Rule
public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind();
@Test
@PortraitLandscape
@org.junit.Ignore
public void testDragIcon() throws Throwable {
clearHomescreen();
mDevice.pressHome();

View File

@ -16,8 +16,6 @@
package com.android.launcher3.tapl;
import static org.junit.Assert.fail;
import android.graphics.Point;
import android.graphics.Rect;
@ -28,11 +26,13 @@ import androidx.test.uiautomator.UiObject2;
import com.android.launcher3.ResourceUtils;
import java.util.Collection;
import java.util.Collections;
/**
* All widgets container.
*/
public final class Widgets extends LauncherInstrumentation.VisibleContainer {
private static final Rect MARGINS = new Rect(100, 100, 100, 100);
private static final int FLING_STEPS = 10;
Widgets(LauncherInstrumentation launcher) {
@ -48,12 +48,12 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
"want to fling forward in widgets")) {
LauncherInstrumentation.log("Widgets.flingForward enter");
final UiObject2 widgetsContainer = verifyActiveContainer();
final int margin = widgetsContainer.getVisibleBounds().bottom -
mLauncher.getRealDisplaySize().y +
ResourceUtils.getNavbarSize(
ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources());
mLauncher.scroll(
widgetsContainer, Direction.DOWN, 1f, new Rect(0, 0, 0, margin), FLING_STEPS);
widgetsContainer,
Direction.DOWN,
1f,
new Rect(0, 0, 0, getBottomGestureMargin(widgetsContainer)),
FLING_STEPS);
try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung forward")) {
verifyActiveContainer();
}
@ -61,6 +61,16 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
}
}
private int getBottomGestureMargin(UiObject2 widgetsContainer) {
return widgetsContainer.getVisibleBounds().bottom - mLauncher.getRealDisplaySize().y +
getBottomGestureSize();
}
private int getBottomGestureSize() {
return ResourceUtils.getNavbarSize(
ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1;
}
/**
* Flings backward (up) and waits the fling's end.
*/
@ -88,32 +98,48 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
}
public Widget getWidget(String labelText) {
final int margin = ResourceUtils.getNavbarSize(
ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1;
final UiObject2 widgetsContainer = verifyActiveContainer();
widgetsContainer.setGestureMargins(0, 0, 0, margin);
final Point displaySize = mLauncher.getRealDisplaySize();
final BySelector labelSelector = By.clazz("android.widget.TextView").text(labelText);
int i = 0;
final BySelector selector = By.clazz("android.widget.TextView").text(labelText);
for (; ; ) {
final UiObject2 label = mLauncher.tryWaitForLauncherObject(selector, 300);
if (label != null) {
final Collection<UiObject2> cells = mLauncher.getObjectsInContainer(
widgetsContainer, "widgets_cell_list_container");
mLauncher.assertTrue("Widgets doesn't have 2 rows", cells.size() >= 2);
for (UiObject2 cell : cells) {
final UiObject2 label = cell.findObject(labelSelector);
if (label == null) continue;
final UiObject2 widget = label.getParent().getParent();
mLauncher.assertEquals(
"View is not WidgetCell",
"com.android.launcher3.widget.WidgetCell",
widget.getClassName());
if (widget.getVisibleBounds().bottom <= displaySize.y - margin) {
if (widget.getVisibleBounds().bottom <= displaySize.y - getBottomGestureSize()) {
return new Widget(mLauncher, widget);
}
}
if (++i > 40) fail("Too many attempts");
mLauncher.scroll(widgetsContainer, Direction.DOWN, 0.7f, MARGINS, 50);
mLauncher.assertTrue("Too many attempts", ++i <= 40);
final UiObject2 lowestCell = Collections.max(cells, (c1, c2) ->
Integer.compare(c1.getVisibleBounds().top, c2.getVisibleBounds().top));
final int gestureStart = lowestCell.getVisibleBounds().top + mLauncher.getTouchSlop();
final int distance = gestureStart - widgetsContainer.getVisibleBounds().top;
final int bottomMargin = widgetsContainer.getVisibleBounds().height() - distance;
mLauncher.scroll(
widgetsContainer,
Direction.DOWN,
1f,
new Rect(
0,
0,
0,
Math.max(bottomMargin, getBottomGestureMargin(widgetsContainer))),
150);
}
}
}