一、DisplayPolicy类中监听滑动事件,然后发送广播事件
Android12类路径:
frameworks/base/services/core/java/com/android/server/wm/DisplayPolicy.javamSystemGestures = new SystemGesturesPointerEventListener(mUiContext, mHandler,new SystemGesturesPointerEventListener.Callbacks() {@Overridepublic void onSwipeFromTop() {synchronized (mLock) {if (mStatusBar != null) {requestTransientBars(mStatusBar);}// 新增mContext.sendBroadcast(new Intent("com.android.action.showstatusbar")); //自定义优化显示状态栏checkAltBarSwipeForTransientBars(ALT_BAR_TOP);}}@Overridepublic 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() {@Overridepublic 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() {@Overridepublic 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();}// 分割线}};