當前位置: 首頁>>代碼示例>>Java>>正文


Java LocationListener類代碼示例

本文整理匯總了Java中android.location.LocationListener的典型用法代碼示例。如果您正苦於以下問題:Java LocationListener類的具體用法?Java LocationListener怎麽用?Java LocationListener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


LocationListener類屬於android.location包,在下文中一共展示了LocationListener類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onDestroy

import android.location.LocationListener; //導入依賴的package包/類
/**
 * Location listeners are removed from manager before the service is destroyed
 */
@Override
public void onDestroy(){
    if (!isAdded){
        addGraphToDB();

        Log.d(TAG, "Added graph before destroying service");
    }


    Log.d(TAG, "Entered onDestroy");

    if (manager != null){
        for (LocationListener listener : locationListeners) {
            manager.removeUpdates(listener);
        }
    }

    super.onDestroy();
}
 
開發者ID:aumarbello,項目名稱:WalkGraph,代碼行數:23,代碼來源:LocationService.java

示例2: initGps

import android.location.LocationListener; //導入依賴的package包/類
private void initGps() {
    if (mLocationManager != null) {
        List<String> providers = mLocationManager.getProviders(true);
        mLocationListeners = new ArrayList<>(providers.size());
        for (String provider : providers) {
            LocationListener listener = new MyLocationListener();
            mLocationListeners.add(listener);
            mLocationManager.requestLocationUpdates(provider, 2000, 5f, listener);
            if (null == mLocation) {
                mLocation = mLocationManager.getLastKnownLocation(provider);
            }
        }
        updateUI(mLocation);
    }

}
 
開發者ID:cm-heclouds,項目名稱:Android-EDP-SDK,代碼行數:17,代碼來源:GpsFragment.java

示例3: register

import android.location.LocationListener; //導入依賴的package包/類
public void register(final LocationListener client) {



        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                activity.runOnUiThread(new Runnable(){
                    @Override
                    public void run() {
                        dLat += (360 * 10)/(2 * Math.PI * R);
                        Location loc = new Location(start);
                        loc.setLatitude(start.getLatitude() - dLat);
                        loc.setLongitude(start.getLongitude());
                        client.onLocationChanged(loc);
                        Log.i(TAG, "Moved");
                    }
                });
            }
        }, 0, 1000);
    }
 
開發者ID:pasho,項目名稱:OsmJet,代碼行數:22,代碼來源:SouthMover.java

示例4: onDeRegistered

import android.location.LocationListener; //導入依賴的package包/類
@Override
public void onDeRegistered()
{
    if(this.mGoogleApiClient != null) {
        mGoogleApiClient.disconnect();
    }

    if(Build.VERSION.SDK_INT >= 23 && !(ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
        for(LocationListener ll : this.locationListeners) {
            this.locationManager.removeUpdates(ll);
        }
    }
    this.timer.cancel();
    this.map = null;
    this.lastKnownLocation = null;
}
 
開發者ID:sztyler,項目名稱:sensordatacollector,代碼行數:17,代碼來源:GPSCollector.java

示例5: ShadowLocationManager

import android.location.LocationListener; //導入依賴的package包/類
@Test
@Ignore
/*
    It appears there is a bug in the ShadowLocationManager.  When updates are removed there is a
    null check against the map of of listeners.  Removing updates does not null the list of providers;
    therefore when listeners are added there are not added to the map.  See line 228 of ShadowLocationManager (Robolectric 3.0-rc2)
 */
public void whenGPSUpdatesAreNoLongerRequiredThenTheGPSListenerIsRemovedFromTheLocationManager() {
    groceryStoreManager.listenForLocationUpdates(true);

    List<LocationListener> locationListeners = shadowLocationManager.getRequestLocationUpdateListeners();
    assertTrue(shadowLocationManager.getProvidersForListener(locationListeners.get(0)).contains(LocationManager.GPS_PROVIDER));

    groceryStoreManager.removeGPSListener();

    locationListeners = shadowLocationManager.getRequestLocationUpdateListeners();
    assertFalse(shadowLocationManager.getProvidersForListener(locationListeners.get(0)).contains(LocationManager.GPS_PROVIDER));
}
 
開發者ID:jameskbride,項目名稱:grocery-reminder,代碼行數:19,代碼來源:GroceryStoreManagerTest.java

示例6: itShouldNotProvideUpdateIfAnyProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldNotProvideUpdateIfAnyProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager, never()).requestLocationUpdates(
            eq(LocationManager.GPS_PROVIDER),
            anyLong(),
            anyFloat(),
            eq(listener));
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:21,代碼來源:LocationTrackerTest.java

示例7: itShouldProvideUpdatesIfAtLeastGPSProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldProvideUpdatesIfAtLeastGPSProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(true);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager).requestLocationUpdates(
            eq(LocationManager.GPS_PROVIDER),
            anyLong(),
            anyFloat(),
            eq(listener));
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:21,代碼來源:LocationTrackerTest.java

示例8: itShouldProvideUpdatesIfAtLeastNetworkProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldProvideUpdatesIfAtLeastNetworkProviderIsAvailable() {
    // given
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(true);

    LocationListener listener = mock(LocationListener.class);

    // when
    locationTracker.startListener(listener);

    // then
    verify(mockedLocationManager)
            .requestLocationUpdates(
                    eq(LocationManager.NETWORK_PROVIDER),
                    anyLong(),
                    anyFloat(),
                    eq(listener));
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:22,代碼來源:LocationTrackerTest.java

示例9: itShouldReturnNullFromLastKnowLocationIfAnyProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldReturnNullFromLastKnowLocationIfAnyProviderIsAvailable() {
    // given
    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertNull(result);
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:21,代碼來源:LocationTrackerTest.java

示例10: itShouldReturnLocationFromLastKnowLocationIfAtLeastGPSProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldReturnLocationFromLastKnowLocationIfAtLeastGPSProviderIsAvailable() {
    // given
    Location expected = mock(Location.class);

    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(true);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(false);

    given(mockedLocationManager.getLastKnownLocation(anyString()))
            .willReturn(expected);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertEquals(expected, result);
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:26,代碼來源:LocationTrackerTest.java

示例11: itShouldReturnLocationFromLastKnowLocationIfAtLeastNetworkProviderIsAvailable

import android.location.LocationListener; //導入依賴的package包/類
@Test
public void itShouldReturnLocationFromLastKnowLocationIfAtLeastNetworkProviderIsAvailable() {
    // given
    Location expected = mock(Location.class);

    List<String> providers =
            Lists.newArrayList(LocationManager.GPS_PROVIDER, LocationManager.NETWORK_PROVIDER);
    given(mockedLocationManager.getProviders(true))
            .willReturn(providers);
    given(mockedLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
            .willReturn(false);
    given(mockedLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER))
            .willReturn(true);

    given(mockedLocationManager.getLastKnownLocation(anyString()))
            .willReturn(expected);

    LocationListener listener = mock(LocationListener.class);

    // when
    Location result = locationTracker.getLastKnowLocation();

    // then
    assertEquals(expected, result);
}
 
開發者ID:cristianoliveira,項目名稱:bikeon-android-app,代碼行數:26,代碼來源:LocationTrackerTest.java

示例12: find

import android.location.LocationListener; //導入依賴的package包/類
public Observable<Coordinate> find() {
    return Observable.create(new Observable.OnSubscribe<Coordinate>() {
        @Override
        public void call(Subscriber<? super Coordinate> subscriber) {
            final Criteria criteria = new Criteria();
            criteria.setAccuracy(Criteria.ACCURACY_COARSE);
            criteria.setPowerRequirement(Criteria.POWER_LOW);

            final String provider = mManager.getBestProvider(criteria, true);
            final LocationListener listener = new InnerLocationListener(subscriber);

            final Looper currentLooper = Looper.myLooper();
            if (currentLooper == null) {
                Looper.prepare();
                mManager.requestSingleUpdate(provider, listener, Looper.myLooper());
                Looper.loop();
            } else {
                mManager.requestSingleUpdate(provider, listener, currentLooper);
            }
        }
    });
}
 
開發者ID:t28hub,項目名稱:rx-weather,代碼行數:23,代碼來源:LocationService.java

示例13: getLocationObserver

import android.location.LocationListener; //導入依賴的package包/類
public Observable<Location> getLocationObserver() {
    return Observable.create(new ObservableOnSubscribe<Location>() {
        @Override
        public void subscribe(final ObservableEmitter<Location> e) throws Exception {
            LocationListener listener = new LocationListenerWithDefaults() {
                @Override
                public void onLocationChanged(Location location) {
                    e.onNext(location);
                }
            };

            if (ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED &&
                    ActivityCompat.checkSelfPermission(activityContext, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {

                ActivityCompat.requestPermissions(activityContext, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 0);

                return;
            }

            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, listener);
        }
    });
}
 
開發者ID:TelerikAcademy,項目名稱:Mobile-Applications-for-Android,代碼行數:24,代碼來源:LocationObserver.java

示例14: unregisterLocationService

import android.location.LocationListener; //導入依賴的package包/類
/**
 * To un-register the Location Service
 */
public final void unregisterLocationService(LocationListener locationListener) throws LocationServiceException
{
	if(gps!=null)
	{	
		if(enableDebugging)
			Log.d(TAG,"Unregister Location Service");
		gps.stopUsingGPS(locationListener); // Change the Listener 
		CAFConfig.setSensorLocation(false);
	}
	else
	{
		Log.d(TAG,"gps is null");
	}
	
}
 
開發者ID:AndroidLearnerchn,項目名稱:AndroidLibraryProject,代碼行數:19,代碼來源:SensorController.java

示例15: unregisterLocationService

import android.location.LocationListener; //導入依賴的package包/類
/**
 * To un-register the Location Service
 */
public final void unregisterLocationService(LocationListener locationListener) throws LocationServiceException
{
	if(locationDataListener!=null)
	{	
		if(enableDebugging)
			Log.d(TAG,"Unregister Location Service");
		locationDataListener.unregisterLocationListener(locationListener); // Change the Listener 
		CAFConfig.setSensorLocation(false);
	}
	else
	{
		Log.d(TAG,"locationDataListener is null");
	}
	
}
 
開發者ID:AndroidLearnerchn,項目名稱:contextawareframework,代碼行數:19,代碼來源:SensorController.java


注:本文中的android.location.LocationListener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。