Round the corners of the mobile signal status bar icon

Add arcs of radius 0.75 dp to the drawing of the mobile signal drawble.

Test: visual
Bug: 37013523
Change-Id: I80e6e7b6888e8e35667b0df191aac7db1e2d2059
This commit is contained in:
Evan Laird
2017-06-01 14:47:27 -04:00
parent e1411aa701
commit ada843203a
2 changed files with 58 additions and 6 deletions

View File

@@ -815,4 +815,7 @@
<dimen name="qs_gutter_height">6dp</dimen>
<!-- Intended corner radius when drawing the mobile signal -->
<dimen name="stat_sys_mobile_signal_corner_radius">0.75dp</dimen>
</resources>

View File

@@ -31,7 +31,6 @@ import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.util.LayoutDirection;
import android.util.Log;
import com.android.settingslib.R;
import com.android.settingslib.Utils;
@@ -82,6 +81,22 @@ public class SignalDrawable extends Drawable {
{-1.9f / VIEWPORT, -1.9f / VIEWPORT},
};
// Rounded corners are achieved by arcing a circle of radius `mCornerRadius` from its tangent
// points along the curve. On the top and left corners of the triangle, the tangents are as
// follows:
// 1) Along the straight lines (y = 0 and x = width):
// Ps = R / tan(45)
// 2) Along the diagonal line (y = x):
// Pd = √((Ps^2) / 2)
//
// I.e., the points where we stop the straight lines lie at (starting drawing from the bottom-
// right corner and counter-clockwise): (width, height - Radius), (width, Ps), (width - Pd, Pd),
// (Pd, height - Pd), (Ps, height), and finally (width - Radius, height).
private static final double TAN_THETA = Math.tan(Math.PI / 8.f);
private final float mCornerRadius;
private final float mCircleOffsetStraight;
private final float mCircleOffsetDiag;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final Paint mForegroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
private final int mDarkModeBackgroundColor;
@@ -113,6 +128,11 @@ public class SignalDrawable extends Drawable {
mIntrinsicSize = context.getResources().getDimensionPixelSize(R.dimen.signal_icon_size);
mHandler = new Handler();
setDarkIntensity(0);
mCornerRadius = context.getResources()
.getDimensionPixelSize(R.dimen.stat_sys_mobile_signal_corner_radius);
mCircleOffsetStraight = mCornerRadius / (float) TAN_THETA;
mCircleOffsetDiag = (float) Math.sqrt(Math.pow(mCircleOffsetStraight, 2.f) / 2.f);
}
@Override
@@ -204,11 +224,40 @@ public class SignalDrawable extends Drawable {
mFullPath.setFillType(FillType.WINDING);
float width = getBounds().width();
float height = getBounds().height();
float padding = (PAD * width);
mFullPath.moveTo(width - padding, height - padding);
mFullPath.lineTo(width - padding, padding);
mFullPath.lineTo(padding, height - padding);
mFullPath.lineTo(width - padding, height - padding);
float padding = (int) (PAD * width); // Stay on pixel boundary
// 1 - Bottom right, above corner
mFullPath.moveTo(width - padding, height - padding - mCornerRadius);
// 2 - Line to top right, below corner
mFullPath.lineTo(width - padding, padding + mCircleOffsetStraight);
// 3 - Arc to top right, on hypotenuse
mFullPath.arcTo(
width - padding - (2 * mCornerRadius),
padding + mCircleOffsetStraight - mCornerRadius,
width - padding,
padding + mCircleOffsetStraight + mCornerRadius,
0.f, -135.f, false
);
// 4 - Line to bottom left, on hypotenuse
mFullPath.lineTo(padding + mCircleOffsetDiag, height - padding - mCircleOffsetDiag);
// 5 - Arc to bottom left, on leg
mFullPath.arcTo(
padding + mCircleOffsetStraight - mCornerRadius,
height - padding - (2 * mCornerRadius),
padding + mCircleOffsetStraight + mCornerRadius,
height - padding,
-135.f, -135.f, false
);
// 6 - Line to bottom rght, before corner
mFullPath.lineTo(width - padding - mCornerRadius, height - padding);
// 7 - Arc to beginning (bottom right, above corner)
mFullPath.arcTo(
width - padding - (2 * mCornerRadius),
height - padding - (2 * mCornerRadius),
width - padding,
height - padding,
90.f, -90.f, false
);
if (mState == STATE_CARRIER_CHANGE) {
float cutWidth = (DOT_CUT_WIDTH * width);