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.twopanelsettingsoverlay; 18 19 import android.app.Fragment; 20 21 import androidx.annotation.NonNull; 22 import androidx.preference.Preference; 23 import androidx.preference.PreferenceFragment; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.tv.settings.system.LeanbackPickerDialogFragment; 27 import com.android.tv.settings.system.LeanbackPickerDialogPreference; 28 import com.android.tv.twopanelsettings.TwoPanelSettingsFragment; 29 30 /** 31 * Base class for settings fragments. Handles launching fragments and dialogs in a reasonably 32 * generic way. Subclasses should only override onPreferenceStartInitialScreen. 33 */ 34 35 public abstract class TwoPanelBaseSettingsFragment extends TwoPanelSettingsFragment { 36 37 @Override onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref)38 public final boolean onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref) { 39 return false; 40 } 41 42 @Override onCreatePreviewFragment(@onNull Fragment caller, Preference pref)43 public Fragment onCreatePreviewFragment(@NonNull Fragment caller, Preference pref) { 44 Fragment f; 45 if (pref instanceof LeanbackPickerDialogPreference) { 46 final LeanbackPickerDialogPreference dialogPreference = (LeanbackPickerDialogPreference) 47 pref; 48 f = dialogPreference.getType().equals("date") 49 ? LeanbackPickerDialogFragment.newDatePickerInstance(pref.getKey()) 50 : LeanbackPickerDialogFragment.newTimePickerInstance(pref.getKey()); 51 f.setTargetFragment(caller, 0); 52 return f; 53 } else { 54 return super.onCreatePreviewFragment(caller, pref); 55 } 56 } 57 } 58