Skip to content

Commit

Permalink
Compile against Android Q SDK where Insets is public API
Browse files Browse the repository at this point in the history
  • Loading branch information
consp1racy committed Mar 28, 2019
1 parent 2f6e31c commit bbd19e2
Show file tree
Hide file tree
Showing 22 changed files with 20 additions and 253 deletions.
3 changes: 1 addition & 2 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions insets-extensions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand All @@ -25,9 +25,6 @@ dependencies {

implementation project(':insets')

compileOnly project(':platform-insets-private')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

testImplementation 'junit:junit:4.12'
Expand Down
5 changes: 1 addition & 4 deletions insets-helper/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand All @@ -26,9 +26,6 @@ dependencies {
implementation project(':insets')
implementation project(':insets-extensions')

compileOnly project(':platform-insets')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

testImplementation 'junit:junit:4.12'
Expand Down
5 changes: 1 addition & 4 deletions insets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand Down Expand Up @@ -33,9 +33,6 @@ android {
*/

dependencies {
compileOnly project(':platform-insets-private')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

testImplementation 'junit:junit:4.12'
Expand Down
35 changes: 2 additions & 33 deletions insets/src/main/java/net/xpece/androidx/optical/InsetsCompat.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package net.xpece.androidx.optical;

import android.annotation.SuppressLint;
import android.graphics.Insets;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.InsetDrawable;
import android.os.Build;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.annotation.RestrictTo;

import java.lang.reflect.Method;

/**
* An Insets instance holds four integer offsets which describe changes to the four
* edges of a Rectangle. By convention, positive values move edges towards the
Expand All @@ -21,7 +18,6 @@
* Insets are immutable so may be treated as values.
*/
@RequiresApi(16)
@SuppressLint("PrivateApi")
@SuppressWarnings("unused")
public final class InsetsCompat {

Expand Down Expand Up @@ -60,7 +56,7 @@ public static Insets of(int left, int top, int right, int bottom) {
return Insets.of(left, top, right, bottom);
} else {
final InsetDrawable insets = new InsetDrawable(null, left, top, right, bottom);
return Reflection.getOpticalBounds(insets);
return insets.getOpticalInsets();
}
}

Expand Down Expand Up @@ -89,31 +85,4 @@ static Insets union(final @NonNull Insets... insets) {
}
return of(left, top, right, bottom);
}

// Having separate class prevents reflective method lookup when it's not needed.
@SuppressWarnings("JavaReflectionMemberAccess")
private static class Reflection {

private static Method METHOD_GET_OPTICAL_INSETS;

static {
try {
METHOD_GET_OPTICAL_INSETS = Drawable.class.getDeclaredMethod("getOpticalInsets");
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
}

private Reflection() {
}

@NonNull
static Insets getOpticalBounds(final @NonNull Drawable drawable) {
try {
return (Insets) METHOD_GET_OPTICAL_INSETS.invoke(drawable);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
}
9 changes: 0 additions & 9 deletions platform-hidden/build.gradle

This file was deleted.

22 changes: 0 additions & 22 deletions platform-hidden/src/main/java/android/graphics/Rect.java

This file was deleted.

20 changes: 0 additions & 20 deletions platform-hidden/src/main/java/android/os/Parcelable.java

This file was deleted.

18 changes: 0 additions & 18 deletions platform-insets-private/build.gradle

This file was deleted.

95 changes: 0 additions & 95 deletions platform-insets-private/src/main/java/android/graphics/Insets.java

This file was deleted.

6 changes: 4 additions & 2 deletions platform-insets/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ apply plugin: 'java-library'
apply plugin: 'maven-publish'

/*
* You don't need this if you compile against Android Q SDK, as Insets are now public API.
*
* This is a compileOnly dependency for consumers who wish to extend Xpece Android Support Optical.
*
* This library can only be compileOnly dependency of other modules if it's not an Android library.
* At the same time we only want to expose the Insets class so we need to hide any other classes
* from the Android SDK in another compileOnly dependency of this module.
*
* This is a compileOnly dependency for consumers who wish to extend this library.
*/

sourceCompatibility = "6"
Expand Down
5 changes: 1 addition & 4 deletions root-constraint-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand All @@ -27,9 +27,6 @@ android {
dependencies {
implementation project(':insets')

compileOnly project(':platform-insets')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

//noinspection GradleDependency
Expand Down
5 changes: 1 addition & 4 deletions root-coordinator-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand All @@ -27,9 +27,6 @@ android {
dependencies {
implementation project(':insets')

compileOnly project(':platform-insets')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

api 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
Expand Down
5 changes: 1 addition & 4 deletions root-flexbox-layout/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'digital.wup.android-maven-publish'

android {
compileSdkVersion 28
compileSdkVersion 'android-Q'

defaultConfig {
minSdkVersion 16
Expand All @@ -27,9 +27,6 @@ android {
dependencies {
implementation project(':insets')

compileOnly project(':platform-insets')
testCompileOnly project(':platform-insets')

implementation 'androidx.annotation:annotation:1.0.2'

//noinspection GradleDependency
Expand Down
Loading

0 comments on commit bbd19e2

Please sign in to comment.