144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer/*
244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * Copyright (c) 2016, The Android Open Source Project
344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer *
444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * Licensed under the Apache License, Version 2.0 (the "License");
544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * you may not use this file except in compliance with the License.
644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * You may obtain a copy of the License at
744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer *
844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer *     http://www.apache.org/licenses/LICENSE-2.0
944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer *
1044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * Unless required by applicable law or agreed to in writing, software
1144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * distributed under the License is distributed on an "AS IS" BASIS,
1244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * See the License for the specific language governing permissions and
1444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * limitations under the License.
1544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer */
1644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerpackage com.android.car.radio;
1744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
1844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerimport android.content.Context;
1944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerimport android.support.annotation.ColorInt;
2044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerimport android.util.AttributeSet;
2144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerimport android.widget.ImageView;
22e342a4866c3ba36567c18ebffa32b213f0bc567dRakesh Iyerimport com.android.car.apps.common.FabDrawable;
2344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
2444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer/**
2544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * A default FAB button for the radio that will color itself based on the accent color defined
2644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer * in the application.
2744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer */
2844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyerpublic class RadioFabButton extends ImageView {
2944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    private final FabDrawable mFabDrawable;
3044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    @ColorInt private final int mEnabledColor;
3144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    @ColorInt private final int mDisabledColor;
3244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
3344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    public RadioFabButton(Context context) {
3444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        super(context);
3544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
3644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
3744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    public RadioFabButton(Context context, AttributeSet attrs) {
3844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        super(context, attrs);
3944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
4044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
4144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    public RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs) {
4244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        super(context, attrs, defStyleAttrs);
4344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
4444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
4544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    public RadioFabButton(Context context, AttributeSet attrs, int defStyleAttrs,
4644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer            int defStyleRes) {
4744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        super(context, attrs, defStyleAttrs, defStyleRes);
4844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
4944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
5044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    {
5144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        Context context = getContext();
5244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
5344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        mFabDrawable = new FabDrawable(context);
5444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        setBackground(mFabDrawable);
5544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
5644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        mEnabledColor = context.getColor(R.color.car_radio_accent_color);
5744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        mDisabledColor = context.getColor(R.color.car_radio_control_fab_button_disabled);
5844f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
5944f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        mFabDrawable.setFabAndStrokeColor(mEnabledColor);
6044f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
6144f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer
6244f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    @Override
6344f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    public void setEnabled(boolean enabled) {
6444f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        super.setEnabled(enabled);
6544f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer        mFabDrawable.setFabAndStrokeColor(enabled ? mEnabledColor : mDisabledColor);
6644f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer    }
6744f17dab6698b8c5d87672f5df71c471bd4b91a3Rakesh Iyer}
68