一、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();
}
// 分割线
}
};