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 android.support.v17.leanback.app;
15 
16 import static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP;
17 
18 import android.app.Fragment;
19 import android.support.annotation.RestrictTo;
20 
21 /**
22  * Fragment used by the background manager.
23  * @hide
24  */
25 @RestrictTo(LIBRARY_GROUP)
26 public final class BackgroundFragment extends Fragment {
27     private BackgroundManager mBackgroundManager;
28 
setBackgroundManager(BackgroundManager backgroundManager)29     void setBackgroundManager(BackgroundManager backgroundManager) {
30         mBackgroundManager = backgroundManager;
31     }
32 
getBackgroundManager()33     BackgroundManager getBackgroundManager() {
34         return mBackgroundManager;
35     }
36 
37     @Override
onStart()38     public void onStart() {
39         super.onStart();
40         // mBackgroundManager might be null:
41         // if BackgroundFragment is just restored by FragmentManager,
42         // and user does not call BackgroundManager.getInstance() yet.
43         if (mBackgroundManager != null) {
44             mBackgroundManager.onActivityStart();
45         }
46     }
47 
48     @Override
onResume()49     public void onResume() {
50         super.onResume();
51         // mBackgroundManager might be null:
52         // if BackgroundFragment is just restored by FragmentManager,
53         // and user does not call BackgroundManager.getInstance() yet.
54         if (mBackgroundManager != null) {
55             mBackgroundManager.onResume();
56         }
57     }
58 
59     @Override
onStop()60     public void onStop() {
61         if (mBackgroundManager != null) {
62             mBackgroundManager.onStop();
63         }
64         super.onStop();
65     }
66 
67     @Override
onDestroy()68     public void onDestroy() {
69         super.onDestroy();
70         // mBackgroundManager might be null:
71         // if BackgroundFragment is just restored by FragmentManager,
72         // and user does not call BackgroundManager.getInstance() yet.
73         if (mBackgroundManager != null) {
74             mBackgroundManager.detach();
75         }
76     }
77 }
78