diff --git a/apk/sample.apk b/apk/sample.apk index 2cc9fb2..8fffe17 100644 Binary files a/apk/sample.apk and b/apk/sample.apk differ diff --git a/app/src/main/java/com/aries/ui/widget/demo/MainActivity.java b/app/src/main/java/com/aries/ui/widget/demo/MainActivity.java index e94989a..122948c 100644 --- a/app/src/main/java/com/aries/ui/widget/demo/MainActivity.java +++ b/app/src/main/java/com/aries/ui/widget/demo/MainActivity.java @@ -9,6 +9,9 @@ import android.view.ViewTreeObserver; import android.widget.TextView; +import androidx.appcompat.app.AlertDialog; +import androidx.core.content.ContextCompat; + import com.aries.ui.helper.navigation.NavigationBarUtil; import com.aries.ui.util.NotchUtil; import com.aries.ui.util.StatusBarUtil; @@ -29,9 +32,6 @@ import java.util.ArrayList; import java.util.List; -import androidx.appcompat.app.AlertDialog; -import androidx.core.content.ContextCompat; - /** * @Author: AriesHoo on 2019/4/11 13:08 * @E-Mail: AriesHoo@126.com @@ -104,6 +104,8 @@ private void showNotch() { .show(); } + boolean mIsFull; + @Override protected void initView(Bundle bundle) { int padding = getResources().getDimensionPixelSize(R.dimen.dp_margin); @@ -114,6 +116,13 @@ protected void initView(Bundle bundle) { mTextView.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelSize(R.dimen.dp_text_size_main)); mTextView.setBackgroundColor(Color.WHITE); mAdapter.addHeaderView(mTextView); + mTextView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + StatusBarUtil.setFullScreen(mContext, !mIsFull); + mIsFull = !mIsFull; + } + }); List list = new ArrayList<>(); list.add(new WidgetEntity("StatusViewHelper", "支持顶部自定义标题栏沉浸效果帮助类。", StatusViewHelperActivity.class)); list.add(new WidgetEntity("KeyboardHelper", "解决软键盘遮住底部输入框问题帮助类。", TitleEditActivity.class)); @@ -152,7 +161,9 @@ public void onGlobalLayout() { + "
屏幕纵横比:" + NavigationBarUtil.getAspectRatio(mContext) + "
是否开启全面屏手势:根据判断系统是否开启虚拟导航栏(如华为可手动开关该方法不是完全正确的):" + NavigationBarUtil.isOpenFullScreenGestures(mContext) + "
是否有导航栏:" + NavigationBarUtil.hasNavBar(mContext) - + "
导航栏高度:" + NavigationBarUtil.getNavigationBarHeight(mContext))); + + "
导航栏高度:" + NavigationBarUtil.getNavigationBarHeight(mContext) + + "
是否隐藏状态栏:" + StatusBarUtil.isStatusBar(mContext) + + "
是否隐藏导航栏:" + NavigationBarUtil.isHideNavigationBar(mContext))); } } } diff --git a/build.gradle b/build.gradle index 420a259..aff6895 100644 --- a/build.gradle +++ b/build.gradle @@ -33,6 +33,6 @@ ext { minLibSdkVersion = 15 targetSdkVersion = 28 supportVersion = "1.0.0" - versionCode = 48 - versionName = "3.2.18" + versionCode = 49 + versionName = "3.2.19" } diff --git a/widget-core/src/main/java/com/aries/ui/helper/navigation/NavigationBarUtil.java b/widget-core/src/main/java/com/aries/ui/helper/navigation/NavigationBarUtil.java index 4e93905..6335c83 100644 --- a/widget-core/src/main/java/com/aries/ui/helper/navigation/NavigationBarUtil.java +++ b/widget-core/src/main/java/com/aries/ui/helper/navigation/NavigationBarUtil.java @@ -35,6 +35,7 @@ * 6、2019-4-15 10:30:13 新增导航栏图标颜色深浅方法{@link #setNavigationBarDarkMode(Window)}{@link #setNavigationBarDarkMode(Activity)} * {@link #setNavigationBarLightMode(Window)} {@link #setNavigationBarLightMode(Activity)} * 7、2019-7-31 21:20:50 增加判断是否支持导航栏文字及icon黑色变化方法{@link #isSupportNavigationBarFontChange()} + * 8、2019-8-1 11:26:10 增加判断是否隐藏导航栏方法{@link #isHideNavigationBar(Window)}{@link #isHideNavigationBar(Activity)} */ public class NavigationBarUtil { @@ -114,6 +115,97 @@ public static boolean isOpenFullScreenGestures(Context context) { return false; } + public static boolean isNavigationAtBottom(Activity activity) { + if (activity == null) { + return false; + } + return isNavigationAtBottom(activity.getWindow()); + } + + /** + * 判断导航栏是否在底部 + * + * @param window + * @return + */ + public static boolean isNavigationAtBottom(Window window) { + if (window == null) { + return false; + } + boolean mInPortrait = (Resources.getSystem().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); + float mSmallestWidthDp = getSmallestWidthDp(window); + return (mSmallestWidthDp >= 600 || mInPortrait); + } + + /** + * 是否隐藏状态栏 + * + * @param activity Activity对象 + * @return 是否隐藏 + */ + public static boolean isHideNavigationBar(Activity activity) { + if (activity == null) { + return false; + } + return isHideNavigationBar(activity.getWindow()); + } + + /** + * 是否隐藏状态栏 + * + * @param window Window对象 + * @return 是否隐藏 + */ + public static boolean isHideNavigationBar(Window window) { + if (window == null) { + return false; + } + return (window.getDecorView().getSystemUiVisibility() & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) + == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + } + + /** + * 判断系统是否支持导航栏文字及图标颜色变化 + * + * @return true支持导航栏文字颜色变化 + */ + public static boolean isSupportNavigationBarFontChange() { + if (RomUtil.isEMUI() && RomUtil.getEMUIVersion().compareTo("EmotionUI_4.1") > 0) { + return true; + } + if (RomUtil.getMIUIVersionCode() >= 6) { + return true; + } + return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; + } + + /** + * 判断当前手机是否为全面屏--通过纵横比 + * + * @param context + * @return + */ + public static boolean isFullScreenDevice(Context context) { + if (context == null) { + return false; + } + if (mHasCheckFullScreen) { + return mIsFullScreenDevice; + } + mHasCheckFullScreen = true; + mIsFullScreenDevice = false; + // 低于 API 21的,都不会是全面屏 + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + return false; + } + mIsFullScreenDevice = getAspectRatio(context) >= mAspectRatio; + return mIsFullScreenDevice; + } + + /** + * @param activity + * @return + */ public static boolean hasNavBar(Activity activity) { if (activity == null) { return false; @@ -135,6 +227,9 @@ public static boolean hasNavBar(Window window) { if (isOpenFullScreenGestures(window.getContext())) { return false; } + if (isHideNavigationBar(window)) { + return false; + } //其他手机根据屏幕真实高度与显示高度是否相同来判断 WindowManager windowManager = window.getWindowManager(); Display d = windowManager.getDefaultDisplay(); @@ -151,6 +246,46 @@ public static boolean hasNavBar(Window window) { return (realWidth - displayWidth) > 0 || (realHeight - displayHeight) > 0; } + /** + * 隐藏导航栏 + * + * @param activity Activity 对象 + * @param isHide 是否隐藏 + */ + public static void hideNavigationBar(Activity activity, boolean isHide) { + if (activity == null) { + return; + } + hideNavigationBar(activity.getWindow(), isHide); + } + + /** + * 隐藏导航栏 + * + * @param window Window 对象 + * @param isHide 是否隐藏 + */ + public static void hideNavigationBar(Window window, boolean isHide) { + if (window == null) { + return; + } + //防止系统栏隐藏时内容区域大小发生变化 + int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | window.getDecorView().getSystemUiVisibility(); + if (isHide) { + if (!isHideNavigationBar(window)) { + uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + } + } else { + if (isHideNavigationBar(window)) { + uiFlags ^= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + ^ View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; + } + } + uiFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + window.getDecorView().setSystemUiVisibility(uiFlags); + } + public static int getFakeNavigationBarHeight(Activity activity) { if (activity == null) { return 0; @@ -268,44 +403,6 @@ public static int getNavigationBarHeight(WindowManager windowManager) { } - /** - * 判断系统是否支持导航栏文字及图标颜色变化 - * - * @return true支持导航栏文字颜色变化 - */ - public static boolean isSupportNavigationBarFontChange() { - if (RomUtil.isEMUI() && RomUtil.getEMUIVersion().compareTo("EmotionUI_4.1") > 0) { - return true; - } - if (RomUtil.getMIUIVersionCode() >= 6) { - return true; - } - return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O; - } - - /** - * 判断当前手机是否为全面屏--通过纵横比 - * - * @param context - * @return - */ - public static boolean isFullScreenDevice(Context context) { - if (context == null) { - return false; - } - if (mHasCheckFullScreen) { - return mIsFullScreenDevice; - } - mHasCheckFullScreen = true; - mIsFullScreenDevice = false; - // 低于 API 21的,都不会是全面屏 - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { - return false; - } - mIsFullScreenDevice = getAspectRatio(context) >= mAspectRatio; - return mIsFullScreenDevice; - } - /** * 获取手机纵横比 * @@ -350,28 +447,6 @@ private static float getSmallestWidthDp(Window window) { return Math.min(widthDp, heightDp); } - public static boolean isNavigationAtBottom(Activity activity) { - if (activity == null) { - return false; - } - return isNavigationAtBottom(activity.getWindow()); - } - - /** - * 判断导航栏是否在底部 - * - * @param window - * @return - */ - public static boolean isNavigationAtBottom(Window window) { - if (window == null) { - return false; - } - boolean mInPortrait = (Resources.getSystem().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT); - float mSmallestWidthDp = getSmallestWidthDp(window); - return (mSmallestWidthDp >= 600 || mInPortrait); - } - public static final int NAVIGATION_BAR_TYPE_DEFAULT = 0; public static final int NAVIGATION_BAR_TYPE_MI_UI = 1; diff --git a/widget-core/src/main/java/com/aries/ui/util/StatusBarUtil.java b/widget-core/src/main/java/com/aries/ui/util/StatusBarUtil.java index 9b79259..62d4092 100644 --- a/widget-core/src/main/java/com/aries/ui/util/StatusBarUtil.java +++ b/widget-core/src/main/java/com/aries/ui/util/StatusBarUtil.java @@ -8,6 +8,8 @@ import android.view.Window; import android.view.WindowManager; +import com.aries.ui.helper.navigation.NavigationBarUtil; + import java.lang.reflect.Field; import java.lang.reflect.Method; @@ -20,6 +22,7 @@ * 2、2019-4-11 10:42:27 新增Activity参数相关的Window参数方法 * {@link #setStatusBarDarkMode(Window)} {@link #setStatusBarLightMode(Window)} * 3、2019-7-15 13:13:46 新增OPPO 4.4(含)-6.0(不含) ColorOS 状态栏黑色文字方法{@link #setStatusBarModeForColorOS(Window, boolean)} + * 4、2019-8-1 10:45:32 增加设置全屏方法{@link #setFullScreen(Window, boolean)}{@link #setFullScreen(Activity, boolean)} */ public class StatusBarUtil { @@ -197,9 +200,6 @@ private static boolean setStatusBarModeForColorOS(Window window, boolean darkTex private static boolean setStatusBarModeForAndroidM(Window window, boolean darkText) { boolean result = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - //int systemUi = darkText ? View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR : View.SYSTEM_UI_FLAG_LAYOUT_STABLE; - //systemUi = changeStatusBarModeRetainFlag(window, systemUi); - //window.getDecorView().setSystemUiVisibility(systemUi); window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); int now = window.getDecorView().getSystemUiVisibility(); int systemUi = darkText ? @@ -261,6 +261,12 @@ public static int retainSystemUiFlag(Window window, int out, int type) { return out; } + /** + * 刘海屏控制 + * + * @param window window 对象 + * @param fit true 控制刘海 false 退出控制 + */ public static void fitsNotchScreen(Window window, boolean fit) { if (window == null) { return; @@ -271,4 +277,101 @@ public static void fitsNotchScreen(Window window, boolean fit) { window.setAttributes(lp); } } + + /** + * 刘海屏控制 + * + * @param activity Activity 对象 + * @param fit true 控制刘海 false 退出控制 + */ + public static void fitsNotchScreen(Activity activity, boolean fit) { + fitsNotchScreen(activity.getWindow(), fit); + } + + /** + * 是否隐藏状态栏 + * + * @param activity Activity 对象 + * @return 是否隐藏 + */ + public static boolean isStatusBar(Activity activity) { + if (activity == null) { + return false; + } + return isStatusBar(activity.getWindow()); + } + + /** + * 是否隐藏状态栏 + * + * @param window Window对象 + * @return 是否隐藏 + */ + public static boolean isStatusBar(Window window) { + if (window == null) { + return false; + } + return (window.getDecorView().getSystemUiVisibility() & View.INVISIBLE) + == View.INVISIBLE; + } + + /** + * 隐藏状态栏 + * + * @param activity Activity 对象 + * @param isHide 是否隐藏 + */ + public static void hideStatusBar(Activity activity, boolean isHide) { + if (activity == null) { + return; + } + hideStatusBar(activity.getWindow(), isHide); + } + + /** + * 隐藏状态栏 + * + * @param window Window 对象 + * @param isHide 是否隐藏 + */ + public static void hideStatusBar(Window window, boolean isHide) { + if (window == null) { + return; + } + //防止系统栏隐藏时内容区域大小发生变化 + int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | window.getDecorView().getSystemUiVisibility(); + if (isHide) { + if (!isStatusBar(window)) { + uiFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.INVISIBLE; + } + } else { + if (isStatusBar(window)) { + uiFlags ^= View.INVISIBLE; + } + } + uiFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + window.getDecorView().setSystemUiVisibility(uiFlags); + } + + /** + * 设置全屏效果 + * + * @param window window 对象 + * @param isFull true 全屏 false 退出全屏 + */ + public static void setFullScreen(Window window, boolean isFull) { + hideStatusBar(window, isFull); + NavigationBarUtil.hideNavigationBar(window, isFull); + } + + /** + * 设置全屏效果 + * + * @param activity Activity 对象 + * @param isFull true 全屏 false 退出全屏 + */ + public static void setFullScreen(Activity activity, boolean isFull) { + setFullScreen(activity.getWindow(), isFull); + } } diff --git a/widget-core/src/main/java/com/aries/ui/view/radius/RadiusTextView.java b/widget-core/src/main/java/com/aries/ui/view/radius/RadiusTextView.java index 6d9f2c1..46cdc79 100644 --- a/widget-core/src/main/java/com/aries/ui/view/radius/RadiusTextView.java +++ b/widget-core/src/main/java/com/aries/ui/view/radius/RadiusTextView.java @@ -2,7 +2,6 @@ import android.content.Context; import android.util.AttributeSet; -import android.util.Log; import android.widget.TextView; import com.aries.ui.view.radius.delegate.RadiusTextViewDelegate; @@ -41,7 +40,6 @@ public RadiusTextViewDelegate getDelegate() { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - Log.i("onMeasure", "viewId:" + this); if (delegate != null && delegate.getWidthHeightEqualEnable() && getWidth() > 0 && getHeight() > 0) { int max = Math.max(getWidth(), getHeight()); int measureSpec = MeasureSpec.makeMeasureSpec(max, MeasureSpec.EXACTLY); @@ -59,7 +57,6 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { - Log.i("onLayout", "viewId:" + this); super.onLayout(changed, left, top, right, bottom); if (delegate != null) { if (delegate.getRadiusHalfHeightEnable()) { diff --git a/widget-core/src/main/java/com/aries/ui/view/title/TitleBarView.java b/widget-core/src/main/java/com/aries/ui/view/title/TitleBarView.java index 1e4c457..0bd4518 100644 --- a/widget-core/src/main/java/com/aries/ui/view/title/TitleBarView.java +++ b/widget-core/src/main/java/com/aries/ui/view/title/TitleBarView.java @@ -575,11 +575,6 @@ protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { mStatusBarHeight = getNeedStatusBarHeight(); //测量子控件宽高 -// measureChild(mLLayoutLeft, widthMeasureSpec, heightMeasureSpec); -// measureChild(mLLayoutRight, widthMeasureSpec, heightMeasureSpec); -// measureChild(mLLayoutCenter, widthMeasureSpec, heightMeasureSpec); -// measureChild(mVDivider, widthMeasureSpec, heightMeasureSpec); -// measureChild(mVStatus, widthMeasureSpec, heightMeasureSpec); measureChildren(widthMeasureSpec, heightMeasureSpec); //重新测量宽高--增加状态栏及下划线的高度开始 //父容器为ConstraintLayout约束布局特殊处理