Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright 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.Gravity;
     21 import android.view.View;
     22 import android.widget.LinearLayout;
     23 
     24 import androidx.transition.AutoTransition;
     25 import androidx.transition.SidePropagation;
     26 import androidx.transition.Transition;
     27 import androidx.transition.TransitionManager;
     28 
     29 import com.example.android.support.transition.R;
     30 
     31 /**
     32  * Demonstrates usage of Slide.
     33  */
     34 public class SidePropagationUsage extends TransitionUsageBase {
     35 
     36     private Transition mTransition;
     37 
     38     private LinearLayout mRoot;
     39 
     40     private boolean mVisible = true;
     41 
     42     @Override
     43     int getLayoutResId() {
     44         return R.layout.slide;
     45     }
     46 
     47     @Override
     48     protected void onCreate(Bundle savedInstanceState) {
     49         super.onCreate(savedInstanceState);
     50 
     51         mTransition = new AutoTransition();
     52         final SidePropagation propagation = new SidePropagation();
     53         propagation.setSide(Gravity.END);
     54         propagation.setPropagationSpeed(0.4f);
     55         mTransition.setPropagation(propagation);
     56 
     57         mRoot = findViewById(R.id.root);
     58         findViewById(R.id.toggle).setOnClickListener(v -> {
     59             mVisible = !mVisible;
     60             TransitionManager.beginDelayedTransition(mRoot, mTransition);
     61             for (int i = 0, count = mRoot.getChildCount(); i < count; i++) {
     62                 mRoot.getChildAt(i).setVisibility(mVisible ? View.VISIBLE : View.GONE);
     63             }
     64         });
     65     }
     66 
     67 }
     68