版权声明
本文来自博客园,作者:观心静 ,转载请注明原文链接: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
本文来自博客园,作者:观心静 ,转载请注明原文链接:https://www.cnblogs.com/guanxinjing/p/17969803
本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。