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){
const bool hardwareAcceleratedCanvas=false;
bool drawingWithRenderNode= mAttachInfo && mAttachInfo->mHardwareAccelerated && hardwareAcceleratedCanvas;;
bool drawingWithRenderNode= mAttachInfo && mAttachInfo->mHardwareAccelerated && hardwareAcceleratedCanvas;
bool more = false;
const bool childHasIdentityMatrix = hasIdentityMatrix();
int parentFlags = parent->mGroupFlags;
@ -2987,7 +2987,7 @@ bool View::draw(Canvas&canvas,ViewGroup*parent,long drawingTime){
canvas.save();
canvas.reset_clip();
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();
canvas.restore();
}
@ -3042,34 +3042,43 @@ int View::getId() const{
int View::getNextFocusLeftId()const{
return mNextFocusLeftId;
}
View& View::setNextFocusLeftId(int id){
mNextFocusLeftId=id;
return *this;
}
int View::getNextFocusRightId()const{
return mNextFocusRightId;
}
View& View::setNextFocusRightId(int id){
mNextFocusRightId=id;
return *this;
}
int View::getNextFocusUpId()const{
return mNextFocusUpId;
}
View& View::setNextFocusUpId(int id){
mNextFocusUpId=id;
return *this;
}
int View::getNextFocusDownId()const{
return mNextFocusDownId;
}
View& View::setNextFocusDownId(int id){
mNextFocusDownId=id;
return *this;
}
int View::getNextFocusForwardId()const{
return mNextFocusForwardId;
}
View& View::setNextFocusForwardId(int id){
mNextFocusForwardId=id;
return *this;
@ -4779,43 +4788,29 @@ bool View::toLocalMotionEvent(MotionEvent& ev){
}
void View::transformMatrixToGlobal(Matrix& matrix){
#if 0
ViewGroup* parent = mParent;
if (parent instanceof View) {
View* vp = (View) parent;
if (mParent){
View* vp = (View*) mParent;
vp->transformMatrixToGlobal(matrix);
matrix.preTranslate(-vp.mScrollX, -vp.mScrollY);
} else if (parent instanceof ViewRootImpl) {
ViewRootImpl vr = (ViewRootImpl) parent;
vr->transformMatrixToGlobal(matrix);
matrix.preTranslate(0, -vr.mCurScrollY);
matrix.translate(-vp->mScrollX, -vp->mScrollY);
}
matrix.preTranslate(mLeft, mTop);
matrix.translate(mLeft, mTop);
if (!hasIdentityMatrix()) {
matrix.preConcat(getMatrix());
Matrix mtx=getMatrix();
matrix.multiply(matrix,mtx);
}
#endif
}
void View::transformMatrixToLocal(Matrix& matrix){
#if 0
ViewGroup* parent = mParent;
if (parent instanceof View) {
View* vp = (View) parent;
if (mParent){
View* vp = (View*) mParent;
vp->transformMatrixToLocal(matrix);
matrix.postTranslate(vp.mScrollX, vp.mScrollY);
} else if (parent instanceof ViewRootImpl) {
ViewRootImpl vr = (ViewRootImpl) parent;
vr->transformMatrixToLocal(matrix);
matrix.postTranslate(0, vr.mCurScrollY);
matrix.translate(vp->mScrollX, vp->mScrollY);
}
matrix.postTranslate(-mLeft, -mTop);
matrix.translate(-mLeft, -mTop);
if (!hasIdentityMatrix()) {
matrix.postConcat(getInverseMatrix());
Matrix inv=getInverseMatrix();
matrix.multiply(matrix,inv);
}
#endif
}
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;
* otherwise don't. mScroller.isFinished should be false when
* 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;
}
@ -396,18 +403,28 @@ bool HorizontalScrollView::onTouchEvent(MotionEvent& ev) {
bool canOverscroll = overscrollMode == OVER_SCROLL_ALWAYS ||
(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
// calls onScrollChanged if applicable.
if (overScrollBy(deltaX, 0, mScrollX, 0, range, 0,
mOverscrollDistance, 0, true)) {
// Break our velocity if we hit a scroll barrier.
mVelocityTracker->clear();
}
overScrollBy(deltaX, 0, mScrollX, 0, range, 0, mOverscrollDistance, 0, true);
if (canOverscroll) {
if (canOverscroll && deltaX!=.0f) {
int pulledToX = oldX + deltaX;
if (pulledToX < 0) {
mEdgeGlowLeft->onPull((float) deltaX / getWidth(),
mEdgeGlowLeft->onPullDistance((float) deltaX / getWidth(),
1.f - ev.getY(activePointerIndex) / getHeight());
if (!mEdgeGlowRight->isFinished()) {
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. */
/* 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 we don't have a valid id, the touch down wasn't on content.
break;
}
int pointerIndex = ev.findPointerIndex(activePointerId);
const int pointerIndex = ev.findPointerIndex(activePointerId);
if (pointerIndex == -1) {
LOGE("Invalid pointerId=%d in onInterceptTouchEvent",activePointerId);
break;
}
int y = (int) ev.getY(pointerIndex);
int yDiff = std::abs(y - mLastMotionY);
const int y = (int) ev.getY(pointerIndex);
const int yDiff = std::abs(y - mLastMotionY);
if (yDiff > mTouchSlop && (getNestedScrollAxes() & SCROLL_AXIS_VERTICAL) == 0) {
mIsBeingDragged = true;
mLastMotionY = y;