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