Android 上下滑隐藏显示状态栏

一、DisplayPolicy类中监听滑动事件,然后发送广播事件

Android12类路径:
frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.java

  mSystemGestures = new SystemGesturesPointerEventListener(mUiContext, mHandler,
                new SystemGesturesPointerEventListener.Callbacks() {
                    @Override
                    public void onSwipeFromTop() {
                        synchronized (mLock) {
                            if (mStatusBar != null) {
                                requestTransientBars(mStatusBar);
                            }
							// 新增
							mContext.sendBroadcast(new Intent("com.android.action.showstatusbar")); //自定义优化显示状态栏
                            checkAltBarSwipeForTransientBars(ALT_BAR_TOP);
                        }
                    }

                    @Override
                    public void onSwipeFromBottom() {
                        synchronized (mLock) {
                            if (mNavigationBar != null
                                    && mNavigationBarPosition == NAV_BAR_BOTTOM) {
								
                                requestTransientBars(mNavigationBar);
                            }
							// 新增
							mContext.sendBroadcast(new Intent("com.android.action.hidestatusbar")); 
							
							// 新增
							mContext.sendBroadcast(new Intent("com.android.action.swipefrombottom")); //自定义上滑广播
						 
                            checkAltBarSwipeForTransientBars(ALT_BAR_BOTTOM);
                        }
                    }

二、状态的显示与隐藏方法

类中frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

新增状态栏显示与隐藏的两个方法

	// 显示状态栏
	private void showStatusBar(){
		if(mPhoneStatusBarWindow!=null){
			mPhoneStatusBarWindow.setVisibility(View.VISIBLE);
		}
	}
	
	// 隐藏状态栏
	private void hideStatubar(){
		if(mPhoneStatusBarWindow!=null){
			mPhoneStatusBarWindow.setVisibility(View.GONE);
		}
	}

三、注册广播

类中 frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

添加广播动作

internalFilter.addAction("com.android.action.showstatusbar");

internalFilter.addAction("com.android.action.hidestatusbar");

    IntentFilter internalFilter = new IntentFilter();
        internalFilter.addAction(BANNER_ACTION_CANCEL);
        internalFilter.addAction(BANNER_ACTION_SETUP);
		
		//添加广播动作
	    internalFilter.addAction("com.android.action.swipefrombottom");
		//添加状态栏隐藏显示广播
		internalFilter.addAction("com.android.action.showstatusbar");
		internalFilter.addAction("com.android.action.hidestatusbar");
		
        mContext.registerReceiver(mBannerActionBroadcastReceiver, internalFilter, PERMISSION_SELF,
                null);

四、调用显示隐藏

类中frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java

调用

else if("com.android.action.showstatusbar".equals(action)){

showStatusBar();

}else if("com.android.action.hidestatusbar".equals(action)){

hideStatubar();

}

    private final BroadcastReceiver mBannerActionBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (BANNER_ACTION_CANCEL.equals(action) || BANNER_ACTION_SETUP.equals(action)) {
                NotificationManager noMan = (NotificationManager)
                        mContext.getSystemService(Context.NOTIFICATION_SERVICE);
                noMan.cancel(com.android.internal.messages.nano.SystemMessageProto.SystemMessage.
                        NOTE_HIDDEN_NOTIFICATIONS);

                Settings.Secure.putInt(mContext.getContentResolver(),
                        Settings.Secure.SHOW_NOTE_ABOUT_NOTIFICATION_HIDING, 0);
                if (BANNER_ACTION_SETUP.equals(action)) {
                    mShadeController.animateCollapsePanels(CommandQueue.FLAG_EXCLUDE_RECENTS_PANEL,
                            true /* force */);
                    mContext.startActivity(new Intent(Settings.ACTION_APP_NOTIFICATION_REDACTION)
                            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

                    );
                }
            }
			// 分割线
			else if("com.android.action.swipefrombottom".equals(action)){
	            //上滑事件
			     Log.d("StatusBar","swipefrombottom---666--");
			  if(!navigationBarState){
			        navigationBarState = true;
			        //加载导航栏
			        createNavigationBar(result);
			        mHandler.postDelayed(new Runnable() {
			                @Override
			                public void run() {
							  navigationBarState = false;
							// 移除导航栏
		                      mNavigationBarController.removeNavigationBar(mDisplayId);
			                }
			            },6000);
			  }
		    }else if("com.android.action.swipefromtop".equals(action)){
			     Log.d("StatusBar","swipefromtop--666-");
			//下滑事件
			   mNavigationBarController.removeNavigationBar(mDisplayId);
		   }else if("com.android.action.showstatusbar".equals(action)){
			   showStatusBar();
		   }else if("com.android.action.hidestatusbar".equals(action)){
			   hideStatubar();
		   }
			// 分割线
			
        }
    };
相关推荐
丘狸尾2 小时前
[cisco 模拟器] ftp服务器配置
android·运维·服务器
van叶~4 小时前
探索未来编程:仓颉语言的优雅设计与无限可能
android·java·数据库·仓颉
Crossoads7 小时前
【汇编语言】端口 —— 「从端口到时间:一文了解CMOS RAM与汇编指令的交汇」
android·java·汇编·深度学习·网络协议·机器学习·汇编语言
li_liuliu8 小时前
Android4.4 在系统中添加自己的System Service
android
C4rpeDime11 小时前
自建MD5解密平台-续
android
鲤籽鲲12 小时前
C# Random 随机数 全面解析
android·java·c#
m0_5485147716 小时前
2024.12.10——攻防世界Web_php_include
android·前端·php
凤邪摩羯16 小时前
Android-性能优化-03-启动优化-启动耗时
android
凤邪摩羯16 小时前
Android-性能优化-02-内存优化-LeakCanary原理解析
android
喀什酱豆腐17 小时前
Handle
android