Guest User

Untitled

a guest
Apr 19th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. public class ExpandableTriangleView extends View {
  2.  
  3. private Paint paint;
  4. private Path path;
  5. private boolean isExpanded;
  6.  
  7. public ExpandableTriangleView(Context context) {
  8. super(context);
  9. paint = new Paint();
  10. paint.setStyle(Paint.Style.FILL);
  11. paint.setColor(Color.parseColor("#cccccc"));
  12. paint.setAntiAlias(true);
  13. }
  14.  
  15. public void expand() {
  16. isExpanded = true;
  17. path = null;
  18. invalidate();
  19. }
  20.  
  21. public void collapse() {
  22. isExpanded = false;
  23. path = null;
  24. invalidate();
  25. }
  26.  
  27. @Override
  28. protected void onDraw(Canvas canvas) {
  29. super.onDraw(canvas);
  30. canvas.drawPath(getTrianglePath(), paint);
  31. }
  32.  
  33. private Path getTrianglePath() {
  34. if (path == null) {
  35. path = new Path();
  36. int width = getWidth();
  37. int height = getHeight();
  38. if (isExpanded) {
  39. path.moveTo(0, 0);
  40. path.lineTo(width, 0);
  41. path.lineTo(width / 2, height);
  42. } else {
  43. path.moveTo(0, 0);
  44. path.lineTo(0, height);
  45. path.lineTo(width, height / 2);
  46. }
  47. }
  48. return path;
  49. }
  50. }
Add Comment
Please, Sign In to add comment