• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package androidx.leanback.app;
15 
16 import static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP;
17 
18 import android.app.Fragment;
19 
20 import androidx.annotation.RestrictTo;
21 
22 /**
23  * Fragment used by the background manager.
24  * @hide
25  */
26 @RestrictTo(LIBRARY_GROUP)
27 public final class BackgroundFragment extends Fragment {
28     private BackgroundManager mBackgroundManager;
29 
setBackgroundManager(BackgroundManager backgroundManager)30     void setBackgroundManager(BackgroundManager backgroundManager) {
31         mBackgroundManager = backgroundManager;
32     }
33 
getBackgroundManager()34     BackgroundManager getBackgroundManager() {
35         return mBackgroundManager;
36     }
37 
38     @Override
onStart()39     public void onStart() {
40         super.onStart();
41         // mBackgroundManager might be null:
42         // if BackgroundFragment is just restored by FragmentManager,
43         // and user does not call BackgroundManager.getInstance() yet.
44         if (mBackgroundManager != null) {
45             mBackgroundManager.onActivityStart();
46         }
47     }
48 
49     @Override
onResume()50     public void onResume() {
51         super.onResume();
52         // mBackgroundManager might be null:
53         // if BackgroundFragment is just restored by FragmentManager,
54         // and user does not call BackgroundManager.getInstance() yet.
55         if (mBackgroundManager != null) {
56             mBackgroundManager.onResume();
57         }
58     }
59 
60     @Override
onStop()61     public void onStop() {
62         if (mBackgroundManager != null) {
63             mBackgroundManager.onStop();
64         }
65         super.onStop();
66     }
67 
68     @Override
onDestroy()69     public void onDestroy() {
70         super.onDestroy();
71         // mBackgroundManager might be null:
72         // if BackgroundFragment is just restored by FragmentManager,
73         // and user does not call BackgroundManager.getInstance() yet.
74         if (mBackgroundManager != null) {
75             mBackgroundManager.detach();
76         }
77     }
78 }
79