Skip to content

Instantly share code, notes, and snippets.

@hron84
Created December 31, 2010 23:53
Show Gist options
  • Save hron84/761436 to your computer and use it in GitHub Desktop.
Save hron84/761436 to your computer and use it in GitHub Desktop.
package me.hron.koponyeg;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class Koponyeg extends Activity {
WebView wvMain;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Log.d(this.getClass().getSimpleName(), "Find view");
try {
wvMain = (WebView) findViewById(R.id.wvMain);
wvMain.getSettings().setJavaScriptEnabled(true);
wvMain.setWebViewClient(new MyWebViewClient());
Log.d(this.getClass().getSimpleName(), "Loading URL");
wvMain.loadUrl("http://m.koponyeg.hu/iphone.php");
Log.d(this.getClass().getSimpleName(), "URL loaded: " + wvMain.getOriginalUrl());
} catch(Exception ex) {
StackTraceElement[] trace = ex.getStackTrace();
String msg = ex.getMessage() + "\n";
for(StackTraceElement t : trace) {
msg += trace.toString() + "\n";
}
Log.e(this.getClass().getSimpleName(), msg);
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_HOME) {
this.finish();
return true;
} else if(keyCode == KeyEvent.KEYCODE_BACK) {
wvMain.goBack();
return true;
} else {
return super.onKeyDown(keyCode, event);
}
}
private class MyWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(Uri.parse(url).getHost().equals("m.koponyeg.hu")) {
return false;
}
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<WebView
android:id="@+id/wvMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
/>
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment