Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2515002a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add setEndpoints method to EdgeLights"

parents 4884beda 6a579b70
Loading
Loading
Loading
Loading
+33 −10
Original line number Original line Diff line number Diff line
@@ -16,6 +16,8 @@


package com.android.systemui.assist.ui;
package com.android.systemui.assist.ui;


import android.util.Log;

import androidx.annotation.ColorInt;
import androidx.annotation.ColorInt;


/**
/**
@@ -29,9 +31,12 @@ import androidx.annotation.ColorInt;
 * counter-clockwise.
 * counter-clockwise.
 */
 */
public final class EdgeLight {
public final class EdgeLight {

    private static final String TAG = "EdgeLight";

    @ColorInt
    @ColorInt
    private int mColor;
    private int mColor;
    private float mOffset;
    private float mStart;
    private float mLength;
    private float mLength;


    /** Copies a list of EdgeLights. */
    /** Copies a list of EdgeLights. */
@@ -45,13 +50,13 @@ public final class EdgeLight {


    public EdgeLight(@ColorInt int color, float offset, float length) {
    public EdgeLight(@ColorInt int color, float offset, float length) {
        mColor = color;
        mColor = color;
        mOffset = offset;
        mStart = offset;
        mLength = length;
        mLength = length;
    }
    }


    public EdgeLight(EdgeLight sourceLight) {
    public EdgeLight(EdgeLight sourceLight) {
        mColor = sourceLight.getColor();
        mColor = sourceLight.getColor();
        mOffset = sourceLight.getOffset();
        mStart = sourceLight.getStart();
        mLength = sourceLight.getLength();
        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
     * Sets the endpoints of the edge light, both measured from the bottom-left corner (see class
     * bottom-left corner (see class description).
     * description). This is a convenience method to avoid separate setStart and setLength calls.
     */
     */
    public float getOffset() {
    public void setEndpoints(float start, float end) {
        return mOffset;
        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
     * Sets the current offset, in units of the total device perimeter and measured from the
     * bottom-left corner (see class description).
     * bottom-left corner (see class description).
     */
     */
    public void setOffset(float offset) {
    public void setStart(float start) {
        mOffset = offset;
        mStart = start;
    }

    public float getEnd() {
        return mStart + mLength;
    }
    }


    /** Returns the center, measured from the bottom-left corner (see class description). */
    /** Returns the center, measured from the bottom-left corner (see class description). */
    public float getCenter() {
    public float getCenter() {
        return mOffset + (mLength / 2.f);
        return mStart + (mLength / 2.f);
    }
    }
}
}
+12 −11
Original line number Original line Diff line number Diff line
@@ -140,10 +140,10 @@ public class InvocationLightsView extends View
            float rightStart = mGuide.getRegionWidth(PerimeterPathGuide.Region.BOTTOM)
            float rightStart = mGuide.getRegionWidth(PerimeterPathGuide.Region.BOTTOM)
                    + (cornerLengthNormalized - arcOffsetNormalized) * (1 - progress);
                    + (cornerLengthNormalized - arcOffsetNormalized) * (1 - progress);


            setLight(0, leftStart, lightLength);
            setLight(0, leftStart, leftStart + lightLength);
            setLight(1, leftStart + lightLength, lightLength);
            setLight(1, leftStart + lightLength, leftStart + lightLength * 2);
            setLight(2, rightStart - (lightLength * 2), lightLength);
            setLight(2, rightStart - (lightLength * 2), rightStart - lightLength);
            setLight(3, rightStart - lightLength, lightLength);
            setLight(3, rightStart - lightLength, rightStart);
            setVisibility(View.VISIBLE);
            setVisibility(View.VISIBLE);
        }
        }
        invalidate();
        invalidate();
@@ -155,7 +155,7 @@ public class InvocationLightsView extends View
    public void hide() {
    public void hide() {
        setVisibility(GONE);
        setVisibility(GONE);
        for (EdgeLight light : mAssistInvocationLights) {
        for (EdgeLight light : mAssistInvocationLights) {
            light.setLength(0);
            light.setEndpoints(0, 0);
        }
        }
        attemptUnregisterNavBarListener();
        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) {
        if (index < 0 || index >= 4) {
            Log.w(TAG, "invalid invocation light index: " + index);
            Log.w(TAG, "invalid invocation light index: " + index);
        }
        }
        mAssistInvocationLights.get(index).setOffset(offset);
        mAssistInvocationLights.get(index).setEndpoints(start, end);
        mAssistInvocationLights.get(index).setLength(length);
    }
    }


    /**
    /**
@@ -268,10 +267,12 @@ public class InvocationLightsView extends View
    }
    }


    private void renderLight(EdgeLight light, Canvas canvas) {
    private void renderLight(EdgeLight light, Canvas canvas) {
        mGuide.strokeSegment(mPath, light.getOffset(), light.getOffset() + light.getLength());
        if (light.getLength() > 0) {
            mGuide.strokeSegment(mPath, light.getStart(), light.getStart() + light.getLength());
            mPaint.setColor(light.getColor());
            mPaint.setColor(light.getColor());
            canvas.drawPath(mPath, mPaint);
            canvas.drawPath(mPath, mPaint);
        }
        }
    }


    private void attemptRegisterNavBarListener() {
    private void attemptRegisterNavBarListener() {
        if (!mRegistered) {
        if (!mRegistered) {