Java Code Examples for com.jraska.falcon.Falcon#takeScreenshotBitmap()

The following examples show how to use com.jraska.falcon.Falcon#takeScreenshotBitmap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActivitiesBelowNotIncludedTest.java    From Falcon with Apache License 2.0 6 votes vote down vote up
@Test
public void activityBelowNotIncluded() throws InterruptedException {

  Bitmap originalScreen = Falcon.takeScreenshotBitmap(_activityRule.getActivity());

  GetTopAcitivtyCallbacks callbacks = new GetTopAcitivtyCallbacks();
  _activityRule.getActivity().getApplication().registerActivityLifecycleCallbacks(callbacks);

  // starts new Activity
  onView(withId(R.id.toolbar)).perform(longClick());

  rotateScreen(callbacks._topActivity);
  Thread.sleep(1000); // Lame! Some idling resource should be used but for what to wait???

  Bitmap bitmap = Falcon.takeScreenshotBitmap(callbacks._topActivity);
  BitmapAssert.assertThatBitmap(bitmap).isRotatedSize(originalScreen);
}
 
Example 2
Source File: Shaky.java    From shaky-android with Apache License 2.0 5 votes vote down vote up
@Nullable
@UiThread
private Bitmap getScreenshotBitmap() {
    try {
        // Attempt to use Falcon to take the screenshot
        return Falcon.takeScreenshotBitmap(activity);
    } catch (Falcon.UnableToTakeScreenshotException exception) {
        // Fallback to using the default screenshot capture mechanism if Falcon does not work (e.g. if it has not
        // been updated to work on newer versions of Android yet)
        View view = activity.getWindow().getDecorView().getRootView();
        return Utils.capture(view);
    }
}
 
Example 3
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesScreenshotToBitmap() {
  Bitmap bitmap = Falcon.takeScreenshotBitmap(_activityRule.getActivity());

  assertThat(bitmap).isNotNull();

  assertThatBitmap(bitmap).hasWidthGreaterThan(SMALLEST_SCREEN_EVER);
  assertThatBitmap(bitmap).hasHeightGreaterThan(SMALLEST_SCREEN_EVER);
}
 
Example 4
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesCorrectScreenshotSize() {
  SampleActivity activity = _activityRule.getActivity();
  Bitmap bitmap = Falcon.takeScreenshotBitmap(activity);

  View decorView = activity.getWindow().getDecorView();
  assertThatBitmap(bitmap).hasWidth(decorView.getWidth());
  assertThatBitmap(bitmap).hasHeight(decorView.getHeight());
}
 
Example 5
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesToastIntoScreenshot() {
  SampleActivity activity = _activityRule.getActivity();
  Bitmap beforeToastBitmap = Falcon.takeScreenshotBitmap(activity);
  onView(withId(R.id.show_toast)).perform(click());

  Bitmap withToastBitmap = Falcon.takeScreenshotBitmap(activity);

  assertThatBitmap(withToastBitmap).isDifferentThan(beforeToastBitmap);
}
 
Example 6
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesDialogIntoScreenshot() {
  SampleActivity activity = _activityRule.getActivity();
  Bitmap beforeToastBitmap = Falcon.takeScreenshotBitmap(activity);
  onView(withId(R.id.show_dialog)).perform(click());

  Bitmap withToastBitmap = Falcon.takeScreenshotBitmap(activity);

  assertThatBitmap(withToastBitmap).isDarkerThan(beforeToastBitmap);
}
 
Example 7
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesPopupIntoScreenshot() {
  SampleActivity activity = _activityRule.getActivity();
  Bitmap beforePopupBitmap = Falcon.takeScreenshotBitmap(activity);
  onView(withId(R.id.show_popup)).perform(click());

  Bitmap withPopupBitmap = Falcon.takeScreenshotBitmap(activity);

  assertThatBitmap(withPopupBitmap).isDifferentThan(beforePopupBitmap);
}
 
Example 8
Source File: FalconDialogInOnCreateTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesDialogOnCreate() {
  DialogOnCreate activity = _activityRule.getActivity();
  onView(withText(DialogOnCreate.DIALOG_TITLE)).check(matches(isDisplayed()));

  Bitmap withDialog = Falcon.takeScreenshotBitmap(activity);
  Espresso.pressBack();
  onView(withText(DialogOnCreate.DIALOG_TITLE)).check(doesNotExist());

  Bitmap afterDialogDismiss = Falcon.takeScreenshotBitmap(activity);

  assertThatBitmap(withDialog).isDarkerThan(afterDialogDismiss);
}
 
Example 9
Source File: FalconFloatingWindowTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesCorrectScreenshotSize() throws InterruptedException {
  waitForActivitiesToFinish();

  Activity activity = _activityRule.getActivity();

  Bitmap bitmap = Falcon.takeScreenshotBitmap(activity);

  View decorView = activity.getWindow().getDecorView();
  assertThatBitmap(bitmap).hasWidth(decorView.getWidth());
  assertThatBitmap(bitmap).hasHeight(decorView.getHeight());
}
 
Example 10
Source File: FalconFloatingWindowTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesToastOutOfWindowIntoScreenshot() {
  assumeNoCI();

  SampleActivity activity = _activityRule.getActivity();
  onView(withId(R.id.show_toast)).perform(click());

  Bitmap bitmap = Falcon.takeScreenshotBitmap(activity);

  View decorView = activity.getWindow().getDecorView();
  assertThatBitmap(bitmap).hasWidthGreaterThan(decorView.getHeight());
}