最近在做自定义SystemUI
NotificationPanelView 包含快速设置与通知的布局
NotificationPanelView.java
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i(TAG, " NotificationPanelView onTouchEvent entry");
if (mBlockTouches || (mQs != null && mQs.isCustomizing())) {
return false;
}
//初始化按下变量
initDownStates(event);
Log.i(TAG, "NotificationPanelView initDownStates end");
if (mListenForHeadsUp && !mHeadsUpTouchHelper.isTrackingHeadsUp()
&& mHeadsUpTouchHelper.onInterceptTouchEvent(event)) {
mIsExpansionFromHeadsUp = true;
MetricsLogger.count(mContext, COUNTER_PANEL_OPEN_PEEK, 1);
}
boolean handled = false;
if ((!mIsExpanding || mHintAnimationRunning)
&& !mQsExpanded
&& mStatusBar.getBarState() != StatusBarState.SHADE
&& !mDozing) {
handled |= mAffordanceHelper.onTouchEvent(event);
}
if (mOnlyAffordanceInThisMotion) {
return true;
}
handled |= mHeadsUpTouchHelper.onTouchEvent(event);
if (!mHeadsUpTouchHelper.isTrackingHeadsUp() && handleQsTouch(event)) {
return true;
}
if (event.getActionMasked() == MotionEvent.ACTION_DOWN && isFullyCollapsed()) {
MetricsLogger.count(mContext, COUNTER_PANEL_OPEN, 1);
//设置通知与设置panel的位置
updateVerticalPanelPosition(event.getX());
handled = true;
}
handled |= super.onTouchEvent(event);
return mDozing ? handled : true;
}
接下来调用updateVerticalPanelPosition
/**
* Updates the vertical position of the panel so it is positioned closer to the touch
* responsible for opening the panel.
*
* @param x the x-coordinate the touch event
*/
protected void updateVerticalPanelPosition(float x) {
Log.i(TAG, "updateVerticalPanelPosition x: " + x);
//获取滚动通知栏的宽度
if (mNotificationStackScroller.getWidth() * 1.75f > getWidth()) {
resetVerticalPanelPosition();
return;
}
//如果执行这说明通知栏的宽度比较小,就会再按下的位置显示通知栏与设置panel
//mPositionMinSideMargin =48, leftMost
float leftMost = mPositionMinSideMargin + mNotificationStackScroller.getWidth() / 2;
float rightMost = getWidth() - mPositionMinSideMargin
- mNotificationStackScroller.getWidth() / 2;
if (Math.abs(x - getWidth() / 2) < mNotificationStackScroller.getWidth() / 4) {
x = getWidth() / 2;
}
x = Math.min(rightMost, Math.max(leftMost, x));
setVerticalPanelTranslation(x -
(mNotificationStackScroller.getLeft() + mNotificationStackScroller.getWidth() / 2));
}
//设置QsFrame与通知栏的X位置
protected void setVerticalPanelTranslation(float translation) {
mNotificationStackScroller.setVerticalPanelTranslation(translation);
mQsFrame.setTranslationX(translation);
int size = mVerticalTranslationListener.size();
for (int i = 0; i < size; i++) {
mVerticalTranslationListener.get(i).run();
}
}