-
Notifications
You must be signed in to change notification settings - Fork 119
/
PlacePicker.java
70 lines (56 loc) · 1.92 KB
/
PlacePicker.java
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
package com.mapbox.mapboxsdk.plugins.places.picker;
import android.app.Activity;
import android.content.Intent;
import com.mapbox.api.geocoding.v5.models.CarmenFeature;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.plugins.places.common.PlaceConstants;
import com.mapbox.mapboxsdk.plugins.places.picker.model.PlacePickerOptions;
import com.mapbox.mapboxsdk.plugins.places.picker.ui.PlacePickerActivity;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public final class PlacePicker {
private PlacePicker() {
// No instances
}
/**
* Returns the {@link CarmenFeature} selected by the user.
*
* @param data the result Intent that was provided in
* {@link Activity#onActivityResult(int, int, Intent)}
* @return the users selected {@link CarmenFeature}
*/
@Nullable
public static CarmenFeature getPlace(Intent data) {
String json = data.getStringExtra(PlaceConstants.RETURNING_CARMEN_FEATURE);
if (json == null) {
return null;
}
return CarmenFeature.fromJson(json);
}
public static CameraPosition getLastCameraPosition(Intent data) {
return data.getParcelableExtra(PlaceConstants.MAP_CAMERA_POSITION);
}
public static class IntentBuilder {
private Intent intent;
/**
* Creates a new builder that creates an intent to launch the place picker activity.
*
* @since 0.1.0
*/
public IntentBuilder() {
intent = new Intent();
}
public IntentBuilder accessToken(@NonNull String accessToken) {
intent.putExtra(PlaceConstants.ACCESS_TOKEN, accessToken);
return this;
}
public IntentBuilder placeOptions(PlacePickerOptions placeOptions) {
intent.putExtra(PlaceConstants.PLACE_OPTIONS, placeOptions);
return this;
}
public Intent build(Activity activity) {
intent.setClass(activity, PlacePickerActivity.class);
return intent;
}
}
}