ArcMotionUsage.java revision ac5fe7c617c66850fff75a9fce9979c6e5674b0f
1/*
2 * Copyright (C) 2017 The Android Open Source Project
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
17package com.example.android.support.transition.widget;
18
19import android.os.Bundle;
20import androidx.transition.ArcMotion;
21import androidx.transition.ChangeBounds;
22import androidx.transition.Transition;
23import androidx.transition.TransitionManager;
24import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
25import android.view.Gravity;
26import android.view.View;
27import android.widget.FrameLayout;
28
29import com.example.android.support.transition.R;
30
31/**
32 * This demonstrates usage of {@link ArcMotion}.
33 */
34public class ArcMotionUsage extends TransitionUsageBase {
35
36    private FrameLayout mRoot;
37    private View mTarget;
38    private Transition mTransition;
39
40    @Override
41    int getLayoutResId() {
42        return R.layout.arc_motion;
43    }
44
45    @Override
46    protected void onCreate(Bundle savedInstanceState) {
47        super.onCreate(savedInstanceState);
48        mRoot = findViewById(R.id.root);
49        mTarget = findViewById(R.id.target);
50        mTransition = new ChangeBounds();
51        mTransition.setPathMotion(new ArcMotion());
52        mTransition.setInterpolator(new FastOutSlowInInterpolator());
53        mTransition.setDuration(500);
54        findViewById(R.id.move).setOnClickListener(new View.OnClickListener() {
55            @Override
56            public void onClick(View v) {
57                TransitionManager.beginDelayedTransition(mRoot, mTransition);
58                FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) mTarget.getLayoutParams();
59                if ((lp.gravity & Gravity.START) == Gravity.START) {
60                    lp.gravity = Gravity.END | Gravity.BOTTOM;
61                } else {
62                    lp.gravity = Gravity.START | Gravity.TOP;
63                }
64                mTarget.setLayoutParams(lp);
65            }
66        });
67    }
68
69}
70