Update BubbleMetadata#setDesiredHeight to be in DPs
Also adds a method to set via res id as well.
Fixes: 127713900
Test: atest NotificationTest; manual - in test app set DP value
Change-Id: Ibc33fff6ca2115d703b0710ba512d98f89135cb2
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 523b200..c9bd95d 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -19,6 +19,7 @@
import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;
import android.annotation.ColorInt;
+import android.annotation.DimenRes;
import android.annotation.DrawableRes;
import android.annotation.IdRes;
import android.annotation.IntDef;
@@ -8519,6 +8520,7 @@
private PendingIntent mDeleteIntent;
private Icon mIcon;
private int mDesiredHeight;
+ @DimenRes private int mDesiredHeightResId;
private int mFlags;
/**
@@ -8545,10 +8547,11 @@
private static final int FLAG_SUPPRESS_INITIAL_NOTIFICATION = 0x00000002;
private BubbleMetadata(PendingIntent expandIntent, PendingIntent deleteIntent,
- Icon icon, int height) {
+ Icon icon, int height, @DimenRes int heightResId) {
mPendingIntent = expandIntent;
mIcon = icon;
mDesiredHeight = height;
+ mDesiredHeightResId = heightResId;
mDeleteIntent = deleteIntent;
}
@@ -8560,6 +8563,7 @@
if (in.readInt() != 0) {
mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in);
}
+ mDesiredHeightResId = in.readInt();
}
/**
@@ -8598,7 +8602,7 @@
}
/**
- * @return the ideal height for the floating window that app content defined by
+ * @return the ideal height, in DPs, for the floating window that app content defined by
* {@link #getIntent()} for this bubble.
*/
public int getDesiredHeight() {
@@ -8606,6 +8610,15 @@
}
/**
+ * @return the resId of ideal height for the floating window that app content defined by
+ * {@link #getIntent()} for this bubble.
+ */
+ @DimenRes
+ public int getDesiredHeightResId() {
+ return mDesiredHeightResId;
+ }
+
+ /**
* @return whether this bubble should auto expand when it is posted.
*
* @see BubbleMetadata.Builder#setAutoExpandBubble(boolean)
@@ -8652,6 +8665,7 @@
if (mDeleteIntent != null) {
mDeleteIntent.writeToParcel(out, 0);
}
+ out.writeInt(mDesiredHeightResId);
}
private void setFlags(int flags) {
@@ -8666,6 +8680,7 @@
private PendingIntent mPendingIntent;
private Icon mIcon;
private int mDesiredHeight;
+ @DimenRes private int mDesiredHeightResId;
private int mFlags;
private PendingIntent mDeleteIntent;
@@ -8718,13 +8733,35 @@
}
/**
- * Sets the desired height for the app content defined by
+ * Sets the desired height in DPs for the app content defined by
* {@link #setIntent(PendingIntent)}, this height may not be respected if there is not
* enough space on the screen or if the provided height is too small to be useful.
+ * <p>
+ * If {@link #setDesiredHeightResId(int)} was previously called on this builder, the
+ * previous value set will be cleared after calling this method, and this value will
+ * be used instead.
*/
@NonNull
public BubbleMetadata.Builder setDesiredHeight(int height) {
mDesiredHeight = Math.max(height, 0);
+ mDesiredHeightResId = 0;
+ return this;
+ }
+
+
+ /**
+ * Sets the desired height via resId for the app content defined by
+ * {@link #setIntent(PendingIntent)}, this height may not be respected if there is not
+ * enough space on the screen or if the provided height is too small to be useful.
+ * <p>
+ * If {@link #setDesiredHeight(int)} was previously called on this builder, the
+ * previous value set will be cleared after calling this method, and this value will
+ * be used instead.
+ */
+ @NonNull
+ public BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int heightResId) {
+ mDesiredHeightResId = heightResId;
+ mDesiredHeight = 0;
return this;
}
@@ -8786,7 +8823,7 @@
throw new IllegalStateException("Must supply an icon for the bubble");
}
BubbleMetadata data = new BubbleMetadata(mPendingIntent, mDeleteIntent,
- mIcon, mDesiredHeight);
+ mIcon, mDesiredHeight, mDesiredHeightResId);
data.setFlags(mFlags);
return data;
}