版權聲明
本文來自博客園,作者:觀心靜 ,轉載請註明原文鏈接:https://www.cnblogs.com/guanxinjing/p/17969803
前言
此博客講解如何禁止狀態欄下拉功能
禁止狀態欄下拉功能
需要修改三個地方,分別是NotificationStackScrollLayout.java 、PhoneStatusBarView.java 、 StatusBarManager.java
不允許鎖屏狀態下拉狀態欄
文件位置: frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@ShadeViewRefactor(RefactorComponent.INPUT)
private final DragDownCallback mDragDownCallback = new DragDownCallback() {
/* Only ever called as a consequence of a lockscreen expansion gesture. */
@Override
public boolean onDraggedDown(View startingChild, int dragLengthY) {
//添加這部分代碼,這裏在判斷是否在鎖屏狀態,如果在鎖屏就返回false,不執行下面的向下拖動的手勢功能
if (mStatusBarState == StatusBarState.KEYGUARD) {
return false;
}
//----------
if (mStatusBarState == StatusBarState.KEYGUARD
&& hasActiveNotifications()) {
mLockscreenGestureLogger.write(
MetricsEvent.ACTION_LS_SHADE,
(int) (dragLengthY / mDisplayMetrics.density),
0 /* velocityDp - N/A */);
if (!mAmbientState.isDozing() || startingChild != null) {
// We have notifications, go to locked shade.
mShadeController.goToLockedShade(startingChild);
if (startingChild instanceof ExpandableNotificationRow) {
ExpandableNotificationRow row = (ExpandableNotificationRow) startingChild;
row.onExpandedByGesture(true /* drag down is always an open */);
}
}
return true;
} else if (mDynamicPrivacyController.isInLockedDownShade()) {
mStatusbarStateController.setLeaveOpenOnKeyguardHide(true);
mStatusBar.dismissKeyguardThenExecute(() -> false /* dismissAction */,
null /* cancelRunnable */, false /* afterKeyguardGone */);
return true;
} else {
// abort gesture.
return false;
}
}
//略.......
文件位置:frameworks/base/core/java/android/app/StatusBarManager.java
/**
* Disable some features in the status bar. Pass the bitwise-or of the DISABLE_* flags.
* To re-enable everything, pass {@link #DISABLE_NONE}.
*
* @hide
*/
@UnsupportedAppUsage
public void disable(int what) {
//加上這行what = what | DISABLE_EXPAND;
what = what | DISABLE_EXPAND;
try {
final int userId = Binder.getCallingUserHandle().getIdentifier();
final IStatusBarService svc = getService();
if (svc != null) {
svc.disableForUser(what, mToken, mContext.getPackageName(), userId);
}
} catch (RemoteException ex) {
throw ex.rethrowFromSystemServer();
}
}
文件位置:frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean barConsumedEvent = mBar.interceptTouchEvent(event);
if (DEBUG_GESTURES) {
if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
event.getActionMasked(), (int) event.getX(), (int) event.getY(),
barConsumedEvent ? 1 : 0);
}
}
// return barConsumedEvent || super.onTouchEvent(event);
return true; //將上面的代碼註釋掉,這裏直接返回true
}
效果圖
end