|
| 1 | + |
1 | 2 | package me.imid.swipebacklayout.lib.app;
|
2 | 3 |
|
3 |
| -import me.imid.swipebacklayout.lib.SwipeBackLayout; |
4 | 4 | import android.app.Activity;
|
5 | 5 | import android.graphics.drawable.ColorDrawable;
|
| 6 | +import android.util.Log; |
6 | 7 | import android.view.LayoutInflater;
|
7 | 8 | import android.view.View;
|
8 | 9 |
|
| 10 | +import java.lang.reflect.Method; |
| 11 | + |
| 12 | +import me.imid.swipebacklayout.lib.SwipeBackLayout; |
| 13 | + |
9 | 14 | /**
|
10 | 15 | * @author Yrom
|
11 |
| - * |
12 | 16 | */
|
13 | 17 | public class SwipeBackActivityHelper {
|
14 | 18 | private Activity mActivity;
|
| 19 | + |
15 | 20 | private SwipeBackLayout mSwipeBackLayout;
|
16 | 21 |
|
17 | 22 | public SwipeBackActivityHelper(Activity activity) {
|
18 | 23 | mActivity = activity;
|
19 | 24 | }
|
20 |
| - |
| 25 | + |
21 | 26 | @SuppressWarnings("deprecation")
|
22 |
| - public void onActivtyCreate(){ |
| 27 | + public void onActivityCreate() { |
23 | 28 | mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(0));
|
24 | 29 | mActivity.getWindow().getDecorView().setBackgroundDrawable(null);
|
25 |
| - mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate(me.imid.swipebacklayout.lib.R.layout.swipeback_layout,null); |
| 30 | + mSwipeBackLayout = (SwipeBackLayout) LayoutInflater.from(mActivity).inflate( |
| 31 | + me.imid.swipebacklayout.lib.R.layout.swipeback_layout, null); |
26 | 32 | }
|
27 |
| - |
28 |
| - public void onPostCreate(){ |
| 33 | + |
| 34 | + public void onPostCreate() { |
29 | 35 | mSwipeBackLayout.attachToActivity(mActivity);
|
| 36 | + convertActivityFromTranslucent(); |
30 | 37 | }
|
31 |
| - |
| 38 | + |
32 | 39 | public View findViewById(int id) {
|
33 | 40 | if (mSwipeBackLayout != null) {
|
34 | 41 | return mSwipeBackLayout.findViewById(id);
|
35 | 42 | }
|
36 | 43 | return null;
|
37 | 44 | }
|
38 |
| - |
| 45 | + |
39 | 46 | public SwipeBackLayout getSwipeBackLayout() {
|
40 | 47 | return mSwipeBackLayout;
|
41 | 48 | }
|
42 | 49 |
|
| 50 | + /** |
| 51 | + * Convert a translucent themed Activity |
| 52 | + * {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque |
| 53 | + * Activity. |
| 54 | + * <p> |
| 55 | + * Call this whenever the background of a translucent Activity has changed |
| 56 | + * to become opaque. Doing so will allow the {@link android.view.Surface} of |
| 57 | + * the Activity behind to be released. |
| 58 | + * <p> |
| 59 | + * This call has no effect on non-translucent activities or on activities |
| 60 | + * with the {@link android.R.attr#windowIsFloating} attribute. |
| 61 | + */ |
| 62 | + public void convertActivityFromTranslucent() { |
| 63 | + try { |
| 64 | + Method method = Activity.class.getDeclaredMethod("convertFromTranslucent", null); |
| 65 | + method.setAccessible(true); |
| 66 | + method.invoke(mActivity, null); |
| 67 | + } catch (Throwable t) { |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Convert a translucent themed Activity |
| 73 | + * {@link android.R.attr#windowIsTranslucent} back from opaque to |
| 74 | + * translucent following a call to {@link #convertActivityFromTranslucent()} |
| 75 | + * . |
| 76 | + * <p> |
| 77 | + * Calling this allows the Activity behind this one to be seen again. Once |
| 78 | + * all such Activities have been redrawn |
| 79 | + * <p> |
| 80 | + * This call has no effect on non-translucent activities or on activities |
| 81 | + * with the {@link android.R.attr#windowIsFloating} attribute. |
| 82 | + */ |
| 83 | + public void convertActivityToTranslucent() { |
| 84 | + try { |
| 85 | + Class<?>[] classes = Activity.class.getDeclaredClasses(); |
| 86 | + Class<?> translucentConversionListenerClazz = null; |
| 87 | + for (Class clazz : classes) { |
| 88 | + if (clazz.getName().contains("TranslucentConversionListener")) { |
| 89 | + translucentConversionListenerClazz = clazz; |
| 90 | + Log.e("class ", |
| 91 | + clazz.getName() + "," + clazz.getCanonicalName() + "," |
| 92 | + + clazz.getSimpleName()); |
| 93 | + } |
| 94 | + } |
| 95 | + Method method = Activity.class.getDeclaredMethod("convertToTranslucent", |
| 96 | + translucentConversionListenerClazz); |
| 97 | + method.setAccessible(true); |
| 98 | + method.invoke(mActivity, new Object[] { |
| 99 | + null |
| 100 | + }); |
| 101 | + } catch (Throwable t) { |
| 102 | + } |
| 103 | + } |
43 | 104 | }
|
0 commit comments