动态隐藏和显示导航栏 (MTK)

1. 添加对应的字段

./vendor/mediatek/proprietary/frameworks/base/settingsprovider/java/com/mediatek/provider/MtkSettingsExt.java

         public static final String DATA_SERVICE_ENABLED = "data_service_enabled";
-
+        
+        /**
+        * control Whether to hide or display navigation bar
+        *
+        *
+        * @hide
+        */
+        public static final String CONTROL_NAVIGATIONBAR_HIDE_MODE = "control_navigationbar_hide_mode";
+        
+       /**
+        * Whether to hide or display navigation bar
+        *
+        *
+        * @hide
+        */
+        public static final String NAVIGATIONBAR_HIDE_MODE = "navigationbar_hide_mode";
         // At one time in Global, then in Secure
 

2. 完成相关数据的初始化:

./vendor/mediatek/proprietary/packages/apps/SettingsProvider/src/com/mediatek/providers/utils/ProvidersUtils.java

 res/values/defaults.xml                                | 3 +++
 res/values/mtk_defaults.xml                            | 2 ++
 src/com/android/providers/settings/DatabaseHelper.java | 2 ++
 src/com/mediatek/providers/utils/ProvidersUtils.java   | 6 ++++++
 4 files changed, 13 insertions(+)

diff --git a/res/values/defaults.xml b/res/values/defaults.xml
index 68c210d..127ca42 100644
--- a/res/values/defaults.xml
+++ b/res/values/defaults.xml
@@ -217,4 +217,7 @@
 
     <!-- Default for Settings.System.VIBRATE_WHEN_RINGING -->
     <bool name="def_vibrate_when_ringing">false</bool>
+
+    <!-- default setting for Settings.Global.POLICY_CONTROL-->
+    <string name="def_policy_control">null</string>
 </resources>
diff --git a/res/values/mtk_defaults.xml b/res/values/mtk_defaults.xml
index 0e1d710..cb63a7e 100644
--- a/res/values/mtk_defaults.xml
+++ b/res/values/mtk_defaults.xml
@@ -19,4 +19,6 @@
     <integer name="def_show_fisrtcrash_dlg">1</integer>
     <!-- M: ALPS04121437 Default for Settings.Global.PRIVATE_DNS_DEFAULT_MODE -->
     <string name="def_private_dns_default_mode">off</string>
+    <integer name="control_navigationbar_hide_mode">1</integer>
+    <integer name="navigationbar_hide_mode">0</integer>
 </resources>
diff --git a/src/com/android/providers/settings/DatabaseHelper.java b/src/com/android/providers/settings/DatabaseHelper.java
index 491150d..bec91ce 100644
--- a/src/com/android/providers/settings/DatabaseHelper.java
+++ b/src/com/android/providers/settings/DatabaseHelper.java
@@ -2610,6 +2610,8 @@ class DatabaseHelper extends SQLiteOpenHelper {
                     R.string.def_car_undock_sound);
             loadStringSetting(stmt, Settings.Global.CHARGING_STARTED_SOUND,
                     R.string.def_wireless_charging_started_sound);
+            loadStringSetting(stmt, Settings.Global.POLICY_CONTROL,
+                    R.string.def_policy_control);
 
             loadIntegerSetting(stmt, Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
                     R.integer.def_dock_audio_media_enabled);
diff --git a/src/com/mediatek/providers/utils/ProvidersUtils.java b/src/com/mediatek/providers/utils/ProvidersUtils.java
index a2f3a7c..c770d0b 100644
--- a/src/com/mediatek/providers/utils/ProvidersUtils.java
+++ b/src/com/mediatek/providers/utils/ProvidersUtils.java
@@ -50,6 +50,12 @@ public class ProvidersUtils {
                 MtkSettingsExt.Global.TELEPHONY_MISC_FEATURE_CONFIG,
                 getIntegerValue(MtkSettingsExt.Global.TELEPHONY_MISC_FEATURE_CONFIG,
                         R.integer.def_telephony_misc_feature_config));
+        loadSetting(stmt, MtkSettingsExt.Global.CONTROL_NAVIGATIONBAR_HIDE_MODE,
+                getIntegerValue(MtkSettingsExt.Global.CONTROL_NAVIGATIONBAR_HIDE_MODE,
+                R.integer.control_navigationbar_hide_mode));
+        loadSetting(stmt, MtkSettingsExt.Global.NAVIGATIONBAR_HIDE_MODE,
+                getIntegerValue(MtkSettingsExt.Global.NAVIGATIONBAR_HIDE_MODE,
+                R.integer.navigationbar_hide_mode));
         loadBooleanSetting(stmt, MtkSettingsExt.Global.AUTO_TIME_GPS, R.bool.def_auto_time_gps);

3. 系统UI 的控制 

diff --git a/src/com/android/systemui/statusbar/phone/StatusBar.java b/src/com/android/systemui/statusbar/phone/StatusBar.java
index 6331910..00e0424 100644
--- a/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -261,6 +261,8 @@ import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
+import static com.mediatek.provider.MtkSettingsExt.Global.NAVIGATIONBAR_HIDE_MODE;
+import static com.mediatek.provider.MtkSettingsExt.Global.CONTROL_NAVIGATIONBAR_HIDE_MODE;
 public class StatusBar extends SystemUI implements DemoMode,
         DragDownHelper.DragDownCallback, ActivityStarter, OnUnlockMethodChangedListener,
         OnHeadsUpChangedListener, CommandQueue.Callbacks, ZenModeController.Callback,
@@ -315,7 +317,7 @@ public class StatusBar extends SystemUI implements DemoMode,
 
     private static final int STATUS_OR_NAV_TRANSIENT =
             View.STATUS_BAR_TRANSIENT | View.NAVIGATION_BAR_TRANSIENT;
-    private static final long AUTOHIDE_TIMEOUT_MS = 2250;
+    private static final long AUTOHIDE_TIMEOUT_MS = 10000;
 
     /**
      * The delay to reset the hint text when the hint animation is finished running.
@@ -349,6 +351,13 @@ public class StatusBar extends SystemUI implements DemoMode,
     private OpSystemUICustomizationFactoryBase mSystemUIFactoryBase = null;
     ///@}
 
+    public static final String HIDE_NAVIGATION_BAR = "android.intent.action.HIDE_NAVIGATION_BAR";
+    public static final String SHOW_NAVIGATION_BAR = "android.intent.action.SHOW_NAVIGATION_BAR";
+    private final String NAVIGATIONBAR_HIDE_KEY = NAVIGATIONBAR_HIDE_MODE;
+    private final String CONTROL_NAVIGATIONBAR_HIDE_KEY = CONTROL_NAVIGATIONBAR_HIDE_MODE;
+    public static final String CLOSE_NAVIGATION_BAR= "android.intent.action.CLOSE_NAVIGATION_BAR";
+    public static final String OPEN_NAVIGATION_BAR= "android.intent.action.OPEN_NAVIGATION_BAR";
+    
     static {
         boolean onlyCoreApps;
         try {
@@ -466,6 +475,7 @@ public class StatusBar extends SystemUI implements DemoMode,
     private ScreenPinningRequest mScreenPinningRequest;
 
     private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
+    private final String AUTO_HIDE_NAV = "immersive.full=*";
 
     // ensure quick settings is disabled until the current user makes it through the setup wizard
     @VisibleForTesting
@@ -801,6 +811,13 @@ public class StatusBar extends SystemUI implements DemoMode,
         Dependency.get(ActivityStarterDelegate.class).setActivityStarterImpl(this);
 
         Dependency.get(ConfigurationController.class).addCallback(this);
+        
+        int controlnavigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                CONTROL_NAVIGATIONBAR_HIDE_KEY, 0);
+        if (controlnavigationMode != 1) {
+            //mHandler.postDelayed(() ->
+               // hideStatusbar(), 1000);
+        }
     }
 
     // ================================================================================
@@ -902,6 +919,20 @@ public class StatusBar extends SystemUI implements DemoMode,
         } catch (RemoteException ex) {
             // no window manager? good luck with that
         }
+        
+        int controlnavigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                CONTROL_NAVIGATIONBAR_HIDE_KEY, 0);
+
+        if (controlnavigationMode != 1) {
+            hideNavigationbar();
+        } else {
+        int navigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                NAVIGATIONBAR_HIDE_KEY, 0);
+            if (navigationMode != 1) {
+            displayNavigationbar();
+        }
+        }
+        
         mScreenPinningNotify = new ScreenPinningNotify(mContext);
         mStackScroller.setLongPressListener(mEntryManager.getNotificationLongClicker());
         mStackScroller.setStatusBar(this);
@@ -1083,7 +1114,15 @@ public class StatusBar extends SystemUI implements DemoMode,
         demoFilter.addAction(ACTION_DEMO);
         context.registerReceiverAsUser(mDemoReceiver, UserHandle.ALL, demoFilter,
                 android.Manifest.permission.DUMP, null);
-
+        
+        IntentFilter controlnavBarFilter = new IntentFilter();
+        controlnavBarFilter.addAction(OPEN_NAVIGATION_BAR);
+        controlnavBarFilter.addAction(CLOSE_NAVIGATION_BAR);
+        context.registerReceiverAsUser(mConNavBarReceiver, UserHandle.ALL, controlnavBarFilter, null, null);
+        IntentFilter navigationBarFilter = new IntentFilter();
+        navigationBarFilter.addAction(SHOW_NAVIGATION_BAR);
+        navigationBarFilter.addAction(HIDE_NAVIGATION_BAR);
+        context.registerReceiverAsUser(mNavigationBarReceiver, UserHandle.ALL, navigationBarFilter, null, null);
         // listen for USER_SETUP_COMPLETE setting (per-user)
         mDeviceProvisionedController.addCallback(mUserSetupObserver);
         mUserSetupObserver.onUserSetupChanged();
@@ -1370,6 +1409,12 @@ public class StatusBar extends SystemUI implements DemoMode,
     }
 
     public int getStatusBarHeight() {
+        int controlnavigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                CONTROL_NAVIGATIONBAR_HIDE_KEY, 0);
+        if (controlnavigationMode != 1)
+            mNaturalBarHeight = 0;
+        else
+            mNaturalBarHeight =-1;
         if (mNaturalBarHeight < 0) {
             final Resources res = mContext.getResources();
             mNaturalBarHeight =
@@ -2498,6 +2543,22 @@ public class StatusBar extends SystemUI implements DemoMode,
                 setInteracting(StatusBarManager.WINDOW_STATUS_BAR, true);
             }
         }
+        
+        int controlnavigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                CONTROL_NAVIGATIONBAR_HIDE_KEY, 1);
+
+        if (controlnavigationMode == 1) {
+            int navigationMode = Settings.Secure.getInt(mContext.getContentResolver(),
+                NAVIGATIONBAR_HIDE_KEY, 0);
+            if (navigationMode != 1) {
+                displayNavigationbar();
+            } else {
+                displayNavigationbar();
+                mHandler.postDelayed(() ->
+                hideNavigationbar(), 10000);
+            }
+        }
+
         return false;
     }
 
@@ -3089,6 +3150,30 @@ public class StatusBar extends SystemUI implements DemoMode,
         }, cancelAction, afterKeyguardGone);
     }
 
+    private BroadcastReceiver mConNavBarReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (DEBUG) Log.v(TAG, "mConNavBarReceiver: " + intent);
+            String action = intent.getAction();
+            if (action.equals(OPEN_NAVIGATION_BAR)) {
+                displayNavigationbar();
+            } else if (action.equals(CLOSE_NAVIGATION_BAR)) {
+                hideNavigationbar();
+            }
+        }
+    };
+    private BroadcastReceiver mNavigationBarReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (DEBUG) Log.v(TAG, "mNavigationBarReceiver: " + intent);
+            String action = intent.getAction();
+            if (action.equals(SHOW_NAVIGATION_BAR)) {
+                setNavbarautodisplay();
+            } else if (action.equals(HIDE_NAVIGATION_BAR)) {
+                setNavbarautohide();
+            }
+        }
+    };
     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -5736,7 +5821,36 @@ public class StatusBar extends SystemUI implements DemoMode,
         }
     }
     /// M: Support "Operator plugin - Customize Carrier Label for PLMN". @}
+    
+    public void displayNavigationbar() {
+        if (mNavigationBarView == null) {
+            mNavigationBarView = NavigationBarFragment.create(mContext, (tag, fragment) -> {
+                mNavigationBar = (NavigationBarFragment) fragment;
+                if (mLightBarController != null) {
+                    mNavigationBar.setLightBarController(mLightBarController);
+                }
+                mNavigationBar.setCurrentSysuiVisibility(mSystemUiVisibility);
+            });
 
+        }
+    }
+
+    public void hideNavigationbar() {
+        if (mNavigationBarView != null) {
+            mWindowManager.removeViewImmediate(mNavigationBarView);
+            mNavigationBarView = null;
+        }
+    }
+    public void setNavbarautodisplay() {
+        mNavigationBar.setCurrentSysuiVisibility(mSystemUiVisibility);
+    }
+
+    public void setNavbarautohide() {
+        mHandler.postDelayed(() ->
+                Settings.Global.putString(mContext.getContentResolver(),
+                Settings.Global.POLICY_CONTROL,AUTO_HIDE_NAV), 10000);
+
+    }
     // M: Add for MTK FaceUnlock to get FaceUnlockController to use.
     public FaceUnlockController getFaceUnlockController() {
         return mFaceUnlockController;

4  设置菜单添加

a/res/values-zh-rCN/strings.xml
+++ b/res/values-zh-rCN/strings.xml
@@ -1063,6 +1063,8 @@
     <string name="search_settings" msgid="1910951467596035063">"搜索"</string>
     <string name="display_settings" msgid="7965901687241669598">"显示"</string>
     <string name="accelerometer_title" msgid="7854608399547349157">"自动旋转屏幕"</string>
+    <string name="control_hide_navigatorbar_title" msgid="9834608399547349257">"导航栏"</string>
+    <string name="hide_navigatorbar_title" msgid="9834608399547349257">"自动隐藏导航栏"</string>
     <string name="color_mode_title" msgid="9186249332902370471">"颜色"</string>
     <string name="color_mode_option_natural" msgid="5013837483986772758">"自然色"</string>
     <string name="color_mode_option_boosted" msgid="8588223970257287524">"效果增强"</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 1e6aad4..def3ea6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2487,6 +2487,8 @@
     <string name="display_settings">Display</string>
     <!-- Sound & display settings screen, accelerometer-based rotation check box label -->
     <string name="accelerometer_title">Auto-rotate screen</string>
+    <string name="control_hide_navigatorbar_title">Navigator bar</string>
+    <string name="hide_navigatorbar_title">Auto Hide navigator bar</string>
     <!-- Display settings screen, Color mode settings title [CHAR LIMIT=30] -->
     <string name="color_mode_title">Colors</string>
     <!-- Display settings screen, Color mode option for "natural(sRGB) color"  [CHAR LIMIT=45] -->
diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml
index df3169d..a1e837e 100644
--- a/res/xml/display_settings.xml
+++ b/res/xml/display_settings.xml
@@ -78,6 +78,14 @@
         android:title="@string/accelerometer_title"
         settings:keywords="@string/keywords_auto_rotate"
         settings:controller="com.android.settings.display.AutoRotatePreferenceController"/>
+    
+    <SwitchPreference
+        android:key="control_hide_navigatorbar"
+        android:title="@string/control_hide_navigatorbar_title" />   
+        
+    <SwitchPreference
+        android:key="hide_navigatorbar"
+        android:title="@string/hide_navigatorbar_title" />
 
     <Preference
         android:key="color_mode"
diff --git a/src/com/android/settings/DisplaySettings.java b/src/com/android/settings/DisplaySettings.java
index 42bfc6f..fdfab15 100644
--- a/src/com/android/settings/DisplaySettings.java
+++ b/src/com/android/settings/DisplaySettings.java
@@ -47,6 +47,9 @@ import com.mediatek.settings.display.MiraVisionPreferenceController;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.android.settings.display.HideNavigatorBarPreferenceController;
+import com.android.settings.display.ControlHideNavigatorBarPreferenceController;
+
 public class DisplaySettings extends DashboardFragment {
     private static final String TAG = "DisplaySettings";
 
@@ -111,6 +114,9 @@ public class DisplaySettings extends DashboardFragment {
         /// M: add for HDMI settings @{
         controllers.add(new HdmiPreferenceController(context));
         /// @}
+        //for NavigatorBar 
+        controllers.add(new ControlHideNavigatorBarPreferenceController(context));        
+        controllers.add(new HideNavigatorBarPreferenceController(context));

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值