1 /* 2 * Copyright (C) 2013 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 package com.example.android.curvedmotion; 17 18 import java.util.ArrayList; 19 import java.util.Collection; 20 21 /** 22 * A simple Path object that holds information about the points along 23 * a path. The API allows you to specify a move location (which essentially 24 * jumps from the previous point in the path to the new one), a line location 25 * (which creates a line segment from the previous location) and a curve 26 * location (which creates a B�zier curve from the previous location). 27 */ 28 public class AnimatorPath { 29 30 // The points in the path 31 ArrayList<PathPoint> mPoints = new ArrayList<PathPoint>(); 32 33 34 /** 35 * Move from the current path point to the new one 36 * specified by x and y. This will create a discontinuity if this point is 37 * neither the first point in the path nor the same as the previous point 38 * in the path. 39 */ moveTo(float x, float y)40 public void moveTo(float x, float y) { 41 mPoints.add(PathPoint.moveTo(x, y)); 42 } 43 44 /** 45 * Create a straight line from the current path point to the new one 46 * specified by x and y. 47 */ lineTo(float x, float y)48 public void lineTo(float x, float y) { 49 mPoints.add(PathPoint.lineTo(x, y)); 50 } 51 52 /** 53 * Create a quadratic B�zier curve from the current path point to the new one 54 * specified by x and y. The curve uses the current path location as the first anchor 55 * point, the control points (c0X, c0Y) and (c1X, c1Y), and (x, y) as the end anchor. 56 */ curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y)57 public void curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y) { 58 mPoints.add(PathPoint.curveTo(c0X, c0Y, c1X, c1Y, x, y)); 59 } 60 61 /** 62 * Returns a Collection of PathPoint objects that describe all points in the path. 63 */ getPoints()64 public Collection<PathPoint> getPoints() { 65 return mPoints; 66 } 67 } 68