• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.bubble;
18 
19 import android.app.PendingIntent;
20 import android.graphics.drawable.Drawable;
21 import android.graphics.drawable.Icon;
22 import android.support.annotation.ColorInt;
23 import android.support.annotation.NonNull;
24 import android.support.annotation.Nullable;
25 import android.support.annotation.Px;
26 import com.google.auto.value.AutoValue;
27 import java.util.Collections;
28 import java.util.List;
29 
30 /** Info for displaying a {@link Bubble} */
31 @AutoValue
32 public abstract class BubbleInfo {
33   @ColorInt
getPrimaryColor()34   public abstract int getPrimaryColor();
35 
getPrimaryIcon()36   public abstract Icon getPrimaryIcon();
37 
38   @Nullable
getAvatar()39   public abstract Drawable getAvatar();
40 
41   @Px
getStartingYPosition()42   public abstract int getStartingYPosition();
43 
44   @NonNull
getActions()45   public abstract List<Action> getActions();
46 
builder()47   public static Builder builder() {
48     return new AutoValue_BubbleInfo.Builder().setActions(Collections.emptyList());
49   }
50 
from(@onNull BubbleInfo bubbleInfo)51   public static Builder from(@NonNull BubbleInfo bubbleInfo) {
52     return builder()
53         .setPrimaryColor(bubbleInfo.getPrimaryColor())
54         .setPrimaryIcon(bubbleInfo.getPrimaryIcon())
55         .setStartingYPosition(bubbleInfo.getStartingYPosition())
56         .setActions(bubbleInfo.getActions())
57         .setAvatar(bubbleInfo.getAvatar());
58   }
59 
60   /** Builder for {@link BubbleInfo} */
61   @AutoValue.Builder
62   public abstract static class Builder {
63 
setPrimaryColor(@olorInt int primaryColor)64     public abstract Builder setPrimaryColor(@ColorInt int primaryColor);
65 
setPrimaryIcon(@onNull Icon primaryIcon)66     public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon);
67 
setAvatar(@ullable Drawable avatar)68     public abstract Builder setAvatar(@Nullable Drawable avatar);
69 
setStartingYPosition(@x int startingYPosition)70     public abstract Builder setStartingYPosition(@Px int startingYPosition);
71 
setActions(List<Action> actions)72     public abstract Builder setActions(List<Action> actions);
73 
build()74     public abstract BubbleInfo build();
75   }
76 
77   /** Represents actions to be shown in the bubble when expanded */
78   @AutoValue
79   public abstract static class Action {
80 
getIconDrawable()81     public abstract Drawable getIconDrawable();
82 
83     @Nullable
getSecondaryIconDrawable()84     public abstract Drawable getSecondaryIconDrawable();
85 
86     @NonNull
getName()87     public abstract CharSequence getName();
88 
89     @NonNull
getIntent()90     public abstract PendingIntent getIntent();
91 
isCheckable()92     public abstract boolean isCheckable();
93 
isChecked()94     public abstract boolean isChecked();
95 
builder()96     public static Builder builder() {
97       return new AutoValue_BubbleInfo_Action.Builder().setCheckable(true).setChecked(false);
98     }
99 
from(@onNull Action action)100     public static Builder from(@NonNull Action action) {
101       return builder()
102           .setIntent(action.getIntent())
103           .setChecked(action.isChecked())
104           .setCheckable(action.isCheckable())
105           .setName(action.getName())
106           .setIconDrawable(action.getIconDrawable())
107           .setSecondaryIconDrawable(action.getSecondaryIconDrawable());
108     }
109 
110     /** Builder for {@link Action} */
111     @AutoValue.Builder
112     public abstract static class Builder {
113 
setIconDrawable(Drawable iconDrawable)114       public abstract Builder setIconDrawable(Drawable iconDrawable);
115 
setSecondaryIconDrawable(@ullable Drawable secondaryIconDrawable)116       public abstract Builder setSecondaryIconDrawable(@Nullable Drawable secondaryIconDrawable);
117 
setName(@onNull CharSequence name)118       public abstract Builder setName(@NonNull CharSequence name);
119 
setIntent(@onNull PendingIntent intent)120       public abstract Builder setIntent(@NonNull PendingIntent intent);
121 
setCheckable(boolean enabled)122       public abstract Builder setCheckable(boolean enabled);
123 
setChecked(boolean checked)124       public abstract Builder setChecked(boolean checked);
125 
build()126       public abstract Action build();
127     }
128   }
129 }
130