From cf9debbdf9f3c5a0ed4b41853705383605c34c88 Mon Sep 17 00:00:00 2001 From: goweii Date: Sun, 22 Jun 2025 20:05:15 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8Dandroid35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +- app/src/main/AndroidManifest.xml | 3 +- build.gradle | 2 +- gradle.properties | 3 + gradle/wrapper/gradle-wrapper.properties | 2 +- swipeback-transformer/build.gradle | 8 +- .../src/main/AndroidManifest.xml | 2 +- swipeback/build.gradle | 8 +- swipeback/src/main/AndroidManifest.xml | 2 +- .../swipeback/utils/TranslucentConverter.java | 108 ++++++++---------- 10 files changed, 68 insertions(+), 78 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 76f32c3..27d43f1 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.0" + + 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/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.properties b/gradle.properties index d546dea..ea7c34d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,5 +13,8 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true +android.nonTransitiveRClass=false +android.nonFinalResIds=false +android.defaults.buildfeatures.buildconfig=true 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..8900c00 100644 --- a/swipeback-transformer/build.gradle +++ b/swipeback-transformer/build.gradle @@ -3,12 +3,14 @@ plugins { } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 35 + buildToolsVersion "35.0.0" + + namespace "per.goweii.swipeback.transformer" defaultConfig { minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 35 versionCode 1 versionName "1.0" 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..83f7fd7 100644 --- a/swipeback/build.gradle +++ b/swipeback/build.gradle @@ -3,12 +3,14 @@ plugins { } android { - compileSdkVersion 30 - buildToolsVersion "30.0.3" + compileSdkVersion 35 + buildToolsVersion "35.0.0" + + namespace "per.goweii.swipeback" defaultConfig { minSdkVersion 16 - targetSdkVersion 30 + targetSdkVersion 35 versionCode 1 versionName "1.0" 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..dcd4c6c 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,7 @@ 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); } public void fromTranslucent() { @@ -59,6 +52,12 @@ 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); + int[] animations = getActivityCloseAnimation(activity); + activity.overridePendingTransition(animations[0], animations[1]); + return; + } if (mInitialedConvertFromTranslucent && mMethodConvertFromTranslucent == null) { return; } @@ -73,6 +72,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 +97,44 @@ private static class ToConverter { private static Method mMethodConvertToTranslucent = null; private static Method mMethodGetActivityOptions = null; - private static void convert(@NonNull Activity activity, final TranslucentCallback callback) { + private static void convert(@NonNull Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + activity.setTranslucent(true); + activity.overridePendingTransition(0, 0); + return; + } if (mInitialedConvertToTranslucent && mMethodConvertToTranslucent == null) { - if (callback != null) { - callback.onTranslucentCallback(false); - } 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 +145,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); - } } From e341df2486bb065d817df0782c9fe57580f1ae2e Mon Sep 17 00:00:00 2001 From: goweii Date: Sun, 22 Jun 2025 20:13:25 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=E9=80=82=E9=85=8Dandroid35?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../per/goweii/android/swipeback/SwipeBackNormalActivity.java | 1 + gradle.properties | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) 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/gradle.properties b/gradle.properties index ea7c34d..d546dea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,8 +13,5 @@ org.gradle.jvmargs=-Xmx1536m # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -android.nonTransitiveRClass=false -android.nonFinalResIds=false -android.defaults.buildfeatures.buildconfig=true From 3e71b49aa336bcbb18f09755520854e5d5fc3446 Mon Sep 17 00:00:00 2001 From: goweii Date: Sun, 22 Jun 2025 20:38:37 +0800 Subject: [PATCH 3/4] =?UTF-8?q?feat:=20=E5=85=BC=E5=AE=B9jitpack?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- swipeback-transformer/build.gradle | 18 ++++++++++++++++++ swipeback/build.gradle | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/swipeback-transformer/build.gradle b/swipeback-transformer/build.gradle index 8900c00..022bb9a 100644 --- a/swipeback-transformer/build.gradle +++ b/swipeback-transformer/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.library' + id 'maven-publish' } android { @@ -28,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 = '3.1.0-alpha' + + afterEvaluate { + from components.release + } + } + } } \ No newline at end of file diff --git a/swipeback/build.gradle b/swipeback/build.gradle index 83f7fd7..e0ab044 100644 --- a/swipeback/build.gradle +++ b/swipeback/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.library' + id 'maven-publish' } android { @@ -28,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 = '3.1.0-alpha' + + afterEvaluate { + from components.release + } + } + } } \ No newline at end of file From dd0287e3a94524aea6f86b3076ce959f22b02977 Mon Sep 17 00:00:00 2001 From: goweii Date: Sat, 30 Aug 2025 21:14:58 +0800 Subject: [PATCH 4/4] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 2 +- swipeback-transformer/build.gradle | 4 ++-- swipeback/build.gradle | 4 ++-- .../swipeback/utils/TranslucentConverter.java | 15 ++++++++++++--- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 27d43f1..d75f2dd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -2,7 +2,7 @@ apply plugin: 'com.android.application' android { compileSdkVersion 35 - buildToolsVersion "35.0.0" + buildToolsVersion "35.0.1" namespace "per.goweii.android.swipeback" diff --git a/swipeback-transformer/build.gradle b/swipeback-transformer/build.gradle index 022bb9a..a29a40b 100644 --- a/swipeback-transformer/build.gradle +++ b/swipeback-transformer/build.gradle @@ -5,7 +5,7 @@ plugins { android { compileSdkVersion 35 - buildToolsVersion "35.0.0" + buildToolsVersion "35.0.1" namespace "per.goweii.swipeback.transformer" @@ -44,7 +44,7 @@ publishing { release(MavenPublication) { groupId = 'com.goweii' artifactId = 'swipeback-transformer' - version = '3.1.0-alpha' + version = '*' afterEvaluate { from components.release diff --git a/swipeback/build.gradle b/swipeback/build.gradle index e0ab044..501d1c0 100644 --- a/swipeback/build.gradle +++ b/swipeback/build.gradle @@ -5,7 +5,7 @@ plugins { android { compileSdkVersion 35 - buildToolsVersion "35.0.0" + buildToolsVersion "35.0.1" namespace "per.goweii.swipeback" @@ -43,7 +43,7 @@ publishing { release(MavenPublication) { groupId = 'com.goweii' artifactId = 'swipeback' - version = '3.1.0-alpha' + version = '*' afterEvaluate { from components.release 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 dcd4c6c..64035f3 100644 --- a/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java +++ b/swipeback/src/main/java/per/goweii/swipeback/utils/TranslucentConverter.java @@ -39,6 +39,7 @@ public boolean isThemeTranslucent() { public void toTranslucent() { if (mIsTranslucent) return; ToConverter.convert(mActivity); + this.mIsTranslucent = true; } public void fromTranslucent() { @@ -54,8 +55,12 @@ private static class FromConverter { private static void convert(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { activity.setTranslucent(false); - int[] animations = getActivityCloseAnimation(activity); - activity.overridePendingTransition(animations[0], animations[1]); + 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) { @@ -100,7 +105,11 @@ private static class ToConverter { private static void convert(@NonNull Activity activity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { activity.setTranslucent(true); - activity.overridePendingTransition(0, 0); + 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) {