diff --git a/.gitignore b/.gitignore index 7bd73298..85278e2a 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ example tmp *.tmp test/libs/*.jar +bin/node_modules diff --git a/README.md b/README.md index 11ef4f9c..c11708f2 100755 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Building --- To create your cordova.jar, copy the commons codec: + mv commons-codec-1.6.jar framework/libs then run in the framework directory: diff --git a/bin/package.json b/bin/package.json index b4231140..81d3900e 100644 --- a/bin/package.json +++ b/bin/package.json @@ -1,21 +1,3 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ { "name": "cordova-android-cli", "description": "CLI tooling for the cordova-android project", @@ -42,4 +24,3 @@ "nodeunit":"0.5.3" } } - diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index f4a3478e..3b5c7d90 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 9a080cc2704171a4169739b2c94ca55427b92f93 +// commit 55e46cecd73e06a4866f084ffa8513219ef68421 -// File generated at :: Thu May 10 2012 15:48:14 GMT-0700 (PDT) +// File generated at :: Fri May 11 2012 10:34:50 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -98,17 +98,7 @@ var documentEventHandlers = {}, document.addEventListener = function(evt, handler, capture) { var e = evt.toLowerCase(); - if (e == 'deviceready') { - channel.onDeviceReady.subscribeOnce(handler); - } else if (e == 'resume') { - channel.onResume.subscribe(handler); - // if subscribing listener after event has already fired, invoke the handler - if (channel.onResume.fired && typeof handler == 'function') { - handler(); - } - } else if (e == 'pause') { - channel.onPause.subscribe(handler); - } else if (typeof documentEventHandlers[e] != 'undefined') { + if (typeof documentEventHandlers[e] != 'undefined') { documentEventHandlers[e].subscribe(handler); } else { m_document_addEventListener.call(document, evt, handler, capture); @@ -126,13 +116,8 @@ window.addEventListener = function(evt, handler, capture) { document.removeEventListener = function(evt, handler, capture) { var e = evt.toLowerCase(); - // Check for pause/resume events first. - if (e == 'resume') { - channel.onResume.unsubscribe(handler); - } else if (e == 'pause') { - channel.onPause.unsubscribe(handler); // If unsubcribing from an event that is handled by a plugin - } else if (typeof documentEventHandlers[e] != "undefined") { + if (typeof documentEventHandlers[e] != "undefined") { documentEventHandlers[e].unsubscribe(handler); } else { m_document_removeEventListener.call(document, evt, handler, capture); @@ -318,6 +303,11 @@ var cordova = { } }; +// Register pause, resume and deviceready channels as events on document. +channel.onPause = cordova.addDocumentEventHandler('pause'); +channel.onResume = cordova.addDocumentEventHandler('resume'); +channel.onDeviceReady = cordova.addDocumentEventHandler('deviceready'); + // Adds deprecation warnings to functions of an object (but only logs a message once) function deprecateFunctions(obj, objLabel) { var newObj = {}; @@ -1101,7 +1091,7 @@ module.exports = { // Let native code know we are all done on the JS side. // Native code will then un-hide the WebView. channel.join(function() { - exec(function(){}, function(){}, 'App', 'show', []); + prompt("", "gap_init:"); }, [channel.onCordovaReady]); }, objects: { @@ -5182,7 +5172,7 @@ window.cordova = require('cordova'); // Fire onDeviceReady event once all constructors have run and // cordova info has been received from native side. channel.join(function() { - channel.onDeviceReady.fire(); + require('cordova').fireDocumentEvent('deviceready'); }, channel.deviceReadyChannelsArray); }, [ channel.onDOMContentLoaded, channel.onNativeReady ]); @@ -5201,4 +5191,5 @@ window.cordova = require('cordova'); }(window)); + })(); \ No newline at end of file diff --git a/framework/project.properties b/framework/project.properties index 0c8710a7..276f1305 100644 --- a/framework/project.properties +++ b/framework/project.properties @@ -10,5 +10,5 @@ # Indicates whether an apk should be generated for each density. split.density=false # Project target. -target=android-15 +target=Google Inc.:Google APIs:15 apk-configurations= diff --git a/framework/src/org/apache/cordova/CordovaLocationListener.java b/framework/src/org/apache/cordova/CordovaLocationListener.java new file mode 100755 index 00000000..3daa211b --- /dev/null +++ b/framework/src/org/apache/cordova/CordovaLocationListener.java @@ -0,0 +1,198 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ +package org.apache.cordova; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import android.location.Location; +import android.location.LocationListener; +import android.location.LocationManager; +import android.os.Bundle; +import android.util.Log; + +public class CordovaLocationListener implements LocationListener { + public static int PERMISSION_DENIED = 1; + public static int POSITION_UNAVAILABLE = 2; + public static int TIMEOUT = 3; + + protected LocationManager locationManager; + private GeoBroker owner; + protected boolean running = false; + + public HashMap watches = new HashMap(); + private List callbacks = new ArrayList(); + + private String TAG = "[Cordova Location Listener]"; + + public CordovaLocationListener(LocationManager manager, GeoBroker broker, String tag) { + this.locationManager = manager; + this.owner = broker; + this.TAG = tag; + } + + protected void fail(int code, String message) { + for (String callbackId: this.callbacks) + { + this.owner.fail(code, message, callbackId); + } + this.callbacks.clear(); + + Iterator it = this.watches.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + this.owner.fail(code, message, (String)pairs.getValue()); + } + } + + private void win(Location loc) { + for (String callbackId: this.callbacks) + { + this.owner.win(loc, callbackId); + } + this.callbacks.clear(); + + Iterator it = this.watches.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry pairs = (Map.Entry)it.next(); + this.owner.win(loc, (String)pairs.getValue()); + } + } + + /** + * Location Listener Methods + */ + + /** + * Called when the provider is disabled by the user. + * + * @param provider + */ + public void onProviderDisabled(String provider) { + Log.d(TAG, "Location provider '" + provider + "' disabled."); + this.fail(POSITION_UNAVAILABLE, "GPS provider disabled."); + } + + /** + * Called when the provider is enabled by the user. + * + * @param provider + */ + public void onProviderEnabled(String provider) { + Log.d(TAG, "Location provider "+ provider + " has been 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) { + Log.d(TAG, "The status of the provider " + provider + " has changed"); + if (status == 0) { + Log.d(TAG, provider + " is OUT OF SERVICE"); + this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Provider " + provider + " is out of service."); + } + else if (status == 1) { + Log.d(TAG, provider + " is TEMPORARILY_UNAVAILABLE"); + } + else { + Log.d(TAG, provider + " is AVAILABLE"); + } + } + + /** + * Called when the location has changed. + * + * @param location + */ + public void onLocationChanged(Location location) { + Log.d(TAG, "The location has been updated!"); + this.win(location); + } + + // PUBLIC + + public int size() { + return this.watches.size() + this.callbacks.size(); + } + + public void addWatch(String timerId, String callbackId) { + this.watches.put(timerId, callbackId); + if (this.size() == 1) { + this.start(); + } + } + public void addCallback(String callbackId) { + this.callbacks.add(callbackId); + if (this.size() == 1) { + this.start(); + } + } + public void clearWatch(String timerId) { + if (this.watches.containsKey(timerId)) { + this.watches.remove(timerId); + } + if (this.size() == 0) { + this.stop(); + } + } + + /** + * Destroy listener. + */ + public void destroy() { + this.stop(); + } + + // LOCAL + + /** + * Start requesting location updates. + * + * @param interval + */ + protected void start() { + if (!this.running) { + if (this.locationManager.getProvider(LocationManager.NETWORK_PROVIDER) != null) { + this.running = true; + this.locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 10, this); + } else { + this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "Network provider is not available."); + } + } + } + + /** + * Stop receiving location updates. + */ + private void stop() { + if (this.running) { + this.locationManager.removeUpdates(this); + this.running = false; + } + } +} diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java index bccc8217..21164e33 100755 --- a/framework/src/org/apache/cordova/DroidGap.java +++ b/framework/src/org/apache/cordova/DroidGap.java @@ -585,7 +585,7 @@ public class DroidGap extends Activity implements CordovaInterface { } // Send pause event to JavaScript - this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};"); + this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('pause');}catch(e){console.log('exception firing pause event from native');};"); // Forward to plugins if (this.appView.pluginManager != null) { @@ -630,7 +630,7 @@ public class DroidGap extends Activity implements CordovaInterface { } // Send resume event to JavaScript - this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};"); + this.appView.loadUrl("javascript:try{cordova.fireDocumentEvent('resume');}catch(e){console.log('exception firing resume event from native');};"); // Forward to plugins if (this.appView.pluginManager != null) { diff --git a/framework/src/org/apache/cordova/GPSListener.java b/framework/src/org/apache/cordova/GPSListener.java new file mode 100755 index 00000000..2b46c7cf --- /dev/null +++ b/framework/src/org/apache/cordova/GPSListener.java @@ -0,0 +1,50 @@ +/* + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +*/ + +package org.apache.cordova; + +import android.location.LocationManager; + +/** + * This class handles requests for GPS location services. + * + */ +public class GPSListener extends CordovaLocationListener { + public GPSListener(LocationManager locationManager, GeoBroker m) { + super(locationManager, m, "[Cordova GPSListener]"); + } + + + /** + * Start requesting location updates. + * + * @param interval + */ + @Override + protected void start() { + if (!this.running) { + if (this.locationManager.getProvider(LocationManager.GPS_PROVIDER) != null) { + this.running = true; + this.locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this); + } else { + this.fail(CordovaLocationListener.POSITION_UNAVAILABLE, "GPS provider is not available."); + } + } + } +} diff --git a/framework/src/org/apache/cordova/GeoBroker.java b/framework/src/org/apache/cordova/GeoBroker.java index aa89d5a1..6a150b35 100755 --- a/framework/src/org/apache/cordova/GeoBroker.java +++ b/framework/src/org/apache/cordova/GeoBroker.java @@ -18,14 +18,15 @@ */ package org.apache.cordova; -import java.util.HashMap; -import java.util.Map.Entry; - import org.apache.cordova.api.Plugin; import org.apache.cordova.api.PluginResult; import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; +import android.content.Context; +import android.location.Location; +import android.location.LocationManager; /* * This class is the interface to the Geolocation. It's bound to the geo object. @@ -34,132 +35,152 @@ import org.json.JSONException; */ public class GeoBroker extends Plugin { - - // List of gGeolocation listeners - private HashMap geoListeners; - private GeoListener global; + private GPSListener gpsListener; + private NetworkListener networkListener; + private LocationManager locationManager; - /** - * Constructor. - */ - public GeoBroker() { - this.geoListeners = new HashMap(); + /** + * Constructor. + */ + public GeoBroker() { + } + + /** + * Executes the request and returns PluginResult. + * + * @param action The action to execute. + * @param args JSONArry of arguments for the plugin. + * @param callbackId The callback id used when calling back into JavaScript. + * @return A PluginResult object with a status and message. + */ + public PluginResult execute(String action, JSONArray args, String callbackId) { + if (this.locationManager == null) { + this.locationManager = (LocationManager) this.ctx.getSystemService(Context.LOCATION_SERVICE); + this.networkListener = new NetworkListener(this.locationManager, this); + this.gpsListener = new GPSListener(this.locationManager, this); + } + PluginResult.Status status = PluginResult.Status.NO_RESULT; + String message = ""; + PluginResult result = new PluginResult(status, message); + result.setKeepCallback(true); + + try { + if (action.equals("getLocation")) { + boolean enableHighAccuracy = args.getBoolean(0); + int maximumAge = args.getInt(1); + Location last = this.locationManager.getLastKnownLocation((enableHighAccuracy ? LocationManager.GPS_PROVIDER : LocationManager.NETWORK_PROVIDER)); + // Check if we can use lastKnownLocation to get a quick reading and use less battery + if ((System.currentTimeMillis() - last.getTime()) <= maximumAge) { + result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(last)); + } else { + this.getCurrentLocation(callbackId, enableHighAccuracy); + } + } + else if (action.equals("addWatch")) { + String id = args.getString(0); + boolean enableHighAccuracy = args.getBoolean(1); + this.addWatch(id, callbackId, enableHighAccuracy); + } + else if (action.equals("clearWatch")) { + String id = args.getString(0); + this.clearWatch(id); + } + } catch (JSONException e) { + result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, e.getMessage()); + } + return result; + } + + private void clearWatch(String id) { + this.gpsListener.clearWatch(id); + this.networkListener.clearWatch(id); } - /** - * Executes the request and returns PluginResult. - * - * @param action The action to execute. - * @param args JSONArry of arguments for the plugin. - * @param callbackId The callback id used when calling back into JavaScript. - * @return A PluginResult object with a status and message. - */ - public PluginResult execute(String action, JSONArray args, String callbackId) { - PluginResult.Status status = PluginResult.Status.OK; - String result = ""; - - try { - if (action.equals("getCurrentLocation")) { - this.getCurrentLocation(args.getBoolean(0), args.getInt(1), args.getInt(2)); - } - else if (action.equals("start")) { - String s = this.start(args.getString(0), args.getBoolean(1), args.getInt(2), args.getInt(3)); - return new PluginResult(status, s); - } - else if (action.equals("stop")) { - this.stop(args.getString(0)); - } - return new PluginResult(status, result); - } catch (JSONException e) { - return new PluginResult(PluginResult.Status.JSON_EXCEPTION); + private void getCurrentLocation(String callbackId, boolean enableHighAccuracy) { + if (enableHighAccuracy) { + this.gpsListener.addCallback(callbackId); + } else { + this.networkListener.addCallback(callbackId); } } + + private void addWatch(String timerId, String callbackId, boolean enableHighAccuracy) { + if (enableHighAccuracy) { + this.gpsListener.addWatch(timerId, callbackId); + } else { + this.networkListener.addWatch(timerId, callbackId); + } + } /** - * Identifies if action to be executed returns a value and should be run synchronously. - * - * @param action The action to execute - * @return T=returns value - */ - public boolean isSynch(String action) { - // Starting listeners is easier to run on main thread, so don't run async. - return true; - } + * Identifies if action to be executed returns a value and should be run synchronously. + * + * @param action The action to execute + * @return T=returns value + */ + public boolean isSynch(String action) { + // Starting listeners is easier to run on main thread, so don't run async. + return true; + } /** * Called when the activity is to be shut down. * Stop listener. */ public void onDestroy() { - java.util.Set> s = this.geoListeners.entrySet(); - java.util.Iterator> it = s.iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - GeoListener listener = entry.getValue(); - listener.destroy(); - } - this.geoListeners.clear(); - if (this.global != null) { - this.global.destroy(); - } - this.global = null; + this.networkListener.destroy(); + this.gpsListener.destroy(); + this.networkListener = null; + this.gpsListener = null; } - //-------------------------------------------------------------------------- - // LOCAL METHODS - //-------------------------------------------------------------------------- - - /** - * Get current location. - * The result is returned to JavaScript via a callback. - * - * @param enableHighAccuracy - * @param timeout - * @param maximumAge - */ - public void getCurrentLocation(boolean enableHighAccuracy, int timeout, int maximumAge) { - - // Create a geolocation listener just for getCurrentLocation and call it "global" - if (this.global == null) { - this.global = new GeoListener(this, "global", maximumAge); + public JSONObject returnLocationJSON(Location loc) { + JSONObject o = new JSONObject(); + + try { + o.put("latitude", loc.getLatitude()); + o.put("longitude", loc.getLongitude()); + o.put("altitude", (loc.hasAltitude() ? loc.getAltitude() : null)); + o.put("accuracy", loc.getAccuracy()); + o.put("heading", (loc.hasBearing() ? (loc.hasSpeed() ? loc.getBearing() : null) : null)); + o.put("speed", loc.getSpeed()); + o.put("timestamp", loc.getTime()); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - else { - this.global.start(maximumAge); - } - } - - /** - * Start geolocation listener and add to listener list. - * - * @param key The listener id - * @param enableHighAccuracy - * @param timeout - * @param maximumAge - * @return - */ - public String start(String key, boolean enableHighAccuracy, int timeout, int maximumAge) { - - // Make sure this listener doesn't already exist - GeoListener listener = geoListeners.get(key); - if (listener == null) { - listener = new GeoListener(this, key, maximumAge); - geoListeners.put(key, listener); - } - - // Start it - listener.start(maximumAge); - return key; - } - - /** - * Stop geolocation listener and remove from listener list. - * - * @param key The listener id - */ - public void stop(String key) { - GeoListener listener = geoListeners.remove(key); - if (listener != null) { - listener.stop(); - } - } + + + return o; + } + public void win(Location loc, String callbackId) { + PluginResult result = new PluginResult(PluginResult.Status.OK, this.returnLocationJSON(loc)); + this.success(result, callbackId); + } + /** + * Location failed. Send error back to JavaScript. + * + * @param code The error code + * @param msg The error message + * @throws JSONException + */ + public void fail(int code, String msg, String callbackId) { + JSONObject obj = new JSONObject(); + String backup = null; + try { + obj.put("code", code); + obj.put("message", msg); + } catch (JSONException e) { + obj = null; + backup = "{'code':" + code + ",'message':'" + msg.replaceAll("'", "\'") + "'}"; + } + PluginResult result; + if (obj != null) { + result = new PluginResult(PluginResult.Status.ERROR, obj); + } else { + result = new PluginResult(PluginResult.Status.ERROR, backup); + } + + this.error(result, callbackId); + } } diff --git a/framework/src/org/apache/cordova/GeoListener.java b/framework/src/org/apache/cordova/GeoListener.java deleted file mode 100755 index 92a2ca66..00000000 --- a/framework/src/org/apache/cordova/GeoListener.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - Licensed to the Apache Software Foundation (ASF) under one - or more contributor license agreements. See the NOTICE file - distributed with this work for additional information - regarding copyright ownership. The ASF licenses this file - to you under the Apache License, Version 2.0 (the - "License"); you may not use this file except in compliance - with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, - software distributed under the License is distributed on an - "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - KIND, either express or implied. See the License for the - specific language governing permissions and limitations - under the License. -*/ -package org.apache.cordova; - -import android.content.Context; -import android.location.Location; -import android.location.LocationManager; - -//import android.webkit.WebView; - -public class GeoListener { - public static int PERMISSION_DENIED = 1; - public static int POSITION_UNAVAILABLE = 2; - public static int TIMEOUT = 3; - - String id; // Listener ID - String successCallback; // - String failCallback; - GpsListener mGps; // GPS listener - NetworkListener mNetwork; // Network listener - LocationManager mLocMan; // Location manager - - private GeoBroker broker; // GeoBroker object - - int interval; - - /** - * Constructor. - * - * @param id Listener id - * @param ctx - * @param time Sampling period in msec - * @param appView - */ - GeoListener(GeoBroker broker, String id, int time) { - this.id = id; - this.interval = time; - this.broker = broker; - this.mGps = null; - this.mNetwork = null; - this.mLocMan = (LocationManager) broker.ctx.getActivity().getSystemService(Context.LOCATION_SERVICE); - - // If GPS provider, then create and start GPS listener - if (this.mLocMan.getProvider(LocationManager.GPS_PROVIDER) != null) { - this.mGps = new GpsListener(broker.ctx, time, this); - } - - // If network provider, then create and start network listener - if (this.mLocMan.getProvider(LocationManager.NETWORK_PROVIDER) != null) { - this.mNetwork = new NetworkListener(broker.ctx, time, this); - } - } - - /** - * Destroy listener. - */ - public void destroy() { - this.stop(); - } - - /** - * Location found. Send location back to JavaScript. - * - * @param loc - */ - void success(Location loc) { - - String params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() + - "," + loc.getAccuracy() + "," + loc.getBearing() + - "," + loc.getSpeed() + "," + loc.getTime(); - - if (id == "global") { - this.stop(); - } - this.broker.sendJavascript("navigator._geo.success('" + id + "'," + params + ");"); - } - - /** - * Location failed. Send error back to JavaScript. - * - * @param code The error code - * @param msg The error message - */ - void fail(int code, String msg) { - this.broker.sendJavascript("navigator._geo.fail('" + this.id + "', '" + code + "', '" + msg + "');"); - this.stop(); - } - - /** - * Start retrieving location. - * - * @param interval - */ - void start(int interval) { - if (this.mGps != null) { - this.mGps.start(interval); - } - if (this.mNetwork != null) { - this.mNetwork.start(interval); - } - if (this.mNetwork == null && this.mGps == null) { - this.fail(POSITION_UNAVAILABLE, "No location providers available."); - } - } - - /** - * Stop listening for location. - */ - void stop() { - if (this.mGps != null) { - this.mGps.stop(); - } - if (this.mNetwork != null) { - this.mNetwork.stop(); - } - } - -} diff --git a/test/src/org/apache/cordova/test/BackButtonTest.java b/test/src/org/apache/cordova/test/BackButtonTest.java new file mode 100644 index 00000000..db09792f --- /dev/null +++ b/test/src/org/apache/cordova/test/BackButtonTest.java @@ -0,0 +1,49 @@ +package org.apache.cordova.test; + +import org.apache.cordova.CordovaWebView; + +import android.test.ActivityInstrumentationTestCase2; +import android.test.TouchUtils; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +public class BackButtonTest extends ActivityInstrumentationTestCase2 { + + private backbuttonmultipage testActivity; + private FrameLayout containerView; + private LinearLayout innerContainer; + private CordovaWebView testView; + private TouchUtils touchTest; + private long TIMEOUT = 5000; + + public BackButtonTest() { + super("org.apache.cordova.test",backbuttonmultipage.class); + } + + protected void setUp() throws Exception { + super.setUp(); + testActivity = this.getActivity(); + containerView = (FrameLayout) testActivity.findViewById(android.R.id.content); + innerContainer = (LinearLayout) containerView.getChildAt(0); + testView = (CordovaWebView) innerContainer.getChildAt(0); + touchTest = new TouchUtils(); + } + + public void testPreconditions(){ + assertNotNull(innerContainer); + assertNotNull(testView); + } + + public void testClick() { + touchTest.tapView(this, testView); + } + + private void sleep() { + try { + Thread.sleep(TIMEOUT ); + } catch (InterruptedException e) { + fail("Unexpected Timeout"); + } + } + +} diff --git a/test/src/org/apache/cordova/test/CordovaActivityTest.java b/test/src/org/apache/cordova/test/CordovaActivityTest.java index 8a38b1ad..3a5b47db 100644 --- a/test/src/org/apache/cordova/test/CordovaActivityTest.java +++ b/test/src/org/apache/cordova/test/CordovaActivityTest.java @@ -33,9 +33,10 @@ public class CordovaActivityTest extends ActivityInstrumentationTestCase2 { + + errorurl testActivity; + private FrameLayout containerView; + private LinearLayout innerContainer; + private CordovaWebView testView; + + public ErrorUrlTest() { + super("org.apache.cordova.test",errorurl.class); + } + + + protected void setUp() throws Exception { + super.setUp(); + testActivity = this.getActivity(); + containerView = (FrameLayout) testActivity.findViewById(android.R.id.content); + innerContainer = (LinearLayout) containerView.getChildAt(0); + testView = (CordovaWebView) innerContainer.getChildAt(0); + + } + + public void testPreconditions(){ + assertNotNull(innerContainer); + assertNotNull(testView); + } + +} diff --git a/test/src/org/apache/cordova/test/HtmlNotFoundTest.java b/test/src/org/apache/cordova/test/HtmlNotFoundTest.java new file mode 100644 index 00000000..4546e5ac --- /dev/null +++ b/test/src/org/apache/cordova/test/HtmlNotFoundTest.java @@ -0,0 +1,11 @@ +package org.apache.cordova.test; + +import android.test.ActivityInstrumentationTestCase2; + +public class HtmlNotFoundTest extends ActivityInstrumentationTestCase2 { + + + public HtmlNotFoundTest() { + super("org.apache.cordova.test",htmlnotfound.class); + } +} diff --git a/test/src/org/apache/cordova/test/IFrameTest.java b/test/src/org/apache/cordova/test/IFrameTest.java new file mode 100644 index 00000000..07fba57a --- /dev/null +++ b/test/src/org/apache/cordova/test/IFrameTest.java @@ -0,0 +1,11 @@ +package org.apache.cordova.test; + +import android.test.ActivityInstrumentationTestCase2; + +public class IFrameTest extends ActivityInstrumentationTestCase2