11c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan/*
21c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * Copyright (C) 2015 The Android Open Source Project
31c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan *
41c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * Licensed under the Apache License, Version 2.0 (the "License");
51c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * you may not use this file except in compliance with the License.
61c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * You may obtain a copy of the License at
71c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan *
81c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan *      http://www.apache.org/licenses/LICENSE-2.0
91c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan *
101c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * Unless required by applicable law or agreed to in writing, software
111c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * distributed under the License is distributed on an "AS IS" BASIS,
121c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
131c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * See the License for the specific language governing permissions and
141c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * limitations under the License.
151c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan */
161c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanpackage com.android.systemui.statusbar.car;
171c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
181c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport android.content.Context;
191c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport android.graphics.drawable.Drawable;
201c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport android.util.AttributeSet;
2148a76eb132342105f119a1a2b5d014358c3c3bfaAnthony Chenimport android.widget.ImageView;
221c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport android.widget.RelativeLayout;
23c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson
241c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport com.android.keyguard.AlphaOptimizedImageButton;
251c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport com.android.systemui.R;
261c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
271c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan/**
281c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * A wrapper view for a car navigation facet, which includes a button icon and a drop down icon.
291c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan */
301c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanpublic class CarNavigationButton extends RelativeLayout {
311c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private static final float SELECTED_ALPHA = 1;
321c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private static final float UNSELECTED_ALPHA = 0.7f;
331c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
341c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private AlphaOptimizedImageButton mIcon;
351c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private AlphaOptimizedImageButton mMoreIcon;
361c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
371c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public CarNavigationButton(Context context, AttributeSet attrs) {
381c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        super(context, attrs);
391c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
401c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
411c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    @Override
421c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void onFinishInflate() {
431c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        super.onFinishInflate();
4451efddbd3bb304de2dd47fa8cd1114ac555958bbAlan Viverette        mIcon = findViewById(R.id.car_nav_button_icon);
4548a76eb132342105f119a1a2b5d014358c3c3bfaAnthony Chen        mIcon.setScaleType(ImageView.ScaleType.CENTER);
461c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setClickable(false);
471c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setBackgroundColor(android.R.color.transparent);
481c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setAlpha(UNSELECTED_ALPHA);
491c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
5051efddbd3bb304de2dd47fa8cd1114ac555958bbAlan Viverette        mMoreIcon = findViewById(R.id.car_nav_button_more_icon);
511c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setClickable(false);
521c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setBackgroundColor(android.R.color.transparent);
531c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setVisibility(INVISIBLE);
541c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setImageDrawable(getContext().getDrawable(R.drawable.car_ic_arrow));
551c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setAlpha(UNSELECTED_ALPHA);
561c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
571c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
581c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void setResources(Drawable icon) {
591c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setImageDrawable(icon);
601c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
611c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
621c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void setSelected(boolean selected, boolean showMoreIcon) {
631c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        if (selected) {
641c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : INVISIBLE);
651c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setAlpha(SELECTED_ALPHA);
661c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mIcon.setAlpha(SELECTED_ALPHA);
671c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        } else {
681c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setVisibility(INVISIBLE);
691c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mIcon.setAlpha(UNSELECTED_ALPHA);
701c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        }
711c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
721c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan}
73