diff options
author | Arne Schwabe <arne@rfc2549.org> | 2014-05-24 12:39:05 +0200 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2014-05-24 12:47:45 +0200 |
commit | 2b2a2e19e1793ae79f80c8e520fb36a56e576e29 (patch) | |
tree | 94e35a34b1b870e21bdf2ec6a695f9237bd08f0b /main | |
parent | cadf1bb896976c5dc04cfd4b1615ad694fec3415 (diff) | |
download | cgeo-2b2a2e19e1793ae79f80c8e520fb36a56e576e29.zip cgeo-2b2a2e19e1793ae79f80c8e520fb36a56e576e29.tar.gz cgeo-2b2a2e19e1793ae79f80c8e520fb36a56e576e29.tar.bz2 |
Implement a small internal browser (using webview) and allow the user to pick the user to select an internal/external browser if c:geo is the default of the geocaching url
Diffstat (limited to 'main')
-rw-r--r-- | main/AndroidManifest.xml | 6 | ||||
-rw-r--r-- | main/res/drawable-mdpi/ic_launcher_browser.png | bin | 0 -> 7151 bytes | |||
-rw-r--r-- | main/res/drawable-xhdpi/ic_launcher_browser.png | bin | 0 -> 21981 bytes | |||
-rw-r--r-- | main/res/drawable-xxhdpi/ic_launcher_browser.png | bin | 0 -> 37607 bytes | |||
-rw-r--r-- | main/res/layout/internal_browser.xml | 12 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 22 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/Waypoint.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/activity/SimpleWebviewActivity.java | 28 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCConnector.java | 2 |
9 files changed, 69 insertions, 3 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml index 4f0135e..dbf370e 100644 --- a/main/AndroidManifest.xml +++ b/main/AndroidManifest.xml @@ -477,6 +477,12 @@ </intent-filter> </activity> + <activity android:name=".activity.SimpleWebviewActivity" + android:label="c:geo internal browser" + android:icon="@drawable/ic_launcher_browser"> + + </activity> + <!-- provide enhanced meta data for caches (and waypoints) when invoking Locus from c:geo --> <provider android:name=".apps.LocusDataStorageProvider" diff --git a/main/res/drawable-mdpi/ic_launcher_browser.png b/main/res/drawable-mdpi/ic_launcher_browser.png Binary files differnew file mode 100644 index 0000000..9bc6817 --- /dev/null +++ b/main/res/drawable-mdpi/ic_launcher_browser.png diff --git a/main/res/drawable-xhdpi/ic_launcher_browser.png b/main/res/drawable-xhdpi/ic_launcher_browser.png Binary files differnew file mode 100644 index 0000000..9412fbe --- /dev/null +++ b/main/res/drawable-xhdpi/ic_launcher_browser.png diff --git a/main/res/drawable-xxhdpi/ic_launcher_browser.png b/main/res/drawable-xxhdpi/ic_launcher_browser.png Binary files differnew file mode 100644 index 0000000..bd8c447 --- /dev/null +++ b/main/res/drawable-xxhdpi/ic_launcher_browser.png diff --git a/main/res/layout/internal_browser.xml b/main/res/layout/internal_browser.xml new file mode 100644 index 0000000..1e09ee0 --- /dev/null +++ b/main/res/layout/internal_browser.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> + +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <WebView + android:id="@+id/webview" + android:layout_width="match_parent" + android:layout_height="match_parent" /> +</LinearLayout>
\ No newline at end of file diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index db36740..0000fcc 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -1,7 +1,9 @@ package cgeo.geocaching; +import android.os.Parcelable; import cgeo.geocaching.DataStore.StorageLocation; import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.activity.SimpleWebviewActivity; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.connector.IConnector; import cgeo.geocaching.connector.ILoggingManager; @@ -497,9 +499,25 @@ public class Geocache implements ICache, IWaypoint { } public void openInBrowser(Activity fromActivity) { - fromActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getBrowserCacheUrl()))); + Intent viewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getUrl())); + + // Check if cgeo is the default, show the chooser to let the user choose a browser + if (viewIntent.resolveActivity(fromActivity.getPackageManager()).getPackageName().equals(fromActivity.getPackageName())) { + Intent chooser = Intent.createChooser(viewIntent, fromActivity.getString(R.string.cache_menu_browser)); + + Intent internalBrowser = new Intent(fromActivity, SimpleWebviewActivity.class); + internalBrowser.setData(Uri.parse(getUrl())); + + chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Parcelable[] {internalBrowser}); + + + fromActivity.startActivity(chooser); + } + else + fromActivity.startActivity(viewIntent); } + private String getCacheUrl() { return getConnector().getCacheUrl(this); } @@ -731,6 +749,8 @@ public class Geocache implements ICache, IWaypoint { return getConnector().getCacheUrl(this); } + public String getCgeoUrl() { return getConnector().getCacheUrl(this); } + public boolean supportsGCVote() { return StringUtils.startsWithIgnoreCase(geocode, "GC"); } diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java index efedff5..275882f 100644 --- a/main/src/cgeo/geocaching/Waypoint.java +++ b/main/src/cgeo/geocaching/Waypoint.java @@ -157,7 +157,7 @@ public class Waypoint implements IWaypoint { } public String getUrl() { - return "http://www.geocaching.com//seek/cache_details.aspx?wp=" + geocode; + return "http://www.geocaching.com/seek/cache_details.aspx?wp=" + geocode; } @Override diff --git a/main/src/cgeo/geocaching/activity/SimpleWebviewActivity.java b/main/src/cgeo/geocaching/activity/SimpleWebviewActivity.java new file mode 100644 index 0000000..54f3667 --- /dev/null +++ b/main/src/cgeo/geocaching/activity/SimpleWebviewActivity.java @@ -0,0 +1,28 @@ +package cgeo.geocaching.activity; + +import android.os.Bundle; +import android.webkit.WebView; +import android.webkit.WebViewClient; +import cgeo.geocaching.R; + +public class SimpleWebviewActivity extends AbstractActionBarActivity { + + private WebView webview; + + class SimplelWebviewClient extends WebViewClient { + @Override + public boolean shouldOverrideUrlLoading(WebView view, String url) { + webview.loadUrl(url); + return true; + } + } + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState, R.layout.internal_browser); + + webview = (WebView) findViewById(R.id.webview); + webview.getSettings().setJavaScriptEnabled(true); + webview.setWebViewClient(new SimplelWebviewClient()); + webview.loadUrl(String.valueOf(getIntent().getData())); + } +} diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index a38bad0..294e969 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -50,7 +50,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, private static final String CACHE_URL_SHORT = "http://coord.info/"; // Double slash is used to force open in browser - private static final String CACHE_URL_LONG = "http://www.geocaching.com//seek/cache_details.aspx?wp="; + private static final String CACHE_URL_LONG = "http://www.geocaching.com/seek/cache_details.aspx?wp="; /** * Pocket queries downloaded from the website use a numeric prefix. The pocket query creator Android app adds a * verbatim "pocketquery" prefix. |