diff options
| author | Grace Kloba <klobag@google.com> | 2009-06-16 11:50:55 -0700 |
|---|---|---|
| committer | Grace Kloba <klobag@google.com> | 2009-06-16 11:50:55 -0700 |
| commit | 60e095c190496d42327f8ec2ef990c044d15a76f (patch) | |
| tree | 44c1c91792f8ade8baf707465192a9d4e75de756 /src/com/android/browser/BrowserActivity.java | |
| parent | 740eadfd4d8fa42701992f4c4123e46f8767755a (diff) | |
Add location info if the VIEW action to the Browser has EXTRA_APPEND_LOCATION on.
Diffstat (limited to 'src/com/android/browser/BrowserActivity.java')
| -rw-r--r-- | src/com/android/browser/BrowserActivity.java | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/src/com/android/browser/BrowserActivity.java b/src/com/android/browser/BrowserActivity.java index cacb640a..4168dc49 100644 --- a/src/com/android/browser/BrowserActivity.java +++ b/src/com/android/browser/BrowserActivity.java @@ -57,6 +57,8 @@ import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.PaintDrawable; import android.hardware.SensorListener; import android.hardware.SensorManager; +import android.location.Location; +import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.Uri; import android.net.WebAddress; @@ -81,6 +83,7 @@ import android.provider.Browser; import android.provider.Contacts; import android.provider.Downloads; import android.provider.MediaStore; +import android.provider.Settings; import android.provider.Contacts.Intents.Insert; import android.text.IClipboard; import android.text.TextUtils; @@ -742,6 +745,7 @@ public class BrowserActivity extends Activity waitForCredentials(); } } else { + urlData.setPostData(getLocationData(intent)); urlData.loadIn(webView); } } else { @@ -806,6 +810,7 @@ public class BrowserActivity extends Activity if (urlData.isEmpty()) { urlData = new UrlData(mSettings.getHomePage()); } + urlData.setPostData(getLocationData(intent)); if (Intent.ACTION_VIEW.equals(action) && (flags & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) != 0) { @@ -986,6 +991,37 @@ public class BrowserActivity extends Activity return new UrlData(url); } + byte[] getLocationData(Intent intent) { + byte[] postData = null; + if (intent != null) { + final String action = intent.getAction(); + if (Intent.ACTION_VIEW.equals(action) + && intent.getBooleanExtra(Browser.EXTRA_APPEND_LOCATION, + false)) { + ContentResolver cr = getContentResolver(); + int use = Settings.Gservices.getInt(cr, + Settings.Gservices.USE_LOCATION_FOR_SERVICES, -1); + if (use == -1) { + // TODO: bring up the consent dialog + } else if (use == 1 + && Settings.Secure.isLocationProviderEnabled(cr, + LocationManager.NETWORK_PROVIDER)) { + Location location = ((LocationManager) getSystemService( + Context.LOCATION_SERVICE)).getLastKnownLocation( + LocationManager.NETWORK_PROVIDER); + if (location != null) { + StringBuilder str = new StringBuilder( + "action=devloc&sll="); + str.append(location.getLatitude()).append(',').append( + location.getLongitude()); + postData = str.toString().getBytes(); + } + } + } + } + return postData; + } + /* package */ static String fixUrl(String inUrl) { if (inUrl.startsWith("http://") || inUrl.startsWith("https://")) return inUrl; @@ -4785,17 +4821,26 @@ public class BrowserActivity extends Activity */ private static class UrlData { String mUrl; - + byte[] mPostData; + UrlData(String url) { this.mUrl = url; } - + + void setPostData(byte[] postData) { + mPostData = postData; + } + boolean isEmpty() { return mUrl == null || mUrl.length() == 0; } private void loadIn(WebView webView) { - webView.loadUrl(mUrl); + if (mPostData != null) { + webView.postUrl(mUrl, mPostData); + } else { + webView.loadUrl(mUrl); + } } }; |
