Skip to content

Commit

Permalink
update 2.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gyf-dev committed May 31, 2017
1 parent f4800e2 commit 66e89bc
Show file tree
Hide file tree
Showing 24 changed files with 675 additions and 177 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
> android studio
```groovy
compile 'com.gyf.barlibrary:barlibrary:2.2.0'
compile 'com.gyf.barlibrary:barlibrary:2.2.1'
```

>eclipse
[barlibrary-2.2.0.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-2.2.0.jar)
[barlibrary-2.2.1.jar](https://github.com/gyf-dev/ImmersionBar/blob/master/jar/barlibrary-2.2.1.jar)

## 版本说明
### [点我](https://github.com/gyf-dev/ImmersionBar/wiki)

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

## 用法
### 初始化
Expand All @@ -41,6 +41,7 @@
.navigationBarAlpha(0.4f) //导航栏透明度,不写默认0.0F
.barAlpha(0.3f) //状态栏和导航栏透明度,不写默认0.0f
.statusBarDarkFont(true) //状态栏字体是深色,不写默认为亮色
.flymeOSStatusBarFontColor(R.color.btn3) //修改flyme OS状态栏字体颜色
.fullScreen(true) //有导航栏的情况下,activity全屏显示,也就是activity最下面被导航栏覆盖,不写默认非全屏
.hideBar(BarHide.FLAG_HIDE_BAR) //隐藏状态栏或导航栏或两者,不写默认不隐藏
.setViewSupportTransformColor(toolbar) //设置支持view变色,支持一个view,不指定颜色,默认和状态栏同色,还有两个重载方法
Expand Down
Binary file removed apk/sample-2.2.0.apk
Binary file not shown.
Binary file added apk/sample-2.2.1.apk
Binary file not shown.
6 changes: 3 additions & 3 deletions barlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ dependencies {
}

task makeJar(type: Copy) {
delete 'build/libs/barlibrary-2.1.9.jar'
delete 'build/libs/barlibrary-2.2.0.jar'
from('build/intermediates/bundles/release/')
into('build/libs/')
include('classes.jar')
rename('classes.jar', 'barlibrary-2.2.0.jar')
rename('classes.jar', 'barlibrary-2.2.1.jar')
}

makeJar.dependsOn(build)
Expand All @@ -51,7 +51,7 @@ publish {
userOrg = 'magic-dev'
groupId = 'com.gyf.barlibrary'
artifactId = 'barlibrary'
publishVersion = '2.2.0'
publishVersion = '2.2.1'
desc = 'Android bar management'
website = 'https://github.com/gyf-dev/ImmersionBar'
}
36 changes: 19 additions & 17 deletions barlibrary/src/main/java/com/gyf/barlibrary/BarParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,32 @@
*/
public class BarParams {
@ColorInt
public int statusBarColor = Color.TRANSPARENT;
public int statusBarColor = Color.TRANSPARENT; //状态栏颜色
@ColorInt
public int navigationBarColor = Color.BLACK;
public int navigationBarColor = Color.BLACK; //导航栏颜色
@FloatRange(from = 0f, to = 1f)
public float statusBarAlpha = 0.0f;
public float statusBarAlpha = 0.0f; //状态栏透明度
@FloatRange(from = 0f, to = 1f)
public float navigationBarAlpha = 0.0f;
public boolean fullScreen = false;
public float navigationBarAlpha = 0.0f; //导航栏透明度
public boolean fullScreen = false; //有导航栏的情况,全屏显示
public boolean fullScreenTemp = fullScreen;
public BarHide barHide = BarHide.FLAG_SHOW_BAR;
public boolean darkFont = false;
public BarHide barHide = BarHide.FLAG_SHOW_BAR; //隐藏Bar
public boolean darkFont = false; //状态栏字体深色与亮色标志位
@ColorInt
public int statusBarColorTransform = Color.BLACK;
public int statusBarColorTransform = Color.BLACK; //状态栏变换后的颜色
@ColorInt
public int navigationBarColorTransform = Color.BLACK;
public View view;
public Map<View, Map<Integer, Integer>> viewMap = new HashMap<>();
public int navigationBarColorTransform = Color.BLACK; //导航栏变换后的颜色
public View view; //支持view变色
public Map<View, Map<Integer, Integer>> viewMap = new HashMap<>(); //支持view变色
@ColorInt
public int viewColorBeforeTransform = statusBarColor;
public int viewColorBeforeTransform = statusBarColor; //view变色前的颜色
@ColorInt
public int viewColorAfterTransform = statusBarColorTransform;
public boolean fits = false;
public int viewColorAfterTransform = statusBarColorTransform; //view变色后的颜色
public boolean fits = false; //解决标题栏与状态栏重叠问题
public int navigationBarColorTem = navigationBarColor;
public View statusBarView;
public View navigationBarView;
public View statusBarViewByHeight;
public View statusBarView; //4.4自定义一个状态栏
public View navigationBarView; //4.4自定义一个导航栏
public View statusBarViewByHeight; //解决标题栏与状态栏重叠问题
@ColorInt
public int flymeOSStatusBarFontColor; //flymeOS状态栏字体变色
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
package com.gyf.barlibrary;

import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
* Flyme OS 修改状态栏字体颜色工具类
* Created by gyf on 2017/05/30.
*/
public class FlymeOSStatusBarFontUtils {
private static Method mSetStatusBarColorIcon;
private static Method mSetStatusBarDarkIcon;
private static Field mStatusBarColorFiled;
private static int SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0;

static {
try {
mSetStatusBarColorIcon = Activity.class.getMethod("setStatusBarDarkIcon", int.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
try {
mSetStatusBarDarkIcon = Activity.class.getMethod("setStatusBarDarkIcon", boolean.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
try {
mStatusBarColorFiled = WindowManager.LayoutParams.class.getField("statusBarColor");
} catch (NoSuchFieldException e) {
e.printStackTrace();
}
try {
Field field = View.class.getField("SYSTEM_UI_FLAG_LIGHT_STATUS_BAR");
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = field.getInt(null);
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}

/**
* 判断颜色是否偏黑色
*
* @param color 颜色
* @param level 级别
* @return
*/
public static boolean isBlackColor(int color, int level) {
int grey = toGrey(color);
return grey < level;
}

/**
* 颜色转换成灰度值
*
* @param rgb 颜色
* @return 灰度值
*/
public static int toGrey(int rgb) {
int blue = rgb & 0x000000FF;
int green = (rgb & 0x0000FF00) >> 8;
int red = (rgb & 0x00FF0000) >> 16;
return (red * 38 + green * 75 + blue * 15) >> 7;
}

/**
* 设置状态栏字体图标颜色
*
* @param activity 当前activity
* @param color 颜色
*/
public static void setStatusBarDarkIcon(Activity activity, int color) {
if (mSetStatusBarColorIcon != null) {
try {
mSetStatusBarColorIcon.invoke(activity, color);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} else {
boolean whiteColor = isBlackColor(color, 50);
if (mStatusBarColorFiled != null) {
setStatusBarDarkIcon(activity, whiteColor, whiteColor);
setStatusBarDarkIcon(activity.getWindow(), color);
} else {
setStatusBarDarkIcon(activity, whiteColor);
}
}
}

/**
* 设置状态栏字体图标颜色(只限全屏非activity情况)
*
* @param window 当前窗口
* @param color 颜色
*/
public static void setStatusBarDarkIcon(Window window, int color) {
try {
setStatusBarColor(window, color);
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
setStatusBarDarkIcon(window.getDecorView(), true);
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 设置状态栏字体图标颜色
*
* @param activity 当前activity
* @param dark 是否深色 true为深色 false 为白色
*/
public static void setStatusBarDarkIcon(Activity activity, boolean dark) {
setStatusBarDarkIcon(activity, dark, true);
}

private static boolean changeMeizuFlag(WindowManager.LayoutParams winParams, String flagName, boolean on) {
try {
Field f = winParams.getClass().getDeclaredField(flagName);
f.setAccessible(true);
int bits = f.getInt(winParams);
Field f2 = winParams.getClass().getDeclaredField("meizuFlags");
f2.setAccessible(true);
int meizuFlags = f2.getInt(winParams);
int oldFlags = meizuFlags;
if (on) {
meizuFlags |= bits;
} else {
meizuFlags &= ~bits;
}
if (oldFlags != meizuFlags) {
f2.setInt(winParams, meizuFlags);
return true;
}
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}

/**
* 设置状态栏颜色
*
* @param view
* @param dark
*/
private static void setStatusBarDarkIcon(View view, boolean dark) {
int oldVis = view.getSystemUiVisibility();
int newVis = oldVis;
if (dark) {
newVis |= SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
} else {
newVis &= ~SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
}
if (newVis != oldVis) {
view.setSystemUiVisibility(newVis);
}
}

/**
* 设置状态栏颜色
*
* @param window
* @param color
*/
private static void setStatusBarColor(Window window, int color) {
WindowManager.LayoutParams winParams = window.getAttributes();
if (mStatusBarColorFiled != null) {
try {
int oldColor = mStatusBarColorFiled.getInt(winParams);
if (oldColor != color) {
mStatusBarColorFiled.set(winParams, color);
window.setAttributes(winParams);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}

/**
* 设置状态栏字体图标颜色(只限全屏非activity情况)
*
* @param window 当前窗口
* @param dark 是否深色 true为深色 false 为白色
*/
public static void setStatusBarDarkIcon(Window window, boolean dark) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
changeMeizuFlag(window.getAttributes(), "MEIZU_FLAG_DARK_STATUS_BAR_ICON", dark);
} else {
View decorView = window.getDecorView();
if (decorView != null) {
setStatusBarDarkIcon(decorView, dark);
setStatusBarColor(window, 0);
}
}
}

private static void setStatusBarDarkIcon(Activity activity, boolean dark, boolean flag) {
if (mSetStatusBarDarkIcon != null) {
try {
mSetStatusBarDarkIcon.invoke(activity, dark);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} else {
if (flag) {
setStatusBarDarkIcon(activity.getWindow(), dark);
}
}
}
}
Loading

0 comments on commit 66e89bc

Please sign in to comment.