• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.settings.applications.intentpicker;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.widget.CheckBox;
23 
24 import androidx.preference.PreferenceViewHolder;
25 
26 import com.android.settings.R;
27 import com.android.settingslib.widget.TwoTargetPreference;
28 
29 /** This customized VerifiedLinksPreference was belonged to Open by default page */
30 public class VerifiedLinksPreference extends TwoTargetPreference {
31     private Context mContext;
32     private View.OnClickListener mOnWidgetClickListener;
33     private boolean mShowCheckBox;
34 
VerifiedLinksPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)35     public VerifiedLinksPreference(Context context, AttributeSet attrs,
36             int defStyleAttr, int defStyleRes) {
37         super(context, attrs, defStyleAttr, defStyleRes);
38         init(context);
39     }
40 
VerifiedLinksPreference(Context context, AttributeSet attrs, int defStyleAttr)41     public VerifiedLinksPreference(Context context, AttributeSet attrs, int defStyleAttr) {
42         this(context, attrs, defStyleAttr, /* defStyleRes= */0);
43     }
44 
VerifiedLinksPreference(Context context, AttributeSet attrs)45     public VerifiedLinksPreference(Context context, AttributeSet attrs) {
46         this(context, attrs, /* defStyleAttr= */ 0);
47     }
48 
VerifiedLinksPreference(Context context)49     public VerifiedLinksPreference(Context context) {
50         this(context, /* attrs= */ null);
51     }
52 
init(Context context)53     private void init(Context context) {
54         mContext = context;
55         mOnWidgetClickListener = null;
56         mShowCheckBox = true;
57         setLayoutResource(R.layout.preference_checkable_two_target);
58         setWidgetLayoutResource(R.layout.verified_links_widget);
59     }
60 
61     /**
62      * Register a callback to be invoked when this widget is clicked.
63      *
64      * @param listener The callback that will run.
65      */
setWidgetFrameClickListener(View.OnClickListener listener)66     public void setWidgetFrameClickListener(View.OnClickListener listener) {
67         mOnWidgetClickListener = listener;
68     }
69 
70     /** Determine the visibility of the {@link CheckBox}. */
setCheckBoxVisible(boolean isVisible)71     public void setCheckBoxVisible(boolean isVisible) {
72         mShowCheckBox = isVisible;
73     }
74 
75     @Override
onBindViewHolder(PreferenceViewHolder view)76     public void onBindViewHolder(PreferenceViewHolder view) {
77         super.onBindViewHolder(view);
78         final View settingsWidget = view.findViewById(android.R.id.widget_frame);
79         final View divider = view.findViewById(R.id.two_target_divider);
80         divider.setVisibility(View.VISIBLE);
81         settingsWidget.setVisibility(View.VISIBLE);
82         if (mOnWidgetClickListener != null) {
83             settingsWidget.setOnClickListener(mOnWidgetClickListener);
84         }
85         final View checkboxContainer = view.findViewById(R.id.checkbox_container);
86         final View parentView = (View) checkboxContainer.getParent();
87         parentView.setEnabled(false);
88         parentView.setClickable(false);
89         CheckBox checkBox = (CheckBox) view.findViewById(com.android.internal.R.id.checkbox);
90         if (checkBox != null) {
91             checkBox.setChecked(true);
92             checkboxContainer.setVisibility(mShowCheckBox ? View.VISIBLE : View.GONE);
93         }
94     }
95 }
96