Skip to content

Commit

Permalink
update 2.1.1,fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
gyf-dev committed May 12, 2017
1 parent de00eee commit 4e2f3a2
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 100 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
## 使用
android studio用户用法如下,2.x.x版本全新的Api,调用更方便

compile 'com.gyf.barlibrary:barlibrary:2.1.0'
compile 'com.gyf.barlibrary:barlibrary:2.1.1'
eclipse用户直接下载jar包

[barlibrary-2.1.0.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-2.1.0.jar)
[barlibrary-2.1.1.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-2.1.1.jar)

版本说明

>2.1.0
>2.1.1
- 全新的链式调用,更方便,删除了1.x.x版本Api
- 修复了4.4不能时刻改变颜色的bug
- 修复了4.4 activity全屏时底部被导航栏遮挡的bug
- 修复4.4旋转屏幕为横屏时底部出现多余的导航栏
- 修复状态栏和布局重叠的问题,调用fitsSystemWindows(true)即可,必须指定状态栏的颜色statusBarColor()
- 增加了View支持变色功能
- 删除[SystemBarTint](https://github.com/jgilfelt/SystemBarTint)的库的依赖

### [1.x.x 用户请点击](https://github.com/gyf-dev/ImmersionBar/blob/master/README_1.x.md)

## 下载demo
###[点我](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/sample-debug.apk)
### [点我](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/sample-debug.apk)

## 用法
### 初始化
Expand Down Expand Up @@ -159,8 +160,10 @@ eclipse用户直接下载jar包
#### 动态图 ####
- android 6.0 有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_6.0.gif"/>
- android 4.4 有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_4.4.gif"/>
- android 4.4 没有导航栏效果
<img width="300" src="https://github.com/gyf-dev/ImmersionBar/blob/master/screenshots/Screenshot_4.4_no.gif"/>
Expand Down
6 changes: 3 additions & 3 deletions barlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ dependencies {
}

task makeJar(type: Copy) {
delete 'build/libs/barlibrary-2.0.0.jar'
delete 'build/libs/barlibrary-2.1.0.jar'
from('build/intermediates/bundles/default/')
into('build/libs/')
include('classes.jar')
rename('classes.jar', 'barlibrary-2.1.0.jar')
rename('classes.jar', 'barlibrary-2.1.1.jar')
}

makeJar.dependsOn(build)
Expand All @@ -53,7 +53,7 @@ publish {
userOrg = 'magic-dev'
groupId = 'com.gyf.barlibrary'
artifactId = 'barlibrary'
publishVersion = '2.1.0'
publishVersion = '2.1.1'
desc = 'Android bar management'
website = 'https://github.com/gyf-dev/ImmersionBar'
}
42 changes: 1 addition & 41 deletions barlibrary/src/main/java/com/gyf/barlibrary/BarConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ class BarConfig {
private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar";

private static String sNavBarOverride;
private final boolean mTranslucentStatusBar;
private final boolean mTranslucentNavBar;
private final int mStatusBarHeight;
private final int mActionBarHeight;
private final boolean mHasNavigationBar;
Expand All @@ -50,7 +48,7 @@ class BarConfig {
}


public BarConfig(Activity activity, boolean translucentStatusBar, boolean traslucentNavBar) {
public BarConfig(Activity activity) {
Resources res = activity.getResources();
mInPortrait = (res.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT);
mSmallestWidthDp = getSmallestWidthDp(activity);
Expand All @@ -59,8 +57,6 @@ public BarConfig(Activity activity, boolean translucentStatusBar, boolean traslu
mNavigationBarHeight = getNavigationBarHeight(activity);
mNavigationBarWidth = getNavigationBarWidth(activity);
mHasNavigationBar = (mNavigationBarHeight > 0);
mTranslucentStatusBar = translucentStatusBar;
mTranslucentNavBar = traslucentNavBar;
}

@TargetApi(14)
Expand Down Expand Up @@ -203,40 +199,4 @@ public int getNavigationBarWidth() {
return mNavigationBarWidth;
}

/**
* Get the layout inset for any system UI that appears at the top of the screen.
*
* @param withActionBar True to include the height of the action bar, False otherwise.
* @return The layout inset (in pixels).
*/
public int getPixelInsetTop(boolean withActionBar) {
return (mTranslucentStatusBar ? mStatusBarHeight : 0) + (withActionBar ? mActionBarHeight : 0);
}

/**
* Get the layout inset for any system UI that appears at the bottom of the screen.
*
* @return The layout inset (in pixels).
*/
public int getPixelInsetBottom() {
if (mTranslucentNavBar && isNavigationAtBottom()) {
return mNavigationBarHeight;
} else {
return 0;
}
}

/**
* Get the layout inset for any system UI that appears at the right of the screen.
*
* @return The layout inset (in pixels).
*/
public int getPixelInsetRight() {
if (mTranslucentNavBar && !isNavigationAtBottom()) {
return mNavigationBarWidth;
} else {
return 0;
}
}

}
65 changes: 15 additions & 50 deletions barlibrary/src/main/java/com/gyf/barlibrary/ImmersionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class ImmersionBar {
private ViewGroup mContentView;

private BarConfig mConfig;
private boolean mStatusBarAvailable;
private boolean mNavBarAvailable;


private ImmersionBar() {
Expand All @@ -51,34 +49,7 @@ private ImmersionBar(Activity activity) {
mWindow = activity.getWindow();
mViewGroup = (ViewGroup) mWindow.getDecorView();
mContentView = (ViewGroup) mActivity.findViewById(android.R.id.content);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// check theme attrs
int[] attrs = {android.R.attr.windowTranslucentStatus,
android.R.attr.windowTranslucentNavigation};
TypedArray a = activity.obtainStyledAttributes(attrs);
try {
mStatusBarAvailable = a.getBoolean(0, false);
mNavBarAvailable = a.getBoolean(1, false);
} finally {
a.recycle();
}

// check window flags
WindowManager.LayoutParams winParams = mWindow.getAttributes();
int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
if ((winParams.flags & bits) != 0) {
mStatusBarAvailable = true;
}
bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION;
if ((winParams.flags & bits) != 0) {
mNavBarAvailable = true;
}
}
mConfig = new BarConfig(activity, mStatusBarAvailable, mNavBarAvailable);
// device might not have virtual navigation keys
if (!mConfig.hasNavigtionBar()) {
mNavBarAvailable = false;
}
mConfig = new BarConfig(activity);

if (!mMap.isEmpty()) {
if (mMap.get(mActivity.getClass().getName()) == null) {
Expand All @@ -100,7 +71,6 @@ private ImmersionBar(Activity activity) {
* @return the immersion bar
*/
public static ImmersionBar with(Activity activity) {

return new ImmersionBar(activity);
}

Expand Down Expand Up @@ -453,22 +423,18 @@ private void setBarColor() {
} else {
mWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mWindow.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (mStatusBarAvailable) {
setupStatusBarView();
}
if (mNavBarAvailable) {
setupNavBarView();
}
// 解决android4.4有导航栏的情况下,activity底部被状态栏遮挡的问题
if (mConfig.hasNavigtionBar() && !mBarParams.fullScreenTemp && !mBarParams.fullScreen) {
setupStatusBarView();
setupNavBarView();
// 解决android4.4有导航栏的情况下,activity底部被导航栏遮挡的问题
if (mConfig.hasNavigtionBar() && !mBarParams.fullScreenTemp
&& !mBarParams.fullScreen && mConfig.isNavigationAtBottom()) {
mContentView.setPadding(0, 0, 0, getNavigationBarHeight(mActivity));
} else {
mContentView.setPadding(0, 0, 0, 0);
}
}
}
mWindow.getDecorView().setSystemUiVisibility(uiFlags);

}

/**
Expand Down Expand Up @@ -499,7 +465,6 @@ private int hideBar(int uiFlags) {
}
}
return uiFlags | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
//activity.getWindow().getDecorView().setSystemUiVisibility(uiFlags);
}

/**
Expand Down Expand Up @@ -634,16 +599,16 @@ private void setupStatusBarView() {
if (mBarParams.statusBarView == null) {
mBarParams.statusBarView = new View(mActivity);
}
mViewGroup.removeView(mBarParams.statusBarView);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(mActivity));
params.gravity = Gravity.TOP;
if (mNavBarAvailable && !isNavigationAtBottom(mActivity)) {
if (!isNavigationAtBottom(mActivity)) {
params.rightMargin = getNavigationBarWidth(mActivity);
}
mBarParams.statusBarView.setLayoutParams(params);
mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
mBarParams.statusBarView.setVisibility(View.VISIBLE);
mViewGroup.removeView(mBarParams.statusBarView);
mViewGroup.addView(mBarParams.statusBarView);
}

Expand All @@ -654,6 +619,7 @@ private void setupNavBarView() {
if (mBarParams.navigationBarView == null) {
mBarParams.navigationBarView = new View(mActivity);
}
mViewGroup.removeView(mBarParams.navigationBarView);
FrameLayout.LayoutParams params;
if (isNavigationAtBottom(mActivity)) {
params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getNavigationBarHeight(mActivity));
Expand All @@ -671,7 +637,6 @@ private void setupNavBarView() {
mBarParams.navigationBarColorTransform, mBarParams.navigationBarAlpha));
}
mBarParams.navigationBarView.setVisibility(View.VISIBLE);
mViewGroup.removeView(mBarParams.navigationBarView);
mViewGroup.addView(mBarParams.navigationBarView);
}

Expand All @@ -684,7 +649,7 @@ private void setupNavBarView() {
*/
@TargetApi(14)
public static boolean hasNavigationBar(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.hasNavigtionBar();
}

Expand All @@ -697,7 +662,7 @@ public static boolean hasNavigationBar(Activity activity) {
*/
@TargetApi(14)
public static int getNavigationBarHeight(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.getNavigationBarHeight();
}

Expand All @@ -710,7 +675,7 @@ public static int getNavigationBarHeight(Activity activity) {
*/
@TargetApi(14)
public static int getNavigationBarWidth(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.getNavigationBarWidth();
}

Expand All @@ -723,7 +688,7 @@ public static int getNavigationBarWidth(Activity activity) {
*/
@TargetApi(14)
public static boolean isNavigationAtBottom(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.isNavigationAtBottom();
}

Expand All @@ -736,7 +701,7 @@ public static boolean isNavigationAtBottom(Activity activity) {
*/
@TargetApi(14)
public static int getStatusBarHeight(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.getStatusBarHeight();
}

Expand All @@ -749,7 +714,7 @@ public static int getStatusBarHeight(Activity activity) {
*/
@TargetApi(14)
public static int getActionBarHeight(Activity activity) {
BarConfig config = new BarConfig(activity, true, true);
BarConfig config = new BarConfig(activity);
return config.getActionBarHeight();
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
classpath 'com.android.tools.build:gradle:2.2.1'
classpath 'com.novoda:bintray-release:0.3.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Binary file added jar/barlibrary-2.1.1.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("沉浸式");
toolbar.setTitleTextColor(Color.WHITE);
ImmersionBar.with(this).init();
// ImmersionBar.with(this)
// .transparentStatusBar() //透明状态栏,不写默认透明色
// .transparentNavigationBar() //透明导航栏,不写默认黑色(设置此方法,fullScreen()方法自动为true)
Expand Down

0 comments on commit 4e2f3a2

Please sign in to comment.