• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.connecteddevice.virtual;
18 
19 import android.content.Context;
20 
21 import androidx.annotation.NonNull;
22 import androidx.annotation.Nullable;
23 import androidx.preference.PreferenceFragmentCompat;
24 import androidx.preference.PreferenceScreen;
25 
26 import com.android.settings.R;
27 import com.android.settings.core.BasePreferenceController;
28 import com.android.settingslib.widget.ActionButtonsPreference;
29 
30 import java.util.Objects;
31 
32 /** This class adds one button to "forget" (ie unpair) the device. */
33 public class VirtualDeviceDetailsButtonsController extends BasePreferenceController {
34 
35     private static final String KEY_VIRTUAL_DEVICE_ACTION_BUTTONS = "virtual_device_action_buttons";
36 
37     @Nullable
38     private PreferenceFragmentCompat mFragment;
39     @Nullable
40     private VirtualDeviceWrapper mDevice;
41 
VirtualDeviceDetailsButtonsController(@onNull Context context)42     public VirtualDeviceDetailsButtonsController(@NonNull Context context) {
43         super(context, KEY_VIRTUAL_DEVICE_ACTION_BUTTONS);
44     }
45 
46     /** One-time initialization when the controller is first created. */
init(@onNull PreferenceFragmentCompat fragment, @NonNull VirtualDeviceWrapper device)47     void init(@NonNull PreferenceFragmentCompat fragment, @NonNull VirtualDeviceWrapper device) {
48         mFragment = fragment;
49         mDevice = device;
50     }
51 
onForgetButtonPressed()52     private void onForgetButtonPressed() {
53         ForgetDeviceDialogFragment fragment =
54                 ForgetDeviceDialogFragment.newInstance(Objects.requireNonNull(mDevice));
55         fragment.show(Objects.requireNonNull(mFragment).getParentFragmentManager(),
56                 ForgetDeviceDialogFragment.TAG);
57     }
58 
59     @Override
displayPreference(@onNull PreferenceScreen screen)60     public void displayPreference(@NonNull PreferenceScreen screen) {
61         ((ActionButtonsPreference) screen.findPreference(getPreferenceKey()))
62                 .setButton1Text(R.string.forget)
63                 .setButton1Icon(R.drawable.ic_settings_delete)
64                 .setButton1OnClickListener((view) -> onForgetButtonPressed())
65                 .setButton1Enabled(true);
66     }
67 
68     @Override
getAvailabilityStatus()69     public int getAvailabilityStatus() {
70         return AVAILABLE;
71     }
72 }
73