diff --git a/selector/src/main/java/com/luck/picture/lib/PictureSelectorPreviewFragment.java b/selector/src/main/java/com/luck/picture/lib/PictureSelectorPreviewFragment.java index 395a5b8e5..dcc6f03ce 100644 --- a/selector/src/main/java/com/luck/picture/lib/PictureSelectorPreviewFragment.java +++ b/selector/src/main/java/com/luck/picture/lib/PictureSelectorPreviewFragment.java @@ -162,6 +162,7 @@ public class PictureSelectorPreviewFragment extends PictureCommonFragment { protected List mAnimViews = new ArrayList<>(); private boolean isPause = false; + private boolean isEnterWindowFullScreen = false; public static PictureSelectorPreviewFragment newInstance() { PictureSelectorPreviewFragment fragment = new PictureSelectorPreviewFragment(); @@ -745,6 +746,7 @@ public void onBackPressed() { onBackCurrentFragment(); } } + exitWindowFullScreen(); } }); titleBar.setTitle((curPosition + 1) + "/" + totalNum); @@ -1294,6 +1296,7 @@ private void onKeyDownBackToMin() { } else { onBackCurrentFragment(); } + exitWindowFullScreen(); } } @@ -1325,20 +1328,10 @@ private void previewFullScreenMode() { @Override public void onAnimationEnd(Animator animation) { isAnimationStart = false; - if (SdkVersionUtils.isP() && isAdded()) { - Window window = requireActivity().getWindow(); - WindowManager.LayoutParams lp = window.getAttributes(); - if (isAnimInit) { - lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; - lp.layoutInDisplayCutoutMode = - WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - window.setAttributes(lp); - window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - } else { - lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); - window.setAttributes(lp); - window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); - } + if (isAnimInit) { + enterWindowFullScreen(); + } else { + exitWindowFullScreen(); } } }); @@ -1350,6 +1343,30 @@ public void onAnimationEnd(Animator animation) { } } + private void enterWindowFullScreen() { + if (SdkVersionUtils.isP() && isAdded() && !isEnterWindowFullScreen) { + isEnterWindowFullScreen = true; + Window window = requireActivity().getWindow(); + WindowManager.LayoutParams lp = window.getAttributes(); + lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; + lp.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + window.setAttributes(lp); + window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + } + } + + private void exitWindowFullScreen() { + if (SdkVersionUtils.isP() && isAdded() && isEnterWindowFullScreen) { + isEnterWindowFullScreen = false; + Window window = requireActivity().getWindow(); + WindowManager.LayoutParams lp = window.getAttributes(); + lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); + window.setAttributes(lp); + window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + } + } + /** * 全屏模式 */