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

The following are top voted examples for showing how to use android.support.test.runner.lifecycle.ActivityLifecycleMonitorRegistry. 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: GitHub   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity() throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
Example 2
Project: NUI_Project   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity() throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
Example 3
Project: DOUSalaries   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity() throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
Example 4
Project: simple-stack   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity()
        throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if(resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
Example 5
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 6
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 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: mvp-dagger   File: TestUtils.java   View source code 6 votes vote down vote up
/**
 * Gets an Activity in the RESUMED stage.
 * <p>
 * This method should never be called from the Main thread. In certain situations there might
 * be more than one Activities in RESUMED stage, but only one is returned.
 * See {@link ActivityLifecycleMonitor}.
 */
public static Activity getCurrentActivity() throws IllegalStateException {
    // The array is just to wrap the Activity and be able to access it from the Runnable.
    final Activity[] resumedActivity = new Activity[1];

    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                resumedActivity[0] = (Activity) resumedActivities.iterator().next();
            } else {
                throw new IllegalStateException("No Activity in stage RESUMED");
            }
        }
    });
    return resumedActivity[0];
}
 
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: 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 14
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 15
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 16
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 17
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 18
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 19
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 20
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 21
Project: GitHub   File: PubkeyListActivityTest.java   View source code 5 votes vote down vote up
public Activity getDisplayedActivityInstance() {
	final Activity[] currentActivity = new Activity[1];
	getInstrumentation().runOnMainSync(new Runnable() {
		public void run() {
			Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
			if (resumedActivities.iterator().hasNext()) {
				currentActivity[0] = resumedActivities.iterator().next();
			}
		}
	});

	return currentActivity[0];
}
 
Example 22
Project: adyen-android   File: EspressoTestUtils.java   View source code 5 votes vote down vote up
private static Activity getActivityInstance() {
    final Activity[] currentActivity = {null};
    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance()
                    .getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                currentActivity[0] = (Activity) resumedActivities.iterator().next();
            }
        }
    });

    return currentActivity[0];
}
 
Example 23
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 24
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 25
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 26
Project: LocaleChanger   File: EspressoUtil.java   View source code 5 votes vote down vote up
public static Activity getCurrentActivity() {
    final Activity[] currentActivity = {null};

    Collection resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
    if (resumedActivities.iterator().hasNext()) {
        currentActivity[0] = (Activity) resumedActivities.iterator().next();
    }


    return currentActivity[0];
}
 
Example 27
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 28
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 29
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 30
Project: asaf-project   File: ProgressBarIdler.java   View source code 5 votes vote down vote up
public static void makeAllProgressBarsIdleForAllResumedActivities(Instrumentation instrumentation) {
    instrumentation.runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.isEmpty()) {
                throw new RuntimeException("Could not change orientation");
            }
            for (Activity activity : resumedActivities) {
                makeAllProgressBarsIdle(activity.findViewById(android.R.id.content).getRootView());
            }
        }
    });
}
 
Example 31
Project: asaf-project   File: ProgressBarIdler.java   View source code 5 votes vote down vote up
public static void makeAllProgressBarsIdleForAllResumedActivities(Instrumentation instrumentation) {
    instrumentation.runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.isEmpty()) {
                throw new RuntimeException("Could not change orientation");
            }
            for (Activity activity : resumedActivities) {
                makeAllProgressBarsIdle(activity.findViewById(android.R.id.content).getRootView());
            }
        }
    });
}
 
Example 32
Project: TherapyGuide   File: SettingsScreenTest.java   View source code 5 votes vote down vote up
private Activity getCurrentActivity() {
    final Activity[] currentActivity = new Activity[1];
    getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()){
                currentActivity[0] = resumedActivities.iterator().next();
            }
        }
    });

    return currentActivity[0];
}
 
Example 33
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 34
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 35
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 36
Project: mangosta-android   File: BaseInstrumentedTest.java   View source code 5 votes vote down vote up
protected Activity getCurrentActivity() {
    InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
        public void run() {
            Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry.getInstance().getActivitiesInStage(RESUMED);
            if (resumedActivities.iterator().hasNext()) {
                mCurrentActivity = resumedActivities.iterator().next();
            }
        }
    });
    return mCurrentActivity;
}
 
Example 37
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 38
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;
}
 
Example 39
Project: tarator   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 40
Project: SmoothClicker   File: ItSettingsActivity.java   View source code 5 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();
            }
        }
    });
    return mResumedActivity;
}