From 5f479ac050b9964d6d26a46dec3dbc75dc1b665b Mon Sep 17 00:00:00 2001 From: Roman Romanov Date: Tue, 22 Nov 2016 13:01:54 +0400 Subject: [PATCH] [android] Map -> Search animation. --- .../layout/fragment_recycler_no_elevation.xml | 9 +++ android/res/layout/fragment_search.xml | 30 +++++---- android/res/layout/fragment_search_recent.xml | 2 +- .../maps/search/SearchActivity.java | 5 ++ .../search/SearchAnimationController.java | 67 +++++++++++++++++++ .../maps/search/SearchCategoriesFragment.java | 8 +++ .../maps/search/SearchFragment.java | 44 ++++++++++-- 7 files changed, 144 insertions(+), 21 deletions(-) create mode 100644 android/res/layout/fragment_recycler_no_elevation.xml create mode 100644 android/src/com/mapswithme/maps/search/SearchAnimationController.java diff --git a/android/res/layout/fragment_recycler_no_elevation.xml b/android/res/layout/fragment_recycler_no_elevation.xml new file mode 100644 index 0000000000..8690ded633 --- /dev/null +++ b/android/res/layout/fragment_recycler_no_elevation.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/android/res/layout/fragment_search.xml b/android/res/layout/fragment_search.xml index 8351a568f9..fbbae56c08 100644 --- a/android/res/layout/fragment_search.xml +++ b/android/res/layout/fragment_search.xml @@ -22,21 +22,25 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> - + android:layout_height="wrap_content"> + - + + diff --git a/android/src/com/mapswithme/maps/search/SearchActivity.java b/android/src/com/mapswithme/maps/search/SearchActivity.java index f915c7f532..73234dcd9f 100644 --- a/android/src/com/mapswithme/maps/search/SearchActivity.java +++ b/android/src/com/mapswithme/maps/search/SearchActivity.java @@ -1,5 +1,6 @@ package com.mapswithme.maps.search; +import android.app.Activity; import android.content.Context; import android.content.Intent; import android.support.annotation.NonNull; @@ -22,6 +23,8 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav final Intent i = new Intent(context, SearchActivity.class); i.putExtra(EXTRA_QUERY, query); context.startActivity(i); + if (context instanceof Activity) + ((Activity) context).overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } @Override @@ -44,6 +47,7 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav if (manager.getBackStackEntryCount() == 0) { NavUtils.navigateUpFromSameTask(this); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); return; } @@ -58,5 +62,6 @@ public class SearchActivity extends BaseMwmFragmentActivity implements CustomNav return; super.onBackPressed(); + overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } } diff --git a/android/src/com/mapswithme/maps/search/SearchAnimationController.java b/android/src/com/mapswithme/maps/search/SearchAnimationController.java new file mode 100644 index 0000000000..556b375016 --- /dev/null +++ b/android/src/com/mapswithme/maps/search/SearchAnimationController.java @@ -0,0 +1,67 @@ +package com.mapswithme.maps.search; + +import android.animation.Animator; +import android.animation.ValueAnimator; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.view.View; + +import com.mapswithme.maps.MwmApplication; +import com.mapswithme.maps.R; +import com.mapswithme.util.UiUtils; + +final class SearchAnimationController +{ + private static final int DURATION = MwmApplication.get().getResources().getInteger(R.integer.anim_menu); + + @NonNull + private final View mToolbar; + @NonNull + private final View mTabBar; + + SearchAnimationController(@NonNull View toolbar, @NonNull View tabBar) + { + mToolbar = toolbar; + mTabBar = tabBar; + } + + void animate(final boolean show, @Nullable final Runnable completion) + { + if (mToolbar.getHeight() == 0 || mTabBar.getHeight() == 0) + { + mToolbar.post(new Runnable() + { + @Override + public void run() + { + animate(show, completion); + } + }); + return; + } + final float translation = -mTabBar.getHeight() - mToolbar.getHeight(); + ValueAnimator animator = + ValueAnimator.ofFloat(show ? translation: 0, show ? 0 : translation); + animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() + { + @Override + public void onAnimationUpdate(ValueAnimator animation) + { + final float value = (float) animation.getAnimatedValue(); + mToolbar.setTranslationY(value); + mTabBar.setTranslationY(value); + } + }); + animator.addListener(new UiUtils.SimpleAnimatorListener() + { + @Override + public void onAnimationEnd(Animator animation) + { + if (completion != null) + completion.run(); + } + }); + animator.setDuration(DURATION); + animator.start(); + } +} diff --git a/android/src/com/mapswithme/maps/search/SearchCategoriesFragment.java b/android/src/com/mapswithme/maps/search/SearchCategoriesFragment.java index 305ea4aabd..77155d2c74 100644 --- a/android/src/com/mapswithme/maps/search/SearchCategoriesFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchCategoriesFragment.java @@ -3,6 +3,8 @@ package com.mapswithme.maps.search; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; + +import com.mapswithme.maps.R; import com.mapswithme.maps.base.BaseMwmRecyclerFragment; public class SearchCategoriesFragment extends BaseMwmRecyclerFragment @@ -14,6 +16,12 @@ public class SearchCategoriesFragment extends BaseMwmRecyclerFragment return new CategoriesAdapter(this); } + @Override + protected int getLayoutRes() + { + return R.layout.fragment_recycler_no_elevation; + } + @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { diff --git a/android/src/com/mapswithme/maps/search/SearchFragment.java b/android/src/com/mapswithme/maps/search/SearchFragment.java index 0a655d7a1b..669afe9e8d 100644 --- a/android/src/com/mapswithme/maps/search/SearchFragment.java +++ b/android/src/com/mapswithme/maps/search/SearchFragment.java @@ -116,7 +116,16 @@ public class SearchFragment extends BaseMwmFragment public void onUpClick() { if (!onBackPressed()) - super.onUpClick(); + { + mAnimationController.animate(false, new Runnable() + { + @Override + public void run() + { + ToolbarController.super.onUpClick(); + } + }); + } } } @@ -125,6 +134,7 @@ public class SearchFragment extends BaseMwmFragment private View mResultsPlaceholder; private SearchToolbarController mToolbarController; + private SearchAnimationController mAnimationController; private SearchAdapter mSearchAdapter; @@ -224,12 +234,13 @@ public class SearchFragment extends BaseMwmFragment mTabFrame = root.findViewById(R.id.tab_frame); ViewPager pager = (ViewPager) mTabFrame.findViewById(R.id.pages); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) - UiUtils.hide(mTabFrame.findViewById(R.id.tabs_divider)); - mToolbarController = new ToolbarController(view); - final TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), pager, (TabLayout) root.findViewById(R.id.tabs)); + TabLayout tabLayout = (TabLayout) root.findViewById(R.id.tabs); + final TabAdapter tabAdapter = new TabAdapter(getChildFragmentManager(), pager, tabLayout); + + mAnimationController = new SearchAnimationController(mToolbarController.getToolbar(), + mTabFrame.findViewById(R.id.tabs_layout)); mResultsFrame = root.findViewById(R.id.results_frame); RecyclerView results = (RecyclerView) mResultsFrame.findViewById(R.id.recycler); @@ -274,6 +285,8 @@ public class SearchFragment extends BaseMwmFragment mToolbarController.deactivate(); } }); + + mAnimationController.animate(true, null); } @Override @@ -480,10 +493,27 @@ public class SearchFragment extends BaseMwmFragment if (mFromRoutePlan) { RoutingController.get().onPoiSelected(null); - return !(getActivity() instanceof SearchActivity); + final boolean isSearchActivity = getActivity() instanceof SearchActivity; + if (isSearchActivity) + closeSearch(); + return true; } - return false; + closeSearch(); + return true; + } + + private void closeSearch() + { + mAnimationController.animate(false, new Runnable() + { + @Override + public void run() + { + getActivity().finish(); + getActivity().overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); + } + }); } public void setRecyclerScrollListener(RecyclerView recycler)