1 /* 2 * Copyright (C) 2017 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.bluetooth; 18 19 import android.bluetooth.BluetoothCsipSetCoordinator; 20 import android.content.Context; 21 22 import androidx.preference.PreferenceFragmentCompat; 23 import androidx.preference.PreferenceScreen; 24 25 import com.android.settings.R; 26 import com.android.settingslib.bluetooth.CachedBluetoothDevice; 27 import com.android.settingslib.core.lifecycle.Lifecycle; 28 import com.android.settingslib.widget.FooterPreference; 29 30 /** 31 * This class adds the device MAC address to a footer. 32 */ 33 public class BluetoothDetailsMacAddressController extends BluetoothDetailsController { 34 public static final String KEY_DEVICE_DETAILS_FOOTER = "device_details_footer"; 35 36 private FooterPreference mFooterPreference; 37 BluetoothDetailsMacAddressController(Context context, PreferenceFragmentCompat fragment, CachedBluetoothDevice device, Lifecycle lifecycle)38 public BluetoothDetailsMacAddressController(Context context, 39 PreferenceFragmentCompat fragment, 40 CachedBluetoothDevice device, 41 Lifecycle lifecycle) { 42 super(context, fragment, device, lifecycle); 43 } 44 45 @Override init(PreferenceScreen screen)46 protected void init(PreferenceScreen screen) { 47 mFooterPreference = screen.findPreference(KEY_DEVICE_DETAILS_FOOTER); 48 mFooterPreference.setTitle(mContext.getString( 49 R.string.bluetooth_device_mac_address, mCachedDevice.getIdentityAddress())); 50 } 51 52 @Override refresh()53 protected void refresh() { 54 if (mCachedDevice.getGroupId() != BluetoothCsipSetCoordinator.GROUP_ID_INVALID) { 55 StringBuilder title = new StringBuilder(mContext.getString( 56 R.string.bluetooth_multuple_devices_mac_address, 57 mCachedDevice.getIdentityAddress())); 58 for (CachedBluetoothDevice member: mCachedDevice.getMemberDevice()) { 59 title.append("\n").append(member.getIdentityAddress()); 60 } 61 mFooterPreference.setTitle(title); 62 } else if (mCachedDevice.getSubDevice() != null) { 63 StringBuilder title = new StringBuilder(mContext.getString( 64 R.string.bluetooth_multuple_devices_mac_address, 65 mCachedDevice.getIdentityAddress())); 66 title.append("\n").append(mCachedDevice.getSubDevice().getIdentityAddress()); 67 mFooterPreference.setTitle(title); 68 } else { 69 mFooterPreference.setTitle(mContext.getString( 70 R.string.bluetooth_device_mac_address, mCachedDevice.getIdentityAddress())); 71 } 72 } 73 74 @Override getPreferenceKey()75 public String getPreferenceKey() { 76 return KEY_DEVICE_DETAILS_FOOTER; 77 } 78 }