Paul,
Leaving your generic idea with a possibility of reuse, create a class called WebInterface and you can trigger an Intent whenever you need to load a WebView, with javascript enabled, error correction if SSL is not loaded and mainly by treating the back button to apply to the web context and not to the application.
Follows:
public class WebInterface extends Activity {
private WebView webView;
private static final String TAG = "WebInterface";
private ProgressDialog progressBar;
private static String URL;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_web_interface);
if(this.getIntent().hasExtra("url")){
//Obtendo o URL.
URL = this.getIntent().getStringExtra("url");
this.webView = (WebView)findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
progressBar = ProgressDialog.show(this, "Aguarde", "Carregando ...");
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i(TAG, "Processando acesso...");
view.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
Log.i(TAG, "Terminou de carregar a URL: " + url);
if (progressBar.isShowing()) {
progressBar.dismiss();
}
}
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
handler.proceed();
}
});
webView.loadUrl(URL);
}else{
this.finish();
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && webView.canGoBack()) {
webView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
<activity
android:name=".modules.web.WebInterface"
android:windowSoftInputMode="stateAlwaysHidden" />