Skip to content

Commit

Permalink
updated to work with Google+ and other apps. Bugs fixed, back-button
Browse files Browse the repository at this point in the history
handling fixed.
  • Loading branch information
toby committed May 29, 2012
1 parent df2bfd2 commit 3061a80
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 20 deletions.
2 changes: 2 additions & 0 deletions .classpath 100644 → 100755
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
<classpathentry kind="output" path="bin/classes"/>
Expand Down
Empty file modified .gitignore 100644 → 100755
Empty file.
12 changes: 12 additions & 0 deletions .project 100644 → 100755
Expand Up @@ -20,14 +20,26 @@
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtend.shared.ui.xtendBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.xtend.shared.ui.xtendXPandNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
Empty file modified AndroidManifest.xml 100644 → 100755
Empty file.
10 changes: 10 additions & 0 deletions META-INF/MANIFEST.MF
@@ -0,0 +1,10 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Xtend Tutorial
Bundle-SymbolicName: xtend.tutorial
Bundle-Version: 2.1.0.qualifier
Bundle-Vendor: Eclipse Modeling
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Require-Bundle: org.eclipse.xtext.xtend2.lib;bundle-version="2.0.0",
org.junit4,
org.aopalliance;bundle-version="1.0.0"
Empty file modified README 100644 → 100755
Empty file.
Empty file modified proguard.cfg 100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion project.properties 100644 → 100755
Expand Up @@ -8,4 +8,4 @@
# project structure.

# Project target.
target=android-7
target=android-10
Empty file modified res/drawable-hdpi/ic_launcher.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified res/drawable-ldpi/ic_launcher.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified res/drawable-mdpi/ic_launcher.png 100644 → 100755
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions res/drawable/loader_bg.xml
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="15dp"/>
<solid android:color="#A0000000"/>
</shape>
23 changes: 13 additions & 10 deletions res/layout/main.xml 100644 → 100755
@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<ProgressBar
android:id="@+id/site_progress"
android:indeterminate="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>

<WebView
android:id="@+id/site_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

<ProgressBar
android:id="@+id/site_progress"
android:indeterminate="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_gravity="center"
android:background="@drawable/loader_bg"
android:padding="20dp"/>

</FrameLayout>
3 changes: 1 addition & 2 deletions res/values/strings.xml 100644 → 100755
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<string name="hello">Hello World, GoogleNewsActivity!</string>
<string name="app_name">GoogleNews</string>
<string name="app_name">Google Apps</string>

</resources>
48 changes: 41 additions & 7 deletions src/com/tobykurien/google_news/GoogleNewsActivity.java 100644 → 100755
Expand Up @@ -5,13 +5,21 @@
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;

public class GoogleNewsActivity extends Activity {
boolean siteLoaded = false;
WebView wv;

String[] googleSites = new String[]{
"google.com", "youtube.com",
"google.co.za"
};

/** Called when the activity is first created. */
@Override
Expand Down Expand Up @@ -44,14 +52,14 @@ public WebView getWebView() {
* @return
*/
public String getSiteUrl() {
return "https://news.google.com/";
return "https://mobile.google.com/";
}

@Override
protected void onStart() {
super.onStart();

WebView wv = getWebView();
wv = getWebView();
if (wv == null) {
finish();
return;
Expand All @@ -64,8 +72,8 @@ protected void onStart() {
pb.setVisibility(View.VISIBLE);

//wv.loadData("<html><head></head><body>Loading Google News...</body></html>", "text/html", null);
wv.enablePlatformNotifications();
wv.getSettings().setJavaScriptEnabled(true);
WebView.enablePlatformNotifications();
wv.getSettings().setJavaScriptEnabled(true);
wv.loadUrl(getSiteUrl());

// wv.getSettings().setUserAgentString("android");
Expand All @@ -89,21 +97,47 @@ public void onPageStarted(WebView view, String url, Bitmap favicon) {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if ((uri.getScheme().equals("http") || uri.getScheme().equals("https"))
&& !uri.getHost().endsWith("google.com")) {
&& !isGoogleSite(uri.getHost())) {
Intent i = new Intent(android.content.Intent.ACTION_VIEW);
i.setData(uri);
startActivity(Intent.createChooser(i, "Open Url"));
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
return true;
} else if (uri.getScheme().equals("mailto")) {
Intent i = new Intent(android.content.Intent.ACTION_SEND);
i.putExtra(android.content.Intent.EXTRA_EMAIL, url);
i.setType("text/html");
startActivity(Intent.createChooser(i, "Send Email"));
startActivity(i);
return true;
}

return super.shouldOverrideUrlLoading(view, url);
}

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
// TODO Auto-generated method stub
super.onReceivedError(view, errorCode, description, failingUrl);
Toast.makeText(GoogleNewsActivity.this, description, Toast.LENGTH_LONG).show();
}
});
}

private boolean isGoogleSite(String host) {
for (String site : googleSites) {
if (host.toLowerCase().endsWith(site.toLowerCase())) {
return true;
}
}
return false;
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && wv.canGoBack()) {
wv.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}

0 comments on commit 3061a80

Please sign in to comment.