1 /*
2  * Copyright (C) 2021 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.customization.picker.themedicon;
17 
18 import android.content.Context;
19 import android.util.AttributeSet;
20 import android.widget.Switch;
21 
22 import androidx.annotation.Nullable;
23 
24 import com.android.themepicker.R;
25 import com.android.wallpaper.picker.SectionView;
26 
27 /**
28  * The {@link SectionView} for themed icon section view
29  */
30 public class ThemedIconSectionView extends SectionView {
31 
32     private Switch mSwitchView;
33 
ThemedIconSectionView(Context context, @Nullable AttributeSet attrs)34     public ThemedIconSectionView(Context context, @Nullable AttributeSet attrs) {
35         super(context, attrs);
36         setTitle(context.getString(R.string.themed_icon_title));
37     }
38 
39     @Override
onFinishInflate()40     protected void onFinishInflate() {
41         super.onFinishInflate();
42         mSwitchView = findViewById(R.id.themed_icon_toggle);
43         setOnClickListener(v -> {
44             mSwitchView.toggle();
45             if (mSectionViewListener != null) {
46                 mSectionViewListener.onViewActivated(getContext(), mSwitchView.isChecked());
47             }
48         });
49     }
50 
51     /** Gets the switch view. */
getSwitch()52     public Switch getSwitch() {
53         return mSwitchView;
54     }
55 }
56