• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 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.car.settings.bluetooth;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.view.View;
22 import android.widget.ProgressBar;
23 
24 import androidx.annotation.XmlRes;
25 
26 import com.android.car.settings.R;
27 import com.android.car.settings.common.SettingsFragment;
28 import com.android.settingslib.bluetooth.LocalBluetoothManager;
29 
30 /**
31  * Hosts {@link BluetoothDevicePickerPreferenceController} to display the list of Bluetooth
32  * devices. The progress bar is shown while this fragment is visible to indicate discovery or
33  * pairing progress.
34  */
35 public class BluetoothDevicePickerFragment extends SettingsFragment {
36 
37     private LocalBluetoothManager mManager;
38     private ProgressBar mProgressBar;
39 
40     @Override
41     @XmlRes
getPreferenceScreenResId()42     protected int getPreferenceScreenResId() {
43         return R.xml.bluetooth_device_picker_fragment;
44     }
45 
46     @Override
onAttach(Context context)47     public void onAttach(Context context) {
48         super.onAttach(context);
49         mManager = BluetoothUtils.getLocalBtManager(context);
50         if (mManager == null) {
51             goBack();
52             return;
53         }
54 
55         use(BluetoothDevicePickerPreferenceController.class,
56                 R.string.pk_bluetooth_device_picker).setLaunchIntent(requireActivity().getIntent());
57     }
58 
59     @Override
onActivityCreated(Bundle savedInstanceState)60     public void onActivityCreated(Bundle savedInstanceState) {
61         super.onActivityCreated(savedInstanceState);
62         mProgressBar = requireActivity().findViewById(R.id.progress_bar);
63     }
64 
65     @Override
onStart()66     public void onStart() {
67         super.onStart();
68         mManager.setForegroundActivity(requireActivity());
69         mProgressBar.setVisibility(View.VISIBLE);
70     }
71 
72     @Override
onStop()73     public void onStop() {
74         super.onStop();
75         mManager.setForegroundActivity(null);
76         mProgressBar.setVisibility(View.GONE);
77     }
78 }
79