Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] #2805 - Implementing Parcelable and adding Builder
Browse files Browse the repository at this point in the history
  • Loading branch information
bleege committed Dec 1, 2015
1 parent 36eb07a commit 339f806
Showing 1 changed file with 112 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
package com.mapbox.mapboxsdk.camera;

import android.os.Parcel;
import android.os.Parcelable;
import com.mapbox.mapboxsdk.geometry.LatLng;

public class CameraPosition {
public final class CameraPosition implements Parcelable {

public static final Parcelable.Creator<CameraPosition> CREATOR
= new Parcelable.Creator<CameraPosition>() {
public CameraPosition createFromParcel(Parcel in) {
float bearing = in.readFloat();
LatLng target = in.readParcelable(LatLng.class.getClassLoader());
float tilt = in.readFloat();
float zoom = in.readFloat();
return new CameraPosition(target, zoom, tilt, bearing);
}

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


/**
* Direction that the camera is pointing in, in degrees clockwise from north.
Expand Down Expand Up @@ -50,4 +68,97 @@ public CameraPosition (LatLng target, float zoom, float tilt, float bearing) thr
this.zoom = zoom;
}


@Override
public int describeContents() {
return 0;
}

@Override
public void writeToParcel(Parcel out, int flags) {
out.writeFloat(bearing);
out.writeParcelable(target, flags);
out.writeFloat(tilt);
out.writeFloat(zoom);
}

/**
* Builds camera position.
*/
public static final class Builder {

private float bearing;
private LatLng target;
private float tilt;
private float zoom;

/**
* Creates an empty builder.
*/
public Builder() {
super();
}

/**
* Create Builder with an existing CameraPosition data.
* @param previous Existing CameraPosition values to use
*/
public Builder(CameraPosition previous) {
super();
if (previous != null) {
this.bearing = previous.bearing;
this.target = previous.target;
this.tilt = previous.tilt;
this.zoom = previous.zoom;
}
}

/**
* Sets the direction that the camera is pointing in, in degrees clockwise from north.
* @param bearing Bearing
* @return Builder
*/
public Builder bearing (float bearing) {
this.bearing = bearing;
return this;
}

/**
* Builds a CameraPosition.
* @return CameraPosition
*/
public CameraPosition build() {
return new CameraPosition(target, zoom, tilt, bearing);
}

/**
* Sets the location that the camera is pointing at.
* @param location Location
* @return Builder
*/
public Builder target(LatLng location) {
this.target = location;
return this;
}

/**
* Set the tilt
* @param tilt Tilt value
* @return Builder
*/
public Builder tilt(float tilt) {
this.tilt = tilt;
return this;
}

/**
* Set the zoom
* @param zoom Zoom value
* @return Builder
*/
public Builder zoom(float zoom) {
this.zoom = zoom;
return this;
}
}
}

0 comments on commit 339f806

Please sign in to comment.