diff --git a/app/build.gradle b/app/build.gradle index 76f32c3..d75f2dd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,15 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 35 + buildToolsVersion "35.0.1" + + namespace "per.goweii.android.swipeback" defaultConfig { applicationId "per.goweii.android.swipeback" minSdkVersion 19 - targetSdkVersion 30 + targetSdkVersion 35 versionCode 1 versionName "1.0" testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b38e429..f055060 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,7 +1,6 @@ + xmlns:tools="http://schemas.android.com/tools"> diff --git a/app/src/main/java/per/goweii/android/swipeback/SwipeBackNormalActivity.java b/app/src/main/java/per/goweii/android/swipeback/SwipeBackNormalActivity.java index 8ffeccf..2332367 100644 --- a/app/src/main/java/per/goweii/android/swipeback/SwipeBackNormalActivity.java +++ b/app/src/main/java/per/goweii/android/swipeback/SwipeBackNormalActivity.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import per.goweii.swipeback.transformer.R; import per.goweii.swipeback.SwipeBackDirection; import per.goweii.swipeback.SwipeBackTransformer; import per.goweii.swipeback.transformer.ParallaxSwipeBackTransformer; diff --git a/build.gradle b/build.gradle index 88220df..a8666ad 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ buildscript { maven { url "https://jitpack.io" } } dependencies { - classpath "com.android.tools.build:gradle:4.1.1" + classpath "com.android.tools.build:gradle:8.7.0" } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4154807..19cfad9 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https://services.gradle.org/distributions/gradle-6.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/swipeback-transformer/build.gradle b/swipeback-transformer/build.gradle index 5953c6e..a29a40b 100644 --- a/swipeback-transformer/build.gradle +++ b/swipeback-transformer/build.gradle @@ -1,14 +1,17 @@ plugins { id 'com.android.library' + id 'maven-publish' } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 35 + buildToolsVersion "35.0.1" + + namespace "per.goweii.swipeback.transformer" defaultConfig { minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 35 versionCode 1 versionName "1.0" @@ -26,9 +29,26 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + publishing { + singleVariant("release") + } } dependencies { implementation project(":swipeback") implementation 'androidx.appcompat:appcompat:1.2.0' +} + +publishing { + publications { + release(MavenPublication) { + groupId = 'com.goweii' + artifactId = 'swipeback-transformer' + version = '*' + + afterEvaluate { + from components.release + } + } + } } \ No newline at end of file diff --git a/swipeback-transformer/src/main/AndroidManifest.xml b/swipeback-transformer/src/main/AndroidManifest.xml index db74651..1d26c87 100644 --- a/swipeback-transformer/src/main/AndroidManifest.xml +++ b/swipeback-transformer/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/swipeback/build.gradle b/swipeback/build.gradle index 92df3ef..501d1c0 100644 --- a/swipeback/build.gradle +++ b/swipeback/build.gradle @@ -1,14 +1,17 @@ plugins { id 'com.android.library' + id 'maven-publish' } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 35 + buildToolsVersion "35.0.1" + + namespace "per.goweii.swipeback" defaultConfig { minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 35 versionCode 1 versionName "1.0" @@ -26,8 +29,25 @@ android { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } + publishing { + singleVariant("release") + } } dependencies { implementation 'androidx.appcompat:appcompat:1.2.0' +} + +publishing { + publications { + release(MavenPublication) { + groupId = 'com.goweii' + artifactId = 'swipeback' + version = '*' + + afterEvaluate { + from components.release + } + } + } } \ No newline at end of file diff --git a/swipeback/src/main/AndroidManifest.xml b/swipeback/src/main/AndroidManifest.xml index 4718a0a..9b65eb0 100644 --- a/swipeback/src/main/AndroidManifest.xml +++ b/swipeback/src/main/AndroidManifest.xml @@ -1 +1 @@ - + diff --git a/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java b/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java index f170cb4..64035f3 100644 --- a/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java +++ b/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java @@ -6,11 +6,8 @@ import android.os.Build; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; -import java.lang.reflect.Proxy; @SuppressWarnings({"rawtypes", "JavaReflectionMemberAccess", "DiscouragedPrivateApi"}) public class TranslucentConverter { @@ -29,6 +26,7 @@ public boolean isTranslucent() { public boolean isThemeTranslucent() { try { + //noinspection resource TypedArray typedArray = mActivity.getTheme().obtainStyledAttributes(new int[]{android.R.attr.windowIsTranslucent}); boolean windowIsTranslucent = typedArray.getBoolean(0, false); typedArray.recycle(); @@ -40,12 +38,8 @@ public boolean isThemeTranslucent() { public void toTranslucent() { if (mIsTranslucent) return; - ToConverter.convert(mActivity, new TranslucentConverter.TranslucentCallback() { - @Override - public void onTranslucentCallback(boolean translucent) { - mIsTranslucent = translucent; - } - }); + ToConverter.convert(mActivity); + this.mIsTranslucent = true; } public void fromTranslucent() { @@ -59,6 +53,16 @@ private static class FromConverter { private static Method mMethodConvertFromTranslucent = null; private static void convert(@NonNull Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + activity.setTranslucent(false); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.clearOverrideActivityTransition(Activity.OVERRIDE_TRANSITION_CLOSE); + } else { + int[] animations = getActivityCloseAnimation(activity); + activity.overridePendingTransition(animations[0], animations[1]); + } + return; + } if (mInitialedConvertFromTranslucent && mMethodConvertFromTranslucent == null) { return; } @@ -73,6 +77,23 @@ private static void convert(@NonNull Activity activity) { } catch (Throwable ignored) { } } + + private static int[] getActivityCloseAnimation(@NonNull Activity activity) { + int enterAnim = 0; + int exitAnim = 0; + try { + //noinspection resource + TypedArray typedArray = activity.getTheme().obtainStyledAttributes(new int[]{ + android.R.attr.activityCloseEnterAnimation, + android.R.attr.activityCloseExitAnimation + }); + enterAnim = typedArray.getResourceId(0, 0); + exitAnim = typedArray.getResourceId(1, 0); + typedArray.recycle(); + } catch (Throwable ignore) { + } + return new int[]{enterAnim, exitAnim}; + } } private static class ToConverter { @@ -81,74 +102,48 @@ private static class ToConverter { private static Method mMethodConvertToTranslucent = null; private static Method mMethodGetActivityOptions = null; - private static void convert(@NonNull Activity activity, final TranslucentCallback callback) { - if (mInitialedConvertToTranslucent && mMethodConvertToTranslucent == null) { - if (callback != null) { - callback.onTranslucentCallback(false); + private static void convert(@NonNull Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + activity.setTranslucent(true); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + activity.overrideActivityTransition(Activity.OVERRIDE_TRANSITION_CLOSE, 0, 0); + } else { + activity.overridePendingTransition(0, 0); } return; } + if (mInitialedConvertToTranslucent && mMethodConvertToTranslucent == null) { + return; + } try { - Object translucentConversionListener = getTranslucentConversionListener(callback); + if (mTranslucentConversionListenerClass == null) { + Class[] clazzArray = Activity.class.getDeclaredClasses(); + for (Class clazz : clazzArray) { + if (clazz.getSimpleName().contains("TranslucentConversionListener")) { + mTranslucentConversionListenerClass = clazz; + } + } + } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - convertActivityToTranslucentAboveL(activity, translucentConversionListener); + convertActivityToTranslucentAboveL(activity); } else { - convertActivityToTranslucentBelowL(activity, translucentConversionListener); - } - if (translucentConversionListener == null) { - if (callback != null) { - callback.onTranslucentCallback(false); - } + convertActivityToTranslucentBelowL(activity); } } catch (Throwable ignored) { - if (callback != null) { - callback.onTranslucentCallback(false); - } } } - private static Object getTranslucentConversionListener(@Nullable final TranslucentCallback callback) throws Throwable { - if (mTranslucentConversionListenerClass == null) { - Class[] clazzArray = Activity.class.getDeclaredClasses(); - for (Class clazz : clazzArray) { - if (clazz.getSimpleName().contains("TranslucentConversionListener")) { - mTranslucentConversionListenerClass = clazz; - } - } - } - if (mTranslucentConversionListenerClass == null) { - return null; - } - return Proxy.newProxyInstance( - mTranslucentConversionListenerClass.getClassLoader(), - new Class[]{mTranslucentConversionListenerClass}, - new InvocationHandler() { - @SuppressWarnings("SuspiciousInvocationHandlerImplementation") - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - boolean translucent = false; - if (args != null && args.length == 1) { - translucent = (Boolean) args[0]; - } - if (callback != null) { - callback.onTranslucentCallback(translucent); - } - return null; - } - }); - } - - private static void convertActivityToTranslucentBelowL(@NonNull Activity activity, @Nullable Object translucentConversionListener) throws Throwable { + private static void convertActivityToTranslucentBelowL(@NonNull Activity activity) throws Throwable { if (mMethodConvertToTranslucent == null) { mInitialedConvertToTranslucent = true; Method method = Activity.class.getDeclaredMethod("convertToTranslucent", mTranslucentConversionListenerClass); method.setAccessible(true); mMethodConvertToTranslucent = method; } - mMethodConvertToTranslucent.invoke(activity, translucentConversionListener); + mMethodConvertToTranslucent.invoke(activity, (Object) null); } - private static void convertActivityToTranslucentAboveL(@NonNull Activity activity, @Nullable Object translucentConversionListener) throws Throwable { + private static void convertActivityToTranslucentAboveL(@NonNull Activity activity) throws Throwable { if (mMethodConvertToTranslucent == null) { mInitialedConvertToTranslucent = true; Method getActivityOptions = Activity.class.getDeclaredMethod("getActivityOptions"); @@ -159,11 +154,7 @@ private static void convertActivityToTranslucentAboveL(@NonNull Activity activit mMethodConvertToTranslucent = method; } Object options = mMethodGetActivityOptions.invoke(activity); - mMethodConvertToTranslucent.invoke(activity, translucentConversionListener, options); + mMethodConvertToTranslucent.invoke(activity, null, options); } } - - public interface TranslucentCallback { - void onTranslucentCallback(boolean translucent); - } }