1 /*
2  * Copyright (C) 2020 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 package com.android.settings.development;
17 
18 import android.content.Context;
19 import android.debug.PairDevice;
20 
21 import androidx.annotation.VisibleForTesting;
22 import androidx.fragment.app.Fragment;
23 import androidx.preference.PreferenceScreen;
24 
25 import com.android.settings.R;
26 import com.android.settings.core.PreferenceControllerMixin;
27 import com.android.settings.widget.EntityHeaderController;
28 import com.android.settingslib.core.AbstractPreferenceController;
29 import com.android.settingslib.core.lifecycle.LifecycleObserver;
30 import com.android.settingslib.widget.LayoutPreference;
31 
32 /**
33  * Controller for logic pertaining to displaying adb device information for the
34  * {@link AdbDeviceDetailsFragment}.
35  */
36 public class AdbDeviceDetailsHeaderController extends AbstractPreferenceController
37         implements PreferenceControllerMixin, LifecycleObserver {
38 
39     private static final String TAG = "AdbDeviceDetailsHeader";
40 
41     @VisibleForTesting
42     static final String KEY_HEADER = "adb_device_header";
43 
44     private PairDevice mPairedDevice;
45     private final Fragment mFragment;
46     private EntityHeaderController mEntityHeaderController;
47 
AdbDeviceDetailsHeaderController( PairDevice pairedDevice, Context context, Fragment fragment)48     public AdbDeviceDetailsHeaderController(
49             PairDevice pairedDevice,
50             Context context,
51             Fragment fragment) {
52         super(context);
53 
54         mPairedDevice = pairedDevice;
55         mFragment = fragment;
56     }
57 
58     @Override
isAvailable()59     public boolean isAvailable() {
60         return true;
61     }
62 
63     @Override
getPreferenceKey()64     public String getPreferenceKey() {
65         return KEY_HEADER;
66     }
67 
68     @Override
displayPreference(PreferenceScreen screen)69     public void displayPreference(PreferenceScreen screen) {
70         super.displayPreference(screen);
71 
72         setupEntityHeader(screen);
73     }
74 
setupEntityHeader(PreferenceScreen screen)75     private void setupEntityHeader(PreferenceScreen screen) {
76         LayoutPreference headerPref = (LayoutPreference) screen.findPreference(KEY_HEADER);
77         mEntityHeaderController =
78                 EntityHeaderController.newInstance(
79                         mFragment.getActivity(), mFragment,
80                         headerPref.findViewById(R.id.entity_header));
81 
82         mEntityHeaderController
83                 .setIcon(mContext.getDrawable(com.android.internal.R.drawable.ic_bt_laptop))
84                 .setLabel(mPairedDevice.name)
85                 .done(true);
86     }
87 }
88 
89