use of com.google.android.gms.location.places.ui.PlaceSelectionListener in project Remindy by abicelis.
the class PlaceActivity method onCreate.
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
// //Enable Lollipop Material Design transitions
// if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP)
// getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place);
if (getIntent().hasExtra(PLACE_TO_EDIT)) {
mPlaceToEdit = (Place) getIntent().getSerializableExtra(PLACE_TO_EDIT);
mPlace = new Place(mPlaceToEdit);
} else {
mPlace = new Place();
}
// Build the Play services client for use by the Fused Location Provider and the Places API.
// Use the addApi() method to request the Google Places API and the Fused Location Provider.
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, /* FragmentActivity */
this).addConnectionCallbacks(this).addApi(LocationServices.API).addApi(Places.GEO_DATA_API).addApi(Places.PLACE_DETECTION_API).build();
mGoogleApiClient.connect();
mAutocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
mAutocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(com.google.android.gms.location.places.Place place) {
//Save lat and long
mPlace.setLatitude(place.getLatLng().latitude);
mPlace.setLongitude(place.getLatLng().longitude);
//Add/Update marker and circle
if (mPlaceMarker == null)
drawMarkerWithCircle(place.getLatLng(), mPlace.getRadius());
else
updateMarkerWithCircle(place.getLatLng());
//Move camera
Location loc = new Location(LocationManager.GPS_PROVIDER);
loc.setLatitude(mPlace.getLatitude());
loc.setLongitude(mPlace.getLongitude());
moveCameraToLocation(loc);
setAliasAndAddress(place.getName().toString(), place.getAddress().toString());
}
@Override
public void onError(Status status) {
SnackbarUtil.showSnackbar(mMapContainer, SnackbarUtil.SnackbarType.ERROR, R.string.error_unexpected, SnackbarUtil.SnackbarDuration.LONG, null);
}
});
mMapContainer = (RelativeLayout) findViewById(R.id.activity_place_map_container);
//mSearch = (EditText) findViewById(R.id.activity_place_search);
//mSearchButton = (ImageView) findViewById(R.id.activity_place_search_button);
mRadius = (SeekBar) findViewById(R.id.activity_place_radius_seekbar);
mRadius.setMax(14);
mRadius.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
mPlace.setRadius((progress + 1) * 100);
mRadiusDisplay.setText(String.valueOf(mPlace.getRadius()) + " m");
if (mPlaceCircle != null)
mPlaceCircle.setRadius(mPlace.getRadius());
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
mRadiusDisplay = (TextView) findViewById(R.id.activity_place_radius_display);
mAlias = (TextView) findViewById(R.id.activity_place_alias);
mAddress = (TextView) findViewById(R.id.activity_place_address);
mAliasAddressEdit = (ImageView) findViewById(R.id.activity_place_alias_address_edit);
mAliasAddressEdit.setOnClickListener(this);
mAliasAddressContainer = (LinearLayout) findViewById(R.id.activity_place_alias_address_container);
setUpToolbar();
}
Aggregations