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