2
2
package me .imid .swipebacklayout .lib ;
3
3
4
4
import android .app .Activity ;
5
+ import android .app .ActivityOptions ;
6
+ import android .os .Build ;
5
7
6
8
import java .lang .reflect .Method ;
7
9
@@ -46,6 +48,17 @@ public static void convertActivityFromTranslucent(Activity activity) {
46
48
* with the {@link android.R.attr#windowIsFloating} attribute.
47
49
*/
48
50
public static void convertActivityToTranslucent (Activity activity ) {
51
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP ) {
52
+ convertActivityToTranslucentAfterL (activity );
53
+ } else {
54
+ convertActivityToTranslucentBeforeL (activity );
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Calling the convertToTranslucent method on platforms before Android 5.0
60
+ */
61
+ public static void convertActivityToTranslucentBeforeL (Activity activity ) {
49
62
try {
50
63
Class <?>[] classes = Activity .class .getDeclaredClasses ();
51
64
Class <?> translucentConversionListenerClazz = null ;
@@ -63,4 +76,28 @@ public static void convertActivityToTranslucent(Activity activity) {
63
76
} catch (Throwable t ) {
64
77
}
65
78
}
79
+
80
+ /**
81
+ * Calling the convertToTranslucent method on platforms after Android 5.0
82
+ */
83
+ private static void convertActivityToTranslucentAfterL (Activity activity ) {
84
+ try {
85
+ Method getActivityOptions = Activity .class .getDeclaredMethod ("getActivityOptions" );
86
+ getActivityOptions .setAccessible (true );
87
+ Object options = getActivityOptions .invoke (activity );
88
+
89
+ Class <?>[] classes = Activity .class .getDeclaredClasses ();
90
+ Class <?> translucentConversionListenerClazz = null ;
91
+ for (Class clazz : classes ) {
92
+ if (clazz .getSimpleName ().contains ("TranslucentConversionListener" )) {
93
+ translucentConversionListenerClazz = clazz ;
94
+ }
95
+ }
96
+ Method convertToTranslucent = Activity .class .getDeclaredMethod ("convertToTranslucent" ,
97
+ translucentConversionListenerClazz , ActivityOptions .class );
98
+ convertToTranslucent .setAccessible (true );
99
+ convertToTranslucent .invoke (activity , null , options );
100
+ } catch (Throwable t ) {
101
+ }
102
+ }
66
103
}
0 commit comments