Home | History | Annotate | Download | only in recents
      1 /*
      2  * Copyright (C) 2018 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.recents;
     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  * Wrapper around {@link android.graphics.drawable.shapes.PathShape}
     27  * that creates a shape with a triangular path (pointing up or down).
     28  */
     29 public class TriangleShape extends PathShape {
     30     private Path mTriangularPath;
     31 
     32     public TriangleShape(Path path, float stdWidth, float stdHeight) {
     33         super(path, stdWidth, stdHeight);
     34         mTriangularPath = path;
     35     }
     36 
     37     public static TriangleShape create(float width, float height, boolean isPointingUp) {
     38         Path triangularPath = new Path();
     39         if (isPointingUp) {
     40             triangularPath.moveTo(0, height);
     41             triangularPath.lineTo(width, height);
     42             triangularPath.lineTo(width / 2, 0);
     43             triangularPath.close();
     44         } else {
     45             triangularPath.moveTo(0, 0);
     46             triangularPath.lineTo(width / 2, height);
     47             triangularPath.lineTo(width, 0);
     48             triangularPath.close();
     49         }
     50         return new TriangleShape(triangularPath, width, height);
     51     }
     52 
     53     /** Create an arrow TriangleShape that points to the left or the right */
     54     public static TriangleShape createHorizontal(
     55             float width, float height, boolean isPointingLeft) {
     56         Path triangularPath = new Path();
     57         if (isPointingLeft) {
     58             triangularPath.moveTo(0, height / 2);
     59             triangularPath.lineTo(width, height);
     60             triangularPath.lineTo(width, 0);
     61             triangularPath.close();
     62         } else {
     63             triangularPath.moveTo(0, height);
     64             triangularPath.lineTo(width, height / 2);
     65             triangularPath.lineTo(0, 0);
     66             triangularPath.close();
     67         }
     68         return new TriangleShape(triangularPath, width, height);
     69     }
     70 
     71     @Override
     72     public void getOutline(@NonNull Outline outline) {
     73         outline.setConvexPath(mTriangularPath);
     74     }
     75 }
     76