Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 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 | */ |
| 16 | package com.android.systemui.statusbar.car; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.graphics.drawable.Drawable; |
| 20 | import android.util.AttributeSet; |
Anthony Chen | 48a76eb | 2016-10-05 18:50:42 -0700 | [diff] [blame] | 21 | import android.widget.ImageView; |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 22 | import android.widget.RelativeLayout; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 23 | |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 24 | import com.android.keyguard.AlphaOptimizedImageButton; |
| 25 | import 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 | */ |
| 30 | public 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(); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame^] | 44 | mIcon = findViewById(R.id.car_nav_button_icon); |
Anthony Chen | 48a76eb | 2016-10-05 18:50:42 -0700 | [diff] [blame] | 45 | mIcon.setScaleType(ImageView.ScaleType.CENTER); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 46 | mIcon.setClickable(false); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 47 | mIcon.setBackgroundColor(android.R.color.transparent); |
| 48 | mIcon.setAlpha(UNSELECTED_ALPHA); |
| 49 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame^] | 50 | mMoreIcon = findViewById(R.id.car_nav_button_more_icon); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 51 | mMoreIcon.setClickable(false); |
Victor Chan | 1c6d058 | 2016-01-09 16:26:37 -0800 | [diff] [blame] | 52 | mMoreIcon.setBackgroundColor(android.R.color.transparent); |
| 53 | mMoreIcon.setVisibility(INVISIBLE); |
| 54 | mMoreIcon.setImageDrawable(getContext().getDrawable(R.drawable.car_ic_arrow)); |
| 55 | mMoreIcon.setAlpha(UNSELECTED_ALPHA); |
| 56 | } |
| 57 | |
| 58 | public void setResources(Drawable icon) { |
| 59 | mIcon.setImageDrawable(icon); |
| 60 | } |
| 61 | |
| 62 | public void setSelected(boolean selected, boolean showMoreIcon) { |
| 63 | if (selected) { |
| 64 | mMoreIcon.setVisibility(showMoreIcon ? VISIBLE : INVISIBLE); |
| 65 | mMoreIcon.setAlpha(SELECTED_ALPHA); |
| 66 | mIcon.setAlpha(SELECTED_ALPHA); |
| 67 | } else { |
| 68 | mMoreIcon.setVisibility(INVISIBLE); |
| 69 | mIcon.setAlpha(UNSELECTED_ALPHA); |
| 70 | } |
| 71 | } |
| 72 | } |