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