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 
17 package com.example.android.support.transition.widget;
18 
19 import android.graphics.Rect;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.widget.FrameLayout;
23 
24 import androidx.annotation.NonNull;
25 import androidx.transition.Explode;
26 import androidx.transition.Transition;
27 import androidx.transition.TransitionManager;
28 
29 import com.example.android.support.transition.R;
30 
31 import java.util.ArrayList;
32 
33 /**
34  * This demonstrates usage of {@link Explode} Transition type.
35  */
36 public class ExplodeUsage extends TransitionUsageBase {
37 
38     private FrameLayout mRoot;
39     private final ArrayList<View> mViews = new ArrayList<>();
40     private final Explode mExplode = new Explode();
41 
42     final Rect mRect = new Rect();
43 
44     @Override
getLayoutResId()45     int getLayoutResId() {
46         return R.layout.explode;
47     }
48 
49     @Override
onCreate(Bundle savedInstanceState)50     protected void onCreate(Bundle savedInstanceState) {
51         super.onCreate(savedInstanceState);
52         mExplode.setEpicenterCallback(new Transition.EpicenterCallback() {
53             @Override
54             public Rect onGetEpicenter(@NonNull Transition transition) {
55                 return mRect;
56             }
57         });
58         mRoot = findViewById(R.id.root);
59         if (mViews.isEmpty()) {
60             mViews.add(findViewById(R.id.view_1));
61             mViews.add(findViewById(R.id.view_2));
62             mViews.add(findViewById(R.id.view_3));
63             mViews.add(findViewById(R.id.view_4));
64         }
65         findViewById(R.id.toggle).setOnClickListener(new View.OnClickListener() {
66             @Override
67             public void onClick(View v) {
68                 v.getGlobalVisibleRect(mRect);
69                 TransitionManager.beginDelayedTransition(mRoot, mExplode);
70                 int vis = mViews.get(0).getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE;
71                 for (View view : mViews) {
72                     view.setVisibility(vis);
73                 }
74             }
75         });
76     }
77 
78 }
79