com.jraska.falcon.Falcon Java Examples

The following examples show how to use com.jraska.falcon.Falcon. 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: SuntimesActivityTestBase.java    From SuntimesWidget with GNU General Public License v3.0 7 votes vote down vote up
public static void captureScreenshot(Activity activity, String subdir, String name)
{
    subdir = subdir.trim();
    if (!subdir.isEmpty() && !subdir.startsWith("/"))
    {
        subdir = "/" + subdir;
    }

    // saves to..
    //     SD card\Android\data\com.forrestguice.suntimeswidget\files\Pictures\test-screenshots\subdir
    File d = activity.getExternalFilesDir(DIRECTORY_PICTURES);
    if (d != null)
    {
        String dirPath = d.getAbsolutePath() + "/" + SCREENSHOT_DIR + subdir;

        File dir = new File(dirPath);
        boolean dirCreated = dir.mkdirs();

        String path = dirPath + "/" + name + ".png";
        File file = new File(path);
        if (file.exists())
        {
            boolean fileDeleted = file.delete();
            if (!fileDeleted) {
                Log.w("captureScreenshot", "Failed to delete file! " + path);
            }
        }

        try {
            Falcon.takeScreenshot(activity, file);
            MediaScannerConnection.scanFile(activity, new String[]{file.getAbsolutePath()}, null, null);

        } catch (Exception e1) {
            Log.e("captureScreenshot", "Failed to write file! " + e1);
        }
    } else {
        Log.e("captureScreenshot", "Failed to write file! getExternalFilesDir() returns null..");
    }
}
 
Example #2
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 #3
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 #4
Source File: SampleActivity.java    From Falcon with Apache License 2.0 5 votes vote down vote up
public void takeScreenshot() {
  File screenshotFile = getScreenshotFile();

  Falcon.takeScreenshot(this, screenshotFile);

  String message = "Screenshot captured to " + screenshotFile.getAbsolutePath();
  Toast.makeText(this, message, Toast.LENGTH_LONG).show();

  Uri uri = Uri.fromFile(screenshotFile);
  Intent scanFileIntent = new Intent(
      Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
  sendBroadcast(scanFileIntent);
}
 
Example #5
Source File: FalconTest.java    From Falcon with Apache License 2.0 5 votes vote down vote up
@Test
public void takesScreenshotToFile() {
  SampleActivity activity = _activityRule.getActivity();
  File newFile = activity.getScreenshotFile();
  _screenshotFile = newFile;

  //check that file does not exist yet
  assertThat(newFile).doesNotExist();

  Falcon.takeScreenshot(activity, newFile);

  assertThatFile(newFile).isBitmap();
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
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 #13
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());
}