Skip to content

Commit 845f49f

Browse files
author
Issac
committed
1.修改gradle文件
2.添加convertActivityFromTranslucent 方法 3.修改函数命名
1 parent e369613 commit 845f49f

File tree

4 files changed

+73
-12
lines changed

4 files changed

+73
-12
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ buildscript {
33
mavenCentral()
44
}
55
dependencies {
6-
classpath 'com.android.tools.build:gradle:0.5.+'
6+
classpath 'com.android.tools.build:gradle:0.6.+'
77
}
88
}
99

library/src/main/java/me/imid/swipebacklayout/lib/app/SwipeBackActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SwipeBackActivity extends FragmentActivity implements SwipeBackActi
1313
protected void onCreate(Bundle savedInstanceState) {
1414
super.onCreate(savedInstanceState);
1515
mHelper = new SwipeBackActivityHelper(this);
16-
mHelper.onActivtyCreate();
16+
mHelper.onActivityCreate();
1717
}
1818

1919
@Override
Lines changed: 70 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,104 @@
1+
12
package me.imid.swipebacklayout.lib.app;
23

3-
import me.imid.swipebacklayout.lib.SwipeBackLayout;
44
import android.app.Activity;
55
import android.graphics.drawable.ColorDrawable;
6+
import android.util.Log;
67
import android.view.LayoutInflater;
78
import android.view.View;
89

10+
import java.lang.reflect.Method;
11+
12+
import me.imid.swipebacklayout.lib.SwipeBackLayout;
13+
914
/**
1015
* @author Yrom
11-
*
1216
*/
1317
public class SwipeBackActivityHelper {
1418
private Activity mActivity;
19+
1520
private SwipeBackLayout mSwipeBackLayout;
1621

1722
public SwipeBackActivityHelper(Activity activity) {
1823
mActivity = activity;
1924
}
20-
25+
2126
@SuppressWarnings("deprecation")
22-
public void onActivtyCreate(){
27+
public void onActivityCreate() {
2328
mActivity.getWindow().setBackgroundDrawable(new ColorDrawable(0));
2429
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);
2632
}
27-
28-
public void onPostCreate(){
33+
34+
public void onPostCreate() {
2935
mSwipeBackLayout.attachToActivity(mActivity);
36+
convertActivityFromTranslucent();
3037
}
31-
38+
3239
public View findViewById(int id) {
3340
if (mSwipeBackLayout != null) {
3441
return mSwipeBackLayout.findViewById(id);
3542
}
3643
return null;
3744
}
38-
45+
3946
public SwipeBackLayout getSwipeBackLayout() {
4047
return mSwipeBackLayout;
4148
}
4249

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+
}
43104
}

library/src/main/java/me/imid/swipebacklayout/lib/app/SwipeBackPreferenceActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class SwipeBackPreferenceActivity extends PreferenceActivity implements S
1313
protected void onCreate(Bundle savedInstanceState) {
1414
super.onCreate(savedInstanceState);
1515
mHelper = new SwipeBackActivityHelper(this);
16-
mHelper.onActivtyCreate();
16+
mHelper.onActivityCreate();
1717
}
1818

1919
@Override

0 commit comments

Comments
 (0)