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();
		   }
			// 分割线
			
        }
    };
相关推荐
晨曦_子画12 分钟前
编程语言之战:AI 之后的 Kotlin 与 Java
android·java·开发语言·人工智能·kotlin
孤客网络科技工作室34 分钟前
AJAX 全面教程:从基础到高级
android·ajax·okhttp
Mr Lee_2 小时前
android 配置鼠标右键快捷对apk进行反编译
android
顾北川_野2 小时前
Android CALL关于电话音频和紧急电话设置和获取
android·音视频
&岁月不待人&3 小时前
Kotlin by lazy和lateinit的使用及区别
android·开发语言·kotlin
Winston Wood4 小时前
Android Parcelable和Serializable的区别与联系
android·序列化
清风徐来辽4 小时前
Android 项目模型配置管理
android
帅得不敢出门5 小时前
Gradle命令编译Android Studio工程项目并签名
android·ide·android studio·gradlew
problc6 小时前
Flutter中文字体设置指南:打造个性化的应用体验
android·javascript·flutter
帅得不敢出门16 小时前
安卓设备adb执行AT指令控制电话卡
android·adb·sim卡·at指令·电话卡