• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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.car.radio;
17 
18 import android.annotation.ColorInt;
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.widget.ImageView;
22 
23 import com.android.car.apps.common.FabDrawable;
24 
25 /**
26  * A default FAB button for the radio that will color itself based on the accent color defined
27  * in the application.
28  */
29 public class RadioFabButton extends ImageView {
30     private final FabDrawable mFabDrawable;
31     @ColorInt private final int mEnabledColor;
32     @ColorInt private final int mDisabledColor;
33 
RadioFabButton(Context context)34     public RadioFabButton(Context context) {
35         super(context);
36     }
37 
RadioFabButton(Context context, AttributeSet attrs)38     public RadioFabButton(Context context, AttributeSet attrs) {
39         super(context, attrs);
40     }
41 
RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs)42     public RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs) {
43         super(context, attrs, defStyleAttrs);
44     }
45 
RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes)46     public RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs,
47             int defStyleRes) {
48         super(context, attrs, defStyleAttrs, defStyleRes);
49     }
50 
51     {
52         Context context = getContext();
53 
54         mFabDrawable = new FabDrawable(context);
55         setBackground(mFabDrawable);
56 
57         mEnabledColor = context.getColor(R.color.car_radio_accent_color);
58         mDisabledColor = context.getColor(R.color.car_radio_control_fab_button_disabled);
59 
60         mFabDrawable.setFabAndStrokeColor(mEnabledColor);
61     }
62 
63     @Override
setEnabled(boolean enabled)64     public void setEnabled(boolean enabled) {
65         super.setEnabled(enabled);
66         mFabDrawable.setFabAndStrokeColor(enabled ? mEnabledColor : mDisabledColor);
67     }
68 }
69