Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java')
-rw-r--r--android/src/com/mapswithme/maps/widget/placepage/BottomPlacePageAnimationController.java95
1 files changed, 62 insertions, 33 deletions
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