Permalink
Browse files

Add intent in order to open web links to Wikipedia in the app. it wil…

…l be very useful for links in email and social networks.
  • Loading branch information...
1 parent 0aa6826 commit 4c670328bee7330095cdd83a64a74f19d44c5b5f @Tpt committed Nov 26, 2011
Showing with 39 additions and 13 deletions.
  1. +7 −0 AndroidManifest.xml
  2. +22 −11 assets/www/js/main.js
  3. +10 −2 src/org/wikipedia/WikipediaActivity.java
View
7 AndroidManifest.xml
@@ -18,6 +18,13 @@
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.VIEW" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+ <data android:host="*.wikipedia.org" android:scheme="http" />
+ <data android:host="*.wikipedia.org" android:scheme="https" />
+ </intent-filter>
</activity>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden">
View
33 assets/www/js/main.js
@@ -39,6 +39,13 @@ function removeCountryCode(localeCode) {
return localeCode;
}
+function getUrlParam() {
+ var url = document.location.search;
+ var reg = /^\?href=(.*)$/;
+ matches = url.match(reg);
+ return matches[1] != undefined ? matches[1] : '';
+}
+
function hideMobileLinks() {
var frameDoc = $("#main")[0].contentDocument;
$('#header', frameDoc).css('display', 'none');
@@ -97,18 +104,22 @@ function loadContent() {
function loadWikiContent() {
showSpinner();
$('#search').addClass('inProgress');
-
- // restore browsing to last visited page
- var historyDB = new Lawnchair({name:"historyDB"}, function() {
- this.all(function(history){
- if(history.length==0 || window.history.length > 1) {
- app.setRootPage(currentLocale.url);
- } else {
- app.setRootPage(history[history.length-1].value);
- }
- });
- });
+ // if there is an url from the system like android indent, open this url, else restore browsing to last visited page
+ var url = getUrlParam();
+ if(url) {
+ app.setRootPage(url);
+ } else {
+ var historyDB = new Lawnchair({name:"historyDB"}, function() {
+ this.all(function(history){
+ if(history.length==0 || window.history.length > 1) {
+ app.setRootPage(currentLocale.url);
+ } else {
+ app.setRootPage(history[history.length-1].value);
+ }
+ });
+ });
+ }
}
function hideOverlays() {
View
12 src/org/wikipedia/WikipediaActivity.java
@@ -1,5 +1,6 @@
package org.wikipedia;
+import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
//import android.util.Log;
@@ -31,8 +32,15 @@ public void onCreate(Bundle savedInstanceState) {
SharedPreferences.Editor editor = preferences.edit();
editor.remove("doSearchNearBy");
editor.commit();
-
- super.loadUrl("file:///android_asset/www/index.html");
+
+ //open directly wikipedia url in the app
+ Intent intent = this.getIntent();
+ String url = "";
+ if (Intent.ACTION_VIEW.equals(intent.getAction())) {
+ url = intent.getData().toString();
+ }
+
+ super.loadUrl("file:///android_asset/www/index.html?href=" + url);
// this.webViewClient = new WikipediaWebViewClient(this);
this.appView.setWebViewClient(this.webViewClient);
}

1 comment on commit 4c67032

Please sign in to comment.