Skip to content

Commit

Permalink
update 2.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gyf-dev committed Aug 21, 2018
1 parent afc4fed commit 8d6961e
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 98 deletions.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,33 @@
> android studio
```groovy
compile 'com.gyf.barlibrary:barlibrary:2.3.0'
implementation 'com.gyf.immersionbar:immersionbar:2.3.1'
```

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

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

## 下载demo
### [下载](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/immersionBar-2.3.0.apk)
### [下载](https://github.com/gyf-dev/ImmersionBar/blob/master/apk/immersionBar-2.3.1.apk)

## 关于全面屏与刘海
- 解决全面屏上下部分留黑或留白问题,以下三种任选其一,或者都写

① 在manifest的Application节点中加入
```xml
<meta-data
android:name="android.max_aspect"
android:value="2.1" />
```
② 在manifest的Application节点下加入如下属性,这句话的意思是支持分屏模式
```xml
android:resizeableActivity="true"
```
③ 升级targetSdkVersion为25以上版本

## 用法
### 初始化
Expand Down
28 changes: 14 additions & 14 deletions barlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
compileSdkVersion 25
buildToolsVersion '26.0.2'
compileSdkVersion 27
buildToolsVersion '27.0.3'

defaultConfig {
minSdkVersion 11
targetSdkVersion 25
targetSdkVersion 27
versionCode 1
versionName "1.0"

Expand All @@ -29,29 +29,29 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.1.1'
testImplementation 'junit:junit:4.12'
}

task makeJar(type: Copy) {
delete 'build/libs/barlibrary-2.2.9.jar'
from('build/intermediates/bundles/default/')
delete 'build/libs/immersionbar-2.3.0.jar'
from('build/intermediates/bundles/release/')
into('build/libs/')
include('classes.jar')
rename('classes.jar', 'barlibrary-2.3.0.jar')
rename('classes.jar', 'immersionbar-2.3.1.jar')
}

makeJar.dependsOn(build)

publish {
userOrg = 'magic-dev'
groupId = 'com.gyf.barlibrary'
artifactId = 'barlibrary'
publishVersion = '2.3.0'
userOrg = 'geyifeng'
groupId = 'com.gyf.immersionbar'
artifactId = 'immersionbar'
publishVersion = '2.3.1'
desc = 'Android bar management'
website = 'https://github.com/gyf-dev/ImmersionBar'
}
119 changes: 78 additions & 41 deletions barlibrary/src/main/java/com/gyf/barlibrary/ImmersionBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.support.v4.content.ContextCompat;
import android.support.v4.graphics.ColorUtils;
import android.support.v4.widget.DrawerLayout;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -27,7 +28,6 @@
import android.view.WindowManager;
import android.widget.FrameLayout;

import java.lang.ref.WeakReference;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -68,10 +68,9 @@ public class ImmersionBar {
* @param activity the activity
*/
private ImmersionBar(Activity activity) {
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
mActivity = activityWeakReference.get();
mActivity = activity;
mWindow = mActivity.getWindow();
mActivityName = activity.getClass().getName();
mActivityName = activity.toString();
mImmersionBarName = mActivityName;
initParams();
}
Expand All @@ -90,24 +89,45 @@ private ImmersionBar(Activity activity, Fragment fragment) {
if (activity == null) {
throw new IllegalArgumentException("Activity不能为空!!!");
}
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
WeakReference<Fragment> fragmentWeakReference = new WeakReference<>(fragment);
mActivity = activityWeakReference.get();
mActivity = activity;
mWindow = mActivity.getWindow();
mActivityName = mActivity.getClass().getName();
mFragmentName = mActivityName + "_AND_" + fragmentWeakReference.get().getClass().getName();
mActivityName = mActivity.toString();
mFragmentName = mActivityName + "_AND_" + fragment.toString();
mImmersionBarName = mFragmentName;
initParams();
}

private ImmersionBar(DialogFragment dialogFragment) {
mActivity = dialogFragment.getActivity();
mDialog = dialogFragment.getDialog();
mWindow = mDialog.getWindow();
mActivityName = mActivity.toString();
mImmersionBarName = mActivityName + "_AND_" + dialogFragment.toString();
initParams();
}

private ImmersionBar(DialogFragment dialogFragment, Dialog dialog) {
WeakReference<DialogFragment> dialogFragmentWeakReference = new WeakReference<>(dialogFragment);
WeakReference<Dialog> dialogWeakReference = new WeakReference<>(dialog);
mActivity = dialogFragmentWeakReference.get().getActivity();
mDialog = dialogWeakReference.get();
mActivity = dialogFragment.getActivity();
mDialog = dialog;
mWindow = mDialog.getWindow();
mActivityName = mActivity.getClass().getName();
mImmersionBarName = mActivityName + "_AND_" + dialogFragmentWeakReference.get().getClass().getName();
mActivityName = mActivity.toString();
mImmersionBarName = mActivityName + "_AND_" + dialog.toString();
initParams();
}

/**
* 在Dialog里初始化
* Instantiates a new Immersion bar.
*
* @param activity the activity
* @param dialog the dialog
*/
private ImmersionBar(Activity activity, Dialog dialog) {
mActivity = activity;
mDialog = dialog;
mWindow = mDialog.getWindow();
mActivityName = mActivity.toString();
mImmersionBarName = mActivityName + "_AND_" + dialog.toString();
initParams();
}

Expand All @@ -120,12 +140,10 @@ private ImmersionBar(DialogFragment dialogFragment, Dialog dialog) {
* @param dialogTag the dialog tag dialog标识,不能为空
*/
private ImmersionBar(Activity activity, Dialog dialog, String dialogTag) {
WeakReference<Activity> activityWeakReference = new WeakReference<>(activity);
WeakReference<Dialog> dialogWeakReference = new WeakReference<>(dialog);
mActivity = activityWeakReference.get();
mDialog = dialogWeakReference.get();
mActivity = activity;
mDialog = dialog;
mWindow = mDialog.getWindow();
mActivityName = mActivity.getClass().getName();
mActivityName = mActivity.toString();
mImmersionBarName = mActivityName + "_AND_" + dialogTag;
initParams();
}
Expand All @@ -135,8 +153,9 @@ private ImmersionBar(Activity activity, Dialog dialog, String dialogTag) {
* Init params.
*/
private void initParams() {
Log.e("mImmersionBarName = ", mImmersionBarName);
mDecorView = (ViewGroup) mWindow.getDecorView();
mContentView = (ViewGroup) mDecorView.findViewById(android.R.id.content);
mContentView = mDecorView.findViewById(android.R.id.content);
mConfig = new BarConfig(mActivity);
if (mMap.get(mImmersionBarName) == null) {
mBarParams = new BarParams();
Expand Down Expand Up @@ -164,54 +183,73 @@ private void initParams() {
* @return the immersion bar
*/
public static ImmersionBar with(@NonNull Activity activity) {
if (activity == null)
throw new IllegalArgumentException("Activity不能为null");
return new ImmersionBar(activity);
}

/**
* 调用该方法必须保证加载Fragment的Activity先初始化,已过时,使用with(Activity activity, Fragment fragment)方法
* 调用该方法必须保证加载Fragment的Activity先初始化
* With immersion bar.
*
* @param fragment the fragment
* @return the immersion bar
*/
public static ImmersionBar with(@NonNull Fragment fragment) {
if (fragment == null)
throw new IllegalArgumentException("Fragment不能为null");
return new ImmersionBar(fragment);
}

public static ImmersionBar with(@NonNull Activity activity, @NonNull Fragment fragment) {
if (activity == null)
throw new IllegalArgumentException("Activity不能为null");
if (fragment == null)
throw new IllegalArgumentException("Fragment不能为null");
return new ImmersionBar(activity, fragment);
}


/**
* 在DialogFragment使用
* With immersion bar.
*
* @param dialogFragment the dialog fragment
* @return the immersion bar
*/
public static ImmersionBar with(@NonNull DialogFragment dialogFragment) {
return new ImmersionBar(dialogFragment);
}

/**
* 在DialogFragment使用,已过时
*
* @param dialogFragment the dialog fragment
* @param dialog the dialog
* @return the immersion bar
* @deprecated 请使用ImmersionBar with(@NonNull DialogFragment dialogFragment)
*/
@Deprecated
public static ImmersionBar with(@NonNull DialogFragment dialogFragment, @NonNull Dialog dialog) {
if (dialogFragment == null)
throw new IllegalArgumentException("DialogFragment不能为null");
if (dialog == null)
throw new IllegalArgumentException("Dialog不能为null");
return new ImmersionBar(dialogFragment, dialog);
}

/**
* 在dialog里使用
* With immersion bar.
*
* @param activity the activity
* @param dialog the dialog
* @return the immersion bar
*/
public static ImmersionBar with(@NonNull Activity activity, @NonNull Dialog dialog) {
return new ImmersionBar(activity, dialog);
}

/**
* 在dialog里使用,已过时
* With immersion bar.
*
* @param activity the activity
* @param dialog the dialog
* @param dialogTag the dialog tag
* @return the immersion bar
* @deprecated 请使用ImmersionBar with(@NonNull Activity activity, @NonNull Dialog dialog)
*/
@Deprecated
public static ImmersionBar with(@NonNull Activity activity, @NonNull Dialog dialog, @NonNull String dialogTag) {
if (activity == null)
throw new IllegalArgumentException("Activity不能为null");
if (dialog == null)
throw new IllegalArgumentException("Dialog不能为null");
if (isEmpty(dialogTag))
throw new IllegalArgumentException("tag不能为null或空");
return new ImmersionBar(activity, dialog, dialogTag);
Expand Down Expand Up @@ -1777,10 +1815,9 @@ private void setTitleBar() {
final ViewGroup.LayoutParams layoutParams = mBarParams.titleBarView.getLayoutParams();
if (layoutParams.height == ViewGroup.LayoutParams.WRAP_CONTENT ||
layoutParams.height == ViewGroup.LayoutParams.MATCH_PARENT) {
mBarParams.titleBarView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
mBarParams.titleBarView.post(new Runnable() {
@Override
public void onGlobalLayout() {
mBarParams.titleBarView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
public void run() {
if (mBarParams.titleBarHeight == 0)
mBarParams.titleBarHeight = mBarParams.titleBarView.getHeight() + mConfig.getStatusBarHeight();
if (mBarParams.titleBarPaddingTopHeight == 0)
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ buildscript {
jcenter()
}
dependencies {

classpath 'com.android.tools.build:gradle:3.0.0'
classpath 'com.novoda:bintray-release:0.5.0'
classpath 'com.novoda:bintray-release:0.8.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
android.enableAapt2=false
android.enableAapt2= false
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Mon Oct 30 09:42:51 CST 2017
#Tue Aug 21 12:31:49 CST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
Binary file added jar/immersionbar-2.3.1.jar
Binary file not shown.
Loading

0 comments on commit 8d6961e

Please sign in to comment.