snow10-android/java/net/chaoswebs/snow10/MainActivity.java
2017-04-01 15:27:55 -05:00

59 lines
1.7 KiB
Java

package net.chaoswebs.snow10;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
// Copyright (c) 2017 Kevin Froman MIT (expat) license
private WebView view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = new WebView(this);
view.setWebViewClient(new WebViewClient(){
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url != null && url.startsWith("http://") || url.startsWith("https://")) {
view.getContext().startActivity(
new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
return true;
} else {
return false;
}
}
});
view.getSettings().setJavaScriptEnabled(true);
view.loadUrl("file:///android_asset/index.html");
setContentView(view);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && view.canGoBack()) {
//if Back key pressed and webview can navigate to previous page
view.goBack();
// go back to previous page
return true;
}
else
{
finish();
// finish the activity
}
return super.onKeyDown(keyCode, event);
}
}