首页 > 代码库 > KK上全屏界面如何实现禁止状态栏下拉?

KK上全屏界面如何实现禁止状态栏下拉?

KK上全屏界面如何实现禁止状态栏下拉?
 
[SOLUTION]
Google从KK开始增加了状态栏透明以及全屏 界面有通知可以下拉状态栏的设计,而这个设计出现的隐患是设置了FULL_SCREEN的界面是无法禁止状态栏下拉的,这样对一些工程测试app可能会造 成一定的影响,但是以google默认的设计,应用端无法修改此设计来满足自己的需求。
MTK 内部已经开发提供新的接口来实现全屏界面禁止下拉状态栏,如果贵司的代码还没有这部分逻辑,请参考如下:
1. frameworks\base\core\java\android\view\View.java
    public static final int SYSTEM_UI_FLAG_IMMERSIVE_STICKY = 0x00001000;
+    /**
+     * @hide
+     *
+     * NOTE: Flag for {@link #setSystemUiVisibility(int)}: It help user to disable transient
+     * status bar triggered by gesture
+     */
+    public static final int SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED = 0x00002000;

2. frameworks\base\policy\src\com\android\internal\policy\impl\PhoneWindowManager.java
  // monitor for system gestures
        mSystemGestures = new SystemGesturesPointerEventListener(context,
                new SystemGesturesPointerEventListener.Callbacks() {
                    @Override
                    public void onSwipeFromTop() {
+                        if (isGestureIsolated())
+                            return;
                        if (mStatusBar != null) {
                            requestTransientBars(mStatusBar);
                        }
                    }
                    @Override
                    public void onSwipeFromBottom() {
+                        if (isGestureIsolated())
+                            return;
                        if (mNavigationBar != null && mNavigationBarOnBottom) {
                            requestTransientBars(mNavigationBar);
                        }
                    }
                    @Override
                    public void onSwipeFromRight() {
+                        if (isGestureIsolated())
+                            return;                   
                        if (mNavigationBar != null && !mNavigationBarOnBottom) {
                            requestTransientBars(mNavigationBar);
                        }
                    }
                    @Override
                    public void onDebug() {
                        // no-op
                    }
+                    private boolean isGestureIsolated() {
+                        WindowState win = mFocusedWindow != null ? mFocusedWindow : mTopFullscreenOpaqueWindowState;
+                        if (win != null && (win.getSystemUiVisibility() & View.SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED) != 0)
+                            return true;
+                        else
+                            return false;
+                    }
                });
3. 請在修改完framework后,將測試app用setSystemUiVisibility的API加上SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED的flag
 
private View mView;
mView = getWindow().getDecorView();
mView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_IMMERSIVE_GESTURE_ISOLATED);