117993c442c26161f684d6c0c6867a746f3148548Craig Stout/* 217993c442c26161f684d6c0c6867a746f3148548Craig Stout * Copyright (C) 2014 The Android Open Source Project 317993c442c26161f684d6c0c6867a746f3148548Craig Stout * 417993c442c26161f684d6c0c6867a746f3148548Craig Stout * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 517993c442c26161f684d6c0c6867a746f3148548Craig Stout * in compliance with the License. You may obtain a copy of the License at 617993c442c26161f684d6c0c6867a746f3148548Craig Stout * 717993c442c26161f684d6c0c6867a746f3148548Craig Stout * http://www.apache.org/licenses/LICENSE-2.0 817993c442c26161f684d6c0c6867a746f3148548Craig Stout * 917993c442c26161f684d6c0c6867a746f3148548Craig Stout * Unless required by applicable law or agreed to in writing, software distributed under the License 1017993c442c26161f684d6c0c6867a746f3148548Craig Stout * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 1117993c442c26161f684d6c0c6867a746f3148548Craig Stout * or implied. See the License for the specific language governing permissions and limitations under 1217993c442c26161f684d6c0c6867a746f3148548Craig Stout * the License. 1317993c442c26161f684d6c0c6867a746f3148548Craig Stout */ 1417993c442c26161f684d6c0c6867a746f3148548Craig Stoutpackage android.support.v17.leanback.app; 1517993c442c26161f684d6c0c6867a746f3148548Craig Stout 1617993c442c26161f684d6c0c6867a746f3148548Craig Stoutimport android.app.Fragment; 1717993c442c26161f684d6c0c6867a746f3148548Craig Stout 1817993c442c26161f684d6c0c6867a746f3148548Craig Stout/** 1917993c442c26161f684d6c0c6867a746f3148548Craig Stout * Fragment used by the background manager. 2017993c442c26161f684d6c0c6867a746f3148548Craig Stout * @hide 2117993c442c26161f684d6c0c6867a746f3148548Craig Stout */ 22f684b94c5f316e9735abc298e00c3f61642b821eCraig Stoutpublic final class BackgroundFragment extends Fragment implements 23f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout BackgroundManager.FragmentStateQueriable { 2417993c442c26161f684d6c0c6867a746f3148548Craig Stout private BackgroundManager mBackgroundManager; 2517993c442c26161f684d6c0c6867a746f3148548Craig Stout 267f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu void setBackgroundManager(BackgroundManager backgroundManager) { 2717993c442c26161f684d6c0c6867a746f3148548Craig Stout mBackgroundManager = backgroundManager; 2817993c442c26161f684d6c0c6867a746f3148548Craig Stout } 2917993c442c26161f684d6c0c6867a746f3148548Craig Stout 307f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu BackgroundManager getBackgroundManager() { 317f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu return mBackgroundManager; 327f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 337f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu 3417993c442c26161f684d6c0c6867a746f3148548Craig Stout @Override 35f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout public void onStart() { 36f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout super.onStart(); 37f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // mBackgroundManager might be null: 38f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // if BackgroundFragment is just restored by FragmentManager, 39f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // and user does not call BackgroundManager.getInstance() yet. 40f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout if (mBackgroundManager != null) { 41f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout mBackgroundManager.onActivityStart(); 42f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout } 43f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout } 44f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout 45f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout @Override 462e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout public void onResume() { 472e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout super.onResume(); 487f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // mBackgroundManager might be null: 497f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // if BackgroundFragment is just restored by FragmentManager, 507f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // and user does not call BackgroundManager.getInstance() yet. 517f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu if (mBackgroundManager != null) { 52f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout mBackgroundManager.onResume(); 537f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 542e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout } 552e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout 562e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout @Override 5717993c442c26161f684d6c0c6867a746f3148548Craig Stout public void onDestroy() { 5817993c442c26161f684d6c0c6867a746f3148548Craig Stout super.onDestroy(); 597f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // mBackgroundManager might be null: 607f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // if BackgroundFragment is just restored by FragmentManager, 617f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // and user does not call BackgroundManager.getInstance() yet. 627f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu if (mBackgroundManager != null) { 637f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu mBackgroundManager.detach(); 647f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 6517993c442c26161f684d6c0c6867a746f3148548Craig Stout } 6617993c442c26161f684d6c0c6867a746f3148548Craig Stout} 67