blob: 5213746e5a12f16693a1bdd81d78c539195e85fb [file] [log] [blame]
Selim Cinek396caca2018-04-10 17:46:46 -07001/*
2 * Copyright (C) 2018 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.internal.widget;
18
19import android.content.Context;
20import android.content.res.ColorStateList;
21import android.graphics.drawable.DrawableWrapper;
22import android.graphics.drawable.GradientDrawable;
23import android.graphics.drawable.InsetDrawable;
24import android.graphics.drawable.RippleDrawable;
25import android.util.AttributeSet;
26import android.view.RemotableViewMethod;
27import android.widget.Button;
28import android.widget.RemoteViews;
29
30/**
31 * A button implementation for the emphasized notification style.
32 *
33 * @hide
34 */
35@RemoteViews.RemoteView
36public class EmphasizedNotificationButton extends Button {
37 private final RippleDrawable mRipple;
38 private final int mStrokeWidth;
39 private final int mStrokeColor;
40
41 public EmphasizedNotificationButton(Context context) {
42 this(context, null);
43 }
44
45 public EmphasizedNotificationButton(Context context, AttributeSet attrs) {
46 this(context, attrs, 0);
47 }
48
49 public EmphasizedNotificationButton(Context context, AttributeSet attrs, int defStyleAttr) {
50 this(context, attrs, defStyleAttr, 0);
51 }
52
53 public EmphasizedNotificationButton(Context context, AttributeSet attrs, int defStyleAttr,
54 int defStyleRes) {
55 super(context, attrs, defStyleAttr, defStyleRes);
56 DrawableWrapper background = (DrawableWrapper) getBackground().mutate();
57 mRipple = (RippleDrawable) background.getDrawable();
58 mStrokeWidth = getResources().getDimensionPixelSize(
59 com.android.internal.R.dimen.emphasized_button_stroke_width);
60 mStrokeColor = getContext().getColor(com.android.internal.R.color.material_grey_300);
61 mRipple.mutate();
62 }
63
64 @RemotableViewMethod
65 public void setRippleColor(ColorStateList color) {
66 mRipple.setColor(color);
67 invalidate();
68 }
69
70 @RemotableViewMethod
71 public void setButtonBackground(ColorStateList color) {
72 GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
73 inner.setColor(color);
74 invalidate();
75 }
76
77 @RemotableViewMethod
78 public void setHasStroke(boolean hasStroke) {
79 GradientDrawable inner = (GradientDrawable) mRipple.getDrawable(0);
80 inner.setStroke(hasStroke ? mStrokeWidth : 0, mStrokeColor);
81 invalidate();
82 }
83}