impl:View::transformMatrixToGlobal View::transformMatrixToLocal;modify horizscrollview

This commit is contained in:
houzh 2023-03-10 01:28:13 +00:00
parent 505b6aac25
commit 2e706d3b43
3 changed files with 55 additions and 43 deletions

View File

@ -2763,7 +2763,7 @@ void View::draw(Canvas&canvas){
bool View::draw(Canvas&canvas,ViewGroup*parent,long drawingTime){ bool View::draw(Canvas&canvas,ViewGroup*parent,long drawingTime){
const bool hardwareAcceleratedCanvas=false; const bool hardwareAcceleratedCanvas=false;
bool drawingWithRenderNode= mAttachInfo && mAttachInfo->mHardwareAccelerated && hardwareAcceleratedCanvas;; bool drawingWithRenderNode= mAttachInfo && mAttachInfo->mHardwareAccelerated && hardwareAcceleratedCanvas;
bool more = false; bool more = false;
const bool childHasIdentityMatrix = hasIdentityMatrix(); const bool childHasIdentityMatrix = hasIdentityMatrix();
int parentFlags = parent->mGroupFlags; int parentFlags = parent->mGroupFlags;
@ -2987,7 +2987,7 @@ bool View::draw(Canvas&canvas,ViewGroup*parent,long drawingTime){
canvas.save(); canvas.save();
canvas.reset_clip(); canvas.reset_clip();
canvas.set_source(cache,0,0); canvas.set_source(cache,0,0);
if(alpha<1)canvas.paint_with_alpha(alpha); if(alpha<1.f)canvas.paint_with_alpha(alpha);
else canvas.paint(); else canvas.paint();
canvas.restore(); canvas.restore();
} }
@ -3042,34 +3042,43 @@ int View::getId() const{
int View::getNextFocusLeftId()const{ int View::getNextFocusLeftId()const{
return mNextFocusLeftId; return mNextFocusLeftId;
} }
View& View::setNextFocusLeftId(int id){ View& View::setNextFocusLeftId(int id){
mNextFocusLeftId=id; mNextFocusLeftId=id;
return *this; return *this;
} }
int View::getNextFocusRightId()const{ int View::getNextFocusRightId()const{
return mNextFocusRightId; return mNextFocusRightId;
} }
View& View::setNextFocusRightId(int id){ View& View::setNextFocusRightId(int id){
mNextFocusRightId=id; mNextFocusRightId=id;
return *this; return *this;
} }
int View::getNextFocusUpId()const{ int View::getNextFocusUpId()const{
return mNextFocusUpId; return mNextFocusUpId;
} }
View& View::setNextFocusUpId(int id){ View& View::setNextFocusUpId(int id){
mNextFocusUpId=id; mNextFocusUpId=id;
return *this; return *this;
} }
int View::getNextFocusDownId()const{ int View::getNextFocusDownId()const{
return mNextFocusDownId; return mNextFocusDownId;
} }
View& View::setNextFocusDownId(int id){ View& View::setNextFocusDownId(int id){
mNextFocusDownId=id; mNextFocusDownId=id;
return *this; return *this;
} }
int View::getNextFocusForwardId()const{ int View::getNextFocusForwardId()const{
return mNextFocusForwardId; return mNextFocusForwardId;
} }
View& View::setNextFocusForwardId(int id){ View& View::setNextFocusForwardId(int id){
mNextFocusForwardId=id; mNextFocusForwardId=id;
return *this; return *this;
@ -4779,43 +4788,29 @@ bool View::toLocalMotionEvent(MotionEvent& ev){
} }
void View::transformMatrixToGlobal(Matrix& matrix){ void View::transformMatrixToGlobal(Matrix& matrix){
#if 0 if (mParent){
ViewGroup* parent = mParent; View* vp = (View*) mParent;
if (parent instanceof View) {
View* vp = (View) parent;
vp->transformMatrixToGlobal(matrix); vp->transformMatrixToGlobal(matrix);
matrix.preTranslate(-vp.mScrollX, -vp.mScrollY); matrix.translate(-vp->mScrollX, -vp->mScrollY);
} else if (parent instanceof ViewRootImpl) {
ViewRootImpl vr = (ViewRootImpl) parent;
vr->transformMatrixToGlobal(matrix);
matrix.preTranslate(0, -vr.mCurScrollY);
} }
matrix.preTranslate(mLeft, mTop); matrix.translate(mLeft, mTop);
if (!hasIdentityMatrix()) { if (!hasIdentityMatrix()) {
matrix.preConcat(getMatrix()); Matrix mtx=getMatrix();
matrix.multiply(matrix,mtx);
} }
#endif
} }
void View::transformMatrixToLocal(Matrix& matrix){ void View::transformMatrixToLocal(Matrix& matrix){
#if 0 if (mParent){
ViewGroup* parent = mParent; View* vp = (View*) mParent;
if (parent instanceof View) {
View* vp = (View) parent;
vp->transformMatrixToLocal(matrix); vp->transformMatrixToLocal(matrix);
matrix.postTranslate(vp.mScrollX, vp.mScrollY); matrix.translate(vp->mScrollX, vp->mScrollY);
} else if (parent instanceof ViewRootImpl) {
ViewRootImpl vr = (ViewRootImpl) parent;
vr->transformMatrixToLocal(matrix);
matrix.postTranslate(0, vr.mCurScrollY);
} }
matrix.translate(-mLeft, -mTop);
matrix.postTranslate(-mLeft, -mTop);
if (!hasIdentityMatrix()) { if (!hasIdentityMatrix()) {
matrix.postConcat(getInverseMatrix()); Matrix inv=getInverseMatrix();
matrix.multiply(matrix,inv);
} }
#endif
} }
View*View::focusSearch(int direction)const{ View*View::focusSearch(int direction)const{

View File

@ -305,7 +305,14 @@ bool HorizontalScrollView::onInterceptTouchEvent(MotionEvent& ev){
/*If being flinged and user touches the screen, initiate drag; /*If being flinged and user touches the screen, initiate drag;
* otherwise don't. mScroller.isFinished should be false when * otherwise don't. mScroller.isFinished should be false when
* being flinged. */ * being flinged. */
mIsBeingDragged = !mScroller->isFinished(); mIsBeingDragged = !mScroller->isFinished()||!mEdgeGlowLeft->isFinished()
||!mEdgeGlowRight->isFinished();
if (!mEdgeGlowLeft->isFinished()) {
mEdgeGlowLeft->onPullDistance(0.f, 1.f - ev.getY() / getHeight());
}
if (!mEdgeGlowRight->isFinished()) {
mEdgeGlowRight->onPullDistance(0.f, ev.getY() / getHeight());
}
break; break;
} }
@ -396,18 +403,28 @@ bool HorizontalScrollView::onTouchEvent(MotionEvent& ev) {
bool canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS || bool canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS ||
(overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0); (overscrollMode == OVER_SCROLL_IF_CONTENT_SCROLLS && range > 0);
const float displacement= ev.getY(activePointerIndex)/getHeight();
if (canOverscroll) {
int consumed = 0;
if (deltaX < 0 && mEdgeGlowRight->getDistance() != .0f) {
consumed = std::round(getWidth()
* mEdgeGlowRight->onPullDistance((float) deltaX / getWidth(),
displacement));
} else if (deltaX > 0 && mEdgeGlowLeft->getDistance() != .0f) {
consumed = std::round(-getWidth()
* mEdgeGlowLeft->onPullDistance((float) -deltaX / getWidth(),
1 - displacement));
}
deltaX -= consumed;
}
// Calling overScrollBy will call onOverScrolled, which // Calling overScrollBy will call onOverScrolled, which
// calls onScrollChanged if applicable. // calls onScrollChanged if applicable.
if (overScrollBy(deltaX, 0, mScrollX, 0, range, 0, overScrollBy(deltaX, 0, mScrollX, 0, range, 0, mOverscrollDistance, 0, true);
mOverscrollDistance, 0, true)) {
// Break our velocity if we hit a scroll barrier.
mVelocityTracker->clear();
}
if (canOverscroll) { if (canOverscroll && deltaX!=.0f) {
int pulledToX = oldX + deltaX; int pulledToX = oldX + deltaX;
if (pulledToX < 0) { if (pulledToX < 0) {
mEdgeGlowLeft->onPull((float) deltaX / getWidth(), mEdgeGlowLeft->onPullDistance((float) deltaX / getWidth(),
1.f - ev.getY(activePointerIndex) / getHeight()); 1.f - ev.getY(activePointerIndex) / getHeight());
if (!mEdgeGlowRight->isFinished()) { if (!mEdgeGlowRight->isFinished()) {
mEdgeGlowRight->onRelease(); mEdgeGlowRight->onRelease();

View File

@ -279,19 +279,19 @@ bool ScrollView::onInterceptTouchEvent(MotionEvent& ev) {
* whether the user has moved far enough from his original down touch. */ * whether the user has moved far enough from his original down touch. */
/* Locally do absolute value. mLastMotionY is set to the y value of the down event.*/ /* Locally do absolute value. mLastMotionY is set to the y value of the down event.*/
int activePointerId = mActivePointerId; const int activePointerId = mActivePointerId;
if (activePointerId == INVALID_POINTER) { if (activePointerId == INVALID_POINTER) {
// If we don't have a valid id, the touch down wasn't on content. // If we don't have a valid id, the touch down wasn't on content.
break; break;
} }
int pointerIndex = ev.findPointerIndex(activePointerId); const int pointerIndex = ev.findPointerIndex(activePointerId);
if (pointerIndex == -1) { if (pointerIndex == -1) {
LOGE("Invalid pointerId=%d in onInterceptTouchEvent",activePointerId); LOGE("Invalid pointerId=%d in onInterceptTouchEvent",activePointerId);
break; break;
} }
int y = (int) ev.getY(pointerIndex); const int y = (int) ev.getY(pointerIndex);
int yDiff = std::abs(y - mLastMotionY); const int yDiff = std::abs(y - mLastMotionY);
if (yDiff > mTouchSlop && (getNestedScrollAxes() & SCROLL_AXIS_VERTICAL) == 0) { if (yDiff > mTouchSlop && (getNestedScrollAxes() & SCROLL_AXIS_VERTICAL) == 0) {
mIsBeingDragged = true; mIsBeingDragged = true;
mLastMotionY = y; mLastMotionY = y;