Java Code Examples for android.support.test.runner.lifecycle.Stage

The following are top voted examples for showing how to use android.support.test.runner.lifecycle.Stage. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: adyen-android   File: EspressoTestUtils.java   View source code 6 votes vote down vote up
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 2
Project: espresso-doppio   File: ComponentFinder.java   View source code 6 votes vote down vote up
@NonNull
public List<Activity> findAllInStage(final Stage activityStage) {
    final List<Activity> foundActivities = new ArrayList<>();
    Runnable task = new Runnable() {
        @Override
        public void run() {
            foundActivities.addAll(ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(activityStage));
        }
    };

    if (Looper.myLooper() != Looper.getMainLooper()) {
        InstrumentationRegistry.getInstrumentation().runOnMainSync(task);
    } else {
        task.run();
    }
    return foundActivities;
}
 
Example 3
Project: AppIntro   File: OrientationChangeAction.java   View source code 6 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
Example 4
Project: tzatziki   File: BaseTest.java   View source code 6 votes vote down vote up
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 5
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 6 votes vote down vote up
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 6
Project: 2016.2-WikiLegis   File: OpenBillListFragmentTest.java   View source code 6 votes vote down vote up
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 7
Project: loadie   File: LoaderManagerProviderFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().fragment.loaderManager;
    final TestActivityWithFragment firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivityWithFragment secondActivity = (TestActivityWithFragment) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.fragment.loaderManager;

            assertNotSame(firstActivity.fragment, secondActivity.fragment);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
Example 8
Project: loadie   File: LoaderManagerProviderActivityTest.java   View source code 6 votes vote down vote up
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().loaderManager;
    final Activity firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivity secondActivity = (TestActivity) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.loaderManager;

            assertNotSame(firstActivity, secondActivity);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
Example 9
Project: loadie   File: LoaderManagerProviderNestedFragmentTest.java   View source code 6 votes vote down vote up
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().fragment.fragment.loaderManager;
    final TestActivityWithNestedFragment firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivityWithNestedFragment secondActivity = (TestActivityWithNestedFragment) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.fragment.fragment.loaderManager;

            assertNotSame(firstActivity.fragment.fragment, secondActivity.fragment.fragment);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
Example 10
Project: loadie   File: LoaderManagerProviderControllerTest.java   View source code 6 votes vote down vote up
@Test
public void loader_manager_is_retained_across_config_changes() {
    final LoaderManager firstLoaderManager = activityRule.getActivity().controller.loaderManager;
    final Activity firstActivity = activityRule.getActivity();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            firstActivity.recreate();
        }
    });
    i.waitForIdleSync();
    i.runOnMainSync(new Runnable() {
        @Override
        public void run() {
            TestActivity secondActivity = (TestActivity) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).iterator().next();
            LoaderManager secondLoaderManager = secondActivity.controller.loaderManager;

            assertNotSame(firstActivity, secondActivity);
            assertSame(firstLoaderManager, secondLoaderManager);
        }
    });
}
 
Example 11
Project: tarator   File: BaseTest.java   View source code 6 votes vote down vote up
private static boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 12
Project: Robolectric-Instrumentation   File: InstrumentationRegistry.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Activity startActivitySync(@NonNull Intent intent) {
    ComponentName componentName = intent.getComponent();
    Class<? extends Activity> cls;
    try {
        cls = (Class<? extends Activity>) Class.forName(componentName.getClassName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    Activity activity = Robolectric.setupActivity(cls);
    ActivityLifecycleMonitorRegistry.registerInstance(activityLifecycleMonitor);
    activityLifecycleMonitor.signalLifecycleChange(Stage.CREATED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.STARTED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.RESUMED, activity);
    return activity;
}
 
Example 13
Project: Robolectric-Instrumentation   File: ActivityLifecycleMonitorImpl.java   View source code 6 votes vote down vote up
@Override
public Stage getLifecycleStageOf(Activity activity) {
    checkMainThread();
    checkNotNull(activity);
    Iterator<ActivityStatus> statusIterator = mActivityStatuses.iterator();
    while (statusIterator.hasNext()) {
        ActivityStatus status = statusIterator.next();
        Activity statusActivity = status.mActivityRef.get();
        if (null == statusActivity) {
            statusIterator.remove();
        } else if (activity == statusActivity) {
            return status.mLifecycleStage;
        }
    }
    throw new IllegalArgumentException("Unknown activity: " + activity);
}
 
Example 14
Project: Robolectric-Instrumentation   File: ActivityLifecycleMonitorImpl.java   View source code 6 votes vote down vote up
@Override
public Collection<Activity> getActivitiesInStage(Stage stage) {
    checkMainThread();
    checkNotNull(stage);

    List<Activity> activities = new ArrayList<Activity>();
    Iterator<ActivityStatus> statusIterator = mActivityStatuses.iterator();
    while (statusIterator.hasNext()) {
        ActivityStatus status = statusIterator.next();
        Activity statusActivity = status.mActivityRef.get();
        if (null == statusActivity) {
            statusIterator.remove();
        } else if (stage == status.mLifecycleStage) {
            activities.add(statusActivity);
        }
    }

    return activities;
}
 
Example 15
Project: SmoothClicker   File: ItIntroScreensActivity.java   View source code 6 votes vote down vote up
/**
 * Retrieves the on going activity
 * @return Activity - The current activity
 */
private static Activity getActivityInstance(){
    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(Stage.RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                mResumedActivity = (Activity) resumedActivities.iterator().next();
            }
            if (resumedActivities.size() <= 0 ){
                mResumedActivity = null;
            }
        }
    });
    return mResumedActivity;
}
 
Example 16
Project: SmoothClicker   File: ItClickerActivity.java   View source code 6 votes vote down vote up
/**
 * Retrieves the on going activity
 * @return Activity - The current activity
 */
private static Activity getActivityInstance(){
    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(Stage.RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                mResumedActivity = (Activity) resumedActivities.iterator().next();
            }
            if (resumedActivities.size() <= 0 ){
                mResumedActivity = null;
            }
        }
    });
    return mResumedActivity;
}
 
Example 17
Project: material-activity-chooser   File: ActivityFinisher.java   View source code 6 votes vote down vote up
@Override
public void run() {
    List<Activity> activities = new ArrayList<>();

    for (Stage s : EnumSet.range(Stage.CREATED, Stage.STOPPED)) {
        activities.addAll(mLifecycleMonitor.getActivitiesInStage(s));
    }

    Log.i(TAG, "Activities that are still in CREATED to STOPPED: " + activities.size());

    for (Activity activity : activities) {
        if (!activity.isFinishing()) {
            try {
                Log.i(TAG, "Finishing mActivityRule: " + activity);
                activity.finish();
            } catch (RuntimeException e) {
                Log.e(TAG, "Failed to finish mActivityRule.", e);
            }
        }
    }
}
 
Example 18
Project: material-activity-chooser   File: ActivityUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an instance of the currently active (displayed) activity.
 * @param activityTestRule test rule
 * @param <T> activity class
 * @return activity instance
 */
public static  <T extends Activity> T getCurrentActivity(@NonNull ActivityTestRule activityTestRule) {
    getInstrumentation().waitForIdleSync();
    final Activity[] activity = new Activity[1];
    try {
        activityTestRule.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                java.util.Collection<Activity> activites = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
                activity[0] = Iterables.getOnlyElement(activites);
            }});
    } catch (Throwable throwable) {
        throwable.printStackTrace();
    }
    //noinspection unchecked
    return (T) activity[0];
}
 
Example 19
Project: AppIntro-Xamarin   File: OrientationChangeAction.java   View source code 6 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);

    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
Example 20
Project: green-coffee   File: ScreenCapture.java   View source code 6 votes vote down vote up
void takeScreenshot(final String path)
{
    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable()
    {
        @Override
        public void run()
        {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            Iterator<Activity> iterator = resumedActivities.iterator();

            if (iterator.hasNext())
            {
                Activity activity = iterator.next();

                try
                {
                    takeScreenshot(activity, path);
                }
                catch (Exception e)
                {
                    // ignore
                }
            }
        }
    });
}
 
Example 21
Project: Meducated-Ninja   File: OrientationChangeAction.java   View source code 6 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = getActivity(view);
    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            activity.setRequestedOrientation(orientation);
        }
    });
    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    uiController.loopMainThreadUntilIdle();
    SystemClock.sleep(512);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
Example 22
Project: spotify-tv   File: EspressoTestRule.java   View source code 6 votes vote down vote up
private boolean closeActivity(Instrumentation instrumentation) throws Exception {
    final Boolean activityClosed = callOnMainSync(instrumentation, new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            final Set<Activity> activities = getActivitiesInStages(Stage.RESUMED,
                    Stage.STARTED, Stage.PAUSED, Stage.STOPPED, Stage.CREATED);
            activities.removeAll(getActivitiesInStages(Stage.DESTROYED));
            if (activities.size() > 0) {
                final Activity activity = activities.iterator().next();
                activity.finish();
                return true;
            } else {
                return false;
            }
        }
    });
    if (activityClosed) {
        instrumentation.waitForIdleSync();
    }
    return activityClosed;
}
 
Example 23
Project: Triad   File: TestActivityInstrumentationTestCase.java   View source code 6 votes vote down vote up
@Override
public TestActivity getActivity() {
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            Collection<Activity> activities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            if (activities.isEmpty()) {
                mActivity = null;
            } else {
                mActivity = (TestActivity) activities.iterator().next();
            }
        }
    };
    if (Looper.myLooper() == Looper.getMainLooper()) {
        runnable.run();
    } else {
        getInstrumentation().runOnMainSync(runnable);
        getInstrumentation().waitForIdleSync();
    }

    return mActivity == null ? super.getActivity() : mActivity;
}
 
Example 24
Project: Robolectric-Instrumentation   File: InstrumentationRegistry.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Activity startActivitySync(@NonNull Intent intent) {
    ComponentName componentName = intent.getComponent();
    Class<? extends Activity> cls;
    try {
        cls = (Class<? extends Activity>) Class.forName(componentName.getClassName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }

    Activity activity = Robolectric.setupActivity(cls);
    ActivityLifecycleMonitorRegistry.registerInstance(activityLifecycleMonitor);
    activityLifecycleMonitor.signalLifecycleChange(Stage.CREATED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.STARTED, activity);
    activityLifecycleMonitor.signalLifecycleChange(Stage.RESUMED, activity);
    return activity;
}
 
Example 25
Project: Robolectric-Instrumentation   File: ActivityLifecycleMonitorImpl.java   View source code 6 votes vote down vote up
@Override
public Stage getLifecycleStageOf(Activity activity) {
    checkMainThread();
    checkNotNull(activity);
    Iterator<ActivityStatus> statusIterator = mActivityStatuses.iterator();
    while (statusIterator.hasNext()) {
        ActivityStatus status = statusIterator.next();
        Activity statusActivity = status.mActivityRef.get();
        if (null == statusActivity) {
            statusIterator.remove();
        } else if (activity == statusActivity) {
            return status.mLifecycleStage;
        }
    }
    throw new IllegalArgumentException("Unknown activity: " + activity);
}
 
Example 26
Project: Robolectric-Instrumentation   File: ActivityLifecycleMonitorImpl.java   View source code 6 votes vote down vote up
@Override
public Collection<Activity> getActivitiesInStage(Stage stage) {
    checkMainThread();
    checkNotNull(stage);

    List<Activity> activities = new ArrayList<Activity>();
    Iterator<ActivityStatus> statusIterator = mActivityStatuses.iterator();
    while (statusIterator.hasNext()) {
        ActivityStatus status = statusIterator.next();
        Activity statusActivity = status.mActivityRef.get();
        if (null == statusActivity) {
            statusIterator.remove();
        } else if (stage == status.mLifecycleStage) {
            activities.add(statusActivity);
        }
    }

    return activities;
}
 
Example 27
Project: adyen-android   File: EspressoTestUtils.java   View source code 5 votes vote down vote up
private static Set<Activity> getActivitiesInStages(Stage... stages) {
    final Set<Activity> activities = Sets.newHashSet();
    final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance();
    for (Stage stage : stages) {
        final Collection<Activity> activitiesInStage = instance.getActivitiesInStage(stage);
        if (activitiesInStage != null) {
            activities.addAll(activitiesInStage);
        }
    }
    return activities;
}
 
Example 28
Project: FancyTrendView   File: OrientationChangeAction.java   View source code 5 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);

    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
Example 29
Project: ChimpCheck   File: ActivityManager.java   View source code 5 votes vote down vote up
protected static Activity getActivityInstance(){
    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        public void run(){
            Collection<Activity> resumedActivity = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            for(Activity act : resumedActivity){
                // Log.i("Chimp-needs-to-know","Got activity : " + act.toString());
                current = act;
            }
        }
    });
    return current;
}
 
Example 30
Project: smart-lens   File: OrientationChangeAction.java   View source code 5 votes vote down vote up
@Override
public void perform(UiController uiController, View view) {
    uiController.loopMainThreadUntilIdle();
    final Activity activity = (Activity) view.getContext();
    activity.setRequestedOrientation(orientation);

    Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.isEmpty()) {
        throw new RuntimeException("Could not change orientation");
    }
}
 
Example 31
Project: wg_planer   File: ActivityFinisher.java   View source code 5 votes vote down vote up
@Override
public void run() {
    final List<Activity> activities = new ArrayList<>();

    for (final Stage stage : EnumSet.range(Stage.CREATED, Stage.STOPPED)) {
        activities.addAll(activityLifecycleMonitor.getActivitiesInStage(stage));
    }

    for (final Activity activity : activities) {
        if (!activity.isFinishing()) {
            activity.finish();
        }
    }
}
 
Example 32
Project: wg_planer   File: CommonSteps.java   View source code 5 votes vote down vote up
@Then("^Toast with text \"([^\"]*)\" is displayed")
public void toastIsDisplayed(String text) throws Exception {
    final Activity[] activity = new Activity[1];
    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            activity[0] = (Activity) ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED).toArray()[0];
        }
    });

    onView(withText(text)).inRoot(withDecorView(not(is(activity[0].getWindow().getDecorView())))).check(matches(isDisplayed()));
}
 
Example 33
Project: TitanCompanion   File: TCBaseTest.java   View source code 5 votes vote down vote up
protected Activity getActivityInstance() {
    final Activity[] currentActivity = {null};

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivity = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
            Iterator<Activity> it = resumedActivity.iterator();
            currentActivity[0] = it.next();
        }
    });

    return currentActivity[0];
}
 
Example 34
Project: espresso-doppio   File: ComponentFinder.java   View source code 5 votes vote down vote up
@Nullable
public Activity findFirstMatching(Stage activityStage, @NonNull Matcher<Activity> matcher) {
    Collection<Activity> foundActivities = findAllInStage(activityStage);
    for (Activity activity : foundActivities) {

        if (matcher.matches(activity)) {
            return activity;
        }
    }
    return null;
}
 
Example 35
Project: espresso-doppio   File: ComponentFinder.java   View source code 5 votes vote down vote up
@NonNull
public List<Activity> findMatching(Stage activityStage, @NonNull Matcher<Activity> matcher) {
    Collection<Activity> foundActivities = findAllInStage(activityStage);
    List<Activity> matchingActivities = new ArrayList<>();
    for (Activity activity : foundActivities) {

        if (matcher.matches(activity)) {
            matchingActivities.add(activity);
        }
    }
    return matchingActivities;
}
 
Example 36
Project: tzatziki   File: BaseTest.java   View source code 5 votes vote down vote up
public static Set<Activity> getActivitiesInStages(Stage... stages) {
    final Set<Activity> activities = Sets.newHashSet();
    final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance();
    for (Stage stage : stages) {
        final Collection<Activity> activitiesInStage = instance.getActivitiesInStage(stage);
        if (activitiesInStage != null) {
            activities.addAll(activitiesInStage);
        }
    }
    return activities;
}
 
Example 37
Project: 2016.2-WikiLegis   File: RegisterUserFragmentTest.java   View source code 5 votes vote down vote up
public static Set<Activity> getActivitiesInStages(Stage... stages) {
    final Set<Activity> activities = Sets.newHashSet();
    final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance();
    for (Stage stage : stages) {
        final Collection<Activity> activitiesInStage = instance.getActivitiesInStage(stage);
        if (activitiesInStage != null) {
            activities.addAll(activitiesInStage);
        }
    }
    return activities;
}
 
Example 38
Project: 2016.2-WikiLegis   File: OpenBillListFragmentTest.java   View source code 5 votes vote down vote up
public static Set<Activity> getActivitiesInStages(Stage... stages) {
    final Set<Activity> activities = Sets.newHashSet();
    final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance();
    for (Stage stage : stages) {
        final Collection<Activity> activitiesInStage = instance.getActivitiesInStage(stage);
        if (activitiesInStage != null) {
            activities.addAll(activitiesInStage);
        }
    }
    return activities;
}
 
Example 39
Project: bigbang   File: BaseInstrumentationTest.java   View source code 5 votes vote down vote up
public Activity getActivityInstance() {
  final Activity[] currentActivity = new Activity[1];
  getInstrumentation().runOnMainSync(() -> {
    Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(Stage.RESUMED);
    if (resumedActivities.iterator().hasNext()) {
      currentActivity[0] = (Activity) resumedActivities.iterator().next();
    }
  });

  return currentActivity[0];
}
 
Example 40
Project: espresso-macchiato   File: EspCloseAllActivitiesFunction.java   View source code 5 votes vote down vote up
public static Set<Activity> getActivitiesInStages(Stage... stages) {
    final Set<Activity> activities = Sets.newHashSet();
    final ActivityLifecycleMonitor instance = ActivityLifecycleMonitorRegistry.getInstance();
    for (Stage stage : stages) {
        activities.addAll(instance.getActivitiesInStage(stage));
    }
    return activities;
}