Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5bbe9e16 authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Changing Condition to an interface to allow using lambdas" into ub-launcher3-master

parents f3c4f778 6edb1b84
Loading
Loading
Loading
Loading
+3 −8
Original line number Diff line number Diff line
@@ -126,12 +126,8 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
            assertNotNull(mAppWidgetManager.getAppWidgetInfo(mWidgetId));
        } else {
            // Verify that the widget id is deleted.
            assertTrue(Wait.atMost(new Condition() {
                @Override
                public boolean isTrue() throws Throwable {
                    return mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null;
                }
            }, DEFAULT_ACTIVITY_TIMEOUT));
            assertTrue(Wait.atMost(() -> mAppWidgetManager.getAppWidgetInfo(mWidgetId) == null,
                    DEFAULT_ACTIVITY_TIMEOUT));
        }
    }

@@ -145,8 +141,7 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
    /**
     * Condition for searching widget id
     */
    private class WidgetSearchCondition extends Condition
            implements Workspace.ItemOperator {
    private class WidgetSearchCondition implements Condition, Workspace.ItemOperator {

        @Override
        public boolean isTrue() throws Throwable {
+1 −1
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
    /**
     * Condition for for an item
     */
    private class ItemSearchCondition extends Condition {
    private class ItemSearchCondition implements Condition {

        private final ItemOperator mOp;

+20 −31
Original line number Diff line number Diff line
@@ -8,47 +8,36 @@ import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

public abstract class Condition {
public interface Condition {

    public abstract boolean isTrue() throws Throwable;
    boolean isTrue() throws Throwable;

    /**
     * Converts the condition to be run on UI thread.
     */
    public static Condition runOnUiThread(final Condition condition) {
    static Condition runOnUiThread(final Condition condition) {
        final MainThreadExecutor executor = new MainThreadExecutor();
        return new Condition() {
            @Override
            public boolean isTrue() throws Throwable {
        return () -> {
            final AtomicBoolean value = new AtomicBoolean(false);
            final Throwable[] exceptions = new Throwable[1];
            final CountDownLatch latch = new CountDownLatch(1);
                executor.execute(new Runnable() {
                    @Override
                    public void run() {
            executor.execute(() -> {
                try {
                    value.set(condition.isTrue());
                } catch (Throwable e) {
                    exceptions[0] = e;
                }

                    }
            });
            latch.await(1, TimeUnit.SECONDS);
            if (exceptions[0] != null) {
                throw exceptions[0];
            }
            return value.get();
            }
        };
    }

    public static Condition minChildCount(final UiObject2 obj, final int childCount) {
        return new Condition() {
            @Override
            public boolean isTrue() {
                return obj.getChildCount() >= childCount;
            }
        };
    static Condition minChildCount(final UiObject2 obj, final int childCount) {
        return () -> obj.getChildCount() >= childCount;
    }
}