|
@@ -1,6 +1,7 @@
|
|
|
package com.cooleshow.base.widgets;
|
|
|
|
|
|
import android.content.res.Configuration;
|
|
|
+import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
@@ -25,28 +26,28 @@ import com.cooleshow.base.R;
|
|
|
*/
|
|
|
public abstract class BaseDialog extends DialogFragment {
|
|
|
|
|
|
- private static final String MARGIN = "margin";
|
|
|
- private static final String WIDTH = "width";
|
|
|
- private static final String HEIGHT = "height";
|
|
|
- private static final String DIM = "dim_amount";
|
|
|
+ private static final String MARGIN = "margin";
|
|
|
+ private static final String WIDTH = "width";
|
|
|
+ private static final String HEIGHT = "height";
|
|
|
+ private static final String DIM = "dim_amount";
|
|
|
private static final String GRAVITY = "gravity";
|
|
|
- private static final String CANCEL = "out_cancel";
|
|
|
- private static final String THEME = "theme";
|
|
|
- private static final String ANIM = "anim_style";
|
|
|
- private static final String LAYOUT = "layout_id";
|
|
|
-
|
|
|
- private int margin;//左右边距
|
|
|
- private int width;//宽度
|
|
|
- private int height;//高度
|
|
|
- private float dimAmount = 0.5f;//灰度深浅
|
|
|
- private int gravity = Gravity.CENTER;//显示的位置
|
|
|
- private boolean outCancel = true;//是否点击外部取消
|
|
|
+ private static final String CANCEL = "out_cancel";
|
|
|
+ private static final String THEME = "theme";
|
|
|
+ private static final String ANIM = "anim_style";
|
|
|
+ private static final String LAYOUT = "layout_id";
|
|
|
+
|
|
|
+ private int margin;//左右边距
|
|
|
+ private int width;//宽度
|
|
|
+ private int height;//高度
|
|
|
+ private float dimAmount = 0.5f;//灰度深浅
|
|
|
+ private int gravity = Gravity.CENTER;//显示的位置
|
|
|
+ private boolean outCancel = true;//是否点击外部取消
|
|
|
@StyleRes
|
|
|
- protected int theme = R.style.BaseDialog; // dialog主题
|
|
|
+ protected int theme = R.style.BaseDialog; // dialog主题
|
|
|
@StyleRes
|
|
|
- private int animStyle;
|
|
|
+ private int animStyle;
|
|
|
@LayoutRes
|
|
|
- protected int layoutId;
|
|
|
+ protected int layoutId;
|
|
|
|
|
|
public abstract int intLayoutId();
|
|
|
|
|
@@ -60,7 +61,8 @@ public abstract class BaseDialog extends DialogFragment {
|
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
setStyle(DialogFragment.STYLE_NO_TITLE, initTheme());
|
|
|
-
|
|
|
+ hideNavigationBar();
|
|
|
+ adjustFullScreen();
|
|
|
//恢复保存的数据
|
|
|
if (savedInstanceState != null) {
|
|
|
margin = savedInstanceState.getInt(MARGIN);
|
|
@@ -75,6 +77,41 @@ public abstract class BaseDialog extends DialogFragment {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private void hideNavigationBar() {
|
|
|
+ int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
|
|
+ | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
|
|
+ | View.SYSTEM_UI_FLAG_IMMERSIVE
|
|
|
+ | View.SYSTEM_UI_FLAG_FULLSCREEN;
|
|
|
+ if (getDialog() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Window window = getDialog().getWindow();
|
|
|
+ if (window == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ window.getDecorView().setSystemUiVisibility(uiOptions);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void adjustFullScreen() {
|
|
|
+ if (getDialog() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Window window = getDialog().getWindow();
|
|
|
+ if (window == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
|
|
+ WindowManager.LayoutParams lp = window.getAttributes();
|
|
|
+ lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
|
|
|
+ window.setAttributes(lp);
|
|
|
+ final View decorView = window.getDecorView();
|
|
|
+ decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
+ | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Nullable
|
|
|
@Override
|
|
|
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
|
@@ -93,6 +130,7 @@ public abstract class BaseDialog extends DialogFragment {
|
|
|
|
|
|
/**
|
|
|
* 屏幕旋转等导致DialogFragment销毁后重建时保存数据
|
|
|
+ *
|
|
|
* @param outState
|
|
|
*/
|
|
|
@Override
|