Skip to content

Commit

Permalink
Make Falcon Android 9 compatible (#39)
Browse files Browse the repository at this point in the history
* Use less reflection to avoid blacklisted APIs

* Downgrade bintray plugin due to build error

* Prepare for next release
  • Loading branch information
jraska authored Aug 22, 2018
1 parent 70e374f commit b70a7fe
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
```


Expand Down
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class FalconTest {

@Rule
public ActivityTestRule<SampleActivity> _activityRule = new ActivityTestRule<>(
SampleActivity.class);
SampleActivity.class);

private File _screenshotFile;

Expand All @@ -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();
}
Expand All @@ -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;
Expand All @@ -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();
Expand All @@ -92,7 +92,7 @@ public void takesToastIntoScreenshot() {

Bitmap withToastBitmap = Falcon.takeScreenshotBitmap(activity);

assertThatBitmap(withToastBitmap).isDarkerThan(beforeToastBitmap);
assertThatBitmap(withToastBitmap).isDifferentThan(beforeToastBitmap);
}

@Test
Expand Down
18 changes: 9 additions & 9 deletions falcon/src/main/java/com/jraska/falcon/Falcon.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,26 +237,26 @@ private static List<ViewRootData> 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;
Expand Down

0 comments on commit b70a7fe

Please sign in to comment.