Skip to content

Commit b391f1f

Browse files
author
Issac
committed
1.Upgrade buildToolsVersion.
2.Bug fix: enable window transparent when scrollToFinishActivity() invoked.
1 parent bd50aaa commit b391f1f

File tree

6 files changed

+82
-67
lines changed

6 files changed

+82
-67
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.6.+'
6+
classpath 'com.android.tools.build:gradle:0.9.+'
77
}
88
}
99

library/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ repositories {
55
}
66

77
dependencies {
8-
compile 'com.android.support:support-v4:13.0.+'
8+
compile 'com.android.support:support-v4:+'
99
}
1010

1111
android {
12-
compileSdkVersion 17
13-
buildToolsVersion "17.0.0"
12+
compileSdkVersion 19
13+
buildToolsVersion "19.1.0"
1414

1515
defaultConfig {
16-
minSdkVersion 14
17-
targetSdkVersion 14
16+
minSdkVersion 7
17+
targetSdkVersion 19
1818
}
1919
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
package me.imid.swipebacklayout.lib;
3+
4+
import android.app.Activity;
5+
6+
import java.lang.reflect.Method;
7+
8+
/**
9+
* Created by Chaojun Wang on 6/9/14.
10+
*/
11+
public class Utils {
12+
private Utils() {
13+
}
14+
15+
/**
16+
* Convert a translucent themed Activity
17+
* {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque
18+
* Activity.
19+
* <p>
20+
* Call this whenever the background of a translucent Activity has changed
21+
* to become opaque. Doing so will allow the {@link android.view.Surface} of
22+
* the Activity behind to be released.
23+
* <p>
24+
* This call has no effect on non-translucent activities or on activities
25+
* with the {@link android.R.attr#windowIsFloating} attribute.
26+
*/
27+
public static void convertActivityFromTranslucent(Activity activity) {
28+
try {
29+
Method method = Activity.class.getDeclaredMethod("convertFromTranslucent");
30+
method.setAccessible(true);
31+
method.invoke(activity);
32+
} catch (Throwable t) {
33+
}
34+
}
35+
36+
/**
37+
* Convert a translucent themed Activity
38+
* {@link android.R.attr#windowIsTranslucent} back from opaque to
39+
* translucent following a call to
40+
* {@link #convertActivityFromTranslucent(android.app.Activity)} .
41+
* <p>
42+
* Calling this allows the Activity behind this one to be seen again. Once
43+
* all such Activities have been redrawn
44+
* <p>
45+
* This call has no effect on non-translucent activities or on activities
46+
* with the {@link android.R.attr#windowIsFloating} attribute.
47+
*/
48+
public static void convertActivityToTranslucent(Activity activity) {
49+
try {
50+
Class<?>[] classes = Activity.class.getDeclaredClasses();
51+
Class<?> translucentConversionListenerClazz = null;
52+
for (Class clazz : classes) {
53+
if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
54+
translucentConversionListenerClazz = clazz;
55+
}
56+
}
57+
Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
58+
translucentConversionListenerClazz);
59+
method.setAccessible(true);
60+
method.invoke(activity, new Object[] {
61+
null
62+
});
63+
} catch (Throwable t) {
64+
}
65+
}
66+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.view.View;
77

88
import me.imid.swipebacklayout.lib.SwipeBackLayout;
9+
import me.imid.swipebacklayout.lib.Utils;
910

1011
public class SwipeBackActivity extends FragmentActivity implements SwipeBackActivityBase {
1112
private SwipeBackActivityHelper mHelper;
@@ -43,6 +44,7 @@ public void setSwipeBackEnable(boolean enable) {
4344

4445
@Override
4546
public void scrollToFinishActivity() {
47+
Utils.convertActivityToTranslucent(this);
4648
getSwipeBackLayout().scrollToFinishActivity();
4749
}
4850
}

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

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
import android.view.LayoutInflater;
77
import android.view.View;
88

9-
import java.lang.reflect.Method;
10-
119
import me.imid.swipebacklayout.lib.SwipeBackLayout;
10+
import me.imid.swipebacklayout.lib.Utils;
1211

1312
/**
1413
* @author Yrom
@@ -32,13 +31,13 @@ public void onActivityCreate() {
3231
@Override
3332
public void onScrollStateChange(int state, float scrollPercent) {
3433
if (state == SwipeBackLayout.STATE_IDLE && scrollPercent == 0) {
35-
convertActivityFromTranslucent();
34+
Utils.convertActivityFromTranslucent(mActivity);
3635
}
3736
}
3837

3938
@Override
4039
public void onEdgeTouch(int edgeFlag) {
41-
convertActivityToTranslucent();
40+
Utils.convertActivityToTranslucent(mActivity);
4241
}
4342

4443
@Override
@@ -50,7 +49,7 @@ public void onScrollOverThreshold() {
5049

5150
public void onPostCreate() {
5251
mSwipeBackLayout.attachToActivity(mActivity);
53-
convertActivityFromTranslucent();
52+
Utils.convertActivityFromTranslucent(mActivity);
5453
}
5554

5655
public View findViewById(int id) {
@@ -63,56 +62,4 @@ public View findViewById(int id) {
6362
public SwipeBackLayout getSwipeBackLayout() {
6463
return mSwipeBackLayout;
6564
}
66-
67-
/**
68-
* Convert a translucent themed Activity
69-
* {@link android.R.attr#windowIsTranslucent} to a fullscreen opaque
70-
* Activity.
71-
* <p>
72-
* Call this whenever the background of a translucent Activity has changed
73-
* to become opaque. Doing so will allow the {@link android.view.Surface} of
74-
* the Activity behind to be released.
75-
* <p>
76-
* This call has no effect on non-translucent activities or on activities
77-
* with the {@link android.R.attr#windowIsFloating} attribute.
78-
*/
79-
public void convertActivityFromTranslucent() {
80-
try {
81-
Method method = Activity.class.getDeclaredMethod("convertFromTranslucent", null);
82-
method.setAccessible(true);
83-
method.invoke(mActivity, null);
84-
} catch (Throwable t) {
85-
}
86-
}
87-
88-
/**
89-
* Convert a translucent themed Activity
90-
* {@link android.R.attr#windowIsTranslucent} back from opaque to
91-
* translucent following a call to {@link #convertActivityFromTranslucent()}
92-
* .
93-
* <p>
94-
* Calling this allows the Activity behind this one to be seen again. Once
95-
* all such Activities have been redrawn
96-
* <p>
97-
* This call has no effect on non-translucent activities or on activities
98-
* with the {@link android.R.attr#windowIsFloating} attribute.
99-
*/
100-
public void convertActivityToTranslucent() {
101-
try {
102-
Class<?>[] classes = Activity.class.getDeclaredClasses();
103-
Class<?> translucentConversionListenerClazz = null;
104-
for (Class clazz : classes) {
105-
if (clazz.getSimpleName().contains("TranslucentConversionListener")) {
106-
translucentConversionListenerClazz = clazz;
107-
}
108-
}
109-
Method method = Activity.class.getDeclaredMethod("convertToTranslucent",
110-
translucentConversionListenerClazz);
111-
method.setAccessible(true);
112-
method.invoke(mActivity, new Object[] {
113-
null
114-
});
115-
} catch (Throwable t) {
116-
}
117-
}
11865
}

samples/build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ dependencies {
1010
}
1111

1212
android {
13-
compileSdkVersion 17
14-
buildToolsVersion "17.0.0"
13+
compileSdkVersion 19
14+
buildToolsVersion "19.1.0"
1515

1616
defaultConfig {
17-
minSdkVersion 14
18-
targetSdkVersion 14
17+
minSdkVersion 7
18+
targetSdkVersion 19
1919
}
2020

2121
signingConfigs {

0 commit comments

Comments
 (0)