diff options
author | Aleksandr Zatsepin <alexzatsepin@users.noreply.github.com> | 2017-05-16 06:16:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-16 06:16:28 +0300 |
commit | 5caaff31245441c8ed971c83ab71cba642959e52 (patch) | |
tree | 21a2010fe25902ee75ffd58d0511a0cbfa30f039 /android | |
parent | 1ac5e0151979e3b6fc885ad2cb692777ae0c28a9 (diff) | |
parent | 19ef1788ec69de3094b4d2a8a9412d918d997cc5 (diff) |
Merge pull request #6042 from goblinr/MAPSME-4465-pp-size-change-detection
[android] Detect PP size change. Stop motion event tracking when PP c…
Diffstat (limited to 'android')
6 files changed, 133 insertions, 56 deletions
diff --git a/android/res/layout/place_page.xml b/android/res/layout/place_page.xml index 76fa88dda7..9dfe3b3d7e 100644 --- a/android/res/layout/place_page.xml +++ b/android/res/layout/place_page.xml @@ -8,7 +8,7 @@ android:overScrollMode="never" android:layout_above="@+id/pp__buttons"> - <LinearLayout + <com.mapswithme.maps.widget.ObservableLinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> @@ -31,7 +31,7 @@ android:layout_width="match_parent" android:layout_height="0dp" android:background="?cardBackground"/> - </LinearLayout> + </com.mapswithme.maps.widget.ObservableLinearLayout> </com.mapswithme.maps.widget.ObservableScrollView> <include diff --git a/android/src/com/mapswithme/maps/widget/ObservableLinearLayout.java b/android/src/com/mapswithme/maps/widget/ObservableLinearLayout.java new file mode 100644 index 0000000000..d6f70dcefe --- /dev/null +++ b/android/src/com/mapswithme/maps/widget/ObservableLinearLayout.java @@ -0,0 +1,54 @@ +package com.mapswithme.maps.widget; + +import android.annotation.TargetApi; +import android.content.Context; +import android.os.Build; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.AttributeSet; +import android.widget.LinearLayout; + +public class ObservableLinearLayout extends LinearLayout +{ + @Nullable + private SizeChangedListener mSizeChangedListener; + + public ObservableLinearLayout(@NonNull Context context) + { + super(context); + } + + public ObservableLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs) + { + super(context, attrs); + } + + public ObservableLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) + { + super(context, attrs, defStyleAttr); + } + + @TargetApi(Build.VERSION_CODES.LOLLIPOP) + public ObservableLinearLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) + { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) + { + super.onSizeChanged(w, h, oldw, oldh); + if (mSizeChangedListener != null) + mSizeChangedListener.onSizeChanged(w, h, oldw, oldh); + } + + public void setSizeChangedListener(@Nullable SizeChangedListener listener) + { + mSizeChangedListener = listener; + } + + public interface SizeChangedListener + { + void onSizeChanged(int width, int height, int oldWidth, int oldHeight); + } +} diff --git a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java index 6fb12554f5..faec6d1188 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/BannerController.java +++ b/android/src/com/mapswithme/maps/widget/placepage/BannerController.java @@ -322,6 +322,11 @@ final class BannerController animator.start(); } + boolean isOpened() + { + return mOpened; + } + interface BannerListener { void onSizeChanged(); diff --git a/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java b/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java index 8da4ac66c3..6f1aaf07d1 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java +++ b/android/src/com/mapswithme/maps/widget/placepage/BasePlacePageAnimationController.java @@ -174,6 +174,4 @@ public abstract class BasePlacePageAnimationController implements ObservableScro animator.setInterpolator(interpolator == null ? INTERPOLATOR : interpolator); animator.start(); } - - protected void onContentSizeChanged() {} } diff --git a/android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java b/android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java index 61d097c937..9277ef8488 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java +++ b/android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java @@ -18,11 +18,13 @@ import android.widget.LinearLayout; import com.mapswithme.maps.R; import com.mapswithme.maps.bookmarks.data.MapObject; +import com.mapswithme.maps.widget.ObservableLinearLayout; import com.mapswithme.maps.widget.placepage.PlacePageView.State; import com.mapswithme.util.UiUtils; import com.mapswithme.util.concurrency.UiThread; class BottomPlacePageAnimationController extends BasePlacePageAnimationController + implements ObservableLinearLayout.SizeChangedListener { @SuppressWarnings("unused") private static final String TAG = BottomPlacePageAnimationController.class.getSimpleName(); @@ -34,9 +36,12 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle private boolean mIsGestureStartedInsideView; private boolean mIsGestureFinished; + private boolean mIsHiding; + private float mScreenHeight; private float mDetailMaxHeight; private float mScrollDelta; + private int mContentHeight; @Nullable private OnBannerOpenListener mBannerOpenListener; @@ -49,6 +54,9 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle if (mLayoutToolbar == null) return; + ((ObservableLinearLayout) mDetailsContent).setSizeChangedListener(this); + mContentHeight = mDetailsContent.getHeight(); + final Toolbar toolbar = (Toolbar) mLayoutToolbar.findViewById(R.id.toolbar); if (toolbar != null) { @@ -65,14 +73,17 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle } DisplayMetrics dm = placePage.getResources().getDisplayMetrics(); - float screenHeight = dm.heightPixels; - mDetailMaxHeight = screenHeight * DETAIL_RATIO; + mScreenHeight = dm.heightPixels; + mDetailMaxHeight = mScreenHeight * DETAIL_RATIO; mScrollDelta = SCROLL_DELTA * dm.density; } @Override protected boolean onInterceptTouchEvent(MotionEvent event) { + if (mIsHiding) + return false; + switch (event.getAction()) { case MotionEvent.ACTION_DOWN: @@ -102,6 +113,10 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle final boolean isBannerTouch = mPlacePage.isBannerTouched(event); if (isInside && !isBannerTouch && mIsGestureStartedInsideView) mGestureDetector.onTouchEvent(event); + mIsDragging = false; + break; + case MotionEvent.ACTION_CANCEL: + mIsDragging = false; break; } @@ -111,7 +126,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override protected boolean onTouchEvent(@NonNull MotionEvent event) { - if (mIsGestureFinished) + if (mIsGestureFinished || mIsHiding) return false; final boolean finishedDrag = (mIsDragging && @@ -159,7 +174,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle private boolean isDetailContentScrollable() { - return mDetailsScroll.getHeight() < mDetailsContent.getHeight(); + return mDetailsScroll.getHeight() < mContentHeight; } private boolean canScroll(float delta) @@ -177,6 +192,9 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { + if (mIsHiding) + return true; + final boolean isVertical = Math.abs(distanceY) > X_TO_Y_SCROLL_RATIO * Math.abs(distanceX); if (isVertical) @@ -185,7 +203,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle if (!translateBy(-distanceY)) { boolean scrollable = isDetailContentScrollable(); - int maxTranslationY = mDetailsScroll.getHeight() - mDetailsContent.getHeight(); + int maxTranslationY = mDetailsScroll.getHeight() - mContentHeight; if ((scrollable && mDetailsScroll.getTranslationY() == 0) || (!scrollable && mDetailsScroll.getTranslationY() <= maxTranslationY)) { @@ -201,6 +219,9 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { + if (mIsHiding) + return true; + finishDrag(-velocityY); return true; } @@ -208,6 +229,9 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override public boolean onSingleTapConfirmed(MotionEvent e) { + if (mIsHiding) + return true; + MotionEvent evt = MotionEvent.obtain(e.getDownTime(), e.getEventTime(), e.getAction(), @@ -240,6 +264,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle private void finishDrag(float distance) { + mIsDragging = false; final float currentTranslation = mDetailsScroll.getTranslationY(); if (currentTranslation > mDetailsScroll.getHeight()) { @@ -303,7 +328,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle float detailsTranslation = mDetailsScroll.getTranslationY() + distanceY; final boolean isScrollable = isDetailContentScrollable(); boolean consumeEvent = true; - final float maxTranslationY = mDetailsScroll.getHeight() - mDetailsContent.getHeight(); + final float maxTranslationY = mDetailsScroll.getHeight() - mContentHeight; if ((isScrollable && detailsTranslation < 0.0f) || detailsTranslation < maxTranslationY) { if (isScrollable) @@ -335,6 +360,9 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override protected void onStateChanged(final State currentState, final State newState, @MapObject.MapObjectType int type) { + if (newState == State.HIDDEN && currentState == newState) + return; + prepareYTranslations(newState, type); mDetailsScroll.setGestureDetector(mGestureDetector); @@ -350,17 +378,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle hidePlacePage(); break; case PREVIEW: - mPreview.addOnLayoutChangeListener(new View.OnLayoutChangeListener() - { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) - { - mPreview.removeOnLayoutChangeListener(this); - showPreview(currentState); - } - }); - mPreview.requestLayout(); + showPreview(currentState); break; case DETAILS: showDetails(); @@ -368,17 +386,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle case FULLSCREEN: if (isDetailContentScrollable()) mDetailsScroll.setGestureDetector(null); - mDetailsScroll.addOnLayoutChangeListener(new View.OnLayoutChangeListener() - { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, - int oldLeft, int oldTop, int oldRight, int oldBottom) - { - mDetailsScroll.removeOnLayoutChangeListener(this); - showFullscreen(); - } - }); - mDetailsScroll.requestLayout(); + showFullscreen(); break; } } @@ -465,7 +473,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle else { mCurrentAnimator = ValueAnimator.ofFloat(mDetailsScroll.getTranslationY(), - mDetailsScroll.getHeight() - mDetailsContent.getHeight()); + mDetailsScroll.getHeight() - mContentHeight); } mCurrentAnimator.addUpdateListener(new UpdateListener()); mCurrentAnimator.addListener(new AnimationListener()); @@ -482,7 +490,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle else { mCurrentAnimator = ValueAnimator.ofFloat(mDetailsScroll.getTranslationY(), - mDetailsScroll.getHeight() - mDetailsContent.getHeight()); + mDetailsScroll.getHeight() - mContentHeight); } mCurrentAnimator.addUpdateListener(new UpdateListener()); mCurrentAnimator.addListener(new AnimationListener()); @@ -493,6 +501,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @SuppressLint("NewApi") private void hidePlacePage() { + mIsHiding = true; if (mLayoutToolbar != null) UiUtils.hide(mLayoutToolbar); @@ -513,6 +522,7 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle @Override public void onAnimationEnd(Animator animation) { + mIsHiding = false; initialVisibility(); mPlacePage.setTranslationY(0); mDetailsScroll.setTranslationY(mDetailsScroll.getHeight()); @@ -563,12 +573,31 @@ class BottomPlacePageAnimationController extends BasePlacePageAnimationControlle mBannerOpenListener = bannerOpenListener; } - @Override - protected void onContentSizeChanged() + private boolean isOverDetailsState() { + return mDetailsScroll.getTranslationY() < mScreenHeight - mDetailMaxHeight; + } + + private void onContentSizeChanged() + { + if (mIsDragging || mCurrentScrollY > 0) + return; + MapObject object = mPlacePage.getMapObject(); if (object != null) - onStateChanged(getState(), getState(), object.getMapObjectType()); + { + State newState = getState(); + if (isOverDetailsState()) + newState = State.FULLSCREEN; + onStateChanged(getState(), newState, object.getMapObjectType()); + } + } + + @Override + public void onSizeChanged(int width, int height, int oldWidth, int oldHeight) + { + mContentHeight = height; + onContentSizeChanged(); } private class UpdateListener implements ValueAnimator.AnimatorUpdateListener diff --git a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java index 75d3e390dc..f2a47777f7 100644 --- a/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java +++ b/android/src/com/mapswithme/maps/widget/placepage/PlacePageView.java @@ -740,13 +740,10 @@ public class PlacePageView extends RelativeLayout else { UiUtils.show(mHotelFacilities); - boolean oldValue = mFacilitiesAdapter.isShowAll(); mFacilitiesAdapter.setShowAll(false); mFacilitiesAdapter.setItems(Arrays.asList(info.mFacilities)); mHotelMoreFacilities.setVisibility(info.mFacilities.length > FacilitiesAdapter.MAX_COUNT ? VISIBLE : GONE); - if (oldValue != mFacilitiesAdapter.isShowAll()) - mAnimationController.onContentSizeChanged(); } } @@ -862,7 +859,11 @@ public class PlacePageView extends RelativeLayout public void onNeedOpenBanner() { if (mBannerController != null) + { + if (!mBannerController.isOpened()) + compensateViewHeight(0); mBannerController.open(); + } } private void compensateViewHeight(int height) @@ -947,12 +948,16 @@ public class PlacePageView extends RelativeLayout int heightCompensation = 0; if (mBannerController != null) { - if ((state == State.HIDDEN || state == State.PREVIEW) && !UiUtils.isLandscape(getContext())) + State lastState = getState(); + boolean isLastStateNotHiddenOrPreview = lastState != State.HIDDEN + && lastState != State.PREVIEW; + if (isLastStateNotHiddenOrPreview && (state == State.HIDDEN || state == State.PREVIEW) + && !UiUtils.isLandscape(getContext())) { if (mBannerController.close()) heightCompensation = mBannerController.getLastBannerHeight(); } - else + else if (isLastStateNotHiddenOrPreview) { mBannerController.open(); } @@ -1590,14 +1595,12 @@ public class PlacePageView extends RelativeLayout case R.id.tv__place_hotel_more: UiUtils.hide(mHotelMoreDescription); mTvHotelDescription.setMaxLines(Integer.MAX_VALUE); - mAnimationController.onContentSizeChanged(); break; case R.id.tv__place_hotel_facilities_more: if (mSponsored != null && mMapObject != null) Statistics.INSTANCE.trackHotelEvent(PP_HOTEL_FACILITIES, mSponsored, mMapObject); UiUtils.hide(mHotelMoreFacilities); mFacilitiesAdapter.setShowAll(true); - mAnimationController.onContentSizeChanged(); break; case R.id.tv__place_hotel_reviews_more: if (isSponsored()) @@ -1817,7 +1820,6 @@ public class PlacePageView extends RelativeLayout mCurrentCountry = null; mDownloaderIcon.show(false); UiUtils.hide(mDownloaderInfo); - mAnimationController.onContentSizeChanged(); } MwmActivity getActivity() @@ -1844,16 +1846,5 @@ public class PlacePageView extends RelativeLayout mPreview.setPadding(mPreview.getPaddingLeft(), mPreview.getPaddingTop(), getPaddingRight(), mMarginBase); } - addOnLayoutChangeListener(new OnLayoutChangeListener() - { - @Override - public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, - int oldTop, int oldRight, int oldBottom) - { - removeOnLayoutChangeListener(this); - mAnimationController.onContentSizeChanged(); - } - }); - requestLayout(); } } |