Eric Erfanian | 938468d | 2017-10-24 14:05:52 -0700 | [diff] [blame^] | 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 | @Px |
| 39 | public abstract int getStartingYPosition(); |
| 40 | |
| 41 | @NonNull |
| 42 | public abstract List<Action> getActions(); |
| 43 | |
| 44 | public static Builder builder() { |
| 45 | return new AutoValue_NewBubbleInfo.Builder().setActions(Collections.emptyList()); |
| 46 | } |
| 47 | |
| 48 | public static Builder from(@NonNull NewBubbleInfo bubbleInfo) { |
| 49 | return builder() |
| 50 | .setPrimaryColor(bubbleInfo.getPrimaryColor()) |
| 51 | .setPrimaryIcon(bubbleInfo.getPrimaryIcon()) |
| 52 | .setStartingYPosition(bubbleInfo.getStartingYPosition()) |
| 53 | .setActions(bubbleInfo.getActions()); |
| 54 | } |
| 55 | |
| 56 | /** Builder for {@link NewBubbleInfo} */ |
| 57 | @AutoValue.Builder |
| 58 | public abstract static class Builder { |
| 59 | |
| 60 | public abstract Builder setPrimaryColor(@ColorInt int primaryColor); |
| 61 | |
| 62 | public abstract Builder setPrimaryIcon(@NonNull Icon primaryIcon); |
| 63 | |
| 64 | public abstract Builder setStartingYPosition(@Px int startingYPosition); |
| 65 | |
| 66 | public abstract Builder setActions(List<Action> actions); |
| 67 | |
| 68 | public abstract NewBubbleInfo build(); |
| 69 | } |
| 70 | |
| 71 | /** Represents actions to be shown in the bubble when expanded */ |
| 72 | @AutoValue |
| 73 | public abstract static class Action { |
| 74 | |
| 75 | public abstract Drawable getIconDrawable(); |
| 76 | |
| 77 | @Nullable |
| 78 | public abstract CharSequence getName(); |
| 79 | |
| 80 | @NonNull |
| 81 | public abstract PendingIntent getIntent(); |
| 82 | |
| 83 | public abstract boolean isEnabled(); |
| 84 | |
| 85 | public abstract boolean isChecked(); |
| 86 | |
| 87 | public static Builder builder() { |
| 88 | return new AutoValue_NewBubbleInfo_Action.Builder().setEnabled(true).setChecked(false); |
| 89 | } |
| 90 | |
| 91 | public static Builder from(@NonNull Action action) { |
| 92 | return builder() |
| 93 | .setIntent(action.getIntent()) |
| 94 | .setChecked(action.isChecked()) |
| 95 | .setEnabled(action.isEnabled()) |
| 96 | .setName(action.getName()) |
| 97 | .setIconDrawable(action.getIconDrawable()); |
| 98 | } |
| 99 | |
| 100 | /** Builder for {@link Action} */ |
| 101 | @AutoValue.Builder |
| 102 | public abstract static class Builder { |
| 103 | |
| 104 | public abstract Builder setIconDrawable(Drawable iconDrawable); |
| 105 | |
| 106 | public abstract Builder setName(@Nullable CharSequence name); |
| 107 | |
| 108 | public abstract Builder setIntent(@NonNull PendingIntent intent); |
| 109 | |
| 110 | public abstract Builder setEnabled(boolean enabled); |
| 111 | |
| 112 | public abstract Builder setChecked(boolean checked); |
| 113 | |
| 114 | public abstract Action build(); |
| 115 | } |
| 116 | } |
| 117 | } |