@SuppressWarnings("deprecation") protected void createViews() { // This builds the view. We could probably get away with NOT having a LinearLayout, but I like // having a bucket! // This builds the view. We could probably get away with NOT having a LinearLayout, but I like // having a bucket! Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth(); int height = display.getHeight(); root = new LinearLayoutSoftKeyboardDetect(this, width, height); root.setOrientation(LinearLayout.VERTICAL); root.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 0.0F)); appView.setId(100); appView.setLayoutParams( new LinearLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0F)); // Add web view but make it invisible while loading URL appView.setVisibility(View.INVISIBLE); root.addView((View) appView); setContentView(root); // TODO: Setting this on the appView causes it to show when <html style="opacity:0">. int backgroundColor = preferences.getInteger("BackgroundColor", Color.BLACK); root.setBackgroundColor(backgroundColor); }
public void onReceivedError(WebView paramWebView, int paramInt, String paramString1, String paramString2) { Object[] arrayOfObject = new Object[3]; arrayOfObject[0] = Integer.valueOf(paramInt); arrayOfObject[1] = paramString1; arrayOfObject[2] = paramString2; LOG.d("Cordova", "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", arrayOfObject); CordovaWebView localCordovaWebView = this.appView; localCordovaWebView.loadUrlTimeout = (1 + localCordovaWebView.loadUrlTimeout); JSONObject localJSONObject = new JSONObject(); try { localJSONObject.put("errorCode", paramInt); localJSONObject.put("description", paramString1); localJSONObject.put("url", paramString2); this.appView.postMessage("onReceivedError", localJSONObject); return; } catch (JSONException localJSONException) { for (;;) { localJSONException.printStackTrace(); } } }
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // Determine if the focus is on the current view or not if (appView != null && appView.getFocusedChild() != null && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) { return appView.onKeyDown(keyCode, event); } else return super.onKeyDown(keyCode, event); }
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (appView != null && (appView.isCustomViewShowing() || appView.getFocusedChild() != null) && (keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_MENU)) { return appView.onKeyUp(keyCode, event); } else { return super.onKeyUp(keyCode, event); } }
@SuppressLint("NewApi") @Deprecated // Call init() instead and override makeWebView() to customize. public void init( CordovaWebView webView, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient) { LOG.d(TAG, "CordovaActivity.init()"); if (!preferences.getBoolean("ShowTitle", false)) { getWindow().requestFeature(Window.FEATURE_NO_TITLE); } if (preferences.getBoolean("SetFullscreen", false)) { Log.d( TAG, "The SetFullscreen configuration is deprecated in favor of Fullscreen, and will be removed in a future version."); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else if (preferences.getBoolean("Fullscreen", false)) { getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } else { getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN, WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN); } appView = webView != null ? webView : makeWebView(); if (appView.pluginManager == null) { appView.init( this, webViewClient != null ? webViewClient : makeWebViewClient(appView), webChromeClient != null ? webChromeClient : makeChromeClient(appView), pluginEntries, whitelist, preferences); } // TODO: Have the views set this themselves. if (preferences.getBoolean("DisallowOverscroll", false)) { appView.setOverScrollMode(View.OVER_SCROLL_NEVER); } createViews(); // TODO: Make this a preference (CB-6153) // Setup the hardware volume controls to handle volume control setVolumeControlStream(AudioManager.STREAM_MUSIC); }
/** * Load the specified URL in the Cordova webview or a new browser instance. * * <p>NOTE: If openExternal is false, only URLs listed in whitelist can be loaded. * * @param url The url to load. * @param openExternal Load url in browser instead of Cordova webview. * @param clearHistory Clear the history stack, so new page becomes top of history * @param params Parameters for new app */ @Deprecated // Call method on appView directly. public void showWebPage( String url, boolean openExternal, boolean clearHistory, HashMap<String, Object> params) { if (this.appView != null) { appView.showWebPage(url, openExternal, clearHistory, params); } }
/** * Go to previous page in history. (We manage our own history) * * @return true if we went back, false if we are already at top */ @Deprecated // Call method on appView directly. public boolean backHistory() { if (this.appView != null) { return appView.backHistory(); } return false; }
/** Load the url into the webview. */ public void loadUrl(String url) { if (appView == null) { init(); } this.splashscreenTime = preferences.getInteger("SplashScreenDelay", this.splashscreenTime); String splash = preferences.getString("SplashScreen", null); if (this.splashscreenTime > 0 && splash != null) { this.splashscreen = getResources().getIdentifier(splash, "drawable", getClass().getPackage().getName()); ; if (this.splashscreen != 0) { this.showSplashScreen(this.splashscreenTime); } } // If keepRunning this.keepRunning = preferences.getBoolean("KeepRunning", true); // Check if the view is attached to anything if (appView.getParent() != null) { // Then load the spinner this.loadSpinner(); } // Load the correct splashscreen if (this.splashscreen != 0) { this.appView.loadUrl(url, this.splashscreenTime); } else { this.appView.loadUrl(url); } }
public View getVideoLoadingProgressView() { if (mVideoProgressView == null) { LinearLayout localLinearLayout = new LinearLayout(appView.getContext()); localLinearLayout.setOrientation(1); Object localObject = new RelativeLayout.LayoutParams(-2, -2); ((RelativeLayout.LayoutParams) localObject).addRule(13); localLinearLayout.setLayoutParams((ViewGroup.LayoutParams) localObject); localObject = new ProgressBar(appView.getContext()); LinearLayout.LayoutParams localLayoutParams = new LinearLayout.LayoutParams(-2, -2); gravity = 17; ((ProgressBar) localObject).setLayoutParams(localLayoutParams); localLinearLayout.addView((View) localObject); mVideoProgressView = localLinearLayout; } return mVideoProgressView; }
/** * Give the host application a chance to take over the control when a new url is about to be * loaded in the current WebView. * * @param view The WebView that is initiating the callback. * @param url The url to be loaded. * @return true to override, false for default behavior */ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) boolean shouldOverrideUrlLoading(WebView view, String url) { // The WebView should support http and https when going on the Internet if (url.startsWith("http:") || url.startsWith("https:")) { // We only need to whitelist sites on the Internet! if (appView.getWhitelist().isUrlWhiteListed(url)) { return false; } } // Give plugins the chance to handle the url else if (this.appView.pluginManager.onOverrideUrlLoading(url)) { } else if (url.startsWith("file://") | url.startsWith("data:")) { // This directory on WebKit/Blink based webviews contains SQLite databases! // DON'T CHANGE THIS UNLESS YOU KNOW WHAT YOU'RE DOING! return url.contains("app_webview"); } else { try { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); intent.addCategory(Intent.CATEGORY_BROWSABLE); intent.setComponent(null); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { intent.setSelector(null); } this.cordova.getActivity().startActivity(intent); } catch (android.content.ActivityNotFoundException e) { LOG.e(TAG, "Error loading url " + url, e); } } // Default behaviour should be to load the default intent, let's see what happens! return true; }
/* * Sends a json object to the client as parameter to a method which is defined in gECB. */ public static void sendJavascript(JSONObject _json) { String _d = "javascript:" + gECB + "(" + _json.toString() + ")"; Log.v(TAG, "sendJavascript: " + _d); if (gECB != null && gWebView != null) { gWebView.sendJavascript(_d); } }
public void onPageFinished(WebView paramWebView, String paramString) { super.onPageFinished(paramWebView, paramString); LOG.d("Cordova", "onPageFinished(" + paramString + ")"); if (this.doClearHistory) { paramWebView.clearHistory(); this.doClearHistory = false; } CordovaWebView localCordovaWebView = this.appView; localCordovaWebView.loadUrlTimeout = (1 + localCordovaWebView.loadUrlTimeout); if (!paramString.equals("about:blank")) { LOG.d("Cordova", "Trying to fire onNativeReady"); this.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}"); this.appView.postMessage("onNativeReady", null); } this.appView.postMessage("onPageFinished", paramString); if (this.appView.getVisibility() == 4) { new Thread(new Runnable() { public void run() { try { Thread.sleep(2000L); CordovaWebViewClient.this.cordova.getActivity().runOnUiThread(new Runnable() { public void run() { CordovaWebViewClient.this.appView.postMessage("spinner", "stop"); } }); return; } catch (InterruptedException localInterruptedException) {} } }).start(); } if (paramString.equals("about:blank")) { this.appView.postMessage("exit", null); } }
/** The final call you receive before your activity is destroyed. */ @Override public void onDestroy() { LOG.d(TAG, "CordovaActivity.onDestroy()"); super.onDestroy(); // hide the splash screen to avoid leaking a window this.removeSplashScreen(); if (this.appView != null) { appView.handleDestroy(); } else { this.activityState = ACTIVITY_EXITING; } }
private void execHelper( final String service, final String action, final String callbackId, final String rawArgs) { CordovaPlugin plugin = getPlugin(service); if (plugin == null) { Log.d(TAG, "exec() call to unknown plugin: " + service); PluginResult cr = new PluginResult(PluginResult.Status.CLASS_NOT_FOUND_EXCEPTION); app.sendPluginResult(cr, callbackId); return; } CallbackContext callbackContext = new CallbackContext(callbackId, app); try { long pluginStartTime = System.currentTimeMillis(); boolean wasValidAction = plugin.execute(action, rawArgs, callbackContext); long duration = System.currentTimeMillis() - pluginStartTime; if (duration > SLOW_EXEC_WARNING_THRESHOLD) { Log.w( TAG, "THREAD WARNING: exec() call to " + service + "." + action + " blocked the main thread for " + duration + "ms. Plugin should use CordovaInterface.getThreadPool()."); } if (!wasValidAction) { PluginResult cr = new PluginResult(PluginResult.Status.INVALID_ACTION); callbackContext.sendPluginResult(cr); } } catch (JSONException e) { PluginResult cr = new PluginResult(PluginResult.Status.JSON_EXCEPTION); callbackContext.sendPluginResult(cr); } catch (Exception e) { Log.e(TAG, "Uncaught exception from plugin", e); callbackContext.error(e.getMessage()); } }
public void onShowCustomView( View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) { appView.showCustomView(paramView, paramCustomViewCallback); }
/** * Construct the chrome client for the default web view object. * * <p>This is intended to be overridable by subclasses of CordovaIntent which require a more * specialized web view. * * @param webView the default constructed web view object */ protected CordovaChromeClient makeChromeClient(CordovaWebView webView) { return webView.makeWebChromeClient(this); }
public void onHideCustomView() { appView.hideCustomView(); }