1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.tv.twopanelsettings;
18 
19 import androidx.leanback.preference.LeanbackPreferenceFragment;
20 
21 /**
22  * Child preference fragment should extend this class to make two panel settings functionality work,
23  * otherwise preview panel would not show up.
24  */
25 public abstract class SettingsPreferenceFragmentBase extends LeanbackPreferenceFragment {
26     @Override
onResume()27     public void onResume() {
28         super.onResume();
29         if (getCallbackFragment() instanceof TwoPanelSettingsFragment) {
30             TwoPanelSettingsFragment parentFragment =
31                     (TwoPanelSettingsFragment) getCallbackFragment();
32             parentFragment.addListenerForFragment(this);
33         }
34     }
35 
36     @Override
onPause()37     public void onPause() {
38         super.onPause();
39         if (getCallbackFragment() instanceof TwoPanelSettingsFragment) {
40             TwoPanelSettingsFragment parentFragment =
41                     (TwoPanelSettingsFragment) getCallbackFragment();
42             parentFragment.removeListenerForFragment(this);
43         }
44     }
45 }
46