Skip to content

Latest commit

 

History

History
134 lines (111 loc) · 3.47 KB

adal-location.md

File metadata and controls

134 lines (111 loc) · 3.47 KB

adal-location

Android library that simplifies obtaining location.

Download

Gradle:

dependencies {
  implementation 'com.massivedisaster.adal:adal-location:0.1.20'
}

Usage

public class FragmentLocation extends BaseFragment {

    private LocationManager mLocationManager;

    @Override
    protected void doOnCreated() {
        getLocation(); 
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mLocationManager = new LocationManager();
        mLocationManager.onCreate(this);
    }

    @Override
    public void onDestroy() {
        mLocationManager.onDestroy();
        super.onDestroy();
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        mLocationManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        mLocationManager.onActivityResult(requestCode, resultCode);
    }

    private void getLocation() {
        mLocationManager.requestSingleLocation(true, new OnLocationManager() {
            @Override
            public void onLocationFound(Location location, boolean isLastKnowLocation) {
              // Use location here.
            }

            @Override
            public void onLocationError(LocationError locationError) {
                switch (locationError) {
                    case DISABLED:
                        // Location disabled.
                        break;
                    case TIMEOUT:
                        // Location timeout.
                        break;
                }
            }

            @Override
            public void onPermissionsDenied() {
                // Permissions denied.
            }

            @Override
            public void onProviderEnabled() {
                // Provider enabled.
            }

            @Override
            public void onProviderDisabled() {
                // Provider disabled.
            }
        });
    }

    private void getLocationUpdates() {
        mLocationManager.requestLocationUpdates(new OnLocationManager() {
            @Override
            public void onLocationFound(Location location, boolean isLastKnowLocation) {
                // Use location here.
            }

            @Override
            public void onLocationError(LocationError locationError) {
                switch (locationError) {
                    case DISABLED:
                        // Location disabled.
                        break;
                    case TIMEOUT:
                        // Location timeout.
                        break;
                }
            }

            @Override
            public void onPermissionsDenied() {
                // Permissions denied.
            }

            @Override
            public void onProviderEnabled() {
                // Provider enabled.
            }

            @Override
            public void onProviderDisabled() {
                // Provider disabled.
            }
        });
    }

    private void stopLocationUpdates() {
        mLocationManager.stopRequestLocation();
    }
}

Contributing

CONTRIBUTING

License

MIT LICENSE