Loading packages/SystemUI/src/com/android/systemui/bubbles/BadgeRenderer.javadeleted 100644 → 0 +0 −97 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.bubbles; import static android.graphics.Paint.ANTI_ALIAS_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.util.Log; import com.android.systemui.R; // XXX: Mostly opied from launcher code / can we share? /** * Contains parameters necessary to draw a badge for an icon (e.g. the size of the badge). */ public class BadgeRenderer { private static final String TAG = TAG_WITH_CLASS_NAME ? "BadgeRenderer" : TAG_BUBBLES; /** The badge sizes are defined as percentages of the app icon size. */ private static final float SIZE_PERCENTAGE = 0.38f; /** Extra scale down of the dot. */ private static final float DOT_SCALE = 0.6f; private final float mDotCenterOffset; private final float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); public BadgeRenderer(Context context) { mDotCenterOffset = getDotCenterOffset(context); mCircleRadius = getDotRadius(mDotCenterOffset); } /** Space between the center of the dot and the top or left of the bubble stack. */ static float getDotCenterOffset(Context context) { final int iconBitmapSize = context.getResources().getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); return SIZE_PERCENTAGE * iconBitmapSize; } static float getDotRadius(float dotCenterOffset) { int size = (int) (DOT_SCALE * dotCenterOffset); return size / 2f; } /** * Draw a circle in the top right corner of the given bounds. * * @param color The color (based on the icon) to use for the badge. * @param iconBounds The bounds of the icon being badged. * @param badgeScale The progress of the animation, from 0 to 1. * @param spaceForOffset How much space to offset the badge up and to the left or right. * @param onLeft Whether the badge should be draw on left or right side. */ public void draw(Canvas canvas, int color, Rect iconBounds, float badgeScale, Point spaceForOffset, boolean onLeft) { if (iconBounds == null) { Log.e(TAG, "Invalid null argument(s) passed in call to draw."); return; } canvas.save(); // We draw the badge relative to its center. int x = onLeft ? iconBounds.left : iconBounds.right; float offset = onLeft ? (mDotCenterOffset / 2) : -(mDotCenterOffset / 2); float badgeCenterX = x + offset; float badgeCenterY = iconBounds.top + mDotCenterOffset / 2; canvas.translate(badgeCenterX + spaceForOffset.x, badgeCenterY - spaceForOffset.y); canvas.scale(badgeScale, badgeScale); mCirclePaint.setColor(color); canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); canvas.restore(); } } packages/SystemUI/src/com/android/systemui/bubbles/BadgedImageView.java +25 −13 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ package com.android.systemui.bubbles; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.ImageView; import com.android.internal.graphics.ColorUtils; import com.android.launcher3.icons.DotRenderer; import com.android.systemui.R; /** Loading @@ -31,17 +33,19 @@ import com.android.systemui.R; */ public class BadgedImageView extends ImageView { private BadgeRenderer mDotRenderer; private int mIconBitmapSize; private DotRenderer mDotRenderer; private Rect mTempBounds = new Rect(); private Point mTempPoint = new Point(); private int mIconBitmapSize; private int mDotColor; private float mDotScale = 0f; private int mUpdateDotColor; private boolean mShowUpdateDot; private boolean mShowDot; private boolean mOnLeft; /** Same as value in Launcher3 IconShape */ private static final int DEFAULT_PATH_SIZE = 100; public BadgedImageView(Context context) { this(context, null); } Loading @@ -58,7 +62,11 @@ public class BadgedImageView extends ImageView { int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mIconBitmapSize = getResources().getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); mDotRenderer = new BadgeRenderer(getContext()); Path iconShapePath = new Path(); float radius = DEFAULT_PATH_SIZE * 0.5f; iconShapePath.addCircle(radius /* x */, radius /* y */, radius, Path.Direction.CW); mDotRenderer = new DotRenderer(mIconBitmapSize, iconShapePath, DEFAULT_PATH_SIZE); TypedArray ta = context.obtainStyledAttributes( new int[] {android.R.attr.colorBackgroundFloating}); Loading @@ -68,11 +76,15 @@ public class BadgedImageView extends ImageView { @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mShowUpdateDot) { if (mShowDot) { getDrawingRect(mTempBounds); mTempPoint.set((getWidth() - mIconBitmapSize) / 2, getPaddingTop()); mDotRenderer.draw(canvas, mUpdateDotColor, mTempBounds, mDotScale, mTempPoint, mOnLeft); DotRenderer.DrawParams params = new DotRenderer.DrawParams(); params.color = mDotColor; params.iconBounds = mTempBounds; params.leftAlign = mOnLeft; params.scale = mDotScale; mDotRenderer.draw(canvas, params); } } Loading @@ -91,8 +103,8 @@ public class BadgedImageView extends ImageView { /** * Set whether the dot should show or not. */ public void setShowDot(boolean showBadge) { mShowUpdateDot = showBadge; public void setShowDot(boolean showDot) { mShowDot = showDot; invalidate(); } Loading @@ -100,14 +112,14 @@ public class BadgedImageView extends ImageView { * @return whether the dot is being displayed. */ public boolean isShowingDot() { return mShowUpdateDot; return mShowDot; } /** * The colour to use for the dot. */ public void setDotColor(int color) { mUpdateDotColor = ColorUtils.setAlphaComponent(color, 255 /* alpha */); mDotColor = ColorUtils.setAlphaComponent(color, 255 /* alpha */); invalidate(); } Loading packages/SystemUI/src/com/android/systemui/bubbles/BubbleFlyoutView.java +19 −7 Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ public class BubbleFlyoutView extends FrameLayout { private final int mPointerSize; private final int mBubbleSize; private final int mBubbleIconBitmapSize; private final float mBubbleIconTopPadding; private final int mFlyoutElevation; private final int mBubbleElevation; private final int mFloatingBackgroundColor; Loading @@ -72,7 +74,7 @@ public class BubbleFlyoutView extends FrameLayout { /** Values related to the 'new' dot which we use to figure out where to collapse the flyout. */ private final float mNewDotRadius; private final float mNewDotSize; private final float mNewDotOffsetFromBubbleBounds; private final float mOriginalDotSize; /** * The paint used to draw the background, whose color changes as the flyout transitions to the Loading Loading @@ -130,6 +132,14 @@ public class BubbleFlyoutView extends FrameLayout { /** The flyout's X translation when at rest (not animating or dragging). */ private float mRestingTranslationX = 0f; /** The badge sizes are defined as percentages of the app icon size. Same value as Launcher3. */ private static final float SIZE_PERCENTAGE = 0.228f; /** Extra scale down of the dot provides room for error in estimating actual dot location. * At the end of the flyout-to-dot animation, wherever the small dot ends up, its disappearance * and the appearance of the larger real dot forms a cohesive animation. */ private static final float DOT_SCALE = 0.6f; /** Callback to run when the flyout is hidden. */ private Runnable mOnHide; Loading @@ -147,10 +157,13 @@ public class BubbleFlyoutView extends FrameLayout { mBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size); mBubbleIconBitmapSize = res.getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); mBubbleIconTopPadding = (mBubbleSize - mBubbleIconBitmapSize) / 2f; mBubbleElevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); mFlyoutElevation = res.getDimensionPixelSize(R.dimen.bubble_flyout_elevation); mNewDotOffsetFromBubbleBounds = BadgeRenderer.getDotCenterOffset(context); mNewDotRadius = BadgeRenderer.getDotRadius(mNewDotOffsetFromBubbleBounds); mOriginalDotSize = SIZE_PERCENTAGE * mBubbleIconBitmapSize; mNewDotRadius = (DOT_SCALE * mOriginalDotSize) / 2f; mNewDotSize = mNewDotRadius * 2f; final TypedArray ta = mContext.obtainStyledAttributes( Loading Loading @@ -219,8 +232,7 @@ public class BubbleFlyoutView extends FrameLayout { post(() -> { // Multi line flyouts get top-aligned to the bubble. if (mFlyoutText.getLineCount() > 1) { float bubbleIconTopPadding = (mBubbleSize - mBubbleIconBitmapSize) / 2f; setTranslationY(stackPos.y + bubbleIconTopPadding); setTranslationY(stackPos.y + mBubbleIconTopPadding); } else { // Single line flyouts are vertically centered with respect to the bubble. setTranslationY( Loading Loading @@ -248,7 +260,7 @@ public class BubbleFlyoutView extends FrameLayout { // Calculate the translation values needed to be in the correct 'new dot' position. final float distanceFromFlyoutLeftToDotCenterX = mFlyoutSpaceFromBubble + mNewDotOffsetFromBubbleBounds / 2; mFlyoutSpaceFromBubble + mBubbleIconTopPadding + mOriginalDotSize / 2; if (mArrowPointingLeft) { mTranslationXWhenDot = -distanceFromFlyoutLeftToDotCenterX - mNewDotRadius; } else { Loading @@ -260,7 +272,7 @@ public class BubbleFlyoutView extends FrameLayout { getHeight() / 2f - mNewDotRadius - mBubbleSize / 2f + mNewDotOffsetFromBubbleBounds / 2; + mOriginalDotSize / 2; }); } Loading Loading
packages/SystemUI/src/com/android/systemui/bubbles/BadgeRenderer.javadeleted 100644 → 0 +0 −97 Original line number Diff line number Diff line /* * Copyright (C) 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.systemui.bubbles; import static android.graphics.Paint.ANTI_ALIAS_FLAG; import static android.graphics.Paint.FILTER_BITMAP_FLAG; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_BUBBLES; import static com.android.systemui.bubbles.BubbleDebugConfig.TAG_WITH_CLASS_NAME; import android.content.Context; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Rect; import android.util.Log; import com.android.systemui.R; // XXX: Mostly opied from launcher code / can we share? /** * Contains parameters necessary to draw a badge for an icon (e.g. the size of the badge). */ public class BadgeRenderer { private static final String TAG = TAG_WITH_CLASS_NAME ? "BadgeRenderer" : TAG_BUBBLES; /** The badge sizes are defined as percentages of the app icon size. */ private static final float SIZE_PERCENTAGE = 0.38f; /** Extra scale down of the dot. */ private static final float DOT_SCALE = 0.6f; private final float mDotCenterOffset; private final float mCircleRadius; private final Paint mCirclePaint = new Paint(ANTI_ALIAS_FLAG | FILTER_BITMAP_FLAG); public BadgeRenderer(Context context) { mDotCenterOffset = getDotCenterOffset(context); mCircleRadius = getDotRadius(mDotCenterOffset); } /** Space between the center of the dot and the top or left of the bubble stack. */ static float getDotCenterOffset(Context context) { final int iconBitmapSize = context.getResources().getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); return SIZE_PERCENTAGE * iconBitmapSize; } static float getDotRadius(float dotCenterOffset) { int size = (int) (DOT_SCALE * dotCenterOffset); return size / 2f; } /** * Draw a circle in the top right corner of the given bounds. * * @param color The color (based on the icon) to use for the badge. * @param iconBounds The bounds of the icon being badged. * @param badgeScale The progress of the animation, from 0 to 1. * @param spaceForOffset How much space to offset the badge up and to the left or right. * @param onLeft Whether the badge should be draw on left or right side. */ public void draw(Canvas canvas, int color, Rect iconBounds, float badgeScale, Point spaceForOffset, boolean onLeft) { if (iconBounds == null) { Log.e(TAG, "Invalid null argument(s) passed in call to draw."); return; } canvas.save(); // We draw the badge relative to its center. int x = onLeft ? iconBounds.left : iconBounds.right; float offset = onLeft ? (mDotCenterOffset / 2) : -(mDotCenterOffset / 2); float badgeCenterX = x + offset; float badgeCenterY = iconBounds.top + mDotCenterOffset / 2; canvas.translate(badgeCenterX + spaceForOffset.x, badgeCenterY - spaceForOffset.y); canvas.scale(badgeScale, badgeScale); mCirclePaint.setColor(color); canvas.drawCircle(0, 0, mCircleRadius, mCirclePaint); canvas.restore(); } }
packages/SystemUI/src/com/android/systemui/bubbles/BadgedImageView.java +25 −13 Original line number Diff line number Diff line Loading @@ -18,12 +18,14 @@ package com.android.systemui.bubbles; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.Point; import android.graphics.Rect; import android.util.AttributeSet; import android.widget.ImageView; import com.android.internal.graphics.ColorUtils; import com.android.launcher3.icons.DotRenderer; import com.android.systemui.R; /** Loading @@ -31,17 +33,19 @@ import com.android.systemui.R; */ public class BadgedImageView extends ImageView { private BadgeRenderer mDotRenderer; private int mIconBitmapSize; private DotRenderer mDotRenderer; private Rect mTempBounds = new Rect(); private Point mTempPoint = new Point(); private int mIconBitmapSize; private int mDotColor; private float mDotScale = 0f; private int mUpdateDotColor; private boolean mShowUpdateDot; private boolean mShowDot; private boolean mOnLeft; /** Same as value in Launcher3 IconShape */ private static final int DEFAULT_PATH_SIZE = 100; public BadgedImageView(Context context) { this(context, null); } Loading @@ -58,7 +62,11 @@ public class BadgedImageView extends ImageView { int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); mIconBitmapSize = getResources().getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); mDotRenderer = new BadgeRenderer(getContext()); Path iconShapePath = new Path(); float radius = DEFAULT_PATH_SIZE * 0.5f; iconShapePath.addCircle(radius /* x */, radius /* y */, radius, Path.Direction.CW); mDotRenderer = new DotRenderer(mIconBitmapSize, iconShapePath, DEFAULT_PATH_SIZE); TypedArray ta = context.obtainStyledAttributes( new int[] {android.R.attr.colorBackgroundFloating}); Loading @@ -68,11 +76,15 @@ public class BadgedImageView extends ImageView { @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); if (mShowUpdateDot) { if (mShowDot) { getDrawingRect(mTempBounds); mTempPoint.set((getWidth() - mIconBitmapSize) / 2, getPaddingTop()); mDotRenderer.draw(canvas, mUpdateDotColor, mTempBounds, mDotScale, mTempPoint, mOnLeft); DotRenderer.DrawParams params = new DotRenderer.DrawParams(); params.color = mDotColor; params.iconBounds = mTempBounds; params.leftAlign = mOnLeft; params.scale = mDotScale; mDotRenderer.draw(canvas, params); } } Loading @@ -91,8 +103,8 @@ public class BadgedImageView extends ImageView { /** * Set whether the dot should show or not. */ public void setShowDot(boolean showBadge) { mShowUpdateDot = showBadge; public void setShowDot(boolean showDot) { mShowDot = showDot; invalidate(); } Loading @@ -100,14 +112,14 @@ public class BadgedImageView extends ImageView { * @return whether the dot is being displayed. */ public boolean isShowingDot() { return mShowUpdateDot; return mShowDot; } /** * The colour to use for the dot. */ public void setDotColor(int color) { mUpdateDotColor = ColorUtils.setAlphaComponent(color, 255 /* alpha */); mDotColor = ColorUtils.setAlphaComponent(color, 255 /* alpha */); invalidate(); } Loading
packages/SystemUI/src/com/android/systemui/bubbles/BubbleFlyoutView.java +19 −7 Original line number Diff line number Diff line Loading @@ -58,6 +58,8 @@ public class BubbleFlyoutView extends FrameLayout { private final int mPointerSize; private final int mBubbleSize; private final int mBubbleIconBitmapSize; private final float mBubbleIconTopPadding; private final int mFlyoutElevation; private final int mBubbleElevation; private final int mFloatingBackgroundColor; Loading @@ -72,7 +74,7 @@ public class BubbleFlyoutView extends FrameLayout { /** Values related to the 'new' dot which we use to figure out where to collapse the flyout. */ private final float mNewDotRadius; private final float mNewDotSize; private final float mNewDotOffsetFromBubbleBounds; private final float mOriginalDotSize; /** * The paint used to draw the background, whose color changes as the flyout transitions to the Loading Loading @@ -130,6 +132,14 @@ public class BubbleFlyoutView extends FrameLayout { /** The flyout's X translation when at rest (not animating or dragging). */ private float mRestingTranslationX = 0f; /** The badge sizes are defined as percentages of the app icon size. Same value as Launcher3. */ private static final float SIZE_PERCENTAGE = 0.228f; /** Extra scale down of the dot provides room for error in estimating actual dot location. * At the end of the flyout-to-dot animation, wherever the small dot ends up, its disappearance * and the appearance of the larger real dot forms a cohesive animation. */ private static final float DOT_SCALE = 0.6f; /** Callback to run when the flyout is hidden. */ private Runnable mOnHide; Loading @@ -147,10 +157,13 @@ public class BubbleFlyoutView extends FrameLayout { mBubbleSize = res.getDimensionPixelSize(R.dimen.individual_bubble_size); mBubbleIconBitmapSize = res.getDimensionPixelSize(R.dimen.bubble_icon_bitmap_size); mBubbleIconTopPadding = (mBubbleSize - mBubbleIconBitmapSize) / 2f; mBubbleElevation = res.getDimensionPixelSize(R.dimen.bubble_elevation); mFlyoutElevation = res.getDimensionPixelSize(R.dimen.bubble_flyout_elevation); mNewDotOffsetFromBubbleBounds = BadgeRenderer.getDotCenterOffset(context); mNewDotRadius = BadgeRenderer.getDotRadius(mNewDotOffsetFromBubbleBounds); mOriginalDotSize = SIZE_PERCENTAGE * mBubbleIconBitmapSize; mNewDotRadius = (DOT_SCALE * mOriginalDotSize) / 2f; mNewDotSize = mNewDotRadius * 2f; final TypedArray ta = mContext.obtainStyledAttributes( Loading Loading @@ -219,8 +232,7 @@ public class BubbleFlyoutView extends FrameLayout { post(() -> { // Multi line flyouts get top-aligned to the bubble. if (mFlyoutText.getLineCount() > 1) { float bubbleIconTopPadding = (mBubbleSize - mBubbleIconBitmapSize) / 2f; setTranslationY(stackPos.y + bubbleIconTopPadding); setTranslationY(stackPos.y + mBubbleIconTopPadding); } else { // Single line flyouts are vertically centered with respect to the bubble. setTranslationY( Loading Loading @@ -248,7 +260,7 @@ public class BubbleFlyoutView extends FrameLayout { // Calculate the translation values needed to be in the correct 'new dot' position. final float distanceFromFlyoutLeftToDotCenterX = mFlyoutSpaceFromBubble + mNewDotOffsetFromBubbleBounds / 2; mFlyoutSpaceFromBubble + mBubbleIconTopPadding + mOriginalDotSize / 2; if (mArrowPointingLeft) { mTranslationXWhenDot = -distanceFromFlyoutLeftToDotCenterX - mNewDotRadius; } else { Loading @@ -260,7 +272,7 @@ public class BubbleFlyoutView extends FrameLayout { getHeight() / 2f - mNewDotRadius - mBubbleSize / 2f + mNewDotOffsetFromBubbleBounds / 2; + mOriginalDotSize / 2; }); } Loading