@Override
 public void onCreate() {
   super.onCreate();
   mLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this, this);
   Location location = mLocationFinder.getLastBestLocation(MAX_DISTANCE_LIMIT, MAX_TIME_LIMIT);
   if (location != null) {
     onLocationChanged(location);
   }
   String provider =
       Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
   if (!"".equals(provider)) {
     LocationManager locationManager =
         (LocationManager) getSystemService(Context.LOCATION_SERVICE);
     final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
     final boolean networkEnabled =
         locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
     mNoProviderEnabled = !gpsEnabled && !networkEnabled;
   }
   // TODO provide own interface for notifying
   // that no providers are available
   if (mNoProviderEnabled) {
     for (LocationListener listener : mListeners) {
       listener.onProviderDisabled(null);
     }
   }
 }
 @Override
 public void onLocationChanged(Location location) {
   mLastLocation = location;
   for (LocationListener listener : mListeners) {
     listener.onLocationChanged(location);
   }
 }
Exemplo n.º 3
0
 @Override
 public void onLocationChanged(Location location) {
   mLocationListener.onLocationChanged(
       location == null
           ? location
           : PrivacyManager.getDefacedLocation(Binder.getCallingUid(), location));
 }
        @Override
        public void onReceive(Context context, Intent intent) {
          String key = LocationManager.KEY_LOCATION_CHANGED;
          Location location = (Location) intent.getExtras().get(key);

          if (locationListener != null && location != null)
            locationListener.onLocationChanged(location);

          locationManager.removeUpdates(singleUpatePI);
        }
Exemplo n.º 5
0
  @Override
  public void setLocationListener(LocationListener listener) {
    mLocationListener = listener;
    if (mLocationProvider != null) {
      mLocationProvider.setLocationListener(mLocationListener);

      final Location lastLocation = mLocationProvider.getLastFix();
      if (lastLocation != null) {
        mLocationListener.onLocationChanged(lastLocation);
      }
    }
  }
Exemplo n.º 6
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.action_gps) {
      if (!utils.isGpsEnabled()) makeGpsDialog().show();
      else {
        Location location = utils.getUserLocation();
        locationListener.onLocationChanged(location);
      }
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
Exemplo n.º 7
0
  @Override
  protected void onResume() {
    super.onResume();
    if (!utils.isGpsEnabled()) makeGpsDialog().show();
    else {
      if (userLocation == null) {
        Location location = utils.getUserLocation();
        locationListener.onLocationChanged(location);
      }
    }

    if (locationListenerEnabled && !utils.isLocationListenerExists())
      utils.setUserLocationRequestInterval(
          locationListener, GpsUtils.GPS_INTERVAL_TIME_INTENSE, GpsUtils.GPS_INTERVAL_TIME_INTENSE);
  }
Exemplo n.º 8
0
  private void comenzarLocalizacion() {
    // Obtenemos una referencia al LocationManager
    locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    // Obtenemos la última posición conocida
    Location loc = locManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    // Mostramos la última posición conocida
    mostrarPosicion(loc);

    // Nos registramos para recibir actualizaciones de la posición
    locListener =
        new LocationListener() {
          @Override
          public void onLocationChanged(Location location) {
            mostrarPosicion(location);
          }

          @Override
          public void onProviderDisabled(String provider) {
            // Toast.makeText(MainActivity.this,"Provider OFF",Toast.LENGTH_SHORT).show();
            GPSActivo = false;
          }

          @Override
          public void onProviderEnabled(String provider) {
            // Toast.makeText(MainActivity.this,"Provider ON ",Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onStatusChanged(String provider, int status, Bundle extras) {
            Log.i("", "Provider Status: " + status);
            Toast.makeText(
                    MainActivity.this,
                    "Provider Status: " + String.valueOf(status),
                    Toast.LENGTH_SHORT)
                .show();
          }
        };

    if (locManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {

      locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 15000, 0, locListener);
      GPSActivo = true;
    } else {
      locListener.onProviderEnabled(LocationManager.GPS_PROVIDER);
    }
  }
Exemplo n.º 9
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_location);

    lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    ll = new MyLocationListener();

    Criteria crit = new Criteria();
    provider = lm.getBestProvider(crit, false);
    Location location = lm.getLastKnownLocation(provider);

    final boolean gpsEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 20, ll);

    if (!gpsEnabled) {
      AlertDialog alertDialog = new AlertDialog.Builder(this).create();
      alertDialog.setTitle("GPS is disabled!");
      alertDialog.setMessage("Open settings?");
      alertDialog.setButton(
          -3,
          "OK",
          new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
              startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
              // not sure how to refresh the activity, so finish this activity and go back to main
              //  when the user user clicks back from the settings page
              finish();
            }
          });
      alertDialog.setIcon(R.drawable.ic_launcher);
      alertDialog.show();
    } else {
      try {
        if (location != null) {
          ll.onLocationChanged(location);
        }

        finish();

      } catch (Exception e) {
        System.out.println("derp:::: " + e);
      }
    }
  }
Exemplo n.º 10
0
 @Override
 public void onLocationChanged(Location location) {
   Location randomLocation = getRandomLocation(location.getProvider(), mBaseLocation, location);
   mLocationListener.onLocationChanged(randomLocation);
 }
Exemplo n.º 11
0
 /** {@inheritDoc} */
 public void cancel() {
   Log.d(TAG, "cancelling location request");
   if (singeUpdateListener != null) singeUpdateListener.onLocationChanged(null);
   locationManager.removeUpdates(singeUpdateListener);
   if (handler != null) handler.removeCallbacksAndMessages(null);
 }
Exemplo n.º 12
0
 public void onProviderDisabled(String provider) {
   if (locationListener != null) locationListener.onProviderDisabled(provider);
 }
Exemplo n.º 13
0
 public void onStatusChanged(String provider, int status, Bundle extras) {
   if (locationListener != null) locationListener.onStatusChanged(provider, status, extras);
 }
Exemplo n.º 14
0
 public void onLocationChanged(Location location) {
   Log.d(TAG, "Single Location Update Received: ");
   if (locationListener != null) locationListener.onLocationChanged(location);
   locationManager.removeUpdates(singeUpdateListener);
   if (handler != null) handler.removeCallbacksAndMessages(null);
 }
Exemplo n.º 15
0
 @Override
 public void onStatusChanged(String provider, int status, Bundle extras) {
   mLocationListener.onStatusChanged(provider, status, extras);
 }
Exemplo n.º 16
0
 @Override
 public void onProviderEnabled(String provider) {
   mLocationListener.onProviderEnabled(provider);
 }
Exemplo n.º 17
0
 public void addLocationListener(LocationListener locationListener) {
   mListeners.add(locationListener);
   if (mLastLocation != null) locationListener.onLocationChanged(mLastLocation);
   if (mNoProviderEnabled) locationListener.onProviderDisabled(null);
 }