Skip to content

Commit 82b6335

Browse files
committed
1. change minSdk to 14.
2. fix bug when change fragment rapidly.
1 parent 94070bf commit 82b6335

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Add the dependency
2424
```groovy
2525
2626
dependencies {
27-
compile ('com.github.niorgai:StatusBarCompat:2.1.1', {
27+
compile ('com.github.niorgai:StatusBarCompat:2.1.2', {
2828
exclude group: 'com.android.support'
2929
})
3030
}

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ android {
99

1010
defaultConfig {
1111
applicationId "qiu.statusbarcompat"
12-
minSdkVersion 15
12+
minSdkVersion 14
1313
targetSdkVersion config.targetSdkVersion
1414
versionCode 1
1515
versionName "1.0"

library/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ android {
88
buildToolsVersion config.buildToolsVersion
99

1010
defaultConfig {
11-
minSdkVersion 15
11+
minSdkVersion 14
1212
targetSdkVersion config.targetSdkVersion
1313
versionCode 1
1414
versionName "1.0"

library/src/main/java/qiu/niorgai/StatusBarCompatKitKat.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.os.Build;
77
import android.support.design.widget.AppBarLayout;
88
import android.support.design.widget.CollapsingToolbarLayout;
9+
import android.support.design.widget.CoordinatorLayout;
910
import android.support.v4.view.ViewCompat;
1011
import android.support.v7.widget.Toolbar;
1112
import android.view.Gravity;
@@ -181,6 +182,19 @@ static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBa
181182
removeFakeStatusBarViewIfExist(activity);
182183
removeMarginTopOfContentChild(mContentChild, statusBarHeight);
183184
final View statusView = addFakeStatusBarView(activity, statusColor, statusBarHeight);
185+
186+
CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();
187+
if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
188+
int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
189+
if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
190+
statusView.setAlpha(1f);
191+
} else {
192+
statusView.setAlpha(0f);
193+
}
194+
} else {
195+
statusView.setAlpha(0f);
196+
}
197+
184198
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
185199
@Override
186200
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {

library/src/main/java/qiu/niorgai/StatusBarCompatLollipop.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.os.Build;
99
import android.support.design.widget.AppBarLayout;
1010
import android.support.design.widget.CollapsingToolbarLayout;
11+
import android.support.design.widget.CoordinatorLayout;
1112
import android.support.v4.view.OnApplyWindowInsetsListener;
1213
import android.support.v4.view.ViewCompat;
1314
import android.support.v4.view.WindowInsetsCompat;
@@ -92,10 +93,11 @@ static void translucentStatusBar(Activity activity, boolean hideStatusBarBackgro
9293
* compat for CollapsingToolbarLayout
9394
*
9495
* 1. change to full-screen mode(like translucentStatusBar).
95-
* 2. set View's FitsSystemWindow to false.
96-
* 3. adjust toolbar's height to layout.
97-
* 4. cancel CollapsingToolbarLayout's WindowInsets, let it layout as normal(now setStatusBarScrimColor is useless).
96+
* 2. cancel CollapsingToolbarLayout's WindowInsets, let it layout as normal(now setStatusBarScrimColor is useless).
97+
* 3. set View's FitsSystemWindow to false.
98+
* 4. adjust toolbar's height to layout.
9899
* 5. change statusBarColor by AppBarLayout's offset.
100+
* 6. add Listener to change statusBarColor
99101
*/
100102
static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBarLayout appBarLayout, final CollapsingToolbarLayout collapsingToolbarLayout,
101103
Toolbar toolbar, final int statusColor) {
@@ -106,6 +108,13 @@ static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBa
106108
window.setStatusBarColor(Color.TRANSPARENT);
107109
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
108110

111+
ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() {
112+
@Override
113+
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
114+
return insets;
115+
}
116+
});
117+
109118
ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
110119
View mChildView = mContentView.getChildAt(0);
111120
if (mChildView != null) {
@@ -124,12 +133,18 @@ static void setStatusBarColorForCollapsingToolbar(Activity activity, final AppBa
124133
toolbar.setTag(true);
125134
}
126135

127-
ViewCompat.setOnApplyWindowInsetsListener(collapsingToolbarLayout, new OnApplyWindowInsetsListener() {
128-
@Override
129-
public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
130-
return insets;
136+
CoordinatorLayout.Behavior behavior = ((CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams()).getBehavior();
137+
if (behavior != null && behavior instanceof AppBarLayout.Behavior) {
138+
int verticalOffset = ((AppBarLayout.Behavior) behavior).getTopAndBottomOffset();
139+
if (Math.abs(verticalOffset) > appBarLayout.getHeight() - collapsingToolbarLayout.getScrimVisibleHeightTrigger()) {
140+
window.setStatusBarColor(statusColor);
141+
} else {
142+
window.setStatusBarColor(Color.TRANSPARENT);
131143
}
132-
});
144+
} else {
145+
window.setStatusBarColor(Color.TRANSPARENT);
146+
}
147+
133148
collapsingToolbarLayout.setFitsSystemWindows(false);
134149
appBarLayout.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
135150
@Override

0 commit comments

Comments
 (0)