From bbd19e228504a97d86c78bd29e15a29d7f93b7f2 Mon Sep 17 00:00:00 2001 From: Eugen Pechanec Date: Thu, 28 Mar 2019 23:46:32 +0100 Subject: [PATCH] Compile against Android Q SDK where Insets is public API --- .idea/gradle.xml | 3 +- insets-extensions/build.gradle | 5 +- insets-helper/build.gradle | 5 +- insets/build.gradle | 5 +- .../xpece/androidx/optical/InsetsCompat.java | 35 +------ platform-hidden/build.gradle | 9 -- .../src/main/java/android/graphics/Rect.java | 22 ----- .../src/main/java/android/os/Parcelable.java | 20 ---- platform-insets-private/build.gradle | 18 ---- .../main/java/android/graphics/Insets.java | 95 ------------------- platform-insets/build.gradle | 6 +- root-constraint-layout/build.gradle | 5 +- root-coordinator-layout/build.gradle | 5 +- root-flexbox-layout/build.gradle | 5 +- root-frame-layout/build.gradle | 5 +- root-linear-layout/build.gradle | 5 +- sample/build.gradle | 3 +- settings.gradle | 2 - widget-appcompat/build.gradle | 5 +- widget-cardbutton/build.gradle | 5 +- widget-cardview/build.gradle | 5 +- widget-material/build.gradle | 5 +- 22 files changed, 20 insertions(+), 253 deletions(-) delete mode 100644 platform-hidden/build.gradle delete mode 100644 platform-hidden/src/main/java/android/graphics/Rect.java delete mode 100644 platform-hidden/src/main/java/android/os/Parcelable.java delete mode 100644 platform-insets-private/build.gradle delete mode 100644 platform-insets-private/src/main/java/android/graphics/Insets.java diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 8185138..746a20c 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -11,9 +11,7 @@ diff --git a/insets-extensions/build.gradle b/insets-extensions/build.gradle index bf31895..661d547 100644 --- a/insets-extensions/build.gradle +++ b/insets-extensions/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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' diff --git a/insets-helper/build.gradle b/insets-helper/build.gradle index 2932960..5c51c6b 100644 --- a/insets-helper/build.gradle +++ b/insets-helper/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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' diff --git a/insets/build.gradle b/insets/build.gradle index 9449972..4def9e6 100644 --- a/insets/build.gradle +++ b/insets/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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' diff --git a/insets/src/main/java/net/xpece/androidx/optical/InsetsCompat.java b/insets/src/main/java/net/xpece/androidx/optical/InsetsCompat.java index 8700686..41e2065 100644 --- a/insets/src/main/java/net/xpece/androidx/optical/InsetsCompat.java +++ b/insets/src/main/java/net/xpece/androidx/optical/InsetsCompat.java @@ -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 @@ -21,7 +18,6 @@ * Insets are immutable so may be treated as values. */ @RequiresApi(16) -@SuppressLint("PrivateApi") @SuppressWarnings("unused") public final class InsetsCompat { @@ -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(); } } @@ -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); - } - } - } } diff --git a/platform-hidden/build.gradle b/platform-hidden/build.gradle deleted file mode 100644 index e12de59..0000000 --- a/platform-hidden/build.gradle +++ /dev/null @@ -1,9 +0,0 @@ -apply plugin: 'java-library' - -/* - * This module contains stubs of classes from Android SDK - * so they're available to Java libraries that need them at compile time. - */ - -sourceCompatibility = "6" -targetCompatibility = "6" diff --git a/platform-hidden/src/main/java/android/graphics/Rect.java b/platform-hidden/src/main/java/android/graphics/Rect.java deleted file mode 100644 index 1f6abbf..0000000 --- a/platform-hidden/src/main/java/android/graphics/Rect.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.graphics; - -import android.os.Parcelable; - -final class Rect implements Parcelable { -} diff --git a/platform-hidden/src/main/java/android/os/Parcelable.java b/platform-hidden/src/main/java/android/os/Parcelable.java deleted file mode 100644 index 548350f..0000000 --- a/platform-hidden/src/main/java/android/os/Parcelable.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.os; - -public interface Parcelable { -} diff --git a/platform-insets-private/build.gradle b/platform-insets-private/build.gradle deleted file mode 100644 index e71e6c7..0000000 --- a/platform-insets-private/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ -apply plugin: 'java-library' - -/* - * 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 this library exposing full API of Insets class. - */ - -dependencies { - compileOnly project(':platform-hidden') - - implementation 'androidx.annotation:annotation:1.0.2' -} - -sourceCompatibility = "6" -targetCompatibility = "6" diff --git a/platform-insets-private/src/main/java/android/graphics/Insets.java b/platform-insets-private/src/main/java/android/graphics/Insets.java deleted file mode 100644 index 9654157..0000000 --- a/platform-insets-private/src/main/java/android/graphics/Insets.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.graphics; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.RestrictTo; - -/** - * 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 - * centre of the rectangle. - *

- * Insets are immutable so may be treated as values. - */ -@SuppressWarnings("unused") -public class Insets { - - @NonNull - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static final Insets NONE = placeholder(); - - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public final int left; - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public final int top; - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public final int right; - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public final int bottom; - - private Insets(int left, int top, int right, int bottom) { - throw new UnsupportedOperationException(); - } - - @NonNull - private static Insets placeholder() { - throw new UnsupportedOperationException("Did you include Optical library proguard rules?"); - } - - // Factory methods - - /** - * Return an Insets instance with the appropriate values. - * - * @param left the left inset - * @param top the top inset - * @param right the right inset - * @param bottom the bottom inset - * @return Insets instance with the appropriate values - */ - @NonNull - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static Insets of(int left, int top, int right, int bottom) { - throw new UnsupportedOperationException(); - } - - /** - * Return an Insets instance with the appropriate values. - * - * @param r the rectangle from which to take the values - * @return an Insets instance with the appropriate values - */ - @NonNull - @RestrictTo(RestrictTo.Scope.LIBRARY_GROUP) - public static Insets of(@Nullable Rect r) { - throw new UnsupportedOperationException(); - } - - /** - * Two Insets instances are equal if they belong to the same class and their fields are - * pairwise equal. - * - * @param o the object to compare this instance with. - * @return true if this object is equal {@code o} - */ - @Override - public boolean equals(@Nullable Object o) { - throw new UnsupportedOperationException(); - } -} diff --git a/platform-insets/build.gradle b/platform-insets/build.gradle index 270f36e..95a01c9 100644 --- a/platform-insets/build.gradle +++ b/platform-insets/build.gradle @@ -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" diff --git a/root-constraint-layout/build.gradle b/root-constraint-layout/build.gradle index b12cf61..596fbac 100644 --- a/root-constraint-layout/build.gradle +++ b/root-constraint-layout/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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 diff --git a/root-coordinator-layout/build.gradle b/root-coordinator-layout/build.gradle index fa1e1a1..38cae20 100644 --- a/root-coordinator-layout/build.gradle +++ b/root-coordinator-layout/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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' diff --git a/root-flexbox-layout/build.gradle b/root-flexbox-layout/build.gradle index 210ffdc..20acdab 100644 --- a/root-flexbox-layout/build.gradle +++ b/root-flexbox-layout/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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 diff --git a/root-frame-layout/build.gradle b/root-frame-layout/build.gradle index af3f561..051eb45 100644 --- a/root-frame-layout/build.gradle +++ b/root-frame-layout/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -27,9 +27,6 @@ android { dependencies { implementation project(':insets') - compileOnly project(':platform-insets') - testCompileOnly project(':platform-insets') - implementation 'androidx.annotation:annotation:1.0.2' testImplementation 'junit:junit:4.12' diff --git a/root-linear-layout/build.gradle b/root-linear-layout/build.gradle index af3f561..051eb45 100644 --- a/root-linear-layout/build.gradle +++ b/root-linear-layout/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -27,9 +27,6 @@ android { dependencies { implementation project(':insets') - compileOnly project(':platform-insets') - testCompileOnly project(':platform-insets') - implementation 'androidx.annotation:annotation:1.0.2' testImplementation 'junit:junit:4.12' diff --git a/sample/build.gradle b/sample/build.gradle index bff1b9f..f473ff5 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { applicationId "net.xpece.androidx.optical.sample" @@ -44,7 +44,6 @@ dependencies { implementation project(':insets-extensions') implementation project(':insets-helper') - compileOnly project(':platform-insets') implementation 'androidx.constraintlayout:constraintlayout:1.1.3' diff --git a/settings.gradle b/settings.gradle index 25b9cae..a5e9e74 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,3 @@ -include ':platform-hidden' -include ':platform-insets-private' include ':platform-insets' include ':insets', ':insets-extensions', ':insets-helper' include ':root-linear-layout' diff --git a/widget-appcompat/build.gradle b/widget-appcompat/build.gradle index c81609e..11bbef4 100644 --- a/widget-appcompat/build.gradle +++ b/widget-appcompat/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -30,9 +30,6 @@ dependencies { implementation project(':insets') implementation project(':insets-helper') - compileOnly project(':platform-insets') - testCompileOnly project(':platform-insets') - implementation 'androidx.annotation:annotation:1.0.2' api 'androidx.appcompat:appcompat:1.0.2' diff --git a/widget-cardbutton/build.gradle b/widget-cardbutton/build.gradle index bb4b3c5..a5e9c86 100644 --- a/widget-cardbutton/build.gradle +++ b/widget-cardbutton/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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 'net.xpece.android:widget-cardbutton:26.0.0-8' diff --git a/widget-cardview/build.gradle b/widget-cardview/build.gradle index 49a73a4..9427055 100644 --- a/widget-cardview/build.gradle +++ b/widget-cardview/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -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.cardview:cardview:1.0.0' diff --git a/widget-material/build.gradle b/widget-material/build.gradle index d3bd4ae..969af7f 100644 --- a/widget-material/build.gradle +++ b/widget-material/build.gradle @@ -3,7 +3,7 @@ apply plugin: 'kotlin-android' apply plugin: 'digital.wup.android-maven-publish' android { - compileSdkVersion 28 + compileSdkVersion 'android-Q' defaultConfig { minSdkVersion 16 @@ -32,9 +32,6 @@ dependencies { api project(':widget-appcompat') - compileOnly project(':platform-insets') - testCompileOnly project(':platform-insets') - implementation 'androidx.annotation:annotation:1.0.2' api 'com.google.android.material:material:1.0.0'