CarNavigationButton.java revision c0d7058b14c24cd07912f5629c26b39b7b4673d5
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;
211c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport android.widget.RelativeLayout;
22c0d7058b14c24cd07912f5629c26b39b7b4673d5Winson
231c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport com.android.keyguard.AlphaOptimizedImageButton;
241c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanimport com.android.systemui.R;
251c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
261c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan/**
271c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan * A wrapper view for a car navigation facet, which includes a button icon and a drop down icon.
281c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan */
291c6d0589f1c6429ca84402227cd5954479cf66edVictor Chanpublic class CarNavigationButton extends RelativeLayout {
301c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private static final float SELECTED_ALPHA = 1;
311c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private static final float UNSELECTED_ALPHA = 0.7f;
321c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
331c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private AlphaOptimizedImageButton mIcon;
341c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    private AlphaOptimizedImageButton mMoreIcon;
351c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
361c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public CarNavigationButton(Context context, AttributeSet attrs) {
371c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        super(context, attrs);
381c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
391c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
401c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    @Override
411c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void onFinishInflate() {
421c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        super.onFinishInflate();
431c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_icon);
441c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setClickable(false);
451c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setBackgroundColor(android.R.color.transparent);
461c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setAlpha(UNSELECTED_ALPHA);
471c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
481c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_more_icon);
491c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setClickable(false);
501c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setBackgroundColor(android.R.color.transparent);
511c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setVisibility(INVISIBLE);
521c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setImageDrawable(getContext().getDrawable(R.drawable.car_ic_arrow));
531c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mMoreIcon.setAlpha(UNSELECTED_ALPHA);
541c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
551c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
561c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void setResources(Drawable icon) {
571c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        mIcon.setImageDrawable(icon);
581c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
591c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan
601c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    public void setSelected(boolean selected, boolean showMoreIcon) {
611c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        if (selected) {
621c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : INVISIBLE);
631c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setAlpha(SELECTED_ALPHA);
641c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mIcon.setAlpha(SELECTED_ALPHA);
651c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        } else {
661c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mMoreIcon.setVisibility(INVISIBLE);
671c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan            mIcon.setAlpha(UNSELECTED_ALPHA);
681c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan        }
691c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan    }
701c6d0589f1c6429ca84402227cd5954479cf66edVictor Chan}
71