• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 com.android.car.settings.testutils;
18 
19 import android.content.Intent;
20 
21 import androidx.annotation.Nullable;
22 import androidx.fragment.app.Fragment;
23 
24 import com.android.car.settings.common.BaseCarSettingsActivity;
25 
26 public class BaseCarSettingsTestActivity extends BaseCarSettingsActivity {
27 
28     private final TestEventListener<Intent> mStartActivityListener = new TestEventListener<>();
29     private boolean mOnBackPressedFlag;
30 
31     @Nullable
32     @Override
getInitialFragment()33     protected Fragment getInitialFragment() {
34         return null;
35     }
36 
37     @Override
onBackPressed()38     public void onBackPressed() {
39         mOnBackPressedFlag = true;
40         super.onBackPressed();
41     }
42 
43     @Override
startActivity(Intent intent)44     public void startActivity(Intent intent) {
45         mStartActivityListener.accept(intent);
46         super.startActivity(intent);
47     }
48 
49     /**
50      * Gets a boolean flag indicating whether onBackPressed has been called.
51      *
52      * @return {@code true} if onBackPressed called, {@code false} otherwise.
53      */
getOnBackPressedFlag()54     public boolean getOnBackPressedFlag() {
55         return mOnBackPressedFlag;
56     }
57 
58     /**
59      * Clear the boolean flag for onBackPressed by setting it to false.
60      */
clearOnBackPressedFlag()61     public void clearOnBackPressedFlag() {
62         mOnBackPressedFlag = false;
63     }
64 
65     /**
66      * Gets an event listener for {@link #startActivity(Intent)}
67      */
getStartActivityListener()68     public TestEventListener<Intent> getStartActivityListener() {
69         return mStartActivityListener;
70     }
71 }
72