PP animations on 7-inch landscape and 10-inch tablets.

This commit is contained in:
Dmitry Yunitsky 2015-02-20 16:38:34 +03:00 committed by Alex Zolotarev
parent ad38b44fa7
commit 569e8cbfe5
5 changed files with 159 additions and 5 deletions

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:placePage="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
@ -16,7 +17,8 @@
android:layout_width="@dimen/panel_width"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_search"
android:layout_margin="@dimen/margin_medium"/>
android:layout_margin="@dimen/margin_medium"
placePage:animationType="leftTop"/>
<RelativeLayout
android:id="@+id/rl__routing_box"

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:placePage="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom">
@ -16,7 +17,8 @@
android:layout_width="@dimen/panel_width"
android:layout_height="wrap_content"
android:layout_below="@+id/toolbar_search"
android:layout_margin="@dimen/margin_medium"/>
android:layout_margin="@dimen/margin_medium"
placePage:animationType="leftTop"/>
<RelativeLayout
android:id="@+id/rl__routing_box"

View file

@ -51,6 +51,8 @@ public abstract class BasePlacePageAnimationController
mPlacePage = placePage;
mPreview = (ViewGroup) placePage.findViewById(R.id.pp__preview);
mDetails = (ViewGroup) placePage.findViewById(R.id.pp__details);
// we don't want to block details scrolling
mDetails.requestDisallowInterceptTouchEvent(true);
mButtons = (ViewGroup) placePage.findViewById(R.id.pp__buttons);
initGestureDetector();
@ -66,7 +68,6 @@ public abstract class BasePlacePageAnimationController
protected boolean onTouchEvent(@NonNull MotionEvent event)
{
// mPlacePage.requestDisallowInterceptTouchEvent(false);
return mGestureDetector.onTouchEvent(event);
}
}

View file

@ -0,0 +1,149 @@
package com.mapswithme.maps.widget.placepage;
import android.support.annotation.NonNull;
import android.support.v4.view.GestureDetectorCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;
import com.nineoldandroids.animation.ValueAnimator;
import com.nineoldandroids.view.ViewHelper;
public class LeftFloatPlacePageAnimationController extends BasePlacePageAnimationController
{
public LeftFloatPlacePageAnimationController(@NonNull PlacePageView placePage)
{
super(placePage);
}
@Override
boolean onInterceptTouchEvent(MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mIsGestureHandled = false;
mDownCoord = event.getRawY();
break;
case MotionEvent.ACTION_MOVE:
if (mDownCoord < mPreview.getY() || mDownCoord > mButtons.getY())
return false;
if (Math.abs(mDownCoord - event.getRawY()) > mTouchSlop)
return true;
break;
}
return false;
}
@Override
protected boolean onTouchEvent(@NonNull MotionEvent event)
{
if (mDownCoord < mPreview.getY() || mDownCoord > mButtons.getY())
return false;
super.onTouchEvent(event);
return true;
}
@Override
protected void initGestureDetector()
{
mGestureDetector = new GestureDetectorCompat(mPlacePage.getContext(), new GestureDetector.SimpleOnGestureListener()
{
private static final int Y_MIN = 1;
private static final int Y_MAX = 100;
private static final int X_TO_Y_SCROLL_RATIO = 2;
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
{
final boolean isVertical = Math.abs(distanceY) > X_TO_Y_SCROLL_RATIO * Math.abs(distanceX);
final boolean isInRange = Math.abs(distanceY) > Y_MIN && Math.abs(distanceY) < Y_MAX;
if (isVertical && isInRange)
{
if (!mIsGestureHandled)
{
if (distanceY < 0)
{
mPlacePage.setState(State.HIDDEN);
Framework.deactivatePopup();
}
mIsGestureHandled = true;
}
return true;
}
return false;
}
});
}
@Override
protected void showPlacePage(final boolean show)
{
if (mIsPlacePageVisible == show)
return; // if state is already same as we need
mPlacePage.setVisibility(View.VISIBLE);
ValueAnimator animator;
if (show)
{
animator = ValueAnimator.ofFloat(mPlacePage.getHeight(), 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mPlacePage, (Float) animation.getAnimatedValue());
}
});
}
else
{
animator = ValueAnimator.ofFloat(0, mPlacePage.getHeight());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mPlacePage, (Float) animation.getAnimatedValue());
if (1f - animation.getAnimatedFraction() < 0.01)
{
mPlacePage.setVisibility(View.INVISIBLE);
mPlacePage.setMapObject(null);
}
}
});
}
animator.setDuration(LONG_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mIsPlacePageVisible = show;
if (mVisibilityChangedListener != null)
{
mVisibilityChangedListener.onPreviewVisibilityChanged(mIsPlacePageVisible);
mVisibilityChangedListener.onPlacePageVisibilityChanged(mIsPlacePageVisible);
}
}
@Override
protected void showPreview(final boolean show)
{
showPlacePage(show);
}
@Override
protected void hidePlacePage()
{
showPlacePage(false);
}
}

View file

@ -174,6 +174,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
final TypedArray attrArray = getContext().obtainStyledAttributes(attrs, R.styleable.PlacePageView, defStyleAttr, 0);
final int animationType = attrArray.getInt(R.styleable.PlacePageView_animationType, 0);
attrArray.recycle();
// switch with values from "animationType" from attrs.xml
switch (animationType)
{
case 0:
@ -183,8 +184,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
mAnimationController = new TopPlacePageAnimationController(this);
break;
case 2:
// FIXME
mAnimationController = new TopPlacePageAnimationController(this);
mAnimationController = new LeftFloatPlacePageAnimationController(this);
break;
case 3:
mAnimationController = new LeftFullAnimationController(this);