SystemUI下拉通知欄和下拉快捷設定欄的對應設定
根據SystemUI下的PanelView,他就是下拉通知欄和下拉快捷設定欄所繼承的父類,這裡面實現了下拉的動作監聽,即是對status bar最下面那根橫線的監聽,當對她進行OnTouch時間時,判斷下拉的狀態,當return true表示,OnTouch事件已經被消費了,不再分給別的元件使用;當return false表示,OnTouch事件未被消費,會分給別的元件使用,由於此處未對事件進行消費,則不會進行後續的操作(比如下拉之類的)
protected void onFinishInflate() {
super.onFinishInflate();mHandleView = findViewById(R.id.handle);
loadDimens();
if (DEBUG) logf("handle view: " + mHandleView);
if (mHandleView != null) {
mHandleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// 20160720 by geo
float checkX = event.getX();
WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
int width = wm.getDefaultDisplay().getWidth();
hidequickstubischeck = SystemProperties.getBoolean("persist.sys.hidequickstub", false);
if (hidequickstubischeck && (checkX > width/2)) {
isClick = false;
}else {
isClick = true;
}
// 20160720 by geo
int pointerIndex = event.findPointerIndex(mTrackingPointer);
if (pointerIndex < 0) {
pointerIndex = 0;
mTrackingPointer = event.getPointerId(pointerIndex);
}
final float y = event.getY(pointerIndex);
final float rawDelta = event.getRawY() - event.getY();
final float rawY = y + rawDelta;
if (DEBUG) logf("handle.onTouch: a=%s p=[%d,%d] y=%.1f rawY=%.1f off=%.1f",
MotionEvent.actionToString(event.getAction()),
mTrackingPointer, pointerIndex,
y, rawY, mTouchOffset);
PanelView.this.getLocationOnScreen(mAbsPos);
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// 20160720 by geo
if (isClick) {
mTracking = true;
mHandleView.setPressed(true);
postInvalidate(); // catch the press state change
mInitialTouchY = y;
mVelocityTracker = FlingTracker.obtain();
trackMovement(event);
mTimeAnimator.cancel(); // end any outstanding animations
mBar.onTrackingStarted(PanelView.this);
mTouchOffset = (rawY - mAbsPos[1]) - mExpandedHeight;
if (mExpandedHeight == 0) {
mJustPeeked = true;
runPeekAnimation();
}
break;
}else{
return false;
// 20160720 by geo
}
case MotionEvent.ACTION_POINTER_UP:
final int upPointer = event.getPointerId(event.getActionIndex());
if (mTrackingPointer == upPointer) {
// gesture is ongoing, find a new pointer to track
final int newIndex = event.getPointerId(0) != upPointer ? 0 : 1;
final float newY = event.getY(newIndex);
final float newRawY = newY + rawDelta;
mTrackingPointer = event.getPointerId(newIndex);
mTouchOffset = (newRawY - mAbsPos[1]) - mExpandedHeight;
mInitialTouchY = newY;
}
break;
case MotionEvent.ACTION_MOVE:
final float h = rawY - mAbsPos[1] - mTouchOffset;
if (h > mPeekHeight) {
if (mPeekAnimator != null && mPeekAnimator.isStarted()) {
mPeekAnimator.cancel();
}
mJustPeeked = false;
}
if (!mJustPeeked) {
PanelView.this.setExpandedHeightInternal(h);
mBar.panelExpansionChanged(PanelView.this, mExpandedFraction);
}
trackMovement(event);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mFinalTouchY = y;
mTracking = false;
mTrackingPointer = -1;
mHandleView.setPressed(false);
postInvalidate(); // catch the press state change
mBar.onTrackingStopped(PanelView.this);
trackMovement(event);
float vel = 0, yVel = 0, xVel = 0;
boolean negative = false;
if (mVelocityTracker != null) {
// the velocitytracker might be null if we got a bad input stream
mVelocityTracker.computeCurrentVelocity(1000);
yVel = mVelocityTracker.getYVelocity();
negative = yVel < 0;
xVel = mVelocityTracker.getXVelocity();
if (xVel < 0) {
xVel = -xVel;
}
if (xVel > mFlingGestureMaxXVelocityPx) {
xVel = mFlingGestureMaxXVelocityPx; // limit how much we care about the x axis
}
vel = (float)Math.hypot(yVel, xVel);
if (vel > mFlingGestureMaxOutputVelocityPx) {
vel = mFlingGestureMaxOutputVelocityPx;
}
mVelocityTracker.recycle();
mVelocityTracker = null;
}
// if you've barely moved your finger, we treat the velocity as 0
// preventing spurious flings due to touch screen jitter
final float deltaY = Math.abs(mFinalTouchY - mInitialTouchY);
if (deltaY < mFlingGestureMinDistPx
|| vel < mFlingExpandMinVelocityPx
) {
vel = 0;
}
if (negative) {
vel = -vel;
}
if (DEBUG) logf("gesture: dy=%f vel=(%f,%f) vlinear=%f",
deltaY,
xVel, yVel,
vel);
fling(vel, true);
break;
}
return true;
}});
}
}