Android Open Source - pyneo-wirelesslocation Network Location Provider V1






From Project

Back to project page pyneo-wirelesslocation.

License

The source code is released under:

GNU General Public License

If you think the Android project pyneo-wirelesslocation listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.pyneo.wirelesslocation;
/*from www . ja  va  2 s. c o  m*/
import internal.com.android.location.provider.LocationProvider;

import android.location.Criteria;
import android.location.Location;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.SystemClock;
import android.os.WorkSource;
import android.util.Log;

public class NetworkLocationProviderV1 extends LocationProvider implements NetworkLocationProvider {
  private static final String TAG = NetworkLocationProviderV1.class.getName();
  private static boolean DEBUG = false;
  static { DEBUG = Log.isLoggable("org.pyneo.android", Log.DEBUG); }

  private long autoTime;
  private boolean autoUpdate;
  private boolean enabledByService = false;
  private boolean enabledBySetting = false;

  public NetworkLocationProviderV1() {
    autoUpdate = false;
    autoTime = Long.MAX_VALUE;
  }

  @Deprecated
  public NetworkLocationProviderV1(final boolean internal) {
    this();
  }

  @Override
  public synchronized void disable() {
    enabledByService = false;
  }

  @Override
  public synchronized void enable() {
    enabledByService = true;
  }

  @Override
  public boolean isActive() {
    return enabledBySetting && enabledByService;
  }

  @Override
  public void onAddListener(final int uid, final WorkSource ws) {
    if (DEBUG) Log.d(TAG, uid + " is listening as " + ws != null ? (ws + " (contents:" + ws.describeContents() + ")") : "[unknown WorkSource]");
  }

  @Override
  public void onDisable() {
    enabledBySetting = false;
  }

  @Override
  public void onEnable() {
    enabledBySetting = true;
  }

  @Override
  public void onEnableLocationTracking(final boolean enable) {
    autoUpdate = enable;
  }

  @Override
  public int onGetAccuracy() {
    return Criteria.ACCURACY_COARSE;
  }

  @Override
  public String onGetInternalState() {
    Log.w(TAG, "Internal State not yet implemented. The application may not work.");
    return "[INTERNAL STATE NOT IMPLEMENTED]";
  }

  @Override
  public int onGetPowerRequirement() {
    return Criteria.POWER_LOW;
  }

  @Override
  public int onGetStatus(final Bundle extras) {
    return android.location.LocationProvider.AVAILABLE;
  }

  @Override
  public long onGetStatusUpdateTime() {
    return SystemClock.elapsedRealtime();
  }

  @Override
  public boolean onHasMonetaryCost() {
    return false;
  }

  @Override
  public void onLocationChanged(Location location) {
    if (DEBUG) Log.d(TAG, "onLocationChanged:");
    if (location != null) {
      if (DEBUG) Log.d(TAG, "onLocationChanged: " + location);
      reportLocation(location);
    }
  }

  @Override
  public boolean onMeetsCriteria(final Criteria criteria) {
    if (criteria.getAccuracy() == Criteria.ACCURACY_FINE) {
      return false;
    }
    if (criteria.isAltitudeRequired()) {
      return false;
    }
    if (criteria.isSpeedRequired()) {
      return false;
    }
    return true;
  }

  @Override
  public void onRemoveListener(final int uid, final WorkSource ws) {
  }

  @Override
  public boolean onRequiresCell() {
    return true;
  }

  @Override
  public boolean onRequiresNetwork() {
    return true;
  }

  @Override
  public boolean onRequiresSatellite() {
    return false;
  }

  @Override
  public boolean onSendExtraCommand(final String command, final Bundle extras) {
    return false;
  }

  @Override
  public void onSetMinTime(final long minTime, final WorkSource ws) {
    autoTime = minTime;
  }

  @Override
  public boolean onSupportsAltitude() {
    return false;
  }

  @Override
  public boolean onSupportsBearing() {
    return true;
  }

  @Override
  public boolean onSupportsSpeed() {
    return false;
  }

  @Override
  public void onUpdateLocation(final Location location) {
  }

  @Override
  public void onUpdateNetworkState(final int state, final NetworkInfo info) {
    if (DEBUG) Log.d(TAG, "onUpdateNetworkState: " + state + " (" + info + ")");
  }
}




Java Source Code List

android.location.GeocoderParams.java
android.location.LocationRequest.java
android.net.NetworkInfo.java
android.os.WorkSource.java
com.android.internal.location.ProviderProperties.java
com.android.internal.location.ProviderRequest.java
com.google.android.location.NetworkLocationService.java
com.google.android.location.geocode.GeocodeService.java
com.google.android.location.internal.server.GoogleLocationService.java
com.google.android.location.internal.server.NetworkLocationService.java
com.google.android.location.network.NetworkLocationService.java
internal.com.android.location.provider.GeocodeProvider.java
internal.com.android.location.provider.LocationProviderBase.java
internal.com.android.location.provider.LocationProvider.java
internal.com.android.location.provider.LocationRequestUnbundled.java
internal.com.android.location.provider.ProviderPropertiesUnbundled.java
internal.com.android.location.provider.ProviderRequestUnbundled.java
org.pyneo.android.TheDictionary.java
org.pyneo.android.TheList.java
org.pyneo.android.cellapi.CellAPI2.java
org.pyneo.android.wirelessid.CellIdPre17API.java
org.pyneo.android.wirelessid.CellId.java
org.pyneo.android.wirelessid.Meta.java
org.pyneo.android.wirelessid.Satellite.java
org.pyneo.android.wirelessid.WifiId.java
org.pyneo.wirelesslocation.GeocodeProvider.java
org.pyneo.wirelesslocation.MainService.java
org.pyneo.wirelesslocation.NetworkLocationProviderV1.java
org.pyneo.wirelesslocation.NetworkLocationProviderV2.java
org.pyneo.wirelesslocation.NetworkLocationProvider.java
org.pyneo.wirelesslocation.WirelessEnvListener.java