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 25 import com.android.settings.core.BasePreferenceController; 26 import com.android.settings.overlay.FeatureFactory; 27 import com.android.settings.overlay.SupportFeatureProvider; 28 29 public class SupportPreferenceController extends BasePreferenceController { 30 31 private final SupportFeatureProvider mSupportFeatureProvider; 32 33 private Activity mActivity; 34 SupportPreferenceController(Context context, String preferenceKey)35 public SupportPreferenceController(Context context, String preferenceKey) { 36 super(context, preferenceKey); 37 mSupportFeatureProvider = FeatureFactory.getFactory(context) 38 .getSupportFeatureProvider(context); 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