当前位置: 首页>>代码示例>>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;未经允许,请勿转载。