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.wifi.p2p; 18 19 import android.content.Context; 20 import android.net.wifi.p2p.WifiP2pDevice; 21 import android.text.TextUtils; 22 23 import androidx.preference.Preference; 24 import androidx.preference.PreferenceScreen; 25 26 import com.android.settings.core.PreferenceControllerMixin; 27 import com.android.settingslib.core.AbstractPreferenceController; 28 29 public class P2pThisDevicePreferenceController extends AbstractPreferenceController 30 implements PreferenceControllerMixin { 31 32 private Preference mPreference; 33 P2pThisDevicePreferenceController(Context context)34 public P2pThisDevicePreferenceController(Context context) { 35 super(context); 36 } 37 38 @Override isAvailable()39 public boolean isAvailable() { 40 return true; 41 } 42 43 @Override getPreferenceKey()44 public String getPreferenceKey() { 45 return "p2p_this_device"; 46 } 47 48 @Override displayPreference(PreferenceScreen screen)49 public void displayPreference(PreferenceScreen screen) { 50 super.displayPreference(screen); 51 mPreference = screen.findPreference(getPreferenceKey()); 52 } 53 setEnabled(boolean enabled)54 public void setEnabled(boolean enabled) { 55 if (mPreference != null) { 56 mPreference.setEnabled(enabled); 57 } 58 } 59 updateDeviceName(WifiP2pDevice thisDevice)60 public void updateDeviceName(WifiP2pDevice thisDevice) { 61 if (mPreference != null && thisDevice != null) { 62 if (TextUtils.isEmpty(thisDevice.deviceName)) { 63 mPreference.setTitle(thisDevice.deviceAddress); 64 } else { 65 mPreference.setTitle(thisDevice.deviceName); 66 } 67 } 68 } 69 } 70