DiscoverableFooterPreferenceController.java revision 4f636b90b8a41bfa3a57678e51d42547c1ba2229
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 17package com.android.settings.connecteddevice; 18 19import android.content.Context; 20import android.content.pm.PackageManager; 21import android.support.v7.preference.PreferenceScreen; 22 23import com.android.internal.annotations.VisibleForTesting; 24import com.android.settings.core.BasePreferenceController; 25import com.android.settings.dashboard.DashboardFragment; 26import com.android.settingslib.widget.FooterPreference; 27import com.android.settingslib.widget.FooterPreferenceMixin; 28 29/** 30 * Controller that shows and updates the bluetooth device name 31 */ 32public class DiscoverableFooterPreferenceController extends BasePreferenceController { 33 private static final String KEY = "discoverable_footer_preference"; 34 35 private FooterPreference mPreference; 36 private FooterPreferenceMixin mFooterPreferenceMixin; 37 38 39 public DiscoverableFooterPreferenceController(Context context) { super(context, KEY); } 40 41 public void init(DashboardFragment fragment) { 42 mFooterPreferenceMixin = new FooterPreferenceMixin(fragment, fragment.getLifecycle()); 43 } 44 45 @VisibleForTesting 46 void init(FooterPreferenceMixin footerPreferenceMixin, FooterPreference preference) { 47 mFooterPreferenceMixin = footerPreferenceMixin; 48 mPreference = preference; 49 } 50 51 @Override 52 public void displayPreference(PreferenceScreen screen) { 53 super.displayPreference(screen); 54 addFooterPreference(screen); 55 } 56 57 @Override 58 public int getAvailabilityStatus() { 59 return mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH) 60 ? AVAILABLE 61 : UNSUPPORTED_ON_DEVICE; 62 } 63 64 private void addFooterPreference(PreferenceScreen screen) { 65 mPreference = mFooterPreferenceMixin.createFooterPreference(); 66 mPreference.setKey(KEY); 67 screen.addPreference(mPreference); 68 } 69}