diff options
| author | 2019-03-22 17:31:16 +0000 | |
|---|---|---|
| committer | 2019-03-22 17:31:16 +0000 | |
| commit | d3304bfd0ab8c8f10051a9cd10df8c23f65e71a9 (patch) | |
| tree | a411a3b14c46c2c671ef0e671331784f2bcf8b74 | |
| parent | 36e132b02a72443ec488dd499e759b7cfb108aa3 (diff) | |
| parent | 7af771a574567f4946c9ffeb6d9b79a8fe0aff9d (diff) | |
Merge "Update BubbleMetadata#setDesiredHeight to be in DPs"
| -rw-r--r-- | api/current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/app/Notification.java | 45 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java | 42 |
3 files changed, 78 insertions, 11 deletions
diff --git a/api/current.txt b/api/current.txt index 272d1d7f1f4d..87a0125eb49a 100644 --- a/api/current.txt +++ b/api/current.txt @@ -5481,6 +5481,7 @@ package android.app { method public boolean getAutoExpandBubble(); method @Nullable public android.app.PendingIntent getDeleteIntent(); method public int getDesiredHeight(); + method @DimenRes public int getDesiredHeightResId(); method @NonNull public android.graphics.drawable.Icon getIcon(); method @NonNull public android.app.PendingIntent getIntent(); method public boolean getSuppressInitialNotification(); @@ -5494,6 +5495,7 @@ package android.app { method @NonNull public android.app.Notification.BubbleMetadata.Builder setAutoExpandBubble(boolean); method @NonNull public android.app.Notification.BubbleMetadata.Builder setDeleteIntent(@Nullable android.app.PendingIntent); method @NonNull public android.app.Notification.BubbleMetadata.Builder setDesiredHeight(int); + method @NonNull public android.app.Notification.BubbleMetadata.Builder setDesiredHeightResId(@DimenRes int); method @NonNull public android.app.Notification.BubbleMetadata.Builder setIcon(@NonNull android.graphics.drawable.Icon); method @NonNull public android.app.Notification.BubbleMetadata.Builder setIntent(@NonNull android.app.PendingIntent); method @NonNull public android.app.Notification.BubbleMetadata.Builder setSuppressInitialNotification(boolean); diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 6e3132b6a5c0..d634aa578429 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -21,6 +21,7 @@ import static android.graphics.drawable.Icon.TYPE_BITMAP; 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; @@ -8521,6 +8522,7 @@ public class Notification implements Parcelable private PendingIntent mDeleteIntent; private Icon mIcon; private int mDesiredHeight; + @DimenRes private int mDesiredHeightResId; private int mFlags; /** @@ -8547,10 +8549,11 @@ public class Notification implements Parcelable 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; } @@ -8562,6 +8565,7 @@ public class Notification implements Parcelable if (in.readInt() != 0) { mDeleteIntent = PendingIntent.CREATOR.createFromParcel(in); } + mDesiredHeightResId = in.readInt(); } /** @@ -8589,7 +8593,7 @@ public class Notification implements Parcelable } /** - * @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() { @@ -8597,6 +8601,15 @@ public class Notification implements Parcelable } /** + * @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) @@ -8643,6 +8656,7 @@ public class Notification implements Parcelable if (mDeleteIntent != null) { mDeleteIntent.writeToParcel(out, 0); } + out.writeInt(mDesiredHeightResId); } private void setFlags(int flags) { @@ -8657,6 +8671,7 @@ public class Notification implements Parcelable private PendingIntent mPendingIntent; private Icon mIcon; private int mDesiredHeight; + @DimenRes private int mDesiredHeightResId; private int mFlags; private PendingIntent mDeleteIntent; @@ -8709,13 +8724,35 @@ public class Notification implements Parcelable } /** - * 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; } @@ -8777,7 +8814,7 @@ public class Notification implements Parcelable 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; } diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java index 14e910f41cab..8e3afd8bcae0 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java +++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleExpandedView.java @@ -43,6 +43,7 @@ import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.ShapeDrawable; import android.os.RemoteException; import android.os.ServiceManager; +import android.os.UserHandle; import android.provider.Settings; import android.service.notification.StatusBarNotification; import android.util.AttributeSet; @@ -457,30 +458,38 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList void updateHeight() { if (usingActivityView()) { Notification.BubbleMetadata data = mEntry.getBubbleMetadata(); - int desiredHeight; + float desiredHeight; if (data == null) { // This is a contentIntent based bubble, lets allow it to be the max height // as it was forced into this mode and not prepared to be small desiredHeight = mStackView.getMaxExpandedHeight(); } else { - desiredHeight = data.getDesiredHeight() > 0 - ? data.getDesiredHeight() - : mMinHeight; + boolean useRes = data.getDesiredHeightResId() != 0; + float desiredPx; + if (useRes) { + desiredPx = getDimenForPackageUser(data.getDesiredHeightResId(), + mEntry.notification.getPackageName(), + mEntry.notification.getUser().getIdentifier()); + } else { + desiredPx = data.getDesiredHeight() + * getContext().getResources().getDisplayMetrics().density; + } + desiredHeight = desiredPx > 0 ? desiredPx : mMinHeight; } int chromeHeight = mPermissionView.getVisibility() != View.VISIBLE ? mHeaderHeight : mPermissionHeight; int max = mStackView.getMaxExpandedHeight() - chromeHeight - mPointerView.getHeight() - mPointerMargin; - int height = Math.min(desiredHeight, max); + float height = Math.min(desiredHeight, max); height = Math.max(height, mMinHeight); LayoutParams lp = (LayoutParams) mActivityView.getLayoutParams(); mNeedsNewHeight = lp.height != height; if (!mKeyboardVisible) { // If the keyboard is visible... don't adjust the height because that will cause // a configuration change and the keyboard will be lost. - lp.height = height; - mBubbleHeight = height; + lp.height = (int) height; + mBubbleHeight = (int) height; mActivityView.setLayoutParams(lp); mNeedsNewHeight = false; } @@ -712,4 +721,23 @@ public class BubbleExpandedView extends LinearLayout implements View.OnClickList mStackView.getNormalizedXPosition(), mStackView.getNormalizedYPosition()); } + + private int getDimenForPackageUser(int resId, String pkg, int userId) { + Resources r; + if (pkg != null) { + try { + if (userId == UserHandle.USER_ALL) { + userId = UserHandle.USER_SYSTEM; + } + r = mPm.getResourcesForApplicationAsUser(pkg, userId); + return r.getDimensionPixelSize(resId); + } catch (PackageManager.NameNotFoundException ex) { + // Uninstalled, don't care + } catch (Resources.NotFoundException e) { + // Invalid res id, return 0 and user our default + Log.e(TAG, "Couldn't find desired height res id", e); + } + } + return 0; + } } |