You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bc...@apache.org on 2012/05/15 06:38:00 UTC

[2/15] android commit: Merging nightmare.

Merging nightmare.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/0d32115c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/0d32115c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/0d32115c

Branch: refs/heads/CordovaWebView
Commit: 0d32115c3fcf9e3136fc7ca21973f76eb5aecabc
Parents: e660768
Author: Bryce Curtis <cu...@gmail.com>
Authored: Mon May 14 23:24:08 2012 -0500
Committer: Bryce Curtis <cu...@gmail.com>
Committed: Mon May 14 23:24:08 2012 -0500

----------------------------------------------------------------------
 .../src/org/apache/cordova/NetworkListener.java    |  139 +--------------
 1 files changed, 9 insertions(+), 130 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/0d32115c/framework/src/org/apache/cordova/NetworkListener.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/NetworkListener.java b/framework/src/org/apache/cordova/NetworkListener.java
index 7fa135f..6eaa8ac 100755
--- a/framework/src/org/apache/cordova/NetworkListener.java
+++ b/framework/src/org/apache/cordova/NetworkListener.java
@@ -16,138 +16,17 @@
        specific language governing permissions and limitations
        under the License.
 */
-package org.apache.cordova;
 
-import org.apache.cordova.api.CordovaInterface;
+package org.apache.cordova;
 
-import android.content.Context;
-import android.location.Location;
 import android.location.LocationManager;
-import android.location.LocationListener;
-import android.os.Bundle;
-
-public class NetworkListener implements LocationListener {
-
-    private CordovaInterface mCtx;              // CordovaActivity object
-
-    private LocationManager mLocMan;           // Location manager object
-    private GeoListener owner;                 // Geolistener object (parent)
-    private boolean hasData = false;           // Flag indicates if location data is available in cLoc
-    private Location cLoc;                     // Last recieved location
-    private boolean running = false;           // Flag indicates if listener is running
-
-    /**
-     * Constructor.  
-     * Automatically starts listening.
-     * 
-     * @param ctx
-     * @param interval
-     * @param m
-     */
-    public NetworkListener(CordovaInterface ctx, int interval, GeoListener m) {
-        this.owner = m;
-        this.mCtx = ctx;
-        this.mLocMan = (LocationManager) this.mCtx.getActivity().getSystemService(Context.LOCATION_SERVICE);
-        this.running = false;
-        this.start(interval);
-    }
-
-    /**
-     * Get last location.
-     * 
-     * @return 				Location object
-     */
-    public Location getLocation() {
-        this.cLoc = this.mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
-        if (this.cLoc != null) {
-            this.hasData = true;
-        }
-        return this.cLoc;
-    }
-
-    /**
-     * Called when the provider is disabled by the user.
-     * 
-     * @param provider
-     */
-    public void onProviderDisabled(String provider) {
-        System.out.println("NetworkListener: The provider " + provider + " is disabled");
-    }
-
-    /**
-     * Called when the provider is enabled by the user.
-     * 
-     * @param provider
-     */
-    public void onProviderEnabled(String provider) {
-        System.out.println("NetworkListener: The provider " + provider + " is enabled");
-    }
-
-    /**
-     * Called when the provider status changes. This method is called when a 
-     * provider is unable to fetch a location or if the provider has recently 
-     * become available after a period of unavailability.
-     * 
-     * @param provider
-     * @param status
-     * @param extras
-     */
-    public void onStatusChanged(String provider, int status, Bundle extras) {
-        System.out.println("NetworkListener: The status of the provider " + provider + " has changed");
-        if (status == 0) {
-            System.out.println("NetworkListener: " + provider + " is OUT OF SERVICE");
-        }
-        else if (status == 1) {
-            System.out.println("NetworkListener: " + provider + " is TEMPORARILY_UNAVAILABLE");
-        }
-        else {
-            System.out.println("NetworkListener: " + provider + " is Available");
-        }
-    }
-
-    /**
-     * Called when the location has changed.
-     * 
-     * @param location
-     */
-    public void onLocationChanged(Location location) {
-        System.out.println("NetworkListener: The location has been updated!");
-        this.hasData = true;
-        this.cLoc = location;
-
-        // The GPS is the primary form of Geolocation in Cordova.  
-        // Only fire the success variables if the GPS is down for some reason.
-        if (!this.owner.mGps.hasLocation()) {
-            this.owner.success(location);
-        }
-    }
-
-    /**
-     * Start requesting location updates.
-     * 
-     * @param interval
-     */
-    public void start(int interval) {
-        if (!this.running) {
-            this.running = true;
-            this.mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
-            this.getLocation();
-
-            // If Network provider has data but GPS provider doesn't, then send ours
-            if (this.hasData && !this.owner.mGps.hasLocation()) {
-                this.owner.success(this.cLoc);
-            }
-        }
-    }
-
-    /**
-     * Stop receiving location updates.
-     */
-    public void stop() {
-        if (this.running) {
-            this.mLocMan.removeUpdates(this);
-        }
-        this.running = false;
-    }
 
+/**
+ * This class handles requests for GPS location services.
+ *
+ */
+public class NetworkListener extends CordovaLocationListener {
+	public NetworkListener(LocationManager locationManager, GeoBroker m) {
+		super(locationManager, m, "[Cordova NetworkListener]");
+	}
 }