blob: 556b375016d7e333cad070e8895180e7543d75f2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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();
}
}
|