Java 类com.google.android.gms.location.FusedLocationProviderApi 实例源码

项目:Leanplum-Android-SDK    文件:LeanplumLocationManagerTest.java   
/**
 * Tests for requestLocation.
 *
 * @throws Exception
 */
@Test
public void requestLocation() throws Exception {
  GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class);
  doReturn(true).when(mockGoogleApiClient).isConnected();

  LocationManager mockLocationManager = spy(mLocationManager);
  Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient);

  FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class);
  Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi);

  // Testing when a customer did not disableLocationCollection.
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class),
      any(LocationRequest.class), any(LocationListener.class));

  // Testing when a customer disableLocationCollection.
  Leanplum.disableLocationCollection();
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verifyNoMoreInteractions(mockLocationProviderApi);
}
项目:DroidAssistant    文件:LocationUpdateReceiver.java   
@Override
public void onReceive(Context context, Intent intent) {
    this.context=context;
    notificationManager=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
    nBuilder = new NotificationCompat.Builder(context);
    nBuilder.setContentTitle("DroidAssistant");
    nBuilder.setTicker("DroidAssistant");
    nBuilder.setSmallIcon(R.drawable.robert_icono);
    nBuilder.setLargeIcon(BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.robert_icono));
    nBuilder.setAutoCancel(true);


    mLastLocation = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
    if(mLastLocation==null) {
    }
    else {
        endLatitude=mLastLocation.getLatitude();
        endLongitude=mLastLocation.getLongitude();
        fetchLocationDB();
    }
}
项目:TrekIndiaMobile    文件:UtilityService.java   
/**
 * Called when the location has been updated
 */
private void locationUpdated(Intent intent) {
    Log.v(TAG, ACTION_LOCATION_UPDATED);

    // Extra new location
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);

    if (location != null) {
        LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude());

        // Store in a local preference as well
        Utils.storeLocation(this, latLngLocation);

        // Send a local broadcast so if an Activity is open it can respond
        // to the updated location
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when the location has been updated
 */
private void locationUpdated(Intent intent) {
    Log.v(TAG, ACTION_LOCATION_UPDATED);

    // Extra new location
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);

    if (location != null) {
        LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude());

        // Store in a local preference as well
        Utils.storeLocation(this, latLngLocation);

        // Send a local broadcast so if an Activity is open it can respond
        // to the updated location
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when the location has been updated
 */
private void locationUpdated(Intent intent) {
    Log.v(TAG, ACTION_LOCATION_UPDATED);

    // Extra new location
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);

    if (location != null) {
        LatLng latLngLocation = new LatLng(location.getLatitude(), location.getLongitude());

        // Store in a local preference as well
        Utils.storeLocation(this, latLngLocation);

        // Send a local broadcast so if an Activity is open it can respond
        // to the updated location
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}
项目:arcgis-runtime-demos-android    文件:GeofenceServiceFast.java   
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();

    if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
      final Location location = intent.getParcelableExtra(
          FusedLocationProviderApi.KEY_LOCATION_CHANGED);
      handleActionCheckLocation(location);
    }
    else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
      handleActionChangeToNormalUpdates();
    }
    else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
      handleActionStartFastUpdates();
    }
  }
}
项目:arcgis-runtime-demos-android    文件:GeofenceServiceNormal.java   
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();

    if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
      final Location location = intent.getParcelableExtra(
          FusedLocationProviderApi.KEY_LOCATION_CHANGED);
      handleActionCheckLocation(location);
    }
    else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
        handleActionStartNormalUpdates();
    }
    else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
      handleActionChangeToFastUpdates();
    }
  }
}
项目:arcgis-runtime-demos-android    文件:GeofenceServiceFast.java   
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();

    if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
      final Location location = intent.getParcelableExtra(
          FusedLocationProviderApi.KEY_LOCATION_CHANGED);
      handleActionCheckLocation(location);
    }
    else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
      handleActionChangeToNormalUpdates();
    }
    else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
      handleActionStartFastUpdates();
    }
  }
}
项目:arcgis-runtime-demos-android    文件:GeofenceServiceNormal.java   
@Override
protected void onHandleIntent(Intent intent) {
  if (intent != null) {
    final String action = intent.getAction();

    if (MainActivity.ACTION_CHECK_LOCATION.equals(action)) {
      final Location location = intent.getParcelableExtra(
          FusedLocationProviderApi.KEY_LOCATION_CHANGED);
      handleActionCheckLocation(location);
    }
    else if (MainActivity.ACTION_START_NORMAL_UPDATES.equals(action)) {
        handleActionStartNormalUpdates();
    }
    else if (MainActivity.ACTION_START_FAST_UPDATES.equals(action)) {
      handleActionChangeToFastUpdates();
    }
  }
}
项目:whereat-android    文件:LocationPublisherTest.java   
@Before
public void setup() {
    lp = spy(LocationPublisher.class);
    lp.mGoogClient = mock(GoogleApiClient.class);
    lp.mLocProvider = mock(FusedLocationProviderApi.class);

    shadowOf(RuntimeEnvironment.application)
        .setComponentNameAndServiceForBindService(
            new ComponentName("org.tlc.whereat.modules.pubsub", "LocationPublisher"),
            mock(IBinder.class));

    lp.mPrefs = ShadowPreferenceManager.getDefaultSharedPreferences(RuntimeEnvironment.application);
    lp.mPrefListener = lp.buildPrefListener();
    lp.mPrefs.registerOnSharedPreferenceChangeListener(lp.mPrefListener);
}
项目:whereat-android    文件:LocationPublisherTest.java   
@Test
public void poll_turnsOnPolling() {
    lp.mLocProvider = mock(FusedLocationProviderApi.class);
    lp.poll();

    verify(lp.mLocProvider).requestLocationUpdates(lp.mGoogClient, lp.mLocReq, lp);
    assertThat(lp.mPolling).isTrue();
}
项目:whereat-android    文件:LocationPublisherTest.java   
@Test
public void stopPolling_stopsPolling() {
    lp.mLocProvider = mock(FusedLocationProviderApi.class);
    lp.stopPolling();

    verify(lp.mLocProvider).removeLocationUpdates(lp.mGoogClient, lp);
    assertThat(lp.mPolling).isFalse();
}
项目:whereat-android    文件:LocationPublisherTest.java   
static LocationPublisher setupMockLocationService(){
    LocationPublisher lp = spy(LocationPublisher.class);
    lp.mGoogClient = mock(GoogleApiClient.class);
    lp.mLocProvider = mock(FusedLocationProviderApi.class);
    bindService();
    return lp;
}
项目:TrekIndiaMobile    文件:UtilityService.java   
/**
 * Called when a location update is requested
 */
private void requestLocationInternal() {
    Log.v(TAG, ACTION_REQUEST_LOCATION);
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (connectionResult.isSuccess() && googleApiClient.isConnected()) {

        Intent locationUpdatedIntent = new Intent(this, UtilityService.class);
        locationUpdatedIntent.setAction(ACTION_LOCATION_UPDATED);

        // Send last known location out first if available
        Location location = FusedLocationApi.getLastLocation(googleApiClient);
        if (location != null) {
            Intent lastLocationIntent = new Intent(locationUpdatedIntent);
            lastLocationIntent.putExtra(
                    FusedLocationProviderApi.KEY_LOCATION_CHANGED, location);
            startService(lastLocationIntent);
        }

        // Request new location
        LocationRequest mLocationRequest = new LocationRequest()
                .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        FusedLocationApi.requestLocationUpdates(
                googleApiClient, mLocationRequest,
                PendingIntent.getService(this, 0, locationUpdatedIntent, 0));

        googleApiClient.disconnect();
    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
}
项目:TrekIndiaMobile    文件:AttractionListFragment.java   
@Override
public void onReceive(Context context, Intent intent) {
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
    if (location != null) {
        mLatestLocation = new LatLng(location.getLatitude(), location.getLongitude());
        mAdapter.mAttractionList = loadAttractionsFromLocation(mLatestLocation);
        mAdapter.notifyDataSetChanged();
    }
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when a location update is requested
 */
private void requestLocationInternal() {
    Log.v(TAG, ACTION_REQUEST_LOCATION);
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (connectionResult.isSuccess() && googleApiClient.isConnected()) {

        Intent locationUpdatedIntent = new Intent(this, UtilityService.class);
        locationUpdatedIntent.setAction(ACTION_LOCATION_UPDATED);

        // Send last known location out first if available
        Location location = FusedLocationApi.getLastLocation(googleApiClient);
        if (location != null) {
            Intent lastLocationIntent = new Intent(locationUpdatedIntent);
            lastLocationIntent.putExtra(
                    FusedLocationProviderApi.KEY_LOCATION_CHANGED, location);
            startService(lastLocationIntent);
        }

        // Request new location
        LocationRequest mLocationRequest = new LocationRequest()
                .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        FusedLocationApi.requestLocationUpdates(
                googleApiClient, mLocationRequest,
                PendingIntent.getService(this, 0, locationUpdatedIntent, 0));

        googleApiClient.disconnect();
    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
}
项目:io2015-codelabs    文件:AttractionListFragment.java   
@Override
public void onReceive(Context context, Intent intent) {
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
    if (location != null) {
        mLatestLocation = new LatLng(location.getLatitude(), location.getLongitude());
        mAdapter.mAttractionList = loadAttractionsFromLocation(mLatestLocation);
        mAdapter.notifyDataSetChanged();
    }
}
项目:io2015-codelabs    文件:UtilityService.java   
/**
 * Called when a location update is requested
 */
private void requestLocationInternal() {
    Log.v(TAG, ACTION_REQUEST_LOCATION);
    GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this)
            .addApi(LocationServices.API)
            .build();

    // It's OK to use blockingConnect() here as we are running in an
    // IntentService that executes work on a separate (background) thread.
    ConnectionResult connectionResult = googleApiClient.blockingConnect(
            Constants.GOOGLE_API_CLIENT_TIMEOUT_S, TimeUnit.SECONDS);

    if (connectionResult.isSuccess() && googleApiClient.isConnected()) {

        Intent locationUpdatedIntent = new Intent(this, UtilityService.class);
        locationUpdatedIntent.setAction(ACTION_LOCATION_UPDATED);

        // Send last known location out first if available
        Location location = FusedLocationApi.getLastLocation(googleApiClient);
        if (location != null) {
            Intent lastLocationIntent = new Intent(locationUpdatedIntent);
            lastLocationIntent.putExtra(
                    FusedLocationProviderApi.KEY_LOCATION_CHANGED, location);
            startService(lastLocationIntent);
        }

        // Request new location
        LocationRequest mLocationRequest = new LocationRequest()
                .setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
        FusedLocationApi.requestLocationUpdates(
                googleApiClient, mLocationRequest,
                PendingIntent.getService(this, 0, locationUpdatedIntent, 0));

        googleApiClient.disconnect();
    } else {
        Log.e(TAG, String.format(Constants.GOOGLE_API_CLIENT_ERROR_MSG,
                connectionResult.getErrorCode()));
    }
}
项目:io2015-codelabs    文件:AttractionListFragment.java   
@Override
public void onReceive(Context context, Intent intent) {
    Location location =
            intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
    if (location != null) {
        mLatestLocation = new LatLng(location.getLatitude(), location.getLongitude());
        mAdapter.mAttractionList = loadAttractionsFromLocation(mLatestLocation);
        mAdapter.notifyDataSetChanged();
    }
}
项目:RxLocation    文件:FusedLocationProviderFactoryImpl.java   
@Override
public FusedLocationProviderApi create() {
    return LocationServices.FusedLocationApi;
}
项目:RxLocation    文件:MockFusedLocationProviderFactoryImpl.java   
@Override
public FusedLocationProviderApi create() {
    return new MockFusedLocationProvider();
}
项目:365browser    文件:LocationProviderGmsCore.java   
LocationProviderGmsCore(GoogleApiClient client, FusedLocationProviderApi locationApi) {
    mGoogleApiClient = client;
    mLocationProviderApi = locationApi;
}
项目:CodenameOne    文件:BackgroundLocationHandler.java   
@Override
protected void onHandleIntent(Intent intent) {
    //String className = intent.getStringExtra("backgroundClass");
    final android.location.Location location = intent.getParcelableExtra(FusedLocationProviderApi.KEY_LOCATION_CHANGED);
    if (AndroidLocationPlayServiceManager.inMemoryBackgroundLocationListener != null) {
        // This is basically just a short-term location request and we are using the in-memory listeners.
        AndroidLocationPlayServiceManager mgr = AndroidLocationPlayServiceManager.inMemoryBackgroundLocationListener;
        mgr.onLocationChanged(location);
        return;
    }
    if (intent.getDataString() == null) {
        System.out.println("BackgroundLocationHandler received update without data string.");
        return;
    }
    String[] params = intent.getDataString().split("[?]");


    //might happen on some occasions, no need to do anything.
    if (location == null) {
        return;
    }
    //if the Display is not initialized we need to launch the CodenameOneBackgroundLocationActivity 
    //activity to handle this
    boolean shouldStopWhenDone = false;
    if (!Display.isInitialized()) {
        shouldStopWhenDone = true;
        AndroidImplementation.startContext(this);
        //Display.init(this);
        /*
        Intent bgIntent = new Intent(getBaseContext(), CodenameOneBackgroundLocationActivity.class);
        Bundle b = new Bundle();
        b.putString("backgroundLocation", params[1]);
        b.putParcelable("Location", location);
        bgIntent.putExtras(b); //Put your id to your next Intent
        bgIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getApplication().startActivity(bgIntent);
                */
    } //else {

    try {
        //the 2nd parameter is the class name we need to create
        LocationListener l = (LocationListener) Class.forName(params[1]).newInstance();
        l.locationUpdated(AndroidLocationManager.convert(location));
    } catch (Exception e) {
        Log.e("Codename One", "background location error", e);
    }
    if (shouldStopWhenDone) {
        AndroidImplementation.stopContext(this);
    }
    //}
}
项目:Reactive-PlayServices    文件:ObservableLocation.java   
public ObservableLocation(GoogleApiClient googleAPIClient, FusedLocationProviderApi locationProviderAPI, LocationRequest request){
    this.mLocationProviderAPI = locationProviderAPI;
    this.mGoogleAPIClient = googleAPIClient;
    this.mLocationRequest = request;
}
项目:Reactive-PlayServices    文件:ObservableLocationTest.java   
private void setupMocks() {
    mockGoogleAPIClient = mock(GoogleApiClient.class);
    mockLocationProvider = mock(FusedLocationProviderApi.class);
}
项目:Reactive-PlayServices    文件:ObservableConnectionTest.java   
private void setupMocks() {
    mockGoogleAPIClient = mock(GoogleApiClient.class);
    mockLocationProvider = mock(FusedLocationProviderApi.class);
}
项目:RxLocation    文件:FusedLocationProviderFactory.java   
FusedLocationProviderApi create();