2 * Copyright (C) 2017 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.settings.bluetooth;
20 import android.content.Context;
21 import android.support.v14.preference.PreferenceFragment;
22 import android.support.v7.preference.PreferenceScreen;
23 import android.util.Pair;
25 import com.android.settings.R;
26 import com.android.settings.applications.LayoutPreference;
27 import com.android.settings.widget.EntityHeaderController;
28 import com.android.settingslib.bluetooth.CachedBluetoothDevice;
29 import com.android.settingslib.core.lifecycle.Lifecycle;
32 * This class adds a header with device name and status (connected/disconnected, etc.).
34 public class BluetoothDetailsHeaderController extends BluetoothDetailsController {
35 private static final String KEY_DEVICE_HEADER = "bluetooth_device_header";
37 private EntityHeaderController mHeaderController;
39 public BluetoothDetailsHeaderController(Context context, PreferenceFragment fragment,
40 CachedBluetoothDevice device, Lifecycle lifecycle) {
41 super(context, fragment, device, lifecycle);
45 protected void init(PreferenceScreen screen) {
46 final LayoutPreference headerPreference =
47 (LayoutPreference) screen.findPreference(KEY_DEVICE_HEADER);
48 mHeaderController = EntityHeaderController.newInstance(mFragment.getActivity(), mFragment,
49 headerPreference.findViewById(R.id.entity_header));
50 screen.addPreference(headerPreference);
53 protected void setHeaderProperties() {
54 Pair<Integer, String> pair = Utils.getBtClassDrawableWithDescription
55 (mContext.getResources(), mCachedDevice);
56 int summaryResourceId = mCachedDevice.getConnectionSummary();
57 mHeaderController.setLabel(mCachedDevice.getName());
58 mHeaderController.setIcon(mContext.getDrawable(pair.first));
59 mHeaderController.setIconContentDescription(pair.second);
60 mHeaderController.setSummary(
61 summaryResourceId > 0 ? mContext.getString(summaryResourceId) : null);
65 protected void refresh() {
66 setHeaderProperties();
67 mHeaderController.done(mFragment.getActivity(), false);
71 public String getPreferenceKey() {
72 return KEY_DEVICE_HEADER;