Android 9 SystemUI之修改Notification的位置

最近在做自定义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();
       }
   }
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值