CarNavigationButton.java revision 1c6d0589f1c6429ca84402227cd5954479cf66ed
1/*
2 * Copyright (C) 2015 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 */
16package com.android.systemui.statusbar.car;
17
18import android.content.Context;
19import android.graphics.drawable.Drawable;
20import android.util.AttributeSet;
21import android.widget.ImageButton;
22import android.widget.ImageView;
23import android.widget.RelativeLayout;
24import com.android.keyguard.AlphaOptimizedImageButton;
25import com.android.systemui.R;
26
27/**
28 * A wrapper view for a car navigation facet, which includes a button icon and a drop down icon.
29 */
30public class CarNavigationButton extends RelativeLayout {
31    private static final float SELECTED_ALPHA = 1;
32    private static final float UNSELECTED_ALPHA = 0.7f;
33
34    private AlphaOptimizedImageButton mIcon;
35    private AlphaOptimizedImageButton mMoreIcon;
36
37    public CarNavigationButton(Context context, AttributeSet attrs) {
38        super(context, attrs);
39    }
40
41    @Override
42    public void onFinishInflate() {
43        super.onFinishInflate();
44        mIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_icon);
45        mIcon.setClickable(false);
46        mIcon.setScaleType(ImageView.ScaleType.CENTER);
47        mIcon.setBackgroundColor(android.R.color.transparent);
48        mIcon.setAlpha(UNSELECTED_ALPHA);
49
50        mMoreIcon = (AlphaOptimizedImageButton) findViewById(R.id.car_nav_button_more_icon);
51        mMoreIcon.setClickable(false);
52        mMoreIcon.setScaleType(ImageView.ScaleType.CENTER);
53        mMoreIcon.setBackgroundColor(android.R.color.transparent);
54        mMoreIcon.setVisibility(INVISIBLE);
55        mMoreIcon.setImageDrawable(getContext().getDrawable(R.drawable.car_ic_arrow));
56        mMoreIcon.setAlpha(UNSELECTED_ALPHA);
57    }
58
59    public void setResources(Drawable icon) {
60        mIcon.setImageDrawable(icon);
61    }
62
63    public void setSelected(boolean selected, boolean showMoreIcon) {
64        if (selected) {
65            mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : INVISIBLE);
66            mMoreIcon.setAlpha(SELECTED_ALPHA);
67            mIcon.setAlpha(SELECTED_ALPHA);
68        } else {
69            mMoreIcon.setVisibility(INVISIBLE);
70            mIcon.setAlpha(UNSELECTED_ALPHA);
71        }
72    }
73}
74