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