1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.assist.ui; 18 19 import android.util.Log; 20 21 import androidx.annotation.ColorInt; 22 23 /** 24 * Represents a line drawn on the perimeter of the display. 25 * 26 * Offsets and lengths are both normalized to the perimeter of the display – ex. a length of 1 27 * is equal to the perimeter of the display. Positions move counter-clockwise as values increase. 28 * 29 * If there is no bottom corner radius, the origin is the bottom-left corner. 30 * If there is a bottom corner radius, the origin is immediately after the bottom corner radius, 31 * counter-clockwise. 32 */ 33 public final class EdgeLight { 34 35 private static final String TAG = "EdgeLight"; 36 37 @ColorInt 38 private int mColor; 39 private float mStart; 40 private float mLength; 41 42 /** Copies a list of EdgeLights. */ copy(EdgeLight[] array)43 public static EdgeLight[] copy(EdgeLight[] array) { 44 EdgeLight[] copy = new EdgeLight[array.length]; 45 for (int i = 0; i < array.length; i++) { 46 copy[i] = new EdgeLight(array[i]); 47 } 48 return copy; 49 } 50 EdgeLight(@olorInt int color, float offset, float length)51 public EdgeLight(@ColorInt int color, float offset, float length) { 52 mColor = color; 53 mStart = offset; 54 mLength = length; 55 } 56 EdgeLight(EdgeLight sourceLight)57 public EdgeLight(EdgeLight sourceLight) { 58 mColor = sourceLight.getColor(); 59 mStart = sourceLight.getStart(); 60 mLength = sourceLight.getLength(); 61 } 62 63 /** Returns the current edge light color. */ 64 @ColorInt getColor()65 public int getColor() { 66 return mColor; 67 } 68 69 /** Sets the edge light color. */ setColor(@olorInt int color)70 public boolean setColor(@ColorInt int color) { 71 boolean changed = mColor != color; 72 mColor = color; 73 return changed; 74 } 75 76 /** Returns the edge light length, in units of the total device perimeter. */ getLength()77 public float getLength() { 78 return mLength; 79 } 80 81 /** Sets the edge light length, in units of the total device perimeter. */ setLength(float length)82 public void setLength(float length) { 83 mLength = length; 84 } 85 86 /** 87 * Sets the endpoints of the edge light, both measured from the bottom-left corner (see class 88 * description). This is a convenience method to avoid separate setStart and setLength calls. 89 */ setEndpoints(float start, float end)90 public void setEndpoints(float start, float end) { 91 if (start > end) { 92 Log.e(TAG, String.format("Endpoint must be >= start (add 1 if necessary). Got [%f, %f]", 93 start, end)); 94 return; 95 } 96 mStart = start; 97 mLength = end - start; 98 } 99 100 /** 101 * Returns the current starting position, in units of the total device perimeter and measured 102 * from the bottom-left corner (see class description). 103 */ getStart()104 public float getStart() { 105 return mStart; 106 } 107 108 /** 109 * Sets the current offset, in units of the total device perimeter and measured from the 110 * bottom-left corner (see class description). 111 */ setStart(float start)112 public void setStart(float start) { 113 mStart = start; 114 } 115 getEnd()116 public float getEnd() { 117 return mStart + mLength; 118 } 119 120 /** Returns the center, measured from the bottom-left corner (see class description). */ getCenter()121 public float getCenter() { 122 return mStart + (mLength / 2.f); 123 } 124 } 125