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.LayoutInflater; 21import android.view.View; 22import android.widget.FrameLayout; 23import android.widget.LinearLayout; 24 25import androidx.interpolator.view.animation.FastOutSlowInInterpolator; 26import androidx.transition.ArcMotion; 27import androidx.transition.ChangeTransform; 28import androidx.transition.TransitionManager; 29 30import com.example.android.support.transition.R; 31 32/** 33 * This demonstrates basic usage of the ChangeTransform Transition. 34 */ 35public class ChangeTransformUsage extends TransitionUsageBase { 36 37 private LinearLayout mRoot; 38 private FrameLayout mContainer1; 39 private FrameLayout mContainer2; 40 private ChangeTransform mChangeTransform; 41 42 @Override 43 int getLayoutResId() { 44 return R.layout.change_transform; 45 } 46 47 @Override 48 protected void onCreate(Bundle savedInstanceState) { 49 super.onCreate(savedInstanceState); 50 mChangeTransform = new ChangeTransform(); 51 mChangeTransform.setInterpolator(new FastOutSlowInInterpolator()); 52 mChangeTransform.setPathMotion(new ArcMotion()); 53 mRoot = findViewById(R.id.root); 54 mContainer1 = findViewById(R.id.container_1); 55 mContainer2 = findViewById(R.id.container_2); 56 findViewById(R.id.toggle).setOnClickListener(new View.OnClickListener() { 57 @Override 58 public void onClick(View v) { 59 TransitionManager.beginDelayedTransition(mRoot, mChangeTransform); 60 toggle(); 61 } 62 }); 63 showRedSquare(mContainer1); 64 } 65 66 void toggle() { 67 if (mContainer2.getChildCount() > 0) { 68 mContainer2.removeAllViews(); 69 showRedSquare(mContainer1); 70 } else { 71 mContainer1.removeAllViews(); 72 showRedSquare(mContainer2); 73 mContainer2.getChildAt(0).setRotation(45); 74 } 75 } 76 77 private void showRedSquare(FrameLayout container) { 78 final View view = LayoutInflater.from(this) 79 .inflate(R.layout.red_square, container, false); 80 container.addView(view); 81 } 82 83} 84