1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
/*
* Copyright (C) 2013 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.example.android.curvedmotion;
/**
* A class that holds information about a location and how the path should get to that
* location from the previous path location (if any). Any PathPoint holds the information for
* its location as well as the instructions on how to traverse the preceding interval from the
* previous location.
*/
public class PathPoint {
/**
* The possible path operations that describe how to move from a preceding PathPoint to the
* location described by this PathPoint.
*/
public static final int MOVE = 0;
public static final int LINE = 1;
public static final int CURVE = 2;
/**
* The location of this PathPoint
*/
float mX, mY;
/**
* The first control point, if any, for a PathPoint of type CURVE
*/
float mControl0X, mControl0Y;
/**
* The second control point, if any, for a PathPoint of type CURVE
*/
float mControl1X, mControl1Y;
/**
* The motion described by the path to get from the previous PathPoint in an AnimatorPath
* to the location of this PathPoint. This can be one of MOVE, LINE, or CURVE.
*/
int mOperation;
/**
* Line/Move constructor
*/
private PathPoint(int operation, float x, float y) {
mOperation = operation;
mX = x;
mY = y;
}
/**
* Curve constructor
*/
private PathPoint(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
mControl0X = c0X;
mControl0Y = c0Y;
mControl1X = c1X;
mControl1Y = c1Y;
mX = x;
mY = y;
mOperation = CURVE;
}
/**
* Constructs and returns a PathPoint object that describes a line to the given xy location.
*/
public static PathPoint lineTo(float x, float y) {
return new PathPoint(LINE, x, y);
}
/**
* Constructs and returns a PathPoint object that describes a curve to the given xy location
* with the control points at c0 and c1.
*/
public static PathPoint curveTo(float c0X, float c0Y, float c1X, float c1Y, float x, float y) {
return new PathPoint(c0X, c0Y, c1X, c1Y, x, y);
}
/**
* Constructs and returns a PathPoint object that describes a discontinuous move to the given
* xy location.
*/
public static PathPoint moveTo(float x, float y) {
return new PathPoint(MOVE, x, y);
}
}
|