Android10.0 导航栏和状态栏动态控制合集

文件清单

	add   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/SharedConfig.java
	modified:   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java
	modified:   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java
	modified:   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
	modified:   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
	modified:   vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

一、动态控制导航栏虚拟按键(Home/RecentAPP/Back)

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/SharedConfig.java

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.phone;

import android.util.Log;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

class SharedConfig {
    
    private SharedConfig(){};
    private static SharedConfig instance;
    private static final String CONFIG_FILE_NAME =  "CONFIG";
    private SharedPreferences sharedPreferences;
    private Editor editor;

    public static final String KEY_PANEL_BAR = "KEY_PANEL_BAR";
    public static final String KEY_PANEL_GONE = "KEY_PANEL_GONE";
    public static final String KEY_NAVIGATION_BAR = "KEY_NAVIGATION_BAR";
    public static final String KEY_NAVIGATION_BUTTON = "KEY_NAVIGATION_BUTTON";
    
    private SharedConfig(Context context) {
        sharedPreferences = context.getSharedPreferences(CONFIG_FILE_NAME, Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();
    }

    public static SharedConfig getInstance(Context context) {
		if (instance == null) {
			instance = new SharedConfig(context);
		}
		return instance;
	}

	public boolean writeData(String key, boolean value) {
		Log.e("systemui", "put   key=" + key + "   value="+value);
		boolean result = false;
		editor.putBoolean(key, value);
		result = editor.commit();
		return result;
	}

	public boolean readBoolean(String key, boolean def) {
		boolean result = sharedPreferences.getBoolean(key, def);
		Log.e("systemui", "get   key=" + key + "   value="+result);
		return result;
	}

	public boolean writeData(String key, String value) {
		Log.e("systemui", "put   key=" + key + "   value="+value);
		boolean result = false;
		editor.putString(key, value);
		result = editor.commit();
		return result;
	}

	public String readString(String key, String def) {
		String result = sharedPreferences.getString(key, def);
		Log.e("systemui", "get   key=" + key + "   value="+result);
		return result;
	}
}

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

@@ -1038,6 +1060,11 @@ public class StatusBar extends SystemUI implements DemoMode,
         filter.addAction(Intent.ACTION_SCREEN_OFF);
         filter.addAction(DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG);
+        // add for handle navigationbar button
+        filter.addAction(OP_BUTTON);
         context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);

+    private static final String OP_BUTTON = "cc.intent.systemui.SHOW_NAVIGATION_BUTTON";

     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -2637,6 +2670,56 @@ public class StatusBar extends SystemUI implements DemoMode,
             }
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
+            }else if (OP_BUTTON.equals(action)) {
+                if(intent.hasExtra("show_navigation_button")){
+                    String buttonStr = intent.getStringExtra("show_navigation_button");
+                    SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BUTTON, buttonStr);
+                    Log.e("StatusBar", "OP_BUTTON: " + buttonStr);
+                    NavigationBarFragment mNavigationBar = mNavigationBarController.getDefaultNavigationBarFragment();
+                    if (mNavigationBar != null) mNavigationBar.notifyNavigationBarScreenOn();
+                }else{
+                    Log.w("StatusBar","didn't contain show_navigation_button key");
+                }
             }

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java

@@ -212,7 +212,8 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback
                 buttonDispatcher = mNavigationBarView.getHomeHandle();
             }
             if (buttonDispatcher != null) {
-                buttonDispatcher.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
+                       //annotaion don't change backButton visiblity
+                //buttonDispatcher.setVisibility(alpha > 0 ? View.VISIBLE : View.INVISIBLE);
                 buttonDispatcher.setAlpha(alpha, animate);
             }
         }
 
-    private void notifyNavigationBarScreenOn() {
-        mNavigationBarView.updateNavButtonIcons();
+    //change private to public
+    public void notifyNavigationBarScreenOn() {
+        if (mNavigationBarView != null) {
+            mNavigationBarView.updateNavButtonIcons();
+        }
     }

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java

@@ -647,6 +647,18 @@ public class NavigationBarView extends FrameLayout implements
         getBackButton().setVisibility(disableBack      ? View.INVISIBLE : View.VISIBLE);
         getHomeButton().setVisibility(disableHome      ? View.INVISIBLE : View.VISIBLE);
         getRecentsButton().setVisibility(disableRecent ? View.INVISIBLE : View.VISIBLE);
+
+        invalidButtonVisibility();
+    }
+       
+       public void invalidButtonVisibility(){
+        //20191211  add recent KeyButton  visibility  invisible
+        String buttonStr = SharedConfig.getInstance(mContext).readString(SharedConfig.KEY_NAVIGATION_BUTTON,
+         "b_h_r");
+        getBackButton().setVisibility(buttonStr.contains("b") ? View.VISIBLE : View.INVISIBLE);  
+        getHomeButton().setVisibility(buttonStr.contains("h") ? View.VISIBLE : View.INVISIBLE);  
+        getRecentsButton().setVisibility(buttonStr.contains("r") ? View.VISIBLE : View.INVISIBLE);
+        //20191211  add recent KeyButton  visibility  invisible
     }


二、动态控制 NavigationBar(显示/隐藏)

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/NavigationBarController.java

@@ -155,6 +155,7 @@ public class NavigationBarController implements Callbacks {
             navBar.setAutoHideController(autoHideController);
             navBar.restoreSystemUiVisibilityState();
             mNavigationBars.append(displayId, navBar);
+            mDisplayId = displayId;
 
             if (result != null) {
                 navBar.setImeWindowStatus(display.getDisplayId(), result.mImeToken,
         });
     }
 
+    //add
+    private int mDisplayId;
+    public void removeNavigationBarView(){
+        removeNavigationBar(mDisplayId);
+    }
+
     private void removeNavigationBar(int displayId) {


vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

@@ -623,6 +624,8 @@ public class StatusBar extends SystemUI implements DemoMode,
             AppOpsManager.OP_COARSE_LOCATION,
             AppOpsManager.OP_FINE_LOCATION};
 
+    RegisterStatusBarResult result = null;
+

         mCommandQueue.addCallback(this);
 
-        RegisterStatusBarResult result = null;
+        /*RegisterStatusBarResult result = null;*/
         try {
             result = mBarService.registerStatusBar(mCommandQueue);
         } catch (RemoteException ex) {
@@ -802,6 +805,14 @@ public class StatusBar extends SystemUI implements DemoMode,
         mStatusBarWindow.setService(this);
         mStatusBarWindow.setOnTouchListener(getStatusBarWindowTouchListener());
 
+        //add ,whether to show status bar[S]
+        boolean showStatusBar = SharedConfig.getInstance(mContext).readBoolean(SharedConfig.KEY_PANEL_GONE, true);
+        Log.v(TAG, "makeStatusBarView showStatusBar=" + showStatusBar);
+        if(mStatusBarWindow!=null)
+            mStatusBarWindow.setVisibility(showStatusBar ? View.VISIBLE : View.GONE);
+        //add ,whether to show status bar[E]
+
+
         putComponent(HeadsUpManager.class, mHeadsUpManager);
 
-        createNavigationBar(result);
+        try {
+            boolean showNav_Temp = SharedConfig.getInstance(mContext).readBoolean(SharedConfig.KEY_NAVIGATION_BAR, true);
+            
+            if (DEBUG) Log.v(TAG, "hasNavigationBar=" + showNav_Temp);
+            if (showNav_Temp) {
+                 createNavigationBar(result);
+            }
+        } catch (Exception ex) {
+            // no window manager? good luck with that
+        }
 
         if (ENABLE_LOCKSCREEN_WALLPAPER) {


+        filter.addAction(OP_NAVIGATION);
         context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
 
         IntentFilter demoFilter = new IntentFilter();

+    private static final String OP_NAVIGATION = "cc.intent.systemui.WHETHER_SHOW_NAVIGATION";
  
  	 private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
             }
             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
+            }else if (OP_NAVIGATION.equals(action)) {
+                if(intent.hasExtra("show_navigation_bar")){
+                    boolean show = intent.getBooleanExtra("show_navigation_bar", true);
+                    Log.e("StatusBar", "OP_NAVIGATION: " + show);
+                     NavigationBarView mNavigationBarView = mNavigationBarController.getDefaultNavigationBarView();
+                    
+                    if (show) {
+                        if (mNavigationBarView != null) return;
+
+                        createNavigationBar(result);
+                        SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, true);
+                    }else{
+                        if (mNavigationBarView == null) return;
+
+                        mNavigationBarController.removeNavigationBarView();
+                        //mNavigationBarView = null;
+                        SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_NAVIGATION_BAR, false);
+                    }
+                }else{
+                    Log.w("StatusBar","didn't contain navigation_bar_show key");
+                }
+            }



三、动态控制 StatusBar(显示/隐藏/禁止下拉)

显示/隐藏

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

@@ -802,6 +805,14 @@ public class StatusBar extends SystemUI implements DemoMode,
         mStatusBarWindow.setService(this);
         mStatusBarWindow.setOnTouchListener(getStatusBarWindowTouchListener());
 
+        //add ,whether to show status bar[S]
+        boolean showStatusBar = SharedConfig.getInstance(mContext).readBoolean(SharedConfig.KEY_PANEL_GONE, true);
+        Log.v(TAG, "makeStatusBarView showStatusBar=" + showStatusBar);
+        if(mStatusBarWindow!=null)
+            mStatusBarWindow.setVisibility(showStatusBar ? View.VISIBLE : View.GONE);
+        //add ,whether to show status bar[E]
+
+

+        filter.addAction(OP_PANELBAR);
+        filter.addAction(OP_STATUSBAR);
         context.registerReceiverAsUser(mBroadcastReceiver, UserHandle.ALL, filter, null, null);
        IntentFilter demoFilter = new IntentFilter();


+    private static final String OP_PANELBAR = "cc.intent.systemui.OPEN_PANEL_ENABLED";
+    private static final String OP_STATUSBAR = "cc.intent.systemui.WHETHER_SHOW_STATUSBAR";

     private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {

             else if (DevicePolicyManager.ACTION_SHOW_DEVICE_MONITORING_DIALOG.equals(action)) {
                 mQSPanel.showDeviceMonitoringDialog();
+            }else if (OP_PANELBAR.equals(action)) {
+                if(intent.hasExtra("open_panel_enabled")){
+                    boolean result = intent.getBooleanExtra("open_panel_enabled",true);
+                    SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_PANEL_BAR, result);
+                    Log.e("StatusBar", "OP_PANELBAR: " + result);
+                }else{
+                    Log.w("StatusBar","didn't contain open_panel_enabled key");
+                }
+            }else if (OP_STATUSBAR.equals(action)) {
+                if(intent.hasExtra("show_status_bar")){
+                    boolean result = intent.getBooleanExtra("show_status_bar",true);
+                    SharedConfig.getInstance(mContext).writeData(SharedConfig.KEY_PANEL_GONE, result);
+                    if(mStatusBarWindow!=null){
+                       mStatusBarWindow.setVisibility(result ? View.VISIBLE : View.GONE);
+                    }
+                    Log.e("StatusBar", "OP_STATUSBAR: " + result);
+                }else{
+                    Log.w("StatusBar","didn't contain show_status_bar key");
+                }
+            }

禁止下拉

vendor/mediatek/proprietary/packages/apps/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java

@@ -230,7 +230,10 @@ public class PhoneStatusBarView extends PanelBar {
             }
         }
 
-        return barConsumedEvent || super.onTouchEvent(event);
+        // modify
+        // return barConsumedEvent || super.onTouchEvent(event);
+        boolean isEnable = SharedConfig.getInstance(mContext).readBoolean(SharedConfig.KEY_PANEL_BAR, true);
+        return isEnable ? barConsumedEvent || super.onTouchEvent(event) : isEnable;
     }
 

你可能感兴趣的:(Android10.0,源码修改)