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 android.os.Bundle; 20 import android.view.View; 21 22 import androidx.annotation.NonNull; 23 import androidx.leanback.preference.LeanbackPreferenceFragmentCompat; 24 25 /** 26 * Child preference fragment should extend this class to make two panel settings functionality work, 27 * otherwise preview panel would not show up. 28 */ 29 public abstract class SettingsPreferenceFragmentBase extends LeanbackPreferenceFragmentCompat { 30 @Override onViewCreated(@onNull View view, Bundle savedInstanceState)31 public void onViewCreated(@NonNull View view, Bundle savedInstanceState) { 32 super.onViewCreated(view, savedInstanceState); 33 if (getCallbackFragment() instanceof TwoPanelSettingsFragment) { 34 TwoPanelSettingsFragment parentFragment = 35 (TwoPanelSettingsFragment) getCallbackFragment(); 36 parentFragment.addListenerForFragment(this); 37 } 38 } 39 40 @Override onDestroyView()41 public void onDestroyView() { 42 super.onDestroyView(); 43 if (getCallbackFragment() instanceof TwoPanelSettingsFragment) { 44 TwoPanelSettingsFragment parentFragment = 45 (TwoPanelSettingsFragment) getCallbackFragment(); 46 parentFragment.removeListenerForFragment(this); 47 } 48 } 49 } 50