blob: 3ee01de66fd53955aa5b9831614e39ec6ce214fb [file] [log] [blame]
Jorim Jaggi40db0292016-06-27 17:58:03 -07001/*
2 * Copyright (C) 2016 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
17package com.android.systemui.statusbar.policy;
18
19import android.annotation.Nullable;
20import android.graphics.drawable.Drawable;
21import android.graphics.drawable.LayerDrawable;
22
23/**
24 * Drawable for {@link KeyButtonView}s which contains an asset for both normal mode and light
25 * navigation bar mode.
26 */
27public class KeyButtonDrawable extends LayerDrawable {
28
29 private final boolean mHasDarkDrawable;
30
31 public static KeyButtonDrawable create(Drawable lightDrawable,
32 @Nullable Drawable darkDrawable) {
33 if (darkDrawable != null) {
34 return new KeyButtonDrawable(
35 new Drawable[] { lightDrawable.mutate(), darkDrawable.mutate() });
36 } else {
37 return new KeyButtonDrawable(new Drawable[] { lightDrawable.mutate() });
38 }
39 }
40
41 private KeyButtonDrawable(Drawable[] drawables) {
42 super(drawables);
43 mutate();
44 mHasDarkDrawable = drawables.length > 1;
45 setDarkIntensity(0f);
46 }
47
48 public void setDarkIntensity(float intensity) {
49 if (!mHasDarkDrawable) {
50 return;
51 }
52 getDrawable(0).setAlpha((int) ((1 - intensity) * 255f));
53 getDrawable(1).setAlpha((int) (intensity * 255f));
54 invalidateSelf();
55 }
56}