forked from organicmaps/organicmaps
[android] Point to Pont -> Search transition animation
This commit is contained in:
parent
5f479ac050
commit
c5890ce4cd
4 changed files with 101 additions and 5 deletions
android/src/com/mapswithme
|
@ -20,6 +20,7 @@ import android.support.v7.widget.Toolbar;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.ImageButton;
|
||||
|
||||
|
@ -148,6 +149,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
|
||||
private View mPositionChooser;
|
||||
|
||||
private ViewGroup mRootView;
|
||||
|
||||
private boolean mIsFragmentContainer;
|
||||
private boolean mIsFullscreen;
|
||||
private boolean mIsFullscreenAnimating;
|
||||
|
@ -529,7 +532,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
.commit();
|
||||
}
|
||||
|
||||
findViewById(R.id.map_fragment_container).setOnTouchListener(this);
|
||||
View container = findViewById(R.id.map_fragment_container);
|
||||
container.setOnTouchListener(this);
|
||||
mRootView = (ViewGroup) container.getParent();
|
||||
}
|
||||
|
||||
private void initNavigationButtons()
|
||||
|
@ -1529,6 +1534,13 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void animateSearchPoiTransition(@NonNull final Rect startRect,
|
||||
@Nullable final Runnable runnable)
|
||||
{
|
||||
Animations.rizeTransition(mRootView, startRect, runnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUberInfoReceived(@NonNull UberInfo info)
|
||||
{
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.mapswithme.maps.routing;
|
|||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.DimenRes;
|
||||
import android.support.annotation.IntRange;
|
||||
import android.support.annotation.MainThread;
|
||||
|
@ -74,6 +75,8 @@ public class RoutingController
|
|||
* @param progress progress to be displayed.
|
||||
* */
|
||||
void updateBuildProgress(@IntRange(from = 0, to = 100) int progress, @Framework.RouterType int router);
|
||||
|
||||
void animateSearchPoiTransition(@NonNull Rect startRect, @Nullable Runnable runnable);
|
||||
}
|
||||
|
||||
private static final RoutingController sInstance = new RoutingController();
|
||||
|
@ -751,7 +754,7 @@ public class RoutingController
|
|||
build();
|
||||
}
|
||||
|
||||
void searchPoi(int slotId)
|
||||
void searchPoi(int slotId, @NonNull Rect startRect)
|
||||
{
|
||||
mLogger.d("searchPoi: " + slotId);
|
||||
Statistics.INSTANCE.trackEvent(Statistics.EventName.ROUTING_SEARCH_POINT);
|
||||
|
@ -759,8 +762,14 @@ public class RoutingController
|
|||
mWaitingPoiPickSlot = slotId;
|
||||
if (mContainer != null)
|
||||
{
|
||||
mContainer.showSearch();
|
||||
mContainer.updateMenu();
|
||||
mContainer.animateSearchPoiTransition(startRect, new Runnable() {
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
mContainer.showSearch();
|
||||
mContainer.updateMenu();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,9 @@ public class SlotFrame extends LinearLayout
|
|||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
RoutingController.get().searchPoi(mOrder);
|
||||
Rect rect = new Rect();
|
||||
mFrame.getGlobalVisibleRect(rect);
|
||||
RoutingController.get().searchPoi(mOrder, rect);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1,10 +1,17 @@
|
|||
package com.mapswithme.util;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Rect;
|
||||
import android.support.annotation.IntDef;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewPropertyAnimator;
|
||||
|
||||
import com.mapswithme.maps.MwmApplication;
|
||||
|
@ -26,6 +33,7 @@ public final class Animations
|
|||
public static final int BOTTOM = 3;
|
||||
|
||||
private static final int DURATION_DEFAULT = MwmApplication.get().getResources().getInteger(R.integer.anim_default);
|
||||
private static final int DURATION_MENU = MwmApplication.get().getResources().getInteger(R.integer.anim_menu);
|
||||
|
||||
public static void appearSliding(final View view, @AnimationDirection int appearFrom, @Nullable final Runnable completionListener)
|
||||
{
|
||||
|
@ -134,4 +142,69 @@ public final class Animations
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void rizeTransition(@NonNull ViewGroup rootView, @NonNull final Rect startRect,
|
||||
@Nullable final Runnable runnable)
|
||||
{
|
||||
Context context = rootView.getContext();
|
||||
final View view = new View(context);
|
||||
TypedArray a = null;
|
||||
try
|
||||
{
|
||||
a = context.obtainStyledAttributes(new int[] { R.attr.cardBackgroundColor });
|
||||
int color = a.getColor(0, ContextCompat.getColor(context, R.color.bg_cards));
|
||||
view.setBackgroundColor(color);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (a != null)
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
DisplayMetrics dm = context.getResources().getDisplayMetrics();
|
||||
final float screenWidth = dm.widthPixels;
|
||||
final float screenHeight = dm.heightPixels;
|
||||
final float width = startRect.width();
|
||||
final float height = startRect.height();
|
||||
ViewGroup.MarginLayoutParams lp = new ViewGroup.MarginLayoutParams((int) width,
|
||||
(int) height);
|
||||
lp.topMargin = startRect.top;
|
||||
lp.leftMargin = startRect.left;
|
||||
final float right = screenWidth - startRect.right;
|
||||
lp.rightMargin = (int) right;
|
||||
rootView.addView(view, lp);
|
||||
|
||||
ValueAnimator animator = ValueAnimator.ofFloat(0.0f, 1.0f);
|
||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
|
||||
{
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation)
|
||||
{
|
||||
final float t = (float) animation.getAnimatedValue();
|
||||
final float topMargin = startRect.top - t * startRect.top;
|
||||
final float leftMargin = startRect.left - t * startRect.left;
|
||||
final float rightMargin = right - t * right;
|
||||
final float newWidth = width + t * (screenWidth - width);
|
||||
final float newHeight = height + t * (screenHeight - height);
|
||||
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
|
||||
lp.width = (int) newWidth;
|
||||
lp.height = (int) newHeight;
|
||||
lp.topMargin = (int) topMargin;
|
||||
lp.leftMargin = (int) leftMargin;
|
||||
lp.rightMargin = (int) rightMargin;
|
||||
view.setLayoutParams(lp);
|
||||
}
|
||||
});
|
||||
animator.addListener(new UiUtils.SimpleAnimatorListener()
|
||||
{
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation)
|
||||
{
|
||||
if (runnable != null)
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
animator.setDuration(DURATION_MENU);
|
||||
animator.start();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue