summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/annotations/PolylineOptions.java
blob: 6a54f948b7046c23bb2fbe079773411d3f401f21 (plain)
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
package com.mapbox.mapboxsdk.annotations;

import android.os.Parcel;
import android.os.Parcelable;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.mapbox.mapboxsdk.geometry.LatLng;

import java.util.ArrayList;
import java.util.List;

/**
 * Builder for composing {@link Polyline} objects.
 * @deprecated As of 7.0.0,
 * use <a href="https://github.com/mapbox/mapbox-plugins-android/tree/master/plugin-annotation">
 *   Mapbox Annotation Plugin</a> instead
 */
@Deprecated
public final class PolylineOptions implements Parcelable {


  public static final Parcelable.Creator<PolylineOptions> CREATOR =
    new Parcelable.Creator<PolylineOptions>() {
      public PolylineOptions createFromParcel(@NonNull Parcel in) {
        return new PolylineOptions(in);
      }

      public PolylineOptions[] newArray(int size) {
        return new PolylineOptions[size];
      }
    };

  private PolylineOptions(Parcel in) {
    polyline = new Polyline();
    ArrayList<LatLng> pointsList = new ArrayList<>();
    in.readList(pointsList, LatLng.class.getClassLoader());
    addAll(pointsList);
    alpha(in.readFloat());
    color(in.readInt());
    width(in.readFloat());
  }

  /**
   * Describe the kinds of special objects contained in this Parcelable's
   * marshalled representation.
   *
   * @return integer 0.
   */
  @Override
  public int describeContents() {
    return 0;
  }

  /**
   * Flatten this object in to a Parcel.
   *
   * @param out   The Parcel in which the object should be written.
   * @param flags Additional flags about how the object should be written. May be 0 or
   *              {@link #PARCELABLE_WRITE_RETURN_VALUE}.
   */
  @Override
  public void writeToParcel(Parcel out, int flags) {
    out.writeList(getPoints());
    out.writeFloat(getAlpha());
    out.writeInt(getColor());
    out.writeFloat(getWidth());
  }

  private Polyline polyline;

  /**
   * Defines options for a polyline.
   */
  public PolylineOptions() {
    polyline = new Polyline();
  }

  /**
   * Adds a vertex to the end of the polyline being built.
   *
   * @param point {@link LatLng} point to be added to polyline geometry.
   * @return This {@link PolylineOptions} object with the given point on the end.
   */
  @NonNull
  public PolylineOptions add(LatLng point) {
    polyline.addPoint(point);
    return this;
  }

  /**
   * Adds vertices to the end of the polyline being built.
   *
   * @param points {@link LatLng} points defining the polyline geometry.
   * @return This {@link PolylineOptions} object with the given point on the end.
   */
  @NonNull
  public PolylineOptions add(LatLng... points) {
    for (LatLng point : points) {
      add(point);
    }
    return this;
  }

  /**
   * Adds vertices to the end of the polyline being built.
   *
   * @param points {@link Iterable} list made up of {@link LatLng} points defining the polyline
   *               geometry
   * @return This {@link PolylineOptions} object with the given points on the end.
   */
  @NonNull
  public PolylineOptions addAll(Iterable<LatLng> points) {
    for (LatLng point : points) {
      add(point);
    }
    return this;
  }

  /**
   * Set the alpha value of the polyline.
   *
   * @param alpha float value between 0 (not visible) and 1.
   * @return This {@link PolylineOptions} object with the given polyline alpha value.
   */
  @NonNull
  public PolylineOptions alpha(float alpha) {
    polyline.setAlpha(alpha);
    return this;
  }

  /**
   * Gets the alpha set for this {@link PolylineOptions} object.
   *
   * @return float value between 0 and 1 defining the alpha.
   */
  public float getAlpha() {
    return polyline.getAlpha();
  }

  /**
   * Sets the color of the polyline as a 32-bit ARGB color. The default color is black.
   *
   * @param color 32-bit ARGB color.
   * @return This {@link PolylineOptions} object with a new color set.
   */
  @NonNull
  public PolylineOptions color(int color) {
    polyline.setColor(color);
    return this;
  }

  /**
   * Gets the color set for this {@link PolylineOptions} object.
   *
   * @return The color of the polyline in ARGB format.
   */
  public int getColor() {
    return polyline.getColor();
  }

  /**
   * Do not use this method. Used internally by the SDK.
   *
   * @return PolyLine The polyline build by this class.
   */
  public Polyline getPolyline() {
    return polyline;
  }

  /**
   * Gets the width set for this {@link PolylineOptions} object.
   *
   * @return The width of the polyline in screen pixels.
   */
  public float getWidth() {
    return polyline.getWidth();
  }

  /**
   * Sets the width of the polyline in screen pixels. The default is 10.
   *
   * @param width float value defining width of polyline using unit pixels.
   * @return This {@link PolylineOptions} object with a new width set.
   */
  @NonNull
  public PolylineOptions width(float width) {
    polyline.setWidth(width);
    return this;
  }

  /**
   * Gets the points set for this {@link PolylineOptions} object.
   *
   * @return a {@link List} of {@link LatLng}s specifying the vertices of the polyline.
   */
  public List<LatLng> getPoints() {
    // the getter gives us a copy, which is the safe thing to do...
    return polyline.getPoints();
  }

  /**
   * Compares this {@link PolylineOptions} object with another {@link PolylineOptions} and
   * determines if their color, alpha, width, and vertices match.
   *
   * @param o Another {@link PolylineOptions} to compare with this object.
   * @return True if color, alpha, width, and vertices match this {@link PolylineOptions} object.
   * Else, false.
   */
  @Override
  public boolean equals(@Nullable Object o) {
    if (this == o) {
      return true;
    }
    if (o == null || getClass() != o.getClass()) {
      return false;
    }

    PolylineOptions polyline = (PolylineOptions) o;

    if (Float.compare(polyline.getAlpha(), getAlpha()) != 0) {
      return false;
    }
    if (getColor() != polyline.getColor()) {
      return false;
    }
    if (Float.compare(polyline.getWidth(), getWidth()) != 0) {
      return false;
    }
    return !(getPoints() != null ? !getPoints().equals(polyline.getPoints()) : polyline.getPoints() != null);
  }

  /**
   * Gives an integer which can be used as the bucket number for storing elements of the set/map.
   * This bucket number is the address of the element inside the set/map. There's no guarantee
   * that this hash value will be consistent between different Java implementations, or even
   * between different execution runs of the same program.
   *
   * @return integer value you can use for storing element.
   */
  @Override
  public int hashCode() {
    int result = 1;
    result = 31 * result + (getAlpha() != +0.0f ? Float.floatToIntBits(getAlpha()) : 0);
    result = 31 * result + getColor();
    result = 31 * result + (getWidth() != +0.0f ? Float.floatToIntBits(getWidth()) : 0);
    result = 31 * result + (getPoints() != null ? getPoints().hashCode() : 0);
    return result;
  }
}