• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.launcher3.views;
17 
18 import android.content.Context;
19 import android.preference.Preference;
20 import android.util.AttributeSet;
21 import android.view.View;
22 import android.view.ViewGroup;
23 
24 /**
25  * Extension of {@link Preference} which makes the widget layout clickable.
26  *
27  * @see #setWidgetLayoutResource(int)
28  */
29 public class ButtonPreference extends Preference {
30 
31     private boolean mWidgetFrameVisible = false;
32 
ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)33     public ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
34         super(context, attrs, defStyleAttr, defStyleRes);
35     }
36 
ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr)37     public ButtonPreference(Context context, AttributeSet attrs, int defStyleAttr) {
38         super(context, attrs, defStyleAttr);
39     }
40 
ButtonPreference(Context context, AttributeSet attrs)41     public ButtonPreference(Context context, AttributeSet attrs) {
42         super(context, attrs);
43     }
44 
ButtonPreference(Context context)45     public ButtonPreference(Context context) {
46         super(context);
47     }
48 
setWidgetFrameVisible(boolean isVisible)49     public void setWidgetFrameVisible(boolean isVisible) {
50         if (mWidgetFrameVisible != isVisible) {
51             mWidgetFrameVisible = isVisible;
52             notifyChanged();
53         }
54     }
55 
56     @Override
onBindView(View view)57     protected void onBindView(View view) {
58         super.onBindView(view);
59 
60         ViewGroup widgetFrame = view.findViewById(android.R.id.widget_frame);
61         if (widgetFrame != null) {
62             widgetFrame.setVisibility(mWidgetFrameVisible ? View.VISIBLE : View.GONE);
63         }
64     }
65 }
66