1 /*
2  * Copyright (C) 2014 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.wallpaperpicker;
18 
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.widget.Button;
22 
23 /**
24  * A Button which becomes translucent when it is disabled
25  */
26 public class AlphaDisableableButton extends Button {
27     public static float DISABLED_ALPHA_VALUE = 0.4f;
AlphaDisableableButton(Context context)28     public AlphaDisableableButton(Context context) {
29         this(context, null);
30     }
31 
AlphaDisableableButton(Context context, AttributeSet attrs)32     public AlphaDisableableButton(Context context, AttributeSet attrs) {
33         this(context, attrs, 0);
34     }
35 
AlphaDisableableButton(Context context, AttributeSet attrs, int defStyleAttr)36     public AlphaDisableableButton(Context context, AttributeSet attrs, int defStyleAttr) {
37         super(context, attrs, defStyleAttr);
38         setLayerType(LAYER_TYPE_HARDWARE, null);
39     }
40 
41     @Override
setEnabled(boolean enabled)42     public void setEnabled(boolean enabled) {
43         super.setEnabled(enabled);
44         if(enabled) {
45             setAlpha(1.0f);
46         } else {
47             setAlpha(DISABLED_ALPHA_VALUE);
48         }
49     }
50 }
51