Home | History | Annotate | Download | only in newbubble
      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.newbubble;
     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 NewBubble} */
     31 @AutoValue
     32 public abstract class NewBubbleInfo {
     33   @ColorInt
     34   public abstract int getPrimaryColor();
     35 
     36   public abstract Icon getPrimaryIcon();
     37 
     38   @Nullable
     39   public abstract Drawable getAvatar();
     40 
     41   @Px
     42   public abstract int getStartingYPosition();
     43 
     44   @NonNull
     45   public abstract List<Action> getActions();
     46 
     47   public static Builder builder() {
     48     return new AutoValue_NewBubbleInfo.Builder().setActions(Collections.emptyList());
     49   }
     50 
     51   public static Builder from(@NonNull NewBubbleInfo 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 NewBubbleInfo} */
     61   @AutoValue.Builder
     62   public abstract static class Builder {
     63 
     64     public abstract Builder setPrimaryColor(@ColorInt int primaryColor);
     65 
     66     public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon);
     67 
     68     public abstract Builder setAvatar(@Nullable Drawable avatar);
     69 
     70     public abstract Builder setStartingYPosition(@Px int startingYPosition);
     71 
     72     public abstract Builder setActions(List<Action> actions);
     73 
     74     public abstract NewBubbleInfo build();
     75   }
     76 
     77   /** Represents actions to be shown in the bubble when expanded */
     78   @AutoValue
     79   public abstract static class Action {
     80 
     81     public abstract Drawable getIconDrawable();
     82 
     83     @Nullable
     84     public abstract Drawable getSecondaryIconDrawable();
     85 
     86     @NonNull
     87     public abstract CharSequence getName();
     88 
     89     @NonNull
     90     public abstract PendingIntent getIntent();
     91 
     92     public abstract boolean isCheckable();
     93 
     94     public abstract boolean isChecked();
     95 
     96     public static Builder builder() {
     97       return new AutoValue_NewBubbleInfo_Action.Builder().setCheckable(true).setChecked(false);
     98     }
     99 
    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 
    114       public abstract Builder setIconDrawable(Drawable iconDrawable);
    115 
    116       public abstract Builder setSecondaryIconDrawable(@Nullable Drawable secondaryIconDrawable);
    117 
    118       public abstract Builder setName(@NonNull CharSequence name);
    119 
    120       public abstract Builder setIntent(@NonNull PendingIntent intent);
    121 
    122       public abstract Builder setCheckable(boolean enabled);
    123 
    124       public abstract Builder setChecked(boolean checked);
    125 
    126       public abstract Action build();
    127     }
    128   }
    129 }
    130