• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package com.android.dialershared.bubble;
18 
19 import android.app.PendingIntent;
20 import android.graphics.drawable.Icon;
21 import android.support.annotation.ColorInt;
22 import android.support.annotation.NonNull;
23 import android.support.annotation.Px;
24 import com.google.auto.value.AutoValue;
25 import java.util.Collections;
26 import java.util.List;
27 
28 /** Info for displaying a {@link Bubble} */
29 @AutoValue
30 public abstract class BubbleInfo {
31   @ColorInt
getPrimaryColor()32   public abstract int getPrimaryColor();
33 
34   @NonNull
getPrimaryIcon()35   public abstract Icon getPrimaryIcon();
36 
37   @NonNull
getPrimaryIntent()38   public abstract PendingIntent getPrimaryIntent();
39 
40   @Px
getStartingYPosition()41   public abstract int getStartingYPosition();
42 
43   @NonNull
getActions()44   public abstract List<Action> getActions();
45 
builder()46   public static Builder builder() {
47     return new AutoValue_BubbleInfo.Builder().setActions(Collections.emptyList());
48   }
49 
from(@onNull BubbleInfo bubbleInfo)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 
setPrimaryColor(@olorInt int primaryColor)63     public abstract Builder setPrimaryColor(@ColorInt int primaryColor);
64 
setPrimaryIcon(@onNull Icon primaryIcon)65     public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon);
66 
setPrimaryIntent(@onNull PendingIntent primaryIntent)67     public abstract Builder setPrimaryIntent(@NonNull PendingIntent primaryIntent);
68 
setStartingYPosition(@x int startingYPosition)69     public abstract Builder setStartingYPosition(@Px int startingYPosition);
70 
setActions(List<Action> actions)71     public abstract Builder setActions(List<Action> actions);
72 
build()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
getIcon()81     public abstract Icon getIcon();
82 
83     @NonNull
getName()84     public abstract CharSequence getName();
85 
86     @NonNull
getIntent()87     public abstract PendingIntent getIntent();
88 
isEnabled()89     public abstract boolean isEnabled();
90 
isChecked()91     public abstract boolean isChecked();
92 
builder()93     public static Builder builder() {
94       return new AutoValue_BubbleInfo_Action.Builder().setEnabled(true).setChecked(false);
95     }
96 
from(@onNull Action action)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 
setIcon(@onNull Icon icon)110       public abstract Builder setIcon(@NonNull Icon icon);
111 
setName(@onNull CharSequence name)112       public abstract Builder setName(@NonNull CharSequence name);
113 
setIntent(@onNull PendingIntent intent)114       public abstract Builder setIntent(@NonNull PendingIntent intent);
115 
setEnabled(boolean enabled)116       public abstract Builder setEnabled(boolean enabled);
117 
setChecked(boolean checked)118       public abstract Builder setChecked(boolean checked);
119 
build()120       public abstract Action build();
121     }
122   }
123 }
124