Search in sources :

Example 1 with ReactiveLocationProvider

use of pl.charmas.android.reactivelocation.ReactiveLocationProvider in project Android-ReactiveLocation by mcharmas.

the class PlacesActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_places);
    currentPlaceView = (TextView) findViewById(R.id.current_place_view);
    queryView = (EditText) findViewById(R.id.place_query_view);
    placeSuggestionsList = (ListView) findViewById(R.id.place_suggestions_list);
    placeSuggestionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            AutocompleteInfo info = (AutocompleteInfo) parent.getAdapter().getItem(position);
            startActivity(PlacesResultActivity.getStartIntent(PlacesActivity.this, info.id));
        }
    });
    reactiveLocationProvider = new ReactiveLocationProvider(this);
}
Also used : AdapterView(android.widget.AdapterView) ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) RxTextView(com.jakewharton.rxbinding.widget.RxTextView)

Example 2 with ReactiveLocationProvider

use of pl.charmas.android.reactivelocation.ReactiveLocationProvider in project Android-ReactiveLocation by mcharmas.

the class PlacesResultActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_places_result);
    placeNameView = (TextView) findViewById(R.id.place_name_view);
    placeLocationView = (TextView) findViewById(R.id.place_location_view);
    placeAddressView = (TextView) findViewById(R.id.place_address_view);
    reactiveLocationProvider = new ReactiveLocationProvider(this);
    getPlaceIdFromIntent();
}
Also used : ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider)

Example 3 with ReactiveLocationProvider

use of pl.charmas.android.reactivelocation.ReactiveLocationProvider in project Android-ReactiveLocation by mcharmas.

the class GeofenceActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    reactiveLocationProvider = new ReactiveLocationProvider(this);
    setContentView(R.layout.activity_geofence);
    initViews();
}
Also used : ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider)

Example 4 with ReactiveLocationProvider

use of pl.charmas.android.reactivelocation.ReactiveLocationProvider in project Android-ReactiveLocation by mcharmas.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    lastKnownLocationView = (TextView) findViewById(R.id.last_known_location_view);
    updatableLocationView = (TextView) findViewById(R.id.updated_location_view);
    addressLocationView = (TextView) findViewById(R.id.address_for_location_view);
    currentActivityView = (TextView) findViewById(R.id.activity_recent_view);
    locationProvider = new ReactiveLocationProvider(getApplicationContext());
    lastKnownLocationObservable = locationProvider.getLastKnownLocation();
    final LocationRequest locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY).setNumUpdates(5).setInterval(100);
    locationUpdatesObservable = locationProvider.checkLocationSettings(new LocationSettingsRequest.Builder().addLocationRequest(locationRequest).setAlwaysShow(//Refrence: http://stackoverflow.com/questions/29824408/google-play-services-locationservices-api-new-option-never
    true).build()).doOnNext(new Action1<LocationSettingsResult>() {

        @Override
        public void call(LocationSettingsResult locationSettingsResult) {
            Status status = locationSettingsResult.getStatus();
            if (status.getStatusCode() == LocationSettingsStatusCodes.RESOLUTION_REQUIRED) {
                try {
                    status.startResolutionForResult(MainActivity.this, REQUEST_CHECK_SETTINGS);
                } catch (IntentSender.SendIntentException th) {
                    Log.e("MainActivity", "Error opening settings activity.", th);
                }
            }
        }
    }).flatMap(new Func1<LocationSettingsResult, Observable<Location>>() {

        @Override
        public Observable<Location> call(LocationSettingsResult locationSettingsResult) {
            return locationProvider.getUpdatedLocation(locationRequest);
        }
    });
    addressObservable = locationProvider.getUpdatedLocation(locationRequest).flatMap(new Func1<Location, Observable<List<Address>>>() {

        @Override
        public Observable<List<Address>> call(Location location) {
            return locationProvider.getReverseGeocodeObservable(location.getLatitude(), location.getLongitude(), 1);
        }
    }).map(new Func1<List<Address>, Address>() {

        @Override
        public Address call(List<Address> addresses) {
            return addresses != null && !addresses.isEmpty() ? addresses.get(0) : null;
        }
    }).map(new AddressToStringFunc()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
    activityObservable = locationProvider.getDetectedActivity(50);
}
Also used : Status(com.google.android.gms.common.api.Status) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) Address(android.location.Address) LocationSettingsRequest(com.google.android.gms.location.LocationSettingsRequest) List(java.util.List) ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider) Func1(rx.functions.Func1) AddressToStringFunc(pl.charmas.android.reactivelocation.sample.utils.AddressToStringFunc) Location(android.location.Location)

Example 5 with ReactiveLocationProvider

use of pl.charmas.android.reactivelocation.ReactiveLocationProvider in project Android-ReactiveLocation by mcharmas.

the class MockLocationsActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mocklocations);
    locationProvider = new ReactiveLocationProvider(this);
    mockLocationSubject = PublishSubject.create();
    mockLocationObservable = mockLocationSubject.asObservable();
    initViews();
}
Also used : ReactiveLocationProvider(pl.charmas.android.reactivelocation.ReactiveLocationProvider)

Aggregations

ReactiveLocationProvider (pl.charmas.android.reactivelocation.ReactiveLocationProvider)5 Address (android.location.Address)1 Location (android.location.Location)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 Status (com.google.android.gms.common.api.Status)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 RxTextView (com.jakewharton.rxbinding.widget.RxTextView)1 List (java.util.List)1 AddressToStringFunc (pl.charmas.android.reactivelocation.sample.utils.AddressToStringFunc)1 Func1 (rx.functions.Func1)1