Home | History | Annotate | Download | only in widget
      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.os.Bundle;
     20 import android.view.LayoutInflater;
     21 import android.view.View;
     22 import android.widget.FrameLayout;
     23 import android.widget.LinearLayout;
     24 
     25 import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
     26 import androidx.transition.ArcMotion;
     27 import androidx.transition.ChangeTransform;
     28 import androidx.transition.TransitionManager;
     29 
     30 import com.example.android.support.transition.R;
     31 
     32 /**
     33  * This demonstrates basic usage of the ChangeTransform Transition.
     34  */
     35 public 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