Animation controller's refactoring.

This commit is contained in:
Dmitry Yunitsky 2015-02-27 11:58:49 +03:00 committed by Alex Zolotarev
parent f7d6c58ced
commit 120b7c60bf
12 changed files with 242 additions and 402 deletions

View file

@ -29,7 +29,7 @@
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_below="@id/pp__details"
android:layout_above="@id/pp__buttons"
android:background="?android:attr/listDivider"/>
<include

View file

@ -37,7 +37,8 @@
android:layout_below="@id/tv__subtitle"
android:gravity="center_vertical"
android:textColor="@color/text_place_page_subtitle"
android:textSize="@dimen/place_page_subtitle"/>
android:textSize="@dimen/place_page_subtitle"
android:visibility="gone"/>
</RelativeLayout>

View file

@ -193,8 +193,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/ll__details_left"
android:paddingTop="@dimen/margin_medium_and_half"
android:visibility="invisible">
android:visibility="invisible"
android:paddingTop="@dimen/margin_medium_and_half">
<View
android:layout_width="match_parent"

View file

@ -10,7 +10,15 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/margin_medium_and_half">
android:paddingBottom="@dimen/margin_medium_and_half"
android:paddingLeft="@dimen/margin_medium_and_half"
android:paddingRight="@dimen/margin_medium_and_half">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginBottom="@dimen/margin_medium_and_half"
android:background="?android:attr/listDivider"/>
<LinearLayout
android:id="@+id/ll__place_name"
@ -167,7 +175,7 @@
android:id="@+id/rl__bookmark_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/margin_medium_and_half">
android:paddingTop="@dimen/margin_medium_and_half">
<ImageView
android:id="@+id/iv__bookmark"

View file

@ -35,6 +35,7 @@
<TextView
android:id="@+id/tv__opened_till"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv__subtitle"

View file

@ -1323,7 +1323,7 @@ public class MWMActivity extends NvEventQueueActivity
if (!mPlacePage.hasMapObject(apiPoint))
{
mPlacePage.setMapObject(apiPoint);
mPlacePage.setState(State.PREVIEW_ONLY);
mPlacePage.setState(State.PREVIEW);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
@ -1352,7 +1352,7 @@ public class MWMActivity extends NvEventQueueActivity
if (!mPlacePage.hasMapObject(poi))
{
mPlacePage.setMapObject(poi);
mPlacePage.setState(State.PREVIEW_ONLY);
mPlacePage.setState(State.PREVIEW);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
@ -1376,7 +1376,7 @@ public class MWMActivity extends NvEventQueueActivity
if (!mPlacePage.hasMapObject(b))
{
mPlacePage.setMapObject(b);
mPlacePage.setState(State.PREVIEW_ONLY);
mPlacePage.setState(State.PREVIEW);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
@ -1403,7 +1403,7 @@ public class MWMActivity extends NvEventQueueActivity
if (!mPlacePage.hasMapObject(mypos))
{
mPlacePage.setMapObject(mypos);
mPlacePage.setState(State.PREVIEW_ONLY);
mPlacePage.setState(State.PREVIEW);
mIvStartRouting.setVisibility(View.GONE);
mTvStartRouting.setVisibility(View.GONE);
mPbRoutingProgress.setVisibility(View.GONE);
@ -1428,7 +1428,7 @@ public class MWMActivity extends NvEventQueueActivity
if (!mPlacePage.hasMapObject(sr))
{
mPlacePage.setMapObject(sr);
mPlacePage.setState(State.PREVIEW_ONLY);
mPlacePage.setState(State.PREVIEW);
mIvStartRouting.setVisibility(View.VISIBLE);
mTvStartRouting.setVisibility(View.VISIBLE);
mPbRoutingProgress.setVisibility(View.GONE);
@ -1609,7 +1609,7 @@ public class MWMActivity extends NvEventQueueActivity
setVerticalToolbarVisible(false);
result = true;
}
if (mPlacePage.getState() == State.FULL_PLACEPAGE)
if (mPlacePage.getState() == State.BOOKMARK)
{
Framework.deactivatePopup();
hideInfoView();

View file

@ -3,10 +3,12 @@ package com.mapswithme.maps.widget.placepage;
import android.support.annotation.NonNull;
import android.support.v4.view.GestureDetectorCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;
/**
* Class is responsible for animations of PP(place page) and PPP(place page preview).
@ -19,6 +21,7 @@ public abstract class BasePlacePageAnimationController
protected PlacePageView mPlacePage;
protected ViewGroup mPreview;
protected ViewGroup mDetails;
protected ViewGroup mBookmarkDetails;
protected ViewGroup mButtons;
// Gestures
protected GestureDetectorCompat mGestureDetector;
@ -40,25 +43,38 @@ public abstract class BasePlacePageAnimationController
abstract void initGestureDetector();
abstract void showPreview(boolean show);
abstract void showPlacePage(boolean show);
abstract void hidePlacePage();
public BasePlacePageAnimationController(@NonNull PlacePageView placePage)
{
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);
mBookmarkDetails = (ViewGroup) mDetails.findViewById(R.id.rl__bookmark_details);
mBookmarkDetails.setOnTouchListener(new View.OnTouchListener()
{
@Override
public boolean onTouch(View v, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
mBookmarkDetails.getParent().requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mBookmarkDetails.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
mButtons = (ViewGroup) placePage.findViewById(R.id.pp__buttons);
initGestureDetector();
mTouchSlop = ViewConfiguration.get(mPlacePage.getContext()).getScaledTouchSlop();
}
abstract void setState(State mCurrentState, State state);
public void setOnVisibilityChangedListener(OnVisibilityChangedListener listener)
{
mVisibilityChangedListener = listener;

View file

@ -70,16 +70,16 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
{
if (distanceY < 0f)
{
if (mPlacePage.getState() == State.FULL_PLACEPAGE)
mPlacePage.setState(State.PREVIEW_ONLY);
else
if (mPlacePage.getState() == State.PREVIEW)
{
mPlacePage.setState(State.HIDDEN);
Framework.deactivatePopup();
mPlacePage.setState(State.HIDDEN);
}
else
mPlacePage.setState(State.PREVIEW);
}
else
mPlacePage.setState(State.FULL_PLACEPAGE);
mPlacePage.setState(State.DETAILS);
mIsGestureHandled = true;
}
@ -96,10 +96,10 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
if (mDownCoord < mPreview.getY() && mDownCoord < mDetails.getY())
return false;
if (mPlacePage.getState() == State.FULL_PLACEPAGE)
mPlacePage.setState(State.PREVIEW_ONLY);
if (mPlacePage.getState() == State.PREVIEW)
mPlacePage.setState(State.DETAILS);
else
mPlacePage.setState(State.FULL_PLACEPAGE);
mPlacePage.setState(State.PREVIEW);
return true;
}
@ -107,18 +107,35 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
}
@Override
protected void showPreview(final boolean show)
void setState(State currentState, State newState)
{
switch (newState)
{
case HIDDEN:
hidePlacePage();
break;
case PREVIEW:
showPreview(currentState);
break;
case BOOKMARK:
showBookmark(currentState);
break;
case DETAILS:
showDetails(currentState);
break;
}
}
protected void showPreview(final State currentState)
{
mPlacePage.setVisibility(View.VISIBLE);
mPreview.setVisibility(View.VISIBLE);
mDetails.setVisibility(View.INVISIBLE);
if (mIsPreviewVisible == show)
return;
ValueAnimator animator;
if (show)
if (currentState == State.HIDDEN)
{
animator = ValueAnimator.ofFloat(mPreview.getHeight(), 0f);
mDetails.setVisibility(View.INVISIBLE);
animator = ValueAnimator.ofFloat(mPreview.getHeight() + mButtons.getHeight(), 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
@ -131,88 +148,88 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
}
else
{
animator = ValueAnimator.ofFloat(0, mPreview.getHeight());
final float detailsHeight = mDetails.getHeight();
animator = ValueAnimator.ofFloat(ViewHelper.getTranslationY(mPreview), 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mPreview, (Float) animation.getAnimatedValue());
ViewHelper.setTranslationY(mButtons, (Float) animation.getAnimatedValue());
ViewHelper.setTranslationY(mDetails, (Float) animation.getAnimatedValue() + detailsHeight);
if (1f - animation.getAnimatedFraction() < 0.01)
{
mPlacePage.setVisibility(View.INVISIBLE);
mPlacePage.setMapObject(null);
}
if (animation.getAnimatedFraction() > .99f)
mDetails.setVisibility(View.INVISIBLE);
}
});
}
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mIsPreviewVisible = show;
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPreviewVisibilityChanged(mIsPreviewVisible);
}
@Override
protected void showPlacePage(final boolean show)
protected void showDetails(final State currentState)
{
mPlacePage.setVisibility(View.VISIBLE);
mPreview.setVisibility(View.VISIBLE);
mDetails.setVisibility(View.VISIBLE);
if (mIsPlacePageVisible == show)
return; // if state is already same as we need
ValueAnimator animator;
final float animHeight = mDetails.getHeight();
if (show)
{
animator = ValueAnimator.ofFloat(animHeight, 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mDetails, (Float) animation.getAnimatedValue());
ViewHelper.setTranslationY(mPreview, (Float) animation.getAnimatedValue() - animHeight);
}
});
}
final float bookmarkHeight = mBookmarkDetails.getHeight();
final float detailsHeight = mDetails.getHeight();
if (currentState == State.PREVIEW)
animator = ValueAnimator.ofFloat(detailsHeight, bookmarkHeight);
else
animator = ValueAnimator.ofFloat(0f, bookmarkHeight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
animator = ValueAnimator.ofFloat(0, animHeight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mDetails, (Float) animation.getAnimatedValue());
ViewHelper.setTranslationY(mPreview, (Float) animation.getAnimatedValue() - animHeight);
ViewHelper.setTranslationY(mPreview, (Float) animation.getAnimatedValue() - detailsHeight);
ViewHelper.setTranslationY(mDetails, (Float) animation.getAnimatedValue());
}
});
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
void showBookmark(final State currentState)
{
mPlacePage.setVisibility(View.VISIBLE);
mPreview.setVisibility(View.VISIBLE);
mDetails.setVisibility(View.VISIBLE);
mBookmarkDetails.setVisibility(View.VISIBLE);
ValueAnimator animator;
final float bookmarkHeight = mBookmarkDetails.getHeight();
final float detailsHeight = mDetails.getHeight();
if (currentState == State.DETAILS)
animator = ValueAnimator.ofFloat(bookmarkHeight, 0f);
else
animator = ValueAnimator.ofFloat(detailsHeight, 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mPreview, (Float) animation.getAnimatedValue() - detailsHeight);
ViewHelper.setTranslationY(mDetails, (Float) animation.getAnimatedValue());
}
});
if (1f - animation.getAnimatedFraction() < 0.01)
{
mDetails.setVisibility(View.INVISIBLE);
ViewHelper.setTranslationY(mPreview, 0f);
}
}
});
}
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
mIsPlacePageVisible = show;
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPlacePageVisibilityChanged(mIsPlacePageVisible);
}
@Override
protected void hidePlacePage()
{
final float animHeight = mPlacePage.getHeight() - mPreview.getTop() - ViewHelper.getTranslationY(mPreview);
final ValueAnimator animator = ValueAnimator.ofFloat(0, animHeight);
final ValueAnimator animator = ValueAnimator.ofFloat(0f, animHeight);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
@ -220,13 +237,13 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
{
ViewHelper.setTranslationY(mPlacePage, (Float) animation.getAnimatedValue());
if (1f - animation.getAnimatedFraction() < 0.01)
if (animation.getAnimatedFraction() > .99f)
{
mIsPlacePageVisible = false;
mIsPreviewVisible = false;
mPlacePage.setVisibility(View.INVISIBLE);
ViewHelper.setTranslationY(mPlacePage, 0f);
ViewHelper.setTranslationY(mPlacePage, 0);
if (mVisibilityChangedListener != null)
{
mVisibilityChangedListener.onPreviewVisibilityChanged(false);
@ -235,7 +252,7 @@ public class BottomPlacePageAnimationController extends BasePlacePageAnimationCo
}
}
});
animator.setDuration(LONG_ANIM_DURATION);
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}

View file

@ -86,16 +86,28 @@ public class LeftFloatPlacePageAnimationController extends BasePlacePageAnimatio
}
@Override
protected void showPlacePage(final boolean show)
void setState(State currentState, State newState)
{
if (mIsPlacePageVisible == show)
return; // if state is already same as we need
switch (newState)
{
case HIDDEN:
hidePlacePage();
break;
case BOOKMARK:
case DETAILS:
case PREVIEW:
showPlacePage(currentState, newState);
break;
}
}
protected void showPlacePage(final State currentState, final State newState)
{
mPlacePage.setVisibility(View.VISIBLE);
ValueAnimator animator;
if (show)
mBookmarkDetails.setVisibility(newState == State.BOOKMARK ? View.VISIBLE : View.GONE);
if (currentState == State.HIDDEN)
{
animator = ValueAnimator.ofFloat(mPlacePage.getHeight(), 0f);
ValueAnimator animator = ValueAnimator.ofFloat(mPlacePage.getHeight(), 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
@ -104,46 +116,37 @@ public class LeftFloatPlacePageAnimationController extends BasePlacePageAnimatio
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);
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
mVisibilityChangedListener.onPlacePageVisibilityChanged(true);
mVisibilityChangedListener.onPreviewVisibilityChanged(true);
}
@Override
protected void showPreview(final boolean show)
{
showPlacePage(show);
}
@Override
protected void hidePlacePage()
{
showPlacePage(false);
ValueAnimator animator;
animator = ValueAnimator.ofFloat(0, mPlacePage.getHeight());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationY(mPlacePage, (Float) animation.getAnimatedValue());
if (animation.getAnimatedFraction() > 0.99f)
{
mPlacePage.setVisibility(View.INVISIBLE);
mVisibilityChangedListener.onPlacePageVisibilityChanged(false);
mVisibilityChangedListener.onPreviewVisibilityChanged(false);
}
}
});
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
}

View file

@ -5,11 +5,11 @@ import android.support.v4.view.GestureDetectorCompat;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.view.animation.AccelerateInterpolator;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;
import com.mapswithme.util.UiUtils;
import com.nineoldandroids.animation.ValueAnimator;
import com.nineoldandroids.view.ViewHelper;
public class LeftFullAnimationController extends BasePlacePageAnimationController
{
@ -81,50 +81,69 @@ public class LeftFullAnimationController extends BasePlacePageAnimationControlle
});
}
@Override
protected void showPreview(final boolean show)
void setState(State currentState, State newState)
{
showPlacePage(show);
switch (newState)
{
case HIDDEN:
hidePlacePage();
break;
case BOOKMARK:
case DETAILS:
case PREVIEW:
showPlacePage(currentState, newState);
break;
}
}
@Override
protected void showPlacePage(final boolean show)
protected void showPlacePage(final State currentState, final State newState)
{
if (mIsPlacePageVisible == show)
return;
TranslateAnimation slide;
if (show)
mPlacePage.setVisibility(View.VISIBLE);
mBookmarkDetails.setVisibility(newState == State.BOOKMARK ? View.VISIBLE : View.GONE);
if (currentState == State.HIDDEN)
{
slide = UiUtils.generateRelativeSlideAnimation(-1, 0, 0, 0);
}
else
{
slide = UiUtils.generateRelativeSlideAnimation(0, -1, 0, 0);
slide.setAnimationListener(new UiUtils.SimpleAnimationListener()
ValueAnimator animator = ValueAnimator.ofFloat(-mPlacePage.getWidth(), 0f);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationEnd(Animation animation)
public void onAnimationUpdate(ValueAnimator animation)
{
mIsPlacePageVisible = false;
mIsPreviewVisible = false;
mPlacePage.setVisibility(View.GONE);
ViewHelper.setTranslationX(mPlacePage, (Float) animation.getAnimatedValue());
}
});
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
slide.setDuration(LONG_ANIM_DURATION);
mPlacePage.startAnimation(slide);
mPlacePage.setVisibility(View.VISIBLE);
if (mVisibilityChangedListener != null)
{
mVisibilityChangedListener.onPlacePageVisibilityChanged(true);
mIsPlacePageVisible = true;
}
mVisibilityChangedListener.onPlacePageVisibilityChanged(true);
mVisibilityChangedListener.onPreviewVisibilityChanged(true);
}
@Override
protected void hidePlacePage()
{
showPlacePage(false);
ValueAnimator animator;
animator = ValueAnimator.ofFloat(0f, -mPlacePage.getWidth());
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
{
@Override
public void onAnimationUpdate(ValueAnimator animation)
{
ViewHelper.setTranslationX(mPlacePage, (Float) animation.getAnimatedValue());
if (animation.getAnimatedFraction() > 0.99f)
{
mPlacePage.setVisibility(View.INVISIBLE);
mVisibilityChangedListener.onPlacePageVisibilityChanged(false);
mVisibilityChangedListener.onPreviewVisibilityChanged(false);
}
}
});
animator.setDuration(SHORT_ANIM_DURATION);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
}

View file

@ -68,7 +68,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
private TextView mTvSchedule;
private LinearLayout mLlWifi;
// Bookmark
private RelativeLayout mRlBookmarkDetails;
private ImageView mIvColor;
private EditText mEtBookmarkName;
private EditText mEtBookmarkNotes;
@ -89,8 +88,9 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
public static enum State
{
HIDDEN,
PREVIEW_ONLY,
FULL_PLACEPAGE
PREVIEW,
BOOKMARK,
DETAILS
}
public PlacePageView(Context context)
@ -150,7 +150,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
mIvColor = (ImageView) mPpDetails.findViewById(R.id.iv__bookmark_color);
mIvColor.setOnClickListener(this);
mRlBookmarkDetails = (RelativeLayout) mPpDetails.findViewById(R.id.rl__bookmark_details);
mEtBookmarkName = (EditText) mPpDetails.findViewById(R.id.et__bookmark_name);
mEtBookmarkName.setOnEditorActionListener(this);
mEtBookmarkNotes = (EditText) mPpDetails.findViewById(R.id.et__bookmark_notes);
@ -177,9 +176,6 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
case 0:
mAnimationController = new BottomPlacePageAnimationController(this);
break;
case 1:
mAnimationController = new TopPlacePageAnimationController(this);
break;
case 2:
mAnimationController = new LeftFloatPlacePageAnimationController(this);
break;
@ -208,22 +204,12 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
public void setState(State state)
{
if (mMapObject != null && mMapObject.getType() == MapObjectType.BOOKMARK && state == State.DETAILS)
state = State.BOOKMARK;
if (mCurrentState != state)
{
// Do some transitions
if (mCurrentState == State.HIDDEN && state == State.PREVIEW_ONLY)
mAnimationController.showPreview(true);
else if (mCurrentState == State.PREVIEW_ONLY && state == State.FULL_PLACEPAGE)
mAnimationController.showPlacePage(true);
else if (mCurrentState == State.PREVIEW_ONLY && state == State.HIDDEN)
mAnimationController.showPreview(false);
else if (mCurrentState == State.FULL_PLACEPAGE && state == State.PREVIEW_ONLY)
mAnimationController.showPlacePage(false);
else if (mCurrentState == State.FULL_PLACEPAGE && state == State.HIDDEN)
mAnimationController.hidePlacePage();
else
return;
mAnimationController.setState(mCurrentState, state);
mCurrentState = state;
}
}
@ -258,39 +244,27 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
{
mMapObject.setDefaultIfEmpty(getResources());
refreshPreview();
refreshDetails();
switch (mMapObject.getType())
{
case POI:
refreshPreview();
refreshDetails();
refreshDistanceToObject(LocationHelper.INSTANCE.getLastLocation());
refreshBookmarkDetails(false);
refreshButtons(false);
break;
case BOOKMARK:
refreshPreview();
refreshDetails();
refreshDistanceToObject(LocationHelper.INSTANCE.getLastLocation());
refreshBookmarkDetails(true);
refreshButtons(false);
break;
case POI:
case ADDITIONAL_LAYER:
refreshPreview();
refreshDetails();
refreshDistanceToObject(LocationHelper.INSTANCE.getLastLocation());
refreshBookmarkDetails(false);
refreshButtons(false);
break;
case API_POINT:
refreshPreview();
refreshDetails();
refreshDistanceToObject(LocationHelper.INSTANCE.getLastLocation());
refreshBookmarkDetails(false);
refreshButtons(false);
refreshButtons(true);
break;
case MY_POSITION:
refreshPreview();
refreshDetails();
refreshMyPosition(LocationHelper.INSTANCE.getLastLocation());
refreshBookmarkDetails(false);
refreshButtons(false);
@ -304,16 +278,13 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
if (isBookmark)
{
final Bookmark bookmark = (Bookmark) mMapObject;
mRlBookmarkDetails.setVisibility(View.VISIBLE);
mEtBookmarkName.setText(bookmark.getName());
mEtBookmarkNotes.setText(bookmark.getBookmarkDescription());
mTvBookmarkGroup.setText(bookmark.getCategoryName(getContext()));
mIvBookmark.setImageResource(R.drawable.ic_bookmark_on);
}
else
{
mRlBookmarkDetails.setVisibility(View.GONE);
mIvBookmark.setImageResource(R.drawable.ic_bookmark_off);
}
}
private void refreshPreview()
@ -329,9 +300,9 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
refreshLatLon();
refreshMetadataOrHide(Metadata.MetadataType.FMD_URL, mLlWebsite, mTvWebsite);
refreshMetadataOrHide(Metadata.MetadataType.FMD_PHONE_NUMBER, mLlPhone, mTvPhone);
// TODO parse schedule (natively?)
refreshMetadataOrHide(Metadata.MetadataType.FMD_OPEN_HOURS, mLlSchedule, mTvSchedule);
refreshMetadataOrHide(Metadata.MetadataType.FMD_INTERNET, mLlWifi, null);
// TODO refresh full details
}
private void refreshButtons(boolean showBackButton)
@ -446,7 +417,8 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
{
setMapObject(null);
mAnimationController.hidePlacePage();
// FIXME
// mAnimationController.hidePlacePage();
}
}
@ -506,6 +478,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
BookmarkManager.INSTANCE.deleteBookmark((Bookmark) mMapObject);
setMapObject(p);
setState(State.DETAILS);
}
else
{
@ -513,6 +486,7 @@ public class PlacePageView extends LinearLayout implements View.OnClickListener,
final Bookmark newBmk = BookmarkManager.INSTANCE.getBookmark(BookmarkManager.INSTANCE.addNewBookmark(
mMapObject.getName(), mMapObject.getLat(), mMapObject.getLon()));
setMapObject(newBmk);
setState(State.BOOKMARK);
}
Framework.invalidate();
break;

View file

@ -1,199 +0,0 @@
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.animation.Animation;
import android.view.animation.TranslateAnimation;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.widget.placepage.PlacePageView.State;
import com.mapswithme.util.UiUtils;
public class TopPlacePageAnimationController extends BasePlacePageAnimationController
{
public TopPlacePageAnimationController(@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 (Math.abs(mDownCoord - event.getRawY()) > mTouchSlop)
return true;
break;
}
return false;
}
@Override
protected void initGestureDetector()
{
// Gestures
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)
{
if (mPlacePage.getState() == State.FULL_PLACEPAGE)
mPlacePage.setState(State.PREVIEW_ONLY);
else
{
mPlacePage.setState(State.HIDDEN);
Framework.deactivatePopup();
}
}
else
mPlacePage.setState(State.FULL_PLACEPAGE);
mIsGestureHandled = true;
}
return true;
}
return false;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e)
{
if (mPlacePage.getState() == State.FULL_PLACEPAGE)
mPlacePage.setState(State.PREVIEW_ONLY);
else
mPlacePage.setState(State.FULL_PLACEPAGE);
return true;
}
});
}
@Override
protected void showPlacePage(final boolean show)
{
if (mIsPlacePageVisible == show)
return; // if state is already same as we need
TranslateAnimation slide;
if (show) // slide up
{
slide = UiUtils.generateRelativeSlideAnimation(0, 0, -1, 0);
slide.setDuration(SHORT_ANIM_DURATION);
UiUtils.show(mDetails);
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPlacePageVisibilityChanged(show);
}
else // slide down
{
slide = UiUtils.generateRelativeSlideAnimation(0, 0, 0, -1);
slide.setDuration(SHORT_ANIM_DURATION);
slide.setFillEnabled(true);
slide.setFillBefore(true);
slide.setAnimationListener(new UiUtils.SimpleAnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
UiUtils.hide(mDetails);
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPlacePageVisibilityChanged(show);
}
});
}
mDetails.startAnimation(slide);
mIsPlacePageVisible = show;
}
@Override
protected void showPreview(final boolean show)
{
if (mIsPreviewVisible == show)
return;
TranslateAnimation slide;
if (show)
{
slide = UiUtils.generateRelativeSlideAnimation(0, 0, -1, 0);
UiUtils.show(mPreview);
slide.setAnimationListener(new UiUtils.SimpleAnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPreviewVisibilityChanged(show);
}
});
}
else
{
slide = UiUtils.generateRelativeSlideAnimation(0, 0, 0, -1);
slide.setAnimationListener(new UiUtils.SimpleAnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
UiUtils.hide(mPreview);
if (mVisibilityChangedListener != null)
mVisibilityChangedListener.onPreviewVisibilityChanged(show);
}
});
}
slide.setDuration(SHORT_ANIM_DURATION);
mPreview.startAnimation(slide);
mIsPreviewVisible = show;
}
@Override
protected void hidePlacePage()
{
final TranslateAnimation slideDown = UiUtils.generateRelativeSlideAnimation(0, 0, 0, -1);
slideDown.setDuration(LONG_ANIM_DURATION);
slideDown.setAnimationListener(new UiUtils.SimpleAnimationListener()
{
@Override
public void onAnimationEnd(Animation animation)
{
mIsPlacePageVisible = false;
mIsPreviewVisible = false;
UiUtils.hide(mPreview);
UiUtils.hide(mDetails);
if (mVisibilityChangedListener != null)
{
mVisibilityChangedListener.onPreviewVisibilityChanged(false);
mVisibilityChangedListener.onPlacePageVisibilityChanged(false);
}
}
});
mPlacePage.startAnimation(slideDown);
}
}