use of com.google.android.gms.common.api.Status in project Thesis by bajnax.
the class LeScanActivity method enableLocation.
public void enableLocation() {
if (googleApiClient == null) {
googleApiClient = new GoogleApiClient.Builder(LeScanActivity.this).addApi(LocationServices.API).addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
@Override
public void onConnected(Bundle bundle) {
}
@Override
public void onConnectionSuspended(int i) {
googleApiClient.connect();
}
}).addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.d("Location error", "Location error " + connectionResult.getErrorCode());
}
}).build();
googleApiClient.connect();
}
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
locationRequest.setInterval(30 * 1000);
locationRequest.setFastestInterval(5 * 1000);
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
builder.setAlwaysShow(true);
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(googleApiClient, builder.build());
result.setResultCallback(new ResultCallback<LocationSettingsResult>() {
@Override
public void onResult(LocationSettingsResult result) {
final Status status = result.getStatus();
switch(status.getStatusCode()) {
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
try {
// requesting to enable Bluetooth
status.startResolutionForResult(LeScanActivity.this, REQUEST_ENABLE_LS);
} catch (IntentSender.SendIntentException e) {
// Ignore the error.
}
break;
}
}
});
}
use of com.google.android.gms.common.api.Status in project Remindy by abicelis.
the class GeofenceUtil method addGeofences.
/* GeoFence management methods */
public static void addGeofences(final Context context, GoogleApiClient googleApiClient) {
checkGoogleApiClient(googleApiClient);
List<Place> places = new RemindyDAO(context).getActivePlaces();
if (places.size() > 0) {
if (PackageManager.PERMISSION_GRANTED == ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)) {
LocationServices.GeofencingApi.addGeofences(googleApiClient, getGeofencingRequest(places), getGeofencePendingIntent(context)).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess())
Toast.makeText(context, "Geofences added/updated!", Toast.LENGTH_SHORT).show();
}
});
}
}
}
use of com.google.android.gms.common.api.Status 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.activity_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();
TapTargetSequenceUtil.showTapTargetSequenceFor(this, TapTargetSequenceType.PLACE_ACTIVITY);
}
use of com.google.android.gms.common.api.Status in project UniPool by divya21raj.
the class BaseActivity method onActivityResult.
// +++++
// For NewEntryDialog
// A place has been received; use requestCode to track the request.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == Activity.RESULT_OK) {
Place place = PlaceAutocomplete.getPlace(this, data);
Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());
LatLng latLng;
switch(requestCode) {
case 1:
latLng = place.getLatLng();
NewEntryDialog.source = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
latLng.longitude);
NewEntryDialog.sourceSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
place.getPhoneNumber());
NewEntryDialog.findSource.setText(NewEntryDialog.sourceSet);
break;
case 2:
latLng = place.getLatLng();
NewEntryDialog.destination = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
latLng.longitude);
NewEntryDialog.destinationSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
place.getPhoneNumber());
NewEntryDialog.findDestination.setText(NewEntryDialog.destinationSet);
break;
}
} else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
Status status = PlaceAutocomplete.getStatus(this, data);
// TODO: Handle the error.
Log.e("Tag", status.getStatusMessage());
} else if (resultCode == RESULT_CANCELED) {
// The user canceled the operation.
// Toast.makeText(getApplicationContext(), "Cancelled...", Toast.LENGTH_SHORT).show();
}
}
use of com.google.android.gms.common.api.Status in project Taskzilla by CMPUT301W18T05.
the class NewTaskActivity method onCreate.
/**
* Activity uses the activity_new_task.xml layout
* New tasks are created through NewTaskController
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
setTitle("Add a Task");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new_task);
AppColors appColors = AppColors.getInstance();
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor(appColors.getActionBarColor())));
actionBar.setTitle(Html.fromHtml("<font color='" + appColors.getActionBarTextColor() + "'>Taskzilla</font>"));
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.dragdropMap);
mapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
newTaskController = new NewTaskController(this, getApplicationContext());
currentLocationButton = findViewById(R.id.currentLocationButton);
Button cancel = findViewById(R.id.CancelButton);
Button addTask = findViewById(R.id.addTaskButton);
final EditText taskName = findViewById(R.id.TaskName);
final EditText taskDescription = findViewById(R.id.Description);
addPhotoButton = findViewById(R.id.AddPhotoButton);
autocompleteFragment = (PlaceAutocompleteFragment) getFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
/**
* When user select a location
* Set hint and set place
* @param place
*/
@Override
public void onPlaceSelected(Place place) {
// TODO: Get info about the selected place.
autocompleteFragment.setHint(place.getName());
taskLocation = place.getLatLng();
}
@Override
public void onError(Status status) {
// TODO: Handle the error.
taskLocation = null;
Log.i("err", "An error occurred: " + status);
}
});
photos = new ArrayList<>();
recyclerPhotosView = findViewById(R.id.listOfPhotos);
layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
recyclerPhotosView.setLayoutManager(layoutManager);
recyclerPhotosViewAdapter = new RecyclerViewAdapter(this, photos, new CustomOnItemClick() {
@Override
public void onColumnClicked(final int position) {
// taken from https://stackoverflow.com/questions/2115758/how-do-i-display-an-alert-dialog-on-android
// 2018-03-16
AlertDialog.Builder alert = new AlertDialog.Builder(NewTaskActivity.this);
alert.setTitle("Delete Photo");
alert.setMessage("Are you sure you want to delete this photo?");
// DELETE CODE
alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
photos.remove(position);
dialogInterface.dismiss();
recyclerPhotosViewAdapter.notifyDataSetChanged();
}
});
// DELETE CANCEL CODE
alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alert.show();
}
});
recyclerPhotosView.setAdapter(recyclerPhotosViewAdapter);
autocompleteFragment.setHint("Task Location");
getLocation();
autocompleteFragment.setBoundsBias(new LatLngBounds(new LatLng(lat - 0.25, lon - 0.25), new LatLng(lat + 0.25, lon + 0.25)));
/* cancel button */
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
newTaskController.cancelTask();
}
});
currentLocationButton.setOnClickListener(new View.OnClickListener() {
/**
* Set loaction to the users current location
* @param view
*/
@Override
public void onClick(View view) {
setCurrentLocation();
}
});
/* add task button */
addTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
newTaskController.addTask(taskName.getText().toString(), cUser, taskDescription.getText().toString(), taskLocation, photos);
}
});
addPhotoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AddPhotoButtonClicked();
}
});
}
Aggregations