blob: b4f81b38c0d522996fed3de0ce6bbc3a67b4938c [file] [log] [blame]
Eric Erfanian2ca43182017-08-31 06:57:16 -07001/*
2 * Copyright (C) 2017 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
sail3bcea982017-09-03 13:57:22 -070017package com.android.bubble;
Eric Erfanian2ca43182017-08-31 06:57:16 -070018
19import android.app.PendingIntent;
20import android.graphics.drawable.Icon;
21import android.support.annotation.ColorInt;
22import android.support.annotation.NonNull;
23import android.support.annotation.Px;
24import com.google.auto.value.AutoValue;
25import java.util.Collections;
26import java.util.List;
27
28/** Info for displaying a {@link Bubble} */
29@AutoValue
30public abstract class BubbleInfo {
31 @ColorInt
32 public abstract int getPrimaryColor();
33
34 @NonNull
35 public abstract Icon getPrimaryIcon();
36
37 @NonNull
38 public abstract PendingIntent getPrimaryIntent();
39
40 @Px
41 public abstract int getStartingYPosition();
42
43 @NonNull
44 public abstract List<Action> getActions();
45
46 public static Builder builder() {
47 return new AutoValue_BubbleInfo.Builder().setActions(Collections.emptyList());
48 }
49
50 public static Builder from(@NonNull BubbleInfo bubbleInfo) {
51 return builder()
52 .setPrimaryIntent(bubbleInfo.getPrimaryIntent())
53 .setPrimaryColor(bubbleInfo.getPrimaryColor())
54 .setPrimaryIcon(bubbleInfo.getPrimaryIcon())
55 .setStartingYPosition(bubbleInfo.getStartingYPosition())
56 .setActions(bubbleInfo.getActions());
57 }
58
59 /** Builder for {@link BubbleInfo} */
60 @AutoValue.Builder
61 public abstract static class Builder {
62
63 public abstract Builder setPrimaryColor(@ColorInt int primaryColor);
64
65 public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon);
66
67 public abstract Builder setPrimaryIntent(@NonNull PendingIntent primaryIntent);
68
69 public abstract Builder setStartingYPosition(@Px int startingYPosition);
70
71 public abstract Builder setActions(List<Action> actions);
72
73 public abstract BubbleInfo build();
74 }
75
76 /** Represents actions to be shown in the bubble when expanded */
77 @AutoValue
78 public abstract static class Action {
79
80 @NonNull
81 public abstract Icon getIcon();
82
83 @NonNull
84 public abstract CharSequence getName();
85
86 @NonNull
87 public abstract PendingIntent getIntent();
88
89 public abstract boolean isEnabled();
90
91 public abstract boolean isChecked();
92
93 public static Builder builder() {
94 return new AutoValue_BubbleInfo_Action.Builder().setEnabled(true).setChecked(false);
95 }
96
97 public static Builder from(@NonNull Action action) {
98 return builder()
99 .setIntent(action.getIntent())
100 .setChecked(action.isChecked())
101 .setEnabled(action.isEnabled())
102 .setName(action.getName())
103 .setIcon(action.getIcon());
104 }
105
106 /** Builder for {@link Action} */
107 @AutoValue.Builder
108 public abstract static class Builder {
109
110 public abstract Builder setIcon(@NonNull Icon icon);
111
112 public abstract Builder setName(@NonNull CharSequence name);
113
114 public abstract Builder setIntent(@NonNull PendingIntent intent);
115
116 public abstract Builder setEnabled(boolean enabled);
117
118 public abstract Builder setChecked(boolean checked);
119
120 public abstract Action build();
121 }
122 }
123}