android4.4上全屏界面实现禁止状态栏下拉

Posted wzzkaifa

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android4.4上全屏界面实现禁止状态栏下拉相关的知识,希望对你有一定的参考价值。

附上我改动的方法:PhoneWindowManager.java里面的改动
--- a/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/frameworks/base/policy/src/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -2863,7 +2863,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
     @Override
     public int adjustSystemUiVisibilityLw(int visibility) {
-        mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
+       if(Settings.System.getInt(mContext.getContentResolver(),"factorytest.touch.mode",0) == 0){
+                mStatusBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
+       }
         mNavigationBarController.adjustSystemUiVisibilityLw(mLastSystemUiFlags, visibility);
         // Reset any bits in mForceClearingStatusBarVisibility that
Acitvity里面使用例如以下方式:
--- a/huaqin/source/packages/FactoryKitTest/src/com/android/huaqin/factory/TestTouchPanelLine2.java
+++ b/huaqin/source/packages/FactoryKitTest/src/com/android/huaqin/factory/TestTouchPanelLine2.java
@@ -32,6 +32,8 @@ import android.view.WindowManager;
 import java.util.ArrayList;
 import java.util.List;
+import android.provider.Settings;
+import android.app.StatusBarManager;
 public class TestTouchPanelLine2 extends Activity {
        private static final String TAG = "TestTouchPanelLine";
@@ -54,6 +56,7 @@ public class TestTouchPanelLine2 extends Activity {
        private static final int MSG_TEST_PANEL_NEXT_ITEM = 100;
        private static final int MSG_TEST_PANEL_START = 101;
        private static final int MSG_TEST_PANEL_STOP = 102;
+       private StatusBarManager mStatusBarManager;
        private Handler mInHandler = new Handler() {
                @Override
@@ -94,6 +97,12 @@ public class TestTouchPanelLine2 extends Activity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
@@ -141,8 +150,22 @@ public class TestTouchPanelLine2 extends Activity {
                                .obtainMessage(FactoryTestMessage.MSG_OPEN_UI_OK);
                msg.arg1 = (int) ID;
                mOutHandler.sendMessage(msg);
+               mStatusBarManager = (StatusBarManager) this.getSystemService(Context.STATUS_BAR_SERVICE);
+               int state= StatusBarManager.DISABLE_EXPAND;
+                   state |= StatusBarManager.DISABLE_NOTIFICATION_ICONS;
+                   state |=  StatusBarManager.DISABLE_SYSTEM_INFO;
+               mStatusBarManager.disable(state);
        }
+           @Override
+           protected void onPause() {
+               int state =  StatusBarManager.DISABLE_NONE;
+               mStatusBarManager.disable(state);
+               super.onPause();
+           }
        @Override
        public boolean onKeyDown(int keyCode, KeyEvent event) {
                // 是否触发按键为back键
 
下面是从MTK Online 上面找到的解决方式。保留备用。
Google从KK開始添加了状态栏透明以及全屏界面有通知能够下拉状态栏的设计,而这个设计出现的隐患是设置了FULL_SCREEN的界面是无法禁止状态栏下拉的。这样对一些project測试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








以上是关于android4.4上全屏界面实现禁止状态栏下拉的主要内容,如果未能解决你的问题,请参考以下文章

Android UI体验之全屏沉浸式透明状态栏效果

Android 系统状态栏一体化

android 透明状态栏是怎样实现的

如何在视图控制器中的标签栏和导航栏上全屏显示弹出视图?

android——禁止状态栏下拉

如何让导航栏在一行上全屏显示以及设置百分比让其居中显示