forked from organicmaps/organicmaps
[android] Map -> Search animation.
This commit is contained in:
parent
24555af0a6
commit
5f479ac050
7 changed files with 144 additions and 21 deletions
9
android/res/layout/fragment_recycler_no_elevation.xml
Normal file
9
android/res/layout/fragment_recycler_no_elevation.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/MwmWidget.FrameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include
|
||||
layout="@layout/recycler_default"/>
|
||||
</FrameLayout>
|
|
@ -22,21 +22,25 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tabs"
|
||||
android:theme="@style/ThemeOverlay.AppCompat"
|
||||
<LinearLayout
|
||||
android:id="@+id/tabs_layout"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/tabs_height"
|
||||
android:elevation="@dimen/appbar_elevation"
|
||||
app:tabIndicatorColor="?colorAccent"
|
||||
app:tabMode="fixed"
|
||||
app:tabGravity="fill"/>
|
||||
android:layout_height="wrap_content">
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/tabs"
|
||||
android:theme="@style/ThemeOverlay.AppCompat"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/tabs_height"
|
||||
app:tabIndicatorColor="?colorAccent"
|
||||
app:tabMode="fixed"
|
||||
app:tabGravity="fill"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/tabs_divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?dividerHorizontal"/>
|
||||
<FrameLayout
|
||||
style="@style/MwmWidget.FrameLayout.Elevation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/pages"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/MwmWidget.FrameLayout.Elevation"
|
||||
style="@style/MwmWidget.FrameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<include layout="@layout/recycler_default"/>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue