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 168e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikasimport static android.support.annotation.RestrictTo.Scope.LIBRARY_GROUP; 17181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu 1817993c442c26161f684d6c0c6867a746f3148548Craig Stoutimport android.app.Fragment; 19c39d9c75590eca86a5e7e32a8824ba04a0d42e9bAlan Viveretteimport android.support.annotation.RestrictTo; 20c39d9c75590eca86a5e7e32a8824ba04a0d42e9bAlan Viverette 2117993c442c26161f684d6c0c6867a746f3148548Craig Stout/** 2217993c442c26161f684d6c0c6867a746f3148548Craig Stout * Fragment used by the background manager. 2317993c442c26161f684d6c0c6867a746f3148548Craig Stout * @hide 2417993c442c26161f684d6c0c6867a746f3148548Craig Stout */ 258e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas@RestrictTo(LIBRARY_GROUP) 26181c8847d5a1169e26755ed690131333b7fff7e9Dake Gupublic final class BackgroundFragment extends Fragment { 2717993c442c26161f684d6c0c6867a746f3148548Craig Stout private BackgroundManager mBackgroundManager; 2817993c442c26161f684d6c0c6867a746f3148548Craig Stout 297f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu void setBackgroundManager(BackgroundManager backgroundManager) { 3017993c442c26161f684d6c0c6867a746f3148548Craig Stout mBackgroundManager = backgroundManager; 3117993c442c26161f684d6c0c6867a746f3148548Craig Stout } 3217993c442c26161f684d6c0c6867a746f3148548Craig Stout 337f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu BackgroundManager getBackgroundManager() { 347f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu return mBackgroundManager; 357f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 367f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu 3717993c442c26161f684d6c0c6867a746f3148548Craig Stout @Override 38f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout public void onStart() { 39f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout super.onStart(); 40f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // mBackgroundManager might be null: 41f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // if BackgroundFragment is just restored by FragmentManager, 42f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout // and user does not call BackgroundManager.getInstance() yet. 43f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout if (mBackgroundManager != null) { 44f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout mBackgroundManager.onActivityStart(); 45f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout } 46f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout } 47f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout 48f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout @Override 492e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout public void onResume() { 502e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout super.onResume(); 517f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // mBackgroundManager might be null: 527f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // if BackgroundFragment is just restored by FragmentManager, 537f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // and user does not call BackgroundManager.getInstance() yet. 547f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu if (mBackgroundManager != null) { 55f684b94c5f316e9735abc298e00c3f61642b821eCraig Stout mBackgroundManager.onResume(); 567f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 572e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout } 582e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout 592e2e91a93f6d03108a73e7b4a05d289589957a0eCraig Stout @Override 60181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu public void onStop() { 61181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu if (mBackgroundManager != null) { 62181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu mBackgroundManager.onStop(); 63181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu } 64181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu super.onStop(); 65181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu } 66181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu 67181c8847d5a1169e26755ed690131333b7fff7e9Dake Gu @Override 6817993c442c26161f684d6c0c6867a746f3148548Craig Stout public void onDestroy() { 6917993c442c26161f684d6c0c6867a746f3148548Craig Stout super.onDestroy(); 707f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // mBackgroundManager might be null: 717f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // if BackgroundFragment is just restored by FragmentManager, 727f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu // and user does not call BackgroundManager.getInstance() yet. 737f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu if (mBackgroundManager != null) { 747f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu mBackgroundManager.detach(); 757f0ed3452a3378c851217cd300950ba2e03f2649Dake Gu } 7617993c442c26161f684d6c0c6867a746f3148548Craig Stout } 7717993c442c26161f684d6c0c6867a746f3148548Craig Stout} 78