mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 23:42:53 +08:00
Merge branch 'master' of git://github.com/phonegap/phonegap-android
This commit is contained in:
commit
36bd034ee5
@ -21,6 +21,7 @@ public class BrowserKey {
|
|||||||
BrowserKey(WebView view, DroidGap action)
|
BrowserKey(WebView view, DroidGap action)
|
||||||
{
|
{
|
||||||
bound = false;
|
bound = false;
|
||||||
|
mAction = action;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void override()
|
public void override()
|
||||||
|
@ -105,9 +105,7 @@ public class DroidGap extends Activity {
|
|||||||
{
|
{
|
||||||
appView.setWebChromeClient(new GapClient(this));
|
appView.setWebChromeClient(new GapClient(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
appView.setWebViewClient(new GapViewClient(this));
|
|
||||||
|
|
||||||
appView.setInitialScale(100);
|
appView.setInitialScale(100);
|
||||||
appView.setVerticalScrollBarEnabled(false);
|
appView.setVerticalScrollBarEnabled(false);
|
||||||
|
|
||||||
@ -181,63 +179,6 @@ public class DroidGap extends Activity {
|
|||||||
{
|
{
|
||||||
appView.loadUrl(url);
|
appView.loadUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GapViewClient extends WebViewClient {
|
|
||||||
|
|
||||||
Context mCtx;
|
|
||||||
|
|
||||||
public GapViewClient(Context ctx)
|
|
||||||
{
|
|
||||||
mCtx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see android.webkit.WebViewClient#shouldOverrideUrlLoading(android.webkit.WebView, java.lang.String)
|
|
||||||
*
|
|
||||||
* Note: Since we override it to make sure that we are using PhoneGap and not some other bullshit
|
|
||||||
* viewer that may or may not exist, we need to make sure that http:// and tel:// still work.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
||||||
// TODO: See about using a switch statement
|
|
||||||
if (url.startsWith("http://"))
|
|
||||||
{
|
|
||||||
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
||||||
startActivity(browse);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(url.startsWith("tel://"))
|
|
||||||
{
|
|
||||||
Intent dial = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
|
|
||||||
startActivity(dial);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(url.startsWith("sms:"))
|
|
||||||
{
|
|
||||||
Uri smsUri = Uri.parse(url);
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, smsUri);
|
|
||||||
intent.setType("vnd.android-dir/mms-sms");
|
|
||||||
startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if(url.startsWith("mailto:"))
|
|
||||||
{
|
|
||||||
Intent mail = new Intent(Intent.ACTION_SENDTO, Uri.parse(url));
|
|
||||||
startActivity(mail);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//We clear the back button state
|
|
||||||
mKey.reset();
|
|
||||||
view.loadUrl(url);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,7 @@ public class GeoBroker {
|
|||||||
private WebView mAppView;
|
private WebView mAppView;
|
||||||
private Context mCtx;
|
private Context mCtx;
|
||||||
private HashMap<String, GeoListener> geoListeners;
|
private HashMap<String, GeoListener> geoListeners;
|
||||||
|
private GeoListener global;
|
||||||
|
|
||||||
public GeoBroker(WebView view, Context ctx)
|
public GeoBroker(WebView view, Context ctx)
|
||||||
{
|
{
|
||||||
@ -25,13 +26,12 @@ public class GeoBroker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getCurrentLocation()
|
public void getCurrentLocation()
|
||||||
{
|
{
|
||||||
GeoListener listener = new GeoListener("global", mCtx, 10000, mAppView);
|
//It's supposed to run async!
|
||||||
Location loc = listener.getCurrentLocation();
|
if(global == null)
|
||||||
String params = loc.getLatitude() + "," + loc.getLongitude() + ", " + loc.getAltitude() + "," + loc.getAccuracy() + "," + loc.getBearing();
|
global = new GeoListener("global", mCtx, 10000, mAppView);
|
||||||
params += "," + loc.getSpeed() + "," + loc.getTime();
|
else
|
||||||
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
|
global.start(10000);
|
||||||
listener.stop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String start(int freq, String key)
|
public String start(int freq, String key)
|
||||||
|
@ -48,7 +48,12 @@ public class GeoListener {
|
|||||||
if(id != "global")
|
if(id != "global")
|
||||||
{
|
{
|
||||||
mAppView.loadUrl("javascript:navigator._geo.success(" + id + "," + params + ")");
|
mAppView.loadUrl("javascript:navigator._geo.success(" + id + "," + params + ")");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mAppView.loadUrl("javascript:navigator.geolocation.gotCurrentPosition(" + params + ")");
|
||||||
|
this.stop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fail()
|
void fail()
|
||||||
@ -63,6 +68,19 @@ public class GeoListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void start(int interval)
|
||||||
|
{
|
||||||
|
if(mGps != null)
|
||||||
|
mGps.start(interval);
|
||||||
|
if(mNetwork != null)
|
||||||
|
mNetwork.start(interval);
|
||||||
|
if(mNetwork == null && mGps == null)
|
||||||
|
{
|
||||||
|
// Really, how the hell were you going to get the location???
|
||||||
|
mAppView.loadUrl("javascript:navigator._geo.fail()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// This stops the listener
|
// This stops the listener
|
||||||
void stop()
|
void stop()
|
||||||
{
|
{
|
||||||
@ -72,14 +90,4 @@ public class GeoListener {
|
|||||||
mNetwork.stop();
|
mNetwork.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getCurrentLocation() {
|
|
||||||
Location loc = null;
|
|
||||||
if (mGps != null)
|
|
||||||
loc = mGps.getLocation();
|
|
||||||
if (loc == null && mNetwork != null)
|
|
||||||
loc = mNetwork.getLocation();
|
|
||||||
if(loc == null)
|
|
||||||
loc = new Location(LocationManager.NETWORK_PROVIDER);
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -41,9 +41,7 @@ public class GpsListener implements LocationListener {
|
|||||||
{
|
{
|
||||||
owner = m;
|
owner = m;
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.start(interval);
|
||||||
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
|
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation()
|
public Location getLocation()
|
||||||
@ -92,6 +90,13 @@ public class GpsListener implements LocationListener {
|
|||||||
public boolean hasLocation() {
|
public boolean hasLocation() {
|
||||||
return hasData;
|
return hasData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start(int interval)
|
||||||
|
{
|
||||||
|
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
mLocMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, interval, 0, this);
|
||||||
|
cLoc = mLocMan.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||||
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
|
@ -40,9 +40,7 @@ public class NetworkListener implements LocationListener {
|
|||||||
{
|
{
|
||||||
owner = m;
|
owner = m;
|
||||||
mCtx = ctx;
|
mCtx = ctx;
|
||||||
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
this.start(interval);
|
||||||
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
|
|
||||||
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation()
|
public Location getLocation()
|
||||||
@ -94,6 +92,13 @@ public class NetworkListener implements LocationListener {
|
|||||||
cLoc = location;
|
cLoc = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void start(int interval)
|
||||||
|
{
|
||||||
|
mLocMan = (LocationManager) mCtx.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
mLocMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, interval, 0, this);
|
||||||
|
cLoc = mLocMan.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||||
|
}
|
||||||
|
|
||||||
public void stop()
|
public void stop()
|
||||||
{
|
{
|
||||||
mLocMan.removeUpdates(this);
|
mLocMan.removeUpdates(this);
|
||||||
|
Loading…
Reference in New Issue
Block a user