Search in sources :

Example 31 with Status

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;
            }
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) Bundle(android.os.Bundle) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) ConnectionResult(com.google.android.gms.common.ConnectionResult)

Example 32 with Status

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();
                }
            });
        }
    }
}
Also used : Status(com.google.android.gms.common.api.Status) RemindyDAO(ve.com.abicelis.remindy.database.RemindyDAO) Place(ve.com.abicelis.remindy.model.Place)

Example 33 with Status

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);
}
Also used : Status(com.google.android.gms.common.api.Status) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) SeekBar(android.widget.SeekBar) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) Place(ve.com.abicelis.remindy.model.Place) Location(android.location.Location)

Example 34 with Status

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();
    }
}
Also used : Status(com.google.android.gms.common.api.Status) LatLng(com.google.android.gms.maps.model.LatLng) GenLocation(garbagecollectors.com.unipool.models.GenLocation) Place(com.google.android.gms.location.places.Place)

Example 35 with Status

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();
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) RecyclerViewAdapter(com.cmput301w18t05.taskzilla.RecyclerViewAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) CustomOnItemClick(com.cmput301w18t05.taskzilla.CustomOnItemClick) NewTaskController(com.cmput301w18t05.taskzilla.controller.NewTaskController) AppColors(com.cmput301w18t05.taskzilla.AppColors) SupportMapFragment(com.google.android.gms.maps.SupportMapFragment) ImageButton(android.widget.ImageButton) Button(android.widget.Button) LatLng(com.google.android.gms.maps.model.LatLng) ActionBar(android.support.v7.app.ActionBar) EditText(android.widget.EditText) Status(com.google.android.gms.common.api.Status) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) PlaceSelectionListener(com.google.android.gms.location.places.ui.PlaceSelectionListener) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ColorDrawable(android.graphics.drawable.ColorDrawable) Place(com.google.android.gms.location.places.Place)

Aggregations

Status (com.google.android.gms.common.api.Status)35 LocationRequest (com.google.android.gms.location.LocationRequest)5 LocationSettingsResult (com.google.android.gms.location.LocationSettingsResult)5 Place (com.google.android.gms.location.places.Place)5 LatLng (com.google.android.gms.maps.model.LatLng)5 Activity (android.app.Activity)4 View (android.view.View)4 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)4 PlaceSelectionListener (com.google.android.gms.location.places.ui.PlaceSelectionListener)4 PendingIntent (android.app.PendingIntent)3 Location (android.location.Location)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 WritableMap (com.facebook.react.bridge.WritableMap)3 Credential (com.google.android.gms.auth.api.credentials.Credential)3 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)3 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)3 IOException (java.io.IOException)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 IntentSender (android.content.IntentSender)2