content: /*
   * Copyright (C) 2017 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.constraintlayoutexamples;
  
  import android.content.Intent;
  import android.content.res.Configuration;
  import android.os.Bundle;
  import android.view.View;
  
  import androidx.appcompat.app.AppCompatActivity;
  
  public class MainActivity extends AppCompatActivity {
      private String mTag = "activity_main";
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(mTag);
      }
  
      @Override
      public void onConfigurationChanged(Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          setContentView(mTag);
      }
  
      public void show(View v) {
          mTag = (String) v.getTag();
          setContentView(mTag);
      }
  
      @Override
      public void onBackPressed() {
          if (!mTag.equals("activity_main")) {
              mTag = "activity_main";
              setContentView(mTag);
          } else {
              super.onBackPressed();
          }
      }
  
      public void showConstraintSetExample(View view) {
          startActivity(new Intent(this, ConstraintSetExampleActivity.class));
      }
  
      private void setContentView(String tag) {
          int id = getResources().getIdentifier(tag, "layout", getPackageName());
          setContentView(id);
      }
  }
  