1 /* 2 * Copyright (C) 2016 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.settingslib.widget; 18 19 import android.content.Context; 20 21 import androidx.preference.PreferenceFragment; 22 import androidx.preference.PreferenceScreen; 23 24 import com.android.settingslib.core.lifecycle.Lifecycle; 25 import com.android.settingslib.core.lifecycle.LifecycleObserver; 26 import com.android.settingslib.core.lifecycle.events.SetPreferenceScreen; 27 28 /** 29 * Framework mixin is deprecated, use the compat version instead. 30 * 31 * @deprecated 32 */ 33 @Deprecated 34 public class FooterPreferenceMixin implements LifecycleObserver, SetPreferenceScreen { 35 36 private final PreferenceFragment mFragment; 37 private FooterPreference mFooterPreference; 38 39 public FooterPreferenceMixin(PreferenceFragment fragment, Lifecycle lifecycle) { 40 mFragment = fragment; 41 lifecycle.addObserver(this); 42 } 43 44 @Override 45 public void setPreferenceScreen(PreferenceScreen preferenceScreen) { 46 if (mFooterPreference != null) { 47 preferenceScreen.addPreference(mFooterPreference); 48 } 49 } 50 51 /** 52 * Creates a new {@link FooterPreference}. 53 */ 54 public FooterPreference createFooterPreference() { 55 final PreferenceScreen screen = mFragment.getPreferenceScreen(); 56 if (mFooterPreference != null && screen != null) { 57 screen.removePreference(mFooterPreference); 58 } 59 mFooterPreference = new FooterPreference(getPrefContext()); 60 61 if (screen != null) { 62 screen.addPreference(mFooterPreference); 63 } 64 return mFooterPreference; 65 } 66 67 /** 68 * Returns an UI context with theme properly set for new Preference objects. 69 */ 70 private Context getPrefContext() { 71 return mFragment.getPreferenceManager().getContext(); 72 } 73 74 public boolean hasFooter() { 75 return mFooterPreference != null; 76 } 77 } 78 79