/* * Load the spinner */ void loadSpinner() { // If loadingDialog property, then show the App loading dialog for first page of app String loading = null; if ((this.appView == null) || !this.appView.canGoBack()) { loading = preferences.getString("LoadingDialog", null); } else { loading = preferences.getString("LoadingPageDialog", null); } if (loading != null) { String title = ""; String message = "Loading Application..."; if (loading.length() > 0) { int comma = loading.indexOf(','); if (comma > 0) { title = loading.substring(0, comma); message = loading.substring(comma + 1); } else { title = ""; message = loading; } } this.spinnerStart(title, message); } }
/** 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); } }
@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); }
@SuppressWarnings("deprecation") protected void loadConfig() { ConfigXmlParser parser = new ConfigXmlParser(); parser.parse(this); preferences = parser.getPreferences(); preferences.setPreferencesBundle(getIntent().getExtras()); preferences.copyIntoIntentExtras(this); whitelist = parser.getWhitelist(); launchUrl = parser.getLaunchUrl(); pluginEntries = parser.getPluginEntries(); Config.parser = parser; }
/** * Report an error to the host application. These errors are unrecoverable (i.e. the main resource * is unavailable). The errorCode parameter corresponds to one of the ERROR_* constants. * * @param errorCode The error code corresponding to an ERROR_* value. * @param description A String describing the error. * @param failingUrl The url that failed to load. */ public void onReceivedError( final int errorCode, final String description, final String failingUrl) { final CordovaActivity me = this; // If errorUrl specified, then load it final String errorUrl = preferences.getString("errorUrl", null); if ((errorUrl != null) && (errorUrl.startsWith("file://") || whitelist.isUrlWhiteListed(errorUrl)) && (!failingUrl.equals(errorUrl))) { // Load URL on UI thread me.runOnUiThread( new Runnable() { public void run() { // Stop "app loading" spinner if showing me.spinnerStop(); me.appView.showWebPage(errorUrl, false, true, null); } }); } // If not, then display error dialog else { final boolean exit = !(errorCode == WebViewClient.ERROR_HOST_LOOKUP); me.runOnUiThread( new Runnable() { public void run() { if (exit) { me.appView.setVisibility(View.GONE); me.displayError( "Application Error", description + " (" + failingUrl + ")", "OK", exit); } } }); } }
@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); }
/** * Called when a message is sent to plugin. * * @param id The message id * @param data The message data * @return Object or null */ public Object onMessage(String id, Object data) { if (!"onScrollChanged".equals(id)) { LOG.d(TAG, "onMessage(" + id + "," + data + ")"); } if ("splashscreen".equals(id)) { if ("hide".equals(data.toString())) { this.removeSplashScreen(); } else { // If the splash dialog is showing don't try to show it again if (this.splashDialog == null || !this.splashDialog.isShowing()) { String splashResource = preferences.getString("SplashScreen", null); if (splashResource != null) { splashscreen = getResources() .getIdentifier(splashResource, "drawable", getClass().getPackage().getName()); } this.showSplashScreen(this.splashscreenTime); } } } else if ("spinner".equals(id)) { if ("stop".equals(data.toString())) { this.spinnerStop(); this.appView.setVisibility(View.VISIBLE); } } else if ("onReceivedError".equals(id)) { JSONObject d = (JSONObject) data; try { this.onReceivedError(d.getInt("errorCode"), d.getString("description"), d.getString("url")); } catch (JSONException e) { e.printStackTrace(); } } else if ("exit".equals(id)) { this.endActivity(); } return null; }
/** Get double property for activity. */ @Deprecated // Call method on preferences directly. public double getDoubleProperty(String name, double defaultValue) { return preferences.getDouble(name, defaultValue); }
/** Get string property for activity. */ @Deprecated // Call method on preferences directly. public String getStringProperty(String name, String defaultValue) { return preferences.getString(name, defaultValue); }
/** Get int property for activity. */ @Deprecated // Call method on preferences directly. public int getIntegerProperty(String name, int defaultValue) { return preferences.getInteger(name, defaultValue); }
/** Get boolean property for activity. */ @Deprecated // Call method on preferences directly. public boolean getBooleanProperty(String name, boolean defaultValue) { return preferences.getBoolean(name, defaultValue); }
/** Load the url into the webview. */ @Override public void loadUrlIntoView(final String url, boolean recreatePlugins) { if (url.equals("about:blank") || url.startsWith("javascript:")) { this.loadUrlNow(url); return; } LOG.d(TAG, ">>> loadUrl(" + url + ")"); recreatePlugins = recreatePlugins || (loadedUrl == null); if (recreatePlugins) { // Don't re-initialize on first load. if (loadedUrl != null) { this.pluginManager.init(); } this.loadedUrl = url; } // Create a timeout timer for loadUrl final AndroidWebView me = this; final int currentLoadUrlTimeout = me.loadUrlTimeout; final int loadUrlTimeoutValue = preferences.getInteger("LoadUrlTimeoutValue", 20000); // Timeout error method final Runnable loadError = new Runnable() { public void run() { me.stopLoading(); LOG.e(TAG, "CordovaWebView: TIMEOUT ERROR!"); if (viewClient != null) { viewClient.onReceivedError( AndroidWebView.this, -6, "The connection to the server was unsuccessful.", url); } } }; // Timeout timer method final Runnable timeoutCheck = new Runnable() { public void run() { try { synchronized (this) { wait(loadUrlTimeoutValue); } } catch (InterruptedException e) { e.printStackTrace(); } // If timeout, then stop loading and handle error if (me.loadUrlTimeout == currentLoadUrlTimeout) { me.cordova.getActivity().runOnUiThread(loadError); } } }; // Load url this.cordova .getActivity() .runOnUiThread( new Runnable() { public void run() { cordova.getThreadPool().execute(timeoutCheck); me.loadUrlNow(url); } }); }