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