• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2024 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  *      https://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.android.devicediagnostics.evaluated
18 
19 import android.app.Activity
20 import android.os.Bundle
21 import android.view.View
22 import androidx.core.view.WindowCompat
23 import androidx.core.view.WindowInsetsCompat
24 import androidx.core.view.WindowInsetsControllerCompat
25 import com.android.devicediagnostics.R
26 
27 class ScreenTestActivity : Activity() {
28     private enum class State {
29         RED,
30         GREEN,
31         BLUE
32     }
33 
34     private var state = State.RED
35         set(value) {
36             when (value) {
37                 State.RED -> rectangle.setBackgroundColor(getColor(R.color.red))
38                 State.GREEN -> rectangle.setBackgroundColor(getColor(R.color.green))
39                 State.BLUE -> rectangle.setBackgroundColor(getColor(R.color.blue))
40             }
41             field = value
42         }
43 
44     private lateinit var rectangle: View
45 
onCreatenull46     override fun onCreate(savedInstanceState: Bundle?) {
47         super.onCreate(savedInstanceState)
48 
49         // Attempt to hide system bars
50         val windowInsetsController = WindowCompat.getInsetsController(window, window.decorView)
51         windowInsetsController.systemBarsBehavior =
52             WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
53         windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
54 
55         setContentView(R.layout.layout_evaluated_screen_test)
56         rectangle = findViewById<View>(R.id.mainLayout) ?: throw AssertionError("Can't find view")
57         rectangle.setOnClickListener {
58             when (state) {
59                 State.RED -> state = State.GREEN
60                 State.GREEN -> state = State.BLUE
61                 State.BLUE -> {
62                     nextTestActivity(this, ScreenTestFinalizeActivity::class.java.name)
63                 }
64             }
65         }
66     }
67 
onStartnull68     override fun onStart() {
69         super.onStart()
70         state = State.RED
71     }
72 }
73