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