1 /* 2 * Copyright (C) 2018 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.settings.support; 18 19 import android.app.Activity; 20 import android.content.Context; 21 import android.text.TextUtils; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.settings.core.BasePreferenceController; 27 import com.android.settings.overlay.FeatureFactory; 28 import com.android.settings.overlay.SupportFeatureProvider; 29 30 public class SupportPreferenceController extends BasePreferenceController { 31 32 private final SupportFeatureProvider mSupportFeatureProvider; 33 34 private Activity mActivity; 35 SupportPreferenceController(Context context, String preferenceKey)36 public SupportPreferenceController(Context context, String preferenceKey) { 37 super(context, preferenceKey); 38 mSupportFeatureProvider = FeatureFactory.getFeatureFactory().getSupportFeatureProvider(); 39 } 40 setActivity(Activity activity)41 public void setActivity(Activity activity) { 42 mActivity = activity; 43 } 44 45 @Override getAvailabilityStatus()46 public int getAvailabilityStatus() { 47 return mSupportFeatureProvider == null ? UNSUPPORTED_ON_DEVICE : AVAILABLE; 48 } 49 50 @Override handlePreferenceTreeClick(Preference preference)51 public boolean handlePreferenceTreeClick(Preference preference) { 52 if (preference == null || mActivity == null || 53 !TextUtils.equals(preference.getKey(), getPreferenceKey())) { 54 return false; 55 } 56 mSupportFeatureProvider.startSupport(mActivity); 57 return true; 58 59 } 60 61 @Override displayPreference(PreferenceScreen screen)62 public void displayPreference(PreferenceScreen screen) { 63 super.displayPreference(screen); 64 Preference pref = screen.findPreference(mPreferenceKey); 65 if (pref != null && mSupportFeatureProvider != null) { 66 mSupportFeatureProvider.applyOverrides(mContext, pref); 67 } 68 } 69 } 70