MPPointF.java
2.28 KB
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
package com.github.mikephil.charting.utils;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.List;
/**
* Created by Tony Patino on 6/24/16.
*/
public class MPPointF extends ObjectPool.Poolable {
private static ObjectPool<MPPointF> pool;
public float x;
public float y;
static {
pool = ObjectPool.create(32, new MPPointF(0,0));
pool.setReplenishPercentage(0.5f);
}
public MPPointF() {
}
public MPPointF(float x, float y) {
this.x = x;
this.y = y;
}
public static MPPointF getInstance(float x, float y) {
MPPointF result = pool.get();
result.x = x;
result.y = y;
return result;
}
public static MPPointF getInstance() {
return pool.get();
}
public static MPPointF getInstance(MPPointF copy) {
MPPointF result = pool.get();
result.x = copy.x;
result.y = copy.y;
return result;
}
public static void recycleInstance(MPPointF instance){
pool.recycle(instance);
}
public static void recycleInstances(List<MPPointF> instances){
pool.recycle(instances);
}
public static final Parcelable.Creator<MPPointF> CREATOR = new Parcelable.Creator<MPPointF>() {
/**
* Return a new point from the data in the specified parcel.
*/
public MPPointF createFromParcel(Parcel in) {
MPPointF r = new MPPointF(0,0);
r.my_readFromParcel(in);
return r;
}
/**
* Return an array of rectangles of the specified size.
*/
public MPPointF[] newArray(int size) {
return new MPPointF[size];
}
};
/**
* Set the point's coordinates from the data stored in the specified
* parcel. To write a point to a parcel, call writeToParcel().
* Provided to support older Android devices.
*
* @param in The parcel to read the point's coordinates from
*/
public void my_readFromParcel(Parcel in) {
x = in.readFloat();
y = in.readFloat();
}
public float getX(){
return this.x;
}
public float getY(){
return this.y;
}
@Override
protected ObjectPool.Poolable instantiate() {
return new MPPointF(0,0);
}
}