blob: 61a72c07df07d7adec002e3a217a7dcafe8490ad [file] [log] [blame]
kailianc52f91212022-01-17 23:10:00 -08001/*
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
17package androidx.camera.previewview.utils;
18
19import android.app.Activity;
20import android.os.Bundle;
21
22import androidx.annotation.NonNull;
23import androidx.annotation.Nullable;
24import androidx.annotation.RequiresApi;
25import androidx.test.espresso.idling.CountingIdlingResource;
26
27/** An empty activity that checks the activity's <em>main</em> window currently has window focus. */
28@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
29public class ForegroundTestActivity extends Activity {
30
31 final CountingIdlingResource mViewReady = new CountingIdlingResource("ViewReady");
32
33 @NonNull
34 public CountingIdlingResource getViewReadyIdlingResource() {
35 return mViewReady;
36 }
37
38 @Override
39 protected void onCreate(@Nullable Bundle savedInstanceState) {
40 super.onCreate(savedInstanceState);
41 mViewReady.increment();
42 }
43
44 @Override
45 public void onWindowFocusChanged(boolean hasFocus) {
46 super.onWindowFocusChanged(hasFocus);
47 if (hasFocus && !mViewReady.isIdleNow()) {
48 mViewReady.decrement();
49 }
50 }
51}