
package me.imid.swipebacklayout.lib;

import android.app.Activity;

import java.lang.reflect.Method;

/**
 * Created by Chaojun Wang on 6/9/14.
 */
public class Utils {
    private Utils() {
    }

    /**
     * Convert a translucent themed Activity
     * {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque
     * Activity.
     * <p>
     * Call this whenever the background of a translucent Activity has changed
     * to become opaque. Doing so will allow the {@link android.view.Surface} of
     * the Activity behind to be released.
     * <p>
     * This call has no effect on non-translucent activities or on activities
     * with the {@link android.R.attr#windowIsFloating} attribute.
     */
    public static void convertActivityFromTranslucent(Activity activity) {
        try {
            Method method = Activity.class.getDeclaredMethod("convertFromTranslucent");
            method.setAccessible(true);
            method.invoke(activity);
        } catch (Throwable t) {
        }
    }

    /**
     * Convert a translucent themed Activity
     * {@link android.R.attr#windowIsTranslucent} back from opaque to
     * translucent following a call to
     * {@link #convertActivityFromTranslucent(android.app.Activity)} .
     * <p>
     * Calling this allows the Activity behind this one to be seen again. Once
     * all such Activities have been redrawn
     * <p>
     * This call has no effect on non-translucent activities or on activities
     * with the {@link android.R.attr#windowIsFloating} attribute.
     */
    public static void convertActivityToTranslucent(Activity activity) {
        try {
            Class<?>[] classes = Activity.class.getDeclaredClasses();
            Class<?> translucentConversionListenerClazz = null;
            for (Class clazz : classes) {
                if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
                    translucentConversionListenerClazz = clazz;
                }
            }
            Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
                    translucentConversionListenerClazz);
            method.setAccessible(true);
            method.invoke(activity, new Object[] {
                null
            });
        } catch (Throwable t) {
        }
    }
}

@@ -60,16 +60,77 @@
 ctivity;
+%0Aimport android.app.ActivityOptions;%0Aimport android.os.Build;
 %0A%0Aimport
@@ -1674,32 +1674,427 @@
 ity activity) %7B%0A
+        if (Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.LOLLIPOP) %7B%0A            convertActivityToTranslucentAfterL(activity);%0A        %7D else %7B%0A            convertActivityToTranslucentBeforeL(activity);%0A        %7D%0A    %7D%0A%0A    /**%0A     * Calling the convertToTranslucent method on platforms before Android 5.0%0A     */%0A    public static void convertActivityToTranslucentBeforeL(Activity activity) %7B%0A
         try %7B%0A  
@@ -2704,16 +2704,16 @@
    null%0A
-
         
@@ -2767,11 +2767,1121 @@
  %7D%0A    %7D
+%0A%0A    /**%0A     * Calling the convertToTranslucent method on platforms after Android 5.0%0A     */%0A    private static void convertActivityToTranslucentAfterL(Activity activity) %7B%0A        try %7B%0A            Method getActivityOptions = Activity.class.getDeclaredMethod(%22getActivityOptions%22);%0A            getActivityOptions.setAccessible(true);%0A            Object options = getActivityOptions.invoke(activity);%0A%0A            Class%3C?%3E%5B%5D classes = Activity.class.getDeclaredClasses();%0A            Class%3C?%3E translucentConversionListenerClazz = null;%0A            for (Class clazz : classes) %7B%0A                if (clazz.getSimpleName().contains(%22TranslucentConversionListener%22)) %7B%0A                    translucentConversionListenerClazz = clazz;%0A                %7D%0A            %7D%0A            Method convertToTranslucent = Activity.class.getDeclaredMethod(%22convertToTranslucent%22,%0A                    translucentConversionListenerClazz, ActivityOptions.class);%0A            convertToTranslucent.setAccessible(true);%0A            convertToTranslucent.invoke(activity, null, options);%0A        %7D catch (Throwable t) %7B%0A        %7D%0A    %7D
 %0A%7D%0A

Change the reflecting method of @Activity#convertToTranslucent after Android L.