1 /*
2  * Copyright 2020 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 androidx.camera.integration.uiwidgets
18 
19 import android.content.Intent
20 import android.os.Bundle
21 import androidx.activity.ComponentActivity
22 import androidx.appcompat.app.AppCompatActivity
23 import androidx.camera.integration.uiwidgets.compose.ComposeCameraActivity
24 import androidx.camera.integration.uiwidgets.databinding.ActivityMainBinding
25 import androidx.camera.integration.uiwidgets.foldable.FoldableCameraActivity
26 import androidx.camera.integration.uiwidgets.rotations.LockedOrientationActivity
27 import androidx.camera.integration.uiwidgets.rotations.OrientationConfigChangesOverriddenActivity
28 import androidx.camera.integration.uiwidgets.rotations.UnlockedOrientationActivity
29 import androidx.camera.integration.uiwidgets.viewpager.ViewPager2Activity
30 import androidx.camera.integration.uiwidgets.viewpager.ViewPagerActivity
31 
32 class MainActivity : AppCompatActivity() {
33 
onCreatenull34     override fun onCreate(savedInstanceState: Bundle?) {
35         super.onCreate(savedInstanceState)
36 
37         val binding = ActivityMainBinding.inflate(layoutInflater)
38         setContentView(binding.root)
39 
40         binding.rotationUnlocked.setOnClickListener {
41             launch(UnlockedOrientationActivity::class.java)
42         }
43         binding.rotationLocked.setOnClickListener { launch(LockedOrientationActivity::class.java) }
44         binding.rotationConfigChanges.setOnClickListener {
45             launch(OrientationConfigChangesOverriddenActivity::class.java)
46         }
47         binding.viewpager.setOnClickListener { launch(ViewPagerActivity::class.java) }
48         binding.viewpager2.setOnClickListener { launch(ViewPager2Activity::class.java) }
49         binding.foldable.setOnClickListener { launch(FoldableCameraActivity::class.java) }
50         binding.compose.setOnClickListener { launch(ComposeCameraActivity::class.java) }
51     }
52 
launchnull53     private fun <A : ComponentActivity> launch(activityClass: Class<A>) {
54         val intent = Intent(this, activityClass)
55         startActivity(intent)
56     }
57 }
58