float
. This type-specific subclass enables performance benefit by allowing
62 | * calls to a {@link #set(Object, Float) set()} function that takes the primitive
63 | * float
type and avoids autoboxing and other overhead associated with the
64 | * Float
class.
65 | *
66 | * @param float
.
76 | */
77 | public abstract void setValue(T object, float value);
78 |
79 | @Override
80 | final public void set(T object, Float value) {
81 | setValue(object, value);
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/OnetimeViewTreeObserver.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation;
2 |
3 | import android.view.View;
4 | import android.view.ViewTreeObserver;
5 |
6 | public class OnetimeViewTreeObserver {
7 | public static void addOnPreDrawListener(final View view, final OnetimeViewTreeObserver.OnPreDrawListener listener) {
8 | view.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
9 | @Override
10 | public boolean onPreDraw() {
11 | view.getViewTreeObserver().removeOnPreDrawListener(this);
12 | listener.onPreDraw();
13 | return false;
14 | }
15 | });
16 | }
17 |
18 | public interface OnPreDrawListener {
19 | void onPreDraw();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/transition/BlinkDebugTransition.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation.transition;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.TargetApi;
7 | import android.content.Context;
8 | import android.graphics.Rect;
9 | import android.os.Build;
10 | import android.transition.Transition;
11 | import android.transition.TransitionValues;
12 | import android.transition.Visibility;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | @TargetApi(Build.VERSION_CODES.KITKAT)
18 | public class BlinkDebugTransition extends Transition {
19 | private static final String PROP_BOUNDS = "mdap:fabTransform:bounds";
20 |
21 | private static final String[] transitionProperties = {
22 | PROP_BOUNDS
23 | };
24 |
25 | public BlinkDebugTransition() {
26 | super();
27 | }
28 |
29 | public BlinkDebugTransition(Context context, AttributeSet attrs) {
30 | super(context, attrs);
31 | setDuration(5000);
32 | }
33 |
34 | @Override
35 | public String[] getTransitionProperties() {
36 | return transitionProperties;
37 | }
38 |
39 | @Override
40 | public void captureStartValues(TransitionValues transitionValues) {
41 | captureValues(transitionValues);
42 | }
43 |
44 | @Override
45 | public void captureEndValues(TransitionValues transitionValues) {
46 | captureValues(transitionValues);
47 | }
48 |
49 |
50 | private void captureValues(TransitionValues transitionValues) {
51 | final View view = transitionValues.view;
52 | if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;
53 |
54 | transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(),
55 | view.getRight(), view.getBottom()));
56 | }
57 |
58 |
59 | @Override
60 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
61 | TransitionValues endValues) {
62 | if (startValues == null || endValues == null) return null;
63 |
64 | final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
65 | final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);
66 |
67 | final View view = endValues.view;
68 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
69 | alphaAnim.setDuration(5);
70 | alphaAnim.setRepeatCount(ValueAnimator.INFINITE);
71 | alphaAnim.setRepeatMode(ValueAnimator.REVERSE);
72 | return alphaAnim;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/transition/BlinkVisibilityDebugTransition.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation.transition;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.content.Context;
7 | import android.graphics.Rect;
8 | import android.transition.TransitionValues;
9 | import android.transition.Visibility;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 |
14 | @SuppressWarnings("unused")
15 | public class BlinkVisibilityDebugTransition extends Visibility {
16 | private static final String PROP_BOUNDS = "mdap:fabTransform:bounds";
17 |
18 | private static final String[] transitionProperties = {
19 | PROP_BOUNDS
20 | };
21 |
22 | public BlinkVisibilityDebugTransition() {
23 | super();
24 | }
25 |
26 | public BlinkVisibilityDebugTransition(Context context, AttributeSet attrs) {
27 | super(context, attrs);
28 | }
29 |
30 | @Override
31 | public String[] getTransitionProperties() {
32 | return transitionProperties;
33 | }
34 |
35 | @Override
36 | public void captureStartValues(TransitionValues transitionValues) {
37 | captureValues(transitionValues);
38 | }
39 |
40 | @Override
41 | public void captureEndValues(TransitionValues transitionValues) {
42 | captureValues(transitionValues);
43 | }
44 |
45 |
46 | private void captureValues(TransitionValues transitionValues) {
47 | final View view = transitionValues.view;
48 | if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;
49 |
50 | transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(),
51 | view.getRight(), view.getBottom()));
52 | }
53 |
54 |
55 | @Override
56 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
57 | TransitionValues endValues) {
58 | if (startValues == null || endValues == null) return null;
59 |
60 | final Rect startBounds = (Rect) startValues.values.get(PROP_BOUNDS);
61 | final Rect endBounds = (Rect) endValues.values.get(PROP_BOUNDS);
62 |
63 | final View view = endValues.view;
64 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
65 | alphaAnim.setDuration(5);
66 | alphaAnim.setRepeatCount(ValueAnimator.INFINITE);
67 | alphaAnim.setRepeatMode(ValueAnimator.REVERSE);
68 | return alphaAnim;
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/transition/FadeInTransition.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation.transition;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.TargetApi;
7 | import android.content.Context;
8 | import android.graphics.Rect;
9 | import android.os.Build;
10 | import android.support.v4.view.animation.LinearOutSlowInInterpolator;
11 | import android.transition.Transition;
12 | import android.transition.TransitionValues;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | /**
18 | * SharedElementTransition cannot Visibility transition like fade
19 | * So I create this transtiion.
20 | */
21 | @TargetApi(Build.VERSION_CODES.KITKAT)
22 | public class FadeInTransition extends Transition {
23 | private static final String PROP_BOUNDS = "mdap:fabTransform:bounds";
24 |
25 | private static final String[] transitionProperties = {
26 | PROP_BOUNDS
27 | };
28 |
29 | public FadeInTransition() {
30 | super();
31 | }
32 |
33 | public FadeInTransition(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | @Override
38 | public String[] getTransitionProperties() {
39 | return transitionProperties;
40 | }
41 |
42 | @Override
43 | public void captureStartValues(TransitionValues transitionValues) {
44 | captureValues(transitionValues);
45 | }
46 |
47 | @Override
48 | public void captureEndValues(TransitionValues transitionValues) {
49 | captureValues(transitionValues);
50 | }
51 |
52 |
53 | private void captureValues(TransitionValues transitionValues) {
54 | final View view = transitionValues.view;
55 | if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;
56 |
57 | transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(),
58 | view.getRight(), view.getBottom()));
59 | }
60 |
61 |
62 | @Override
63 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
64 | TransitionValues endValues) {
65 | if (startValues == null || endValues == null) return null;
66 |
67 | final View view = endValues.view;
68 | view.setAlpha(0f);
69 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
70 | alphaAnim.setDuration(getDuration());
71 | alphaAnim.setInterpolator(getInterpolator());
72 | return alphaAnim;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/transition/FadeOutTransition.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation.transition;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.animation.ValueAnimator;
6 | import android.annotation.TargetApi;
7 | import android.content.Context;
8 | import android.graphics.Rect;
9 | import android.os.Build;
10 | import android.support.v4.view.animation.LinearOutSlowInInterpolator;
11 | import android.transition.Transition;
12 | import android.transition.TransitionValues;
13 | import android.util.AttributeSet;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 |
17 | /**
18 | * SharedElementTransition cannot Visibility transition like fade
19 | * So I create this transtiion.
20 | */
21 | @TargetApi(Build.VERSION_CODES.KITKAT)
22 | public class FadeOutTransition extends Transition {
23 | private static final String PROP_BOUNDS = "mdap:fabTransform:bounds";
24 |
25 | private static final String[] transitionProperties = {
26 | PROP_BOUNDS
27 | };
28 |
29 | public FadeOutTransition() {
30 | super();
31 | }
32 |
33 | public FadeOutTransition(Context context, AttributeSet attrs) {
34 | super(context, attrs);
35 | }
36 |
37 | @Override
38 | public String[] getTransitionProperties() {
39 | return transitionProperties;
40 | }
41 |
42 | @Override
43 | public void captureStartValues(TransitionValues transitionValues) {
44 | captureValues(transitionValues);
45 | }
46 |
47 | @Override
48 | public void captureEndValues(TransitionValues transitionValues) {
49 | captureValues(transitionValues);
50 | }
51 |
52 |
53 | private void captureValues(TransitionValues transitionValues) {
54 | final View view = transitionValues.view;
55 | if (view == null || view.getWidth() <= 0 || view.getHeight() <= 0) return;
56 |
57 | transitionValues.values.put(PROP_BOUNDS, new Rect(view.getLeft(), view.getTop(),
58 | view.getRight(), view.getBottom()));
59 | }
60 |
61 |
62 | @Override
63 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues,
64 | TransitionValues endValues) {
65 | if (startValues == null || endValues == null) return null;
66 |
67 | final View view = endValues.view;
68 | view.setAlpha(1f);
69 | ValueAnimator alphaAnim = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
70 | alphaAnim.setDuration(getDuration());
71 | alphaAnim.setInterpolator(getInterpolator());
72 | return alphaAnim;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/github/takahirom/materialelement/animation/transition/LiftOff.java:
--------------------------------------------------------------------------------
1 | package com.github.takahirom.materialelement.animation.transition;
2 |
3 | import android.animation.Animator;
4 | import android.animation.ObjectAnimator;
5 | import android.content.Context;
6 | import android.content.res.TypedArray;
7 | import android.transition.Transition;
8 | import android.transition.TransitionValues;
9 | import android.util.AttributeSet;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 |
13 | import com.github.takahirom.materialelement.R;
14 |
15 |
16 | /**
17 | * A transition that animates the elevation of a View from a given value down to zero.
18 | * 19 | * Useful for creating parent↔child navigation transitions 20 | * (https://www.google.com/design/spec/patterns/navigational-transitions.html#navigational-transitions-parent-to-child) 21 | * when combined with a {@link android.transition.ChangeBounds} on a shared element. 22 | */ 23 | public class LiftOff extends Transition { 24 | 25 | private static final String PROPNAME_ELEVATION = "plaid:liftoff:elevation"; 26 | 27 | private static final String[] transitionProperties = { 28 | PROPNAME_ELEVATION 29 | }; 30 | 31 | private final float initialElevation; 32 | private final float finalElevation; 33 | 34 | public LiftOff(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | final TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LiftOff); 37 | initialElevation = ta.getDimension(R.styleable.LiftOff_initialElevation, 0f); 38 | finalElevation = ta.getDimension(R.styleable.LiftOff_finalElevation, 0f); 39 | ta.recycle(); 40 | } 41 | 42 | @Override 43 | public String[] getTransitionProperties() { 44 | return transitionProperties; 45 | } 46 | 47 | @Override 48 | public void captureStartValues(TransitionValues transitionValues) { 49 | transitionValues.values.put(PROPNAME_ELEVATION, initialElevation); 50 | } 51 | 52 | @Override 53 | public void captureEndValues(TransitionValues transitionValues) { 54 | transitionValues.values.put(PROPNAME_ELEVATION, finalElevation); 55 | } 56 | 57 | @Override 58 | public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, 59 | TransitionValues endValues) { 60 | return ObjectAnimator.ofFloat(endValues.view, View.TRANSLATION_Z, 61 | initialElevation, finalElevation); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /app/src/main/java/com/github/takahirom/materialelement/animation/transition/StaggeredDistanceSlide.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package com.github.takahirom.materialelement.animation.transition; 18 | 19 | import android.animation.Animator; 20 | import android.animation.AnimatorListenerAdapter; 21 | import android.animation.ObjectAnimator; 22 | import android.annotation.TargetApi; 23 | import android.content.Context; 24 | import android.content.res.TypedArray; 25 | import android.os.Build; 26 | import android.support.annotation.Keep; 27 | import android.transition.TransitionValues; 28 | import android.transition.Visibility; 29 | import android.util.AttributeSet; 30 | import android.view.View; 31 | import android.view.ViewGroup; 32 | 33 | import com.github.takahirom.materialelement.R; 34 | 35 | import java.util.List; 36 | 37 | 38 | /** 39 | * An alternative to {@link android.transition.Slide} which staggers elements by distance 40 | * rather than using start delays. That is elements start from/end at a progressively increasing 41 | * displacement such that they come together/move apart over the same duration as they default_window_enter/exit. 42 | * This can produce more cohesive choreography. The displacement factor can be controlled by the 43 | * {@code spread} attribute. 44 | *
45 | * Currently only supports entering/exiting from the bottom edge.
46 | */
47 | @TargetApi(Build.VERSION_CODES.LOLLIPOP)
48 | public class StaggeredDistanceSlide extends Visibility {
49 |
50 | private static final String PROPNAME_SCREEN_LOCATION = "android:visibility:screenLocation";
51 |
52 | private int spread = 1;
53 |
54 | public StaggeredDistanceSlide() {
55 | super();
56 | }
57 |
58 | @Keep
59 | public StaggeredDistanceSlide(Context context, AttributeSet attrs) {
60 | super(context, attrs);
61 | final TypedArray a =
62 | context.obtainStyledAttributes(attrs, R.styleable.StaggeredDistanceSlide);
63 | spread = a.getInteger(R.styleable.StaggeredDistanceSlide_spread, spread);
64 | a.recycle();
65 | }
66 |
67 | public int getSpread() {
68 | return spread;
69 | }
70 |
71 | public void setSpread(int spread) {
72 | this.spread = spread;
73 | }
74 |
75 | @Override
76 | public Animator onAppear(ViewGroup sceneRoot, View view,
77 | TransitionValues startValues, TransitionValues endValues) {
78 | int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION);
79 | return createAnimator(view, sceneRoot.getHeight() + (position[1] * spread), 0f);
80 | }
81 |
82 | @Override
83 | public Animator onDisappear(ViewGroup sceneRoot, View view,
84 | TransitionValues startValues, TransitionValues endValues) {
85 | int[] position = (int[]) endValues.values.get(PROPNAME_SCREEN_LOCATION);
86 | return createAnimator(view, 0f, sceneRoot.getHeight() + (position[1] * spread));
87 | }
88 |
89 | private Animator createAnimator(
90 | final View view, float startTranslationY, float endTranslationY) {
91 | view.setTranslationY(startTranslationY);
92 | final List