@Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { // if we are in developer mode or beta if (MetaioCloudPlugin.Settings.developerMode) Toast.makeText(getApplicationContext(), consoleMessage.message(), Toast.LENGTH_LONG).show(); MetaioCloudPlugin.log(consoleMessage.message()); return super.onConsoleMessage(consoleMessage); }
@Override public void onPageStarted(WebView view, String url, Bitmap favicon) { MetaioCloudPlugin.log("Started loading " + url); mProgressView.setVisibility(View.VISIBLE); if (mButtonStop != null) { mButtonStop.setEnabled(true); } changeButtonState(view); super.onPageStarted(view, url, favicon); }
@Override public void onPageFinished(WebView view, String url) { MetaioCloudPlugin.log("Finished loading " + url); mProgressView.setVisibility(View.GONE); if (mButtonStop != null) { mButtonStop.setEnabled(false); } changeButtonState(view); view.resumeTimers(); super.onPageFinished(view, url); }
@Override public boolean onJsAlert(WebView view, String url, String message, final JsResult result) { MetaioCloudPlugin.log("onJsAlert " + message); // display javascript alerts as AlertDialogs new AlertDialog.Builder(view.getContext()) .setTitle("javaScript dialog") .setMessage(message) .setPositiveButton( android.R.string.ok, new AlertDialog.OnClickListener() { public void onClick(DialogInterface dialog, int which) { result.confirm(); } }) .setCancelable(false) .create() .show(); return true; }
@SuppressLint("SetJavaScriptEnabled") @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { // get url and navigatio preference (default true) final String url = getIntent().getStringExtra(getPackageName() + ".URL"); final boolean navigation = getIntent().getBooleanExtra(getPackageName() + ".NAVIGATION", true); setContentView(R.layout.webviewnav); // if we want navigation bar and not hide it, make it visible. Make it invisible if not. if (navigation && !hideNavigationBar) { findViewById(R.id.webBottomBar).setVisibility(View.VISIBLE); } else { findViewById(R.id.webBottomBar).setVisibility(View.GONE); } mButtonBack = (ImageButton) findViewById(R.id.buttonWebBack); mButtonForward = (ImageButton) findViewById(R.id.buttonWebForward); mButtonStop = (ImageButton) findViewById(R.id.buttonWebStop); mProgressView = (ProgressBar) findViewById(R.id.progressBar); mProgressView.setIndeterminate(true); // init webview mWebView = (WebView) findViewById(R.id.webView); // disable hw accel as it creates flickering pages, html5 video won't work with this if (Build.VERSION.SDK_INT >= 11 && Build.VERSION.SDK_INT < 16) mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); // This hides white bar on the right mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY); WebSettings settings = mWebView.getSettings(); // enable plugins before java script settings.setPluginState(PluginState.ON); // TODO test these two settings with a big webpage (cafe lotty?) settings.setLoadWithOverviewMode(true); settings.setUseWideViewPort(true); // enable javascript and zoom controls settings.setJavaScriptEnabled(true); settings.setBuiltInZoomControls(true); settings.setGeolocationEnabled(true); settings.setDatabaseEnabled(true); String databasePath = getDir("database_ext", Context.MODE_PRIVATE).getPath(); settings.setDatabasePath(databasePath); settings.setGeolocationDatabasePath(databasePath); settings.setDomStorageEnabled(true); settings.setAppCacheEnabled(true); // allow XMLHttpRequests if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) settings.setAllowUniversalAccessFromFileURLs(true); MetaioWebViewClient client = new MetaioWebViewClient(); mWebView.setWebViewClient(client); mWebView.setWebChromeClient(new MetaioWebChromeClient()); registerForContextMenu(mWebView); if (savedInstanceState != null) { mWebView.restoreState(savedInstanceState); } else { // if we don't have to override the url, load it in the webview if (!client.shouldOverrideUrlLoading(mWebView, url)) mWebView.loadUrl(url); } } catch (Exception e) { MetaioCloudPlugin.log(Log.ERROR, "WebViewActivity.onCreate", e); } }
@Override public void onLoadResource(WebView view, String url) { super.onLoadResource(view, url); view.resumeTimers(); MetaioCloudPlugin.log("onLoadResource " + url); }
@Override public boolean shouldOverrideUrlLoading(WebView view, String url) { JunaioChannel channel = null; try { // Try to launch default intent first if valid Intent intent = MetaioCloudPlugin.getDefaultIntent(url); if (intent != null) { try { startActivity(intent); return true; } catch (Exception e) { MetaioCloudPlugin.log( Log.ERROR, "WebViewActivity: Failed to launched the default intent"); return false; } } } catch (Exception e) { } try { if (url.compareToIgnoreCase("junaio://?action=closewebview") == 0) { MetaioCloudPlugin.log("Closing webview: " + url); finish(); return true; } else if ((channel = MetaioCloudUtils.parseUrl(Uri.parse(url))) != null && channel.getChannelID() > -1) { MetaioCloudPlugin.log("Channel ID: " + channel.getChannelID()); MetaioCloudPlugin.getDataSource() .loadPOIsAndChannelInformationForID(channel.getChannelID()); finish(); return true; } // Open in Google Docs viewer if supported file type (based on file extention) else if (MetaioCloudPlugin.isSupportedOnGoogleDocs(url) && !url.contains("docs.google.com/gview?embedded")) { url = "http://docs.google.com/gview?embedded=true&url=" + url; view.loadUrl(url); return true; } else if (url.contains("youtube.com")) { Uri parsedUrl = Uri.parse(url); Intent youtubeIntent = new Intent(Intent.ACTION_VIEW, parsedUrl); startActivity(youtubeIntent); finish(); return true; } else if (url.startsWith("http")) { view.loadUrl(url); return false; // load it in webview } else { Intent externalIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); externalIntent.addCategory(Intent.CATEGORY_BROWSABLE); startActivity(externalIntent); return true; } } catch (Exception e) { return false; } // return false; }
@Override public boolean onJsTimeout() { MetaioCloudPlugin.log("onJsTimeout"); return false; }