Use correct bounds for scroll bar rendering.
Bug:30001373 Change-Id: I20c77a2d97096bda451c3a871fd6be7ad699b047
This commit is contained in:
@@ -20,6 +20,7 @@ import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Rect;
|
||||
|
||||
/**
|
||||
* Helper class for drawing round scroll bars on round Wear devices.
|
||||
@@ -53,7 +54,7 @@ class RoundScrollbarRenderer {
|
||||
mParent = parent;
|
||||
}
|
||||
|
||||
public void drawRoundScrollbars(Canvas canvas, float alpha) {
|
||||
public void drawRoundScrollbars(Canvas canvas, float alpha, Rect bounds) {
|
||||
if (alpha == 0) {
|
||||
return;
|
||||
}
|
||||
@@ -83,10 +84,11 @@ class RoundScrollbarRenderer {
|
||||
|
||||
// Draw the track and the scroll bar.
|
||||
mRect.set(
|
||||
0 + thumbWidth / 2,
|
||||
0 + thumbWidth / 2,
|
||||
mParent.getWidth() - thumbWidth / 2,
|
||||
mParent.getHeight() - thumbWidth / 2);
|
||||
bounds.left - thumbWidth / 2,
|
||||
bounds.top,
|
||||
bounds.right - thumbWidth / 2,
|
||||
bounds.bottom);
|
||||
|
||||
canvas.drawArc(mRect, -SCROLLBAR_ANGLE_RANGE / 2, SCROLLBAR_ANGLE_RANGE, false,
|
||||
mTrackPaint);
|
||||
canvas.drawArc(mRect, startAngle, sweepAngle, false, mThumbPaint);
|
||||
|
||||
@@ -14770,6 +14770,37 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
}
|
||||
|
||||
private void getVerticalScrollBarBounds(Rect bounds) {
|
||||
if (mRoundScrollbarRenderer == null) {
|
||||
getStraightVerticalScrollBarBounds(bounds);
|
||||
} else {
|
||||
getRoundVerticalScrollBarBounds(bounds);
|
||||
}
|
||||
}
|
||||
|
||||
private void getRoundVerticalScrollBarBounds(Rect bounds) {
|
||||
final int inside = (mViewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0;
|
||||
int verticalScrollbarPosition = mVerticalScrollbarPosition;
|
||||
if (verticalScrollbarPosition == SCROLLBAR_POSITION_DEFAULT) {
|
||||
verticalScrollbarPosition = isLayoutRtl() ?
|
||||
SCROLLBAR_POSITION_LEFT : SCROLLBAR_POSITION_RIGHT;
|
||||
}
|
||||
final int width = mRight - mLeft;
|
||||
final int height = mBottom - mTop;
|
||||
switch (verticalScrollbarPosition) {
|
||||
default:
|
||||
case SCROLLBAR_POSITION_RIGHT:
|
||||
bounds.left = mScrollX - (mUserPaddingRight & inside);
|
||||
break;
|
||||
case SCROLLBAR_POSITION_LEFT:
|
||||
bounds.left = mScrollX + (mUserPaddingLeft & inside);
|
||||
break;
|
||||
}
|
||||
bounds.top = mScrollY + (mPaddingTop & inside);
|
||||
bounds.right = bounds.left + width;
|
||||
bounds.bottom = mScrollY + height - (mUserPaddingBottom & inside);
|
||||
}
|
||||
|
||||
private void getStraightVerticalScrollBarBounds(Rect bounds) {
|
||||
final int inside = (mViewFlags & SCROLLBARS_OUTSIDE_MASK) == 0 ? ~0 : 0;
|
||||
final int size = getVerticalScrollbarWidth();
|
||||
int verticalScrollbarPosition = mVerticalScrollbarPosition;
|
||||
@@ -14848,8 +14879,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
// Fork out the scroll bar drawing for round wearable devices.
|
||||
if (mRoundScrollbarRenderer != null) {
|
||||
if (drawVerticalScrollBar) {
|
||||
final Rect bounds = cache.mScrollBarBounds;
|
||||
getVerticalScrollBarBounds(bounds);
|
||||
mRoundScrollbarRenderer.drawRoundScrollbars(
|
||||
canvas, (float) cache.scrollBar.getAlpha() / 255f);
|
||||
canvas, (float) cache.scrollBar.getAlpha() / 255f, bounds);
|
||||
if (invalidate) {
|
||||
invalidate();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user