1/*
2 * Copyright 2018 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.coordinatorlayout.widget;
18
19import android.os.Bundle;
20import android.view.WindowManager;
21
22import androidx.annotation.LayoutRes;
23import androidx.testutils.RecreatedActivity;
24
25abstract class BaseTestActivity extends RecreatedActivity {
26
27    private boolean mDestroyed;
28
29    @Override
30    protected void onCreate(Bundle savedInstanceState) {
31        super.onCreate(savedInstanceState);
32        overridePendingTransition(0, 0);
33
34        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
35        final int contentView = getContentViewLayoutResId();
36        if (contentView > 0) {
37            setContentView(contentView);
38        }
39        onContentViewSet();
40        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
41    }
42
43    @Override
44    public void finish() {
45        super.finish();
46        overridePendingTransition(0, 0);
47    }
48
49    @LayoutRes
50    protected abstract int getContentViewLayoutResId();
51
52    protected void onContentViewSet() {}
53
54    @Override
55    protected void onDestroy() {
56        super.onDestroy();
57        mDestroyed = true;
58    }
59
60    @Override
61    public boolean isDestroyed() {
62        return mDestroyed;
63    }
64}
65