blob: 793842f871200f88305737d27bca154e52f6235d [file] [log] [blame]
Fan Zhangdd5828c2018-10-03 12:58:51 -07001/*
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
17package com.android.settings.support;
18
19import android.app.Activity;
20import android.content.Context;
21import android.text.TextUtils;
22
23import androidx.preference.Preference;
24
25import com.android.settings.core.BasePreferenceController;
26import com.android.settings.overlay.FeatureFactory;
27import com.android.settings.overlay.SupportFeatureProvider;
28
29public class SupportPreferenceController extends BasePreferenceController {
30
31 private final SupportFeatureProvider mSupportFeatureProvider;
32
33 private Activity mActivity;
34
35 public SupportPreferenceController(Context context, String preferenceKey) {
36 super(context, preferenceKey);
37 mSupportFeatureProvider = FeatureFactory.getFactory(context)
38 .getSupportFeatureProvider(context);
39 }
40
41 public void setActivity(Activity activity) {
42 mActivity = activity;
43 }
44
45 @Override
46 public int getAvailabilityStatus() {
47 return mSupportFeatureProvider == null ? UNSUPPORTED_ON_DEVICE : AVAILABLE;
48 }
49
50 @Override
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}