-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from z-chu/master
优化图片选择页UI, 适配预览页的横竖屏切换
- Loading branch information
Showing
8 changed files
with
163 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
imagepicker/src/main/java/com/lzy/imagepicker/util/NavigationBarChangeListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.lzy.imagepicker.util; | ||
|
||
import android.app.Activity; | ||
import android.graphics.Rect; | ||
import android.view.View; | ||
import android.view.ViewTreeObserver; | ||
|
||
|
||
/** | ||
* Created by z-chu on 2017/9/4 | ||
* 用于监听导航栏的显示和隐藏,主要用于适配华为EMUI系统上虚拟导航栏可随时收起和展开的情况 | ||
*/ | ||
|
||
public class NavigationBarChangeListener implements ViewTreeObserver.OnGlobalLayoutListener { | ||
|
||
|
||
/** | ||
* 监听竖屏模式导航栏的显示和隐藏 | ||
*/ | ||
public static final int ORIENTATION_VERTICAL = 1; | ||
|
||
/** | ||
* 监听横屏模式导航栏的显示和隐藏 | ||
*/ | ||
public static final int ORIENTATION_HORIZONTAL = 2; | ||
|
||
private Rect rect; | ||
|
||
private View rootView; | ||
|
||
private boolean isShowNavigationBar = false; | ||
|
||
private int orientation; | ||
|
||
private OnSoftInputStateChangeListener listener; | ||
|
||
|
||
public NavigationBarChangeListener(View rootView, int orientation) { | ||
this.rootView = rootView; | ||
this.orientation = orientation; | ||
rect = new Rect(); | ||
} | ||
|
||
@Override | ||
public void onGlobalLayout() { | ||
rect.setEmpty(); | ||
rootView.getWindowVisibleDisplayFrame(rect); | ||
int heightDiff = 0; | ||
if (orientation == ORIENTATION_VERTICAL) { | ||
heightDiff = rootView.getHeight() - (rect.bottom - rect.top); | ||
} else if (orientation == ORIENTATION_HORIZONTAL) { | ||
heightDiff = rootView.getWidth() - (rect.right - rect.left); | ||
} | ||
int navigationBarHeight = Utils.hasVirtualNavigationBar(rootView.getContext()) ? | ||
Utils.getNavigationBarHeight(rootView.getContext()) : 0; | ||
if (heightDiff >= navigationBarHeight && heightDiff < navigationBarHeight * 2) { | ||
if (!isShowNavigationBar && listener != null) { | ||
listener.onNavigationBarShow(orientation, heightDiff); | ||
} | ||
isShowNavigationBar = true; | ||
} else { | ||
|
||
if (isShowNavigationBar && listener != null) { | ||
listener.onNavigationBarHide(orientation); | ||
} | ||
isShowNavigationBar = false; | ||
} | ||
} | ||
|
||
public void setListener(OnSoftInputStateChangeListener listener) { | ||
this.listener = listener; | ||
} | ||
|
||
public interface OnSoftInputStateChangeListener { | ||
void onNavigationBarShow(int orientation, int height); | ||
|
||
void onNavigationBarHide(int orientation); | ||
} | ||
|
||
public static NavigationBarChangeListener with(View rootView) { | ||
return with(rootView, ORIENTATION_VERTICAL); | ||
} | ||
|
||
public static NavigationBarChangeListener with(Activity activity) { | ||
return with(activity.findViewById(android.R.id.content), ORIENTATION_VERTICAL); | ||
} | ||
|
||
public static NavigationBarChangeListener with(View rootView, int orientation) { | ||
NavigationBarChangeListener softInputHeightListener = new NavigationBarChangeListener(rootView, orientation); | ||
rootView.getViewTreeObserver().addOnGlobalLayoutListener(softInputHeightListener); | ||
return softInputHeightListener; | ||
} | ||
|
||
public static NavigationBarChangeListener with(Activity activity, int orientation) { | ||
return with(activity.findViewById(android.R.id.content), orientation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<gradient | ||
android:angle="270" | ||
android:startColor="#19000000" | ||
android:endColor="#00000000" | ||
/> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters