content: /*
   * Copyright (C) 2021 The Android Open Source Project
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package com.example.android.constraintapi;
  
  //BEGIN_INCLUDE(Example)
  import android.content.Context;
  import android.os.Bundle;
  import android.support.constraint.ConstraintLayout;
  import android.support.constraint.ConstraintSet;
  import android.support.transition.TransitionManager;
  import android.support.v7.app.AppCompatActivity;
  import android.view.View;
  
  public class MainActivity extends AppCompatActivity {
      ConstraintSet mConstraintSet1 = new ConstraintSet(); // create a Constraint Set
      ConstraintSet mConstraintSet2 = new ConstraintSet(); // create a Constraint Set
      ConstraintLayout mConstraintLayout; // cache the ConstraintLayout
      boolean mOld = true;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          Context context = this;
          mConstraintSet2.clone(context, R.layout.state2); // get constraints from layout
          setContentView(R.layout.state1);
          mConstraintLayout = (ConstraintLayout) findViewById(R.id.activity_main);
          mConstraintSet1.clone(mConstraintLayout); // get constraints from ConstraintSet
      }
  
      /**
       * @TODO: add description
       * @param view
       */
      public void foo(View view) {
          TransitionManager.beginDelayedTransition(mConstraintLayout);
          if (mOld = !mOld) {
              mConstraintSet1.applyTo(mConstraintLayout); // set new constraints
          }  else {
              mConstraintSet2.applyTo(mConstraintLayout); // set new constraints
          }
      }
  }
  //END_INCLUDE(Example)
  