Add setEndpoints method to EdgeLights

Also changes 'offset' to 'start' for clarity.

Bug: 141366370
Test: manual
Change-Id: I814c6d3ca25a0b9391bfb2424f822a83bb8ef12f
This commit is contained in:
Miranda Kephart
2019-09-23 15:46:41 -04:00
parent a198f02a97
commit 6a579b70dd
2 changed files with 45 additions and 21 deletions

View File

@@ -16,6 +16,8 @@
package com.android.systemui.assist.ui;
import android.util.Log;
import androidx.annotation.ColorInt;
/**
@@ -29,9 +31,12 @@ import androidx.annotation.ColorInt;
* counter-clockwise.
*/
public final class EdgeLight {
private static final String TAG = "EdgeLight";
@ColorInt
private int mColor;
private float mOffset;
private float mStart;
private float mLength;
/** Copies a list of EdgeLights. */
@@ -45,13 +50,13 @@ public final class EdgeLight {
public EdgeLight(@ColorInt int color, float offset, float length) {
mColor = color;
mOffset = offset;
mStart = offset;
mLength = length;
}
public EdgeLight(EdgeLight sourceLight) {
mColor = sourceLight.getColor();
mOffset = sourceLight.getOffset();
mStart = sourceLight.getStart();
mLength = sourceLight.getLength();
}
@@ -77,23 +82,41 @@ public final class EdgeLight {
}
/**
* Returns the current offset, in units of the total device perimeter and measured from the
* bottom-left corner (see class description).
* Sets the endpoints of the edge light, both measured from the bottom-left corner (see class
* description). This is a convenience method to avoid separate setStart and setLength calls.
*/
public float getOffset() {
return mOffset;
public void setEndpoints(float start, float end) {
if (start > end) {
Log.e(TAG, String.format("Endpoint must be >= start (add 1 if necessary). Got [%f, %f]",
start, end));
return;
}
mStart = start;
mLength = end - start;
}
/**
* Returns the current starting position, in units of the total device perimeter and measured
* from the bottom-left corner (see class description).
*/
public float getStart() {
return mStart;
}
/**
* Sets the current offset, in units of the total device perimeter and measured from the
* bottom-left corner (see class description).
*/
public void setOffset(float offset) {
mOffset = offset;
public void setStart(float start) {
mStart = start;
}
public float getEnd() {
return mStart + mLength;
}
/** Returns the center, measured from the bottom-left corner (see class description). */
public float getCenter() {
return mOffset + (mLength / 2.f);
return mStart + (mLength / 2.f);
}
}

View File

@@ -140,10 +140,10 @@ public class InvocationLightsView extends View
float rightStart = mGuide.getRegionWidth(PerimeterPathGuide.Region.BOTTOM)
+ (cornerLengthNormalized - arcOffsetNormalized) * (1 - progress);
setLight(0, leftStart, lightLength);
setLight(1, leftStart + lightLength, lightLength);
setLight(2, rightStart - (lightLength * 2), lightLength);
setLight(3, rightStart - lightLength, lightLength);
setLight(0, leftStart, leftStart + lightLength);
setLight(1, leftStart + lightLength, leftStart + lightLength * 2);
setLight(2, rightStart - (lightLength * 2), rightStart - lightLength);
setLight(3, rightStart - lightLength, rightStart);
setVisibility(View.VISIBLE);
}
invalidate();
@@ -155,7 +155,7 @@ public class InvocationLightsView extends View
public void hide() {
setVisibility(GONE);
for (EdgeLight light : mAssistInvocationLights) {
light.setLength(0);
light.setEndpoints(0, 0);
}
attemptUnregisterNavBarListener();
}
@@ -235,12 +235,11 @@ public class InvocationLightsView extends View
}
}
protected void setLight(int index, float offset, float length) {
protected void setLight(int index, float start, float end) {
if (index < 0 || index >= 4) {
Log.w(TAG, "invalid invocation light index: " + index);
}
mAssistInvocationLights.get(index).setOffset(offset);
mAssistInvocationLights.get(index).setLength(length);
mAssistInvocationLights.get(index).setEndpoints(start, end);
}
/**
@@ -268,9 +267,11 @@ public class InvocationLightsView extends View
}
private void renderLight(EdgeLight light, Canvas canvas) {
mGuide.strokeSegment(mPath, light.getOffset(), light.getOffset() + light.getLength());
mPaint.setColor(light.getColor());
canvas.drawPath(mPath, mPaint);
if (light.getLength() > 0) {
mGuide.strokeSegment(mPath, light.getStart(), light.getStart() + light.getLength());
mPaint.setColor(light.getColor());
canvas.drawPath(mPath, mPaint);
}
}
private void attemptRegisterNavBarListener() {