From b70a7fe75128e9bde5ec767528510825a888701b Mon Sep 17 00:00:00 2001 From: Josef Raska <6277721+jraska@users.noreply.github.com> Date: Wed, 22 Aug 2018 18:28:55 +0200 Subject: [PATCH] Make Falcon Android 9 compatible (#39) * Use less reflection to avoid blacklisted APIs * Downgrade bintray plugin due to build error * Prepare for next release --- .travis.yml | 4 ++-- README.md | 6 +++--- build.gradle | 10 +++++----- .../com/jraska/falcon/sample/Assumptions.java | 5 ++++- .../sample/FalconDialogInOnCreateTest.java | 2 ++ .../com/jraska/falcon/sample/FalconTest.java | 10 +++++----- .../main/java/com/jraska/falcon/Falcon.java | 18 +++++++++--------- 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/.travis.yml b/.travis.yml index a92ae7b..1ff2e22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,8 @@ android: - tools - platform-tools - tools - - build-tools-27.0.3 - - android-27 + - build-tools-28.0.2 + - android-28 - extra-google-m2repository - extra-android-m2repository diff --git a/README.md b/README.md index bc771fd..ea33b8b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Check falcon-sample and its android tests for more example usage. Grab via Gradle: ```groovy -compile 'com.jraska:falcon:2.0.1' +compile 'com.jraska:falcon:2.1.0' ``` ## Spoon Compat @@ -48,8 +48,8 @@ public void awesomeTest() { ``` #### Gradle ```groovy -androidTestCompile 'com.jraska:falcon:2.0.1' -androidTestCompile 'com.jraska:falcon-spoon-compat:2.0.1' +androidTestCompile 'com.jraska:falcon:2.1.0' +androidTestCompile 'com.jraska:falcon-spoon-compat:2.1.0' ``` diff --git a/build.gradle b/build.gradle index e2b5d3b..3c1e351 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { google() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7' classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' } @@ -21,12 +21,12 @@ allprojects { } ext { - version = '2.0.1' - versionCode = 12 + version = '2.1.0' + versionCode = 13 minSdkVersion = 14 - compileSdkVersion = 27 + compileSdkVersion = 28 targetSdkVersion = compileSdkVersion - buildToolsVersion = '27.0.3' + buildToolsVersion = '28.0.2' sourceCompatibility = JavaVersion.VERSION_1_7 } diff --git a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/Assumptions.java b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/Assumptions.java index 1b18287..3f633c3 100644 --- a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/Assumptions.java +++ b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/Assumptions.java @@ -4,7 +4,6 @@ import org.junit.Assume; import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.lessThan; public final class Assumptions { public static void assumeNoCI() { @@ -14,4 +13,8 @@ public static void assumeNoCI() { public static boolean isContinuousIntegration() { return BuildConfig.CI_BUILD; } + + public static void assumePlatformHasDialogIssue() { + Assume.assumeTrue(Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT); + } } diff --git a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconDialogInOnCreateTest.java b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconDialogInOnCreateTest.java index 2bdfff8..ebd4c63 100644 --- a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconDialogInOnCreateTest.java +++ b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconDialogInOnCreateTest.java @@ -22,6 +22,8 @@ public class FalconDialogInOnCreateTest { // Tests https://github.com/jraska/Falcon/issues/11 @Test public void takesDialogOnCreate() { + Assumptions.assumePlatformHasDialogIssue(); + DialogOnCreate activity = _activityRule.getActivity(); onView(withText(DialogOnCreate.DIALOG_TITLE)).check(matches(isDisplayed())); diff --git a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconTest.java b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconTest.java index 26dbdd2..8370667 100644 --- a/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconTest.java +++ b/falcon-sample/src/androidTest/java/com/jraska/falcon/sample/FalconTest.java @@ -31,7 +31,7 @@ public class FalconTest { @Rule public ActivityTestRule _activityRule = new ActivityTestRule<>( - SampleActivity.class); + SampleActivity.class); private File _screenshotFile; @@ -40,7 +40,7 @@ public class FalconTest { //region Setup Methods @After - public void after() throws Exception { + public void after() { if (_screenshotFile != null) { assertThat(_screenshotFile.delete()).isTrue(); } @@ -51,7 +51,7 @@ public void after() throws Exception { //region Test methods @Test - public void takesScreenshotToFile() throws Exception { + public void takesScreenshotToFile() { SampleActivity activity = _activityRule.getActivity(); File newFile = activity.getScreenshotFile(); _screenshotFile = newFile; @@ -65,7 +65,7 @@ public void takesScreenshotToFile() throws Exception { } @Test - public void takesScreenshotToBitmap() throws Exception { + public void takesScreenshotToBitmap() { Bitmap bitmap = Falcon.takeScreenshotBitmap(_activityRule.getActivity()); assertThat(bitmap).isNotNull(); @@ -92,7 +92,7 @@ public void takesToastIntoScreenshot() { Bitmap withToastBitmap = Falcon.takeScreenshotBitmap(activity); - assertThatBitmap(withToastBitmap).isDarkerThan(beforeToastBitmap); + assertThatBitmap(withToastBitmap).isDifferentThan(beforeToastBitmap); } @Test diff --git a/falcon/src/main/java/com/jraska/falcon/Falcon.java b/falcon/src/main/java/com/jraska/falcon/Falcon.java index a7dfb9e..552abb8 100644 --- a/falcon/src/main/java/com/jraska/falcon/Falcon.java +++ b/falcon/src/main/java/com/jraska/falcon/Falcon.java @@ -237,26 +237,26 @@ private static List viewRootData(Object[] roots, LayoutParams[] pa for (int i = 0; i < roots.length; i++) { Object root = roots[i]; - View view = (View) getFieldValue("mView", root); + View rootView = (View) getFieldValue("mView", root); // fixes https://github.com/jraska/Falcon/issues/10 - if (view == null) { + if (rootView == null) { Log.e(TAG, "null View stored as root in Global window manager, skipping"); continue; } - if(!view.isShown()){ + if(!rootView.isShown()){ continue; } - Object attachInfo = getFieldValue("mAttachInfo", root); - int top = (int) getFieldValue("mWindowTop", attachInfo); - int left = (int) getFieldValue("mWindowLeft", attachInfo); + int[] location = new int[2]; + rootView.getLocationOnScreen(location); - Rect winFrame = (Rect) getFieldValue("mWinFrame", root); - Rect area = new Rect(left, top, left + winFrame.width(), top + winFrame.height()); + int left = location[0]; + int top = location[1]; + Rect area = new Rect(left, top, left + rootView.getWidth(), top + rootView.getHeight()); - rootViews.add(new ViewRootData(view, area, params[i])); + rootViews.add(new ViewRootData(rootView, area, params[i])); } return rootViews;