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.google.android.car.kitchensink.customizationtool;
18 
19 import android.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.Switch;
24 
25 import androidx.annotation.NonNull;
26 import androidx.annotation.Nullable;
27 import androidx.fragment.app.Fragment;
28 
29 import com.google.android.car.kitchensink.R;
30 
31 /**
32  * Provides methods to enable or disable the Customization Tool service.
33  */
34 public class CustomizationToolFragment extends Fragment {
35 
36     private CustomizationToolController mCustomizationToolController;
37     private Switch mCustomizationToolSwitch;
38 
39     @Nullable
40     @Override
onCreateView(@onNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)41     public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
42                              @Nullable Bundle savedInstanceState) {
43         return inflater.inflate(R.layout.customization_tool, container, false);
44     }
45 
46     @Override
onViewCreated(@onNull View view, @Nullable Bundle savedInstanceState)47     public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
48         mCustomizationToolController = new CustomizationToolController(getContext());
49 
50         mCustomizationToolSwitch = view.findViewById(R.id.customization_tool_switch);
51         mCustomizationToolSwitch.setOnClickListener(v ->
52                 mCustomizationToolController.toggleCustomizationTool(
53                         mCustomizationToolSwitch.isChecked()));
54         mCustomizationToolSwitch.setChecked(
55                 mCustomizationToolController.isCustomizationToolActive());
56     }
57 }
58