1 /* 2 * Copyright (C) 2023 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.wm.shell.common.bubbles; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.graphics.Point; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import java.util.ArrayList; 26 import java.util.List; 27 28 /** 29 * Represents an update to bubbles state. This is passed through 30 * {@link com.android.wm.shell.bubbles.IBubblesListener} to launcher so that taskbar may render 31 * bubbles. This should be kept this as minimal as possible in terms of data. 32 */ 33 public class BubbleBarUpdate implements Parcelable { 34 35 public static final String BUNDLE_KEY = "update"; 36 37 public final boolean initialState; 38 public boolean expandedChanged; 39 public boolean expanded; 40 public boolean shouldShowEducation; 41 @Nullable 42 public String selectedBubbleKey; 43 @Nullable 44 public BubbleInfo addedBubble; 45 @Nullable 46 public BubbleInfo updatedBubble; 47 @Nullable 48 public String suppressedBubbleKey; 49 @Nullable 50 public String unsupressedBubbleKey; 51 @Nullable 52 public BubbleBarLocation bubbleBarLocation; 53 @Nullable 54 public Point expandedViewDropTargetSize; 55 public boolean showOverflowChanged; 56 public boolean showOverflow; 57 58 // This is only populated if bubbles have been removed. 59 public List<RemovedBubble> removedBubbles = new ArrayList<>(); 60 61 // This is only populated if the order of the bubbles has changed. 62 public List<String> bubbleKeysInOrder = new ArrayList<>(); 63 64 // This is only populated the first time a listener is connected so it gets the current state. 65 public List<BubbleInfo> currentBubbleList = new ArrayList<>(); 66 67 BubbleBarUpdate()68 public BubbleBarUpdate() { 69 this(false); 70 } 71 BubbleBarUpdate(boolean initialState)72 private BubbleBarUpdate(boolean initialState) { 73 this.initialState = initialState; 74 } 75 BubbleBarUpdate(Parcel parcel)76 public BubbleBarUpdate(Parcel parcel) { 77 initialState = parcel.readBoolean(); 78 expandedChanged = parcel.readBoolean(); 79 expanded = parcel.readBoolean(); 80 shouldShowEducation = parcel.readBoolean(); 81 selectedBubbleKey = parcel.readString(); 82 addedBubble = parcel.readParcelable(BubbleInfo.class.getClassLoader(), 83 BubbleInfo.class); 84 updatedBubble = parcel.readParcelable(BubbleInfo.class.getClassLoader(), 85 BubbleInfo.class); 86 suppressedBubbleKey = parcel.readString(); 87 unsupressedBubbleKey = parcel.readString(); 88 removedBubbles = parcel.readParcelableList(new ArrayList<>(), 89 RemovedBubble.class.getClassLoader(), RemovedBubble.class); 90 parcel.readStringList(bubbleKeysInOrder); 91 currentBubbleList = parcel.readParcelableList(new ArrayList<>(), 92 BubbleInfo.class.getClassLoader(), BubbleInfo.class); 93 bubbleBarLocation = parcel.readParcelable(BubbleBarLocation.class.getClassLoader(), 94 BubbleBarLocation.class); 95 expandedViewDropTargetSize = parcel.readParcelable(Point.class.getClassLoader(), 96 Point.class); 97 showOverflowChanged = parcel.readBoolean(); 98 showOverflow = parcel.readBoolean(); 99 } 100 101 /** 102 * Returns whether anything has changed in this update. 103 */ anythingChanged()104 public boolean anythingChanged() { 105 return expandedChanged 106 || selectedBubbleKey != null 107 || addedBubble != null 108 || updatedBubble != null 109 || !removedBubbles.isEmpty() 110 || !bubbleKeysInOrder.isEmpty() 111 || suppressedBubbleKey != null 112 || unsupressedBubbleKey != null 113 || !currentBubbleList.isEmpty() 114 || bubbleBarLocation != null 115 || showOverflowChanged; 116 } 117 118 @NonNull 119 @Override toString()120 public String toString() { 121 return "BubbleBarUpdate{" 122 + " initialState=" + initialState 123 + " expandedChanged=" + expandedChanged 124 + " expanded=" + expanded 125 + " selectedBubbleKey=" + selectedBubbleKey 126 + " shouldShowEducation=" + shouldShowEducation 127 + " addedBubble=" + addedBubble 128 + " updatedBubble=" + updatedBubble 129 + " suppressedBubbleKey=" + suppressedBubbleKey 130 + " unsuppressedBubbleKey=" + unsupressedBubbleKey 131 + " removedBubbles=" + removedBubbles 132 + " bubbles=" + bubbleKeysInOrder 133 + " currentBubbleList=" + currentBubbleList 134 + " bubbleBarLocation=" + bubbleBarLocation 135 + " expandedViewDropTargetSize=" + expandedViewDropTargetSize 136 + " showOverflowChanged=" + showOverflowChanged 137 + " showOverflow=" + showOverflow 138 + " }"; 139 } 140 141 @Override describeContents()142 public int describeContents() { 143 return 0; 144 } 145 146 @Override writeToParcel(Parcel parcel, int flags)147 public void writeToParcel(Parcel parcel, int flags) { 148 parcel.writeBoolean(initialState); 149 parcel.writeBoolean(expandedChanged); 150 parcel.writeBoolean(expanded); 151 parcel.writeBoolean(shouldShowEducation); 152 parcel.writeString(selectedBubbleKey); 153 parcel.writeParcelable(addedBubble, flags); 154 parcel.writeParcelable(updatedBubble, flags); 155 parcel.writeString(suppressedBubbleKey); 156 parcel.writeString(unsupressedBubbleKey); 157 parcel.writeParcelableList(removedBubbles, flags); 158 parcel.writeStringList(bubbleKeysInOrder); 159 parcel.writeParcelableList(currentBubbleList, flags); 160 parcel.writeParcelable(bubbleBarLocation, flags); 161 parcel.writeParcelable(expandedViewDropTargetSize, flags); 162 parcel.writeBoolean(showOverflowChanged); 163 parcel.writeBoolean(showOverflow); 164 } 165 166 /** 167 * Create update for initial set of values. 168 * <p> 169 * Used when bubble bar is newly created. 170 */ createInitialState()171 public static BubbleBarUpdate createInitialState() { 172 return new BubbleBarUpdate(true); 173 } 174 175 @NonNull 176 public static final Creator<BubbleBarUpdate> CREATOR = 177 new Creator<>() { 178 public BubbleBarUpdate createFromParcel(Parcel source) { 179 return new BubbleBarUpdate(source); 180 } 181 182 public BubbleBarUpdate[] newArray(int size) { 183 return new BubbleBarUpdate[size]; 184 } 185 }; 186 } 187