Search in sources :

Example 11 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.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();
}
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 12 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)

Aggregations

Status (com.google.android.gms.common.api.Status)12 Activity (android.app.Activity)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 Credential (com.google.android.gms.auth.api.credentials.Credential)3 Location (android.location.Location)2 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)2 Func1 (rx.functions.Func1)2 Place (ve.com.abicelis.remindy.model.Place)2 PendingIntent (android.app.PendingIntent)1 Address (android.location.Address)1 SeekBar (android.widget.SeekBar)1 CredentialTaskApi (com.firebase.ui.auth.util.CredentialTaskApi)1 GoogleApiClientTaskHelper (com.firebase.ui.auth.util.GoogleApiClientTaskHelper)1 GoogleSignInHelper (com.firebase.ui.auth.util.GoogleSignInHelper)1 CredentialRequest (com.google.android.gms.auth.api.credentials.CredentialRequest)1 CredentialRequestResult (com.google.android.gms.auth.api.credentials.CredentialRequestResult)1 GeofencingRequest (com.google.android.gms.location.GeofencingRequest)1 LocationRequest (com.google.android.gms.location.LocationRequest)1 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)1 LocationSettingsResult (com.google.android.gms.location.LocationSettingsResult)1