| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package com.android.wm.shell.common; |
| 18 |
|
| 19 |
import android.graphics.Outline; |
| 20 |
import android.graphics.Path; |
| 21 |
import android.graphics.drawable.shapes.PathShape; |
| 22 |
|
| 23 |
import androidx.annotation.NonNull; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public class TriangleShape extends PathShape { |
| 32 |
private Path mTriangularPath; |
| 33 |
|
| 34 |
public TriangleShape(Path path, float stdWidth, float stdHeight) { |
| 35 |
super(path, stdWidth, stdHeight); |
| 36 |
mTriangularPath = path; |
| 37 |
} |
| 38 |
|
| 39 |
public static TriangleShape create(float width, float height, boolean isPointingUp) { |
| 40 |
Path triangularPath = new Path(); |
| 41 |
if (isPointingUp) { |
| 42 |
triangularPath.moveTo(0, height); |
| 43 |
triangularPath.lineTo(width, height); |
| 44 |
triangularPath.lineTo(width / 2, 0); |
| 45 |
triangularPath.close(); |
| 46 |
} else { |
| 47 |
triangularPath.moveTo(0, 0); |
| 48 |
triangularPath.lineTo(width / 2, height); |
| 49 |
triangularPath.lineTo(width, 0); |
| 50 |
triangularPath.close(); |
| 51 |
} |
| 52 |
return new TriangleShape(triangularPath, width, height); |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
public static TriangleShape createHorizontal( |
| 57 |
float width, float height, boolean isPointingLeft) { |
| 58 |
Path triangularPath = new Path(); |
| 59 |
if (isPointingLeft) { |
| 60 |
triangularPath.moveTo(0, height / 2); |
| 61 |
triangularPath.lineTo(width, height); |
| 62 |
triangularPath.lineTo(width, 0); |
| 63 |
triangularPath.close(); |
| 64 |
} else { |
| 65 |
triangularPath.moveTo(0, height); |
| 66 |
triangularPath.lineTo(width, height / 2); |
| 67 |
triangularPath.lineTo(0, 0); |
| 68 |
triangularPath.close(); |
| 69 |
} |
| 70 |
return new TriangleShape(triangularPath, width, height); |
| 71 |
} |
| 72 |
|
| 73 |
@Override |
| 74 |
public void getOutline(@NonNull Outline outline) { |
| 75 |
outline.setPath(mTriangularPath); |
| 76 |
} |
| 77 |
} |