Skip to content
This repository has been archived by the owner on Sep 21, 2018. It is now read-only.

Commit

Permalink
Add intent in order to open web links to Wikipedia in the app. it wil…
Browse files Browse the repository at this point in the history
…l be very useful for links in email and social networks.
  • Loading branch information
Tpt committed Nov 26, 2011
1 parent 0aa6826 commit 4c67032
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
7 changes: 7 additions & 0 deletions AndroidManifest.xml
Expand Up @@ -18,6 +18,13 @@
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </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>
<activity android:name="com.phonegap.DroidGap" android:label="@string/app_name" <activity android:name="com.phonegap.DroidGap" android:label="@string/app_name"
android:configChanges="orientation|keyboardHidden"> android:configChanges="orientation|keyboardHidden">
Expand Down
33 changes: 22 additions & 11 deletions assets/www/js/main.js
Expand Up @@ -39,6 +39,13 @@ function removeCountryCode(localeCode) {
return 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() { function hideMobileLinks() {
var frameDoc = $("#main")[0].contentDocument; var frameDoc = $("#main")[0].contentDocument;
$('#header', frameDoc).css('display', 'none'); $('#header', frameDoc).css('display', 'none');
Expand Down Expand Up @@ -97,18 +104,22 @@ function loadContent() {
function loadWikiContent() { function loadWikiContent() {
showSpinner(); showSpinner();
$('#search').addClass('inProgress'); $('#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() { function hideOverlays() {
Expand Down
12 changes: 10 additions & 2 deletions src/org/wikipedia/WikipediaActivity.java
@@ -1,5 +1,6 @@
package org.wikipedia; package org.wikipedia;


import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
//import android.util.Log; //import android.util.Log;
Expand Down Expand Up @@ -31,8 +32,15 @@ public void onCreate(Bundle savedInstanceState) {
SharedPreferences.Editor editor = preferences.edit(); SharedPreferences.Editor editor = preferences.edit();
editor.remove("doSearchNearBy"); editor.remove("doSearchNearBy");
editor.commit(); 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.webViewClient = new WikipediaWebViewClient(this);
this.appView.setWebViewClient(this.webViewClient); this.appView.setWebViewClient(this.webViewClient);
} }
Expand Down

1 comment on commit 4c67032

@bvibber
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.