From 21a34a8980d0b65d03828cf720d1f640c99db7e1 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 8 Mar 2011 22:00:33 -0600 Subject: [PATCH 1/3] Ticket 106 - Simplify splash screen logic based upon idea from vadim. --- framework/src/com/phonegap/DroidGap.java | 25 ++++++++---------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index fded363f..7953d8ad 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -16,12 +16,12 @@ import android.content.Intent; import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Color; -import android.graphics.Picture; import android.media.AudioManager; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.KeyEvent; +import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; @@ -31,7 +31,6 @@ import android.webkit.JsPromptResult; import android.webkit.WebSettings; import android.webkit.WebStorage; import android.webkit.WebView; -import android.webkit.WebView.PictureListener; import android.webkit.WebViewClient; import android.webkit.GeolocationPermissions.Callback; import android.webkit.WebSettings.LayoutAlgorithm; @@ -111,8 +110,8 @@ public class DroidGap extends PhonegapActivity { protected WebView appView; protected WebViewClient webViewClient; - private LinearLayout root; - boolean bound = false; + protected LinearLayout root; + public boolean bound = false; public CallbackServer callbackServer; protected PluginManager pluginManager; protected boolean cancelLoadUrl = false; @@ -235,7 +234,8 @@ public class DroidGap extends PhonegapActivity { // Bind PhoneGap objects to JavaScript this.bindBrowser(this.appView); - // Add web view + // Add web view but make it invisible while loading URL + this.appView.setVisibility(View.INVISIBLE); root.addView(this.appView); setContentView(root); @@ -302,8 +302,7 @@ public class DroidGap extends PhonegapActivity { // If spashscreen this.splashscreen = this.getIntegerProperty("splashscreen", 0); if (this.splashscreen != 0) { - this.appView.setBackgroundColor(0); - this.appView.setBackgroundResource(splashscreen); + root.setBackgroundResource(this.splashscreen); } // If hideLoadingDialogOnPageLoad @@ -1009,16 +1008,8 @@ public class DroidGap extends PhonegapActivity { // from the JS side when the JS gets to that code. appView.loadUrl("javascript:try{ PhoneGap.onNativeReady.fire();}catch(e){_nativeReady = true;}"); - // If splash screen is showing, clear it - if (this.ctx.splashscreen != 0) { - this.ctx.splashscreen = 0; - appView.setPictureListener(new PictureListener(){ - public void onNewPicture(WebView viewtwo, Picture picture) { - appView.setBackgroundResource(0); - appView.setPictureListener(null); - } - }); - } + // Make app view visible + appView.setVisibility(View.VISIBLE); // Stop "app loading" spinner if showing if (this.ctx.hideLoadingDialogOnPageLoad) { From 1fc56921aaa6ac1feaea03696922c8434a41f7cd Mon Sep 17 00:00:00 2001 From: macdonst Date: Thu, 10 Mar 2011 04:23:56 +0800 Subject: [PATCH 2/3] Ticket #90: Move _createEvent from File to PhoneGap Got rid of _createEvent from file.js as it is redundant code. --- framework/assets/js/file.js | 184 +++++------------------------------- 1 file changed, 25 insertions(+), 159 deletions(-) diff --git a/framework/assets/js/file.js b/framework/assets/js/file.js index aa1c43e9..75c8e64f 100755 --- a/framework/assets/js/file.js +++ b/framework/assets/js/file.js @@ -39,22 +39,6 @@ function File(name, fullPath, type, lastModifiedDate, size) { this.size = size || 0; } -/** - * Create an event object since we can't set target on DOM event. - * - * @param type - * @param target - * - */ -File._createEvent = function(type, target) { - // Can't create event object, since we can't set target (its readonly) - //var evt = document.createEvent('Events'); - //evt.initEvent("onload", false, false); - var evt = {"type": type}; - evt.target = target; - return evt; -}; - function FileError() { this.code = null; } @@ -185,18 +169,15 @@ FileReader.prototype.abort = function() { // If error callback if (typeof this.onerror === "function") { - evt = File._createEvent("error", this); - this.onerror(evt); + this.onerror({"type":"error", "target":this}); } // If abort callback if (typeof this.onabort === "function") { - evt = File._createEvent("abort", this); - this.onabort(evt); + this.oneabort({"type":"abort", "target":this}); } // If load end callback if (typeof this.onloadend === "function") { - evt = File._createEvent("loadend", this); - this.onloadend(evt); + this.onloadend({"type":"loadend", "target":this}); } }; @@ -219,8 +200,7 @@ FileReader.prototype.readAsText = function(file, encoding) { // If loadstart callback if (typeof this.onloadstart === "function") { - var evt = File._createEvent("loadstart", this); - this.onloadstart(evt); + this.onloadstart({"type":"loadstart", "target":this}); } // Default encoding is UTF-8 @@ -245,8 +225,6 @@ FileReader.prototype.readAsText = function(file, encoding) { // If onload callback if (typeof me.onload === "function") { - evt = File._createEvent("load", me); - me.onload(evt); } // DONE state @@ -254,8 +232,7 @@ FileReader.prototype.readAsText = function(file, encoding) { // If onloadend callback if (typeof me.onloadend === "function") { - evt = File._createEvent("loadend", me); - me.onloadend(evt); + me.onloadend({"type":"loadend", "target":me}); } }, @@ -272,8 +249,7 @@ FileReader.prototype.readAsText = function(file, encoding) { // If onerror callback if (typeof me.onerror === "function") { - evt = File._createEvent("error", me); - me.onerror(evt); + me.onerror({"type":"error", "target":me}); } // DONE state @@ -281,8 +257,7 @@ FileReader.prototype.readAsText = function(file, encoding) { // If onloadend callback if (typeof me.onloadend === "function") { - evt = File._createEvent("loadend", me); - me.onloadend(evt); + me.onloadend({"type":"loadend", "target":me}); } } ); @@ -309,8 +284,7 @@ FileReader.prototype.readAsDataURL = function(file) { // If loadstart callback if (typeof this.onloadstart === "function") { - var evt = File._createEvent("loadstart", this); - this.onloadstart(evt); + this.onloadstart({"type":"loadstart", "target":this}); } var me = this; @@ -332,8 +306,7 @@ FileReader.prototype.readAsDataURL = function(file) { // If onload callback if (typeof me.onload === "function") { - evt = File._createEvent("load", me); - me.onload(evt); + me.onload({"type":"load", "target":me}); } // DONE state @@ -341,8 +314,7 @@ FileReader.prototype.readAsDataURL = function(file) { // If onloadend callback if (typeof me.onloadend === "function") { - evt = File._createEvent("loadend", me); - me.onloadend(evt); + me.onloadend({"type":"loadend", "target":me}); } }, @@ -359,8 +331,7 @@ FileReader.prototype.readAsDataURL = function(file) { // If onerror callback if (typeof me.onerror === "function") { - evt = File._createEvent("error", me); - me.onerror(evt); + me.onerror({"type":"error", "target":me}); } // DONE state @@ -368,8 +339,7 @@ FileReader.prototype.readAsDataURL = function(file) { // If onloadend callback if (typeof me.onloadend === "function") { - evt = File._createEvent("loadend", me); - me.onloadend(evt); + me.onloadend({"type":"loadend", "target":me}); } } ); @@ -456,115 +426,21 @@ FileWriter.prototype.abort = function() { // If error callback if (typeof this.onerror === "function") { - evt = File._createEvent("error", this); - this.onerror(evt); + this.onerror({"type":"error", "target":this}); } // If abort callback if (typeof this.onabort === "function") { - evt = File._createEvent("abort", this); - this.onabort(evt); + this.oneabort({"type":"abort", "target":this}); } this.readyState = FileWriter.DONE; // If write end callback if (typeof this.onwriteend == "function") { - evt = File._createEvent("writeend", this); - this.onwriteend(evt); + this.onwriteend({"type":"writeend", "target":this}); } }; -/** - * @Deprecated: use write instead - * - * @param file to write the data to - * @param text to be written - * @param bAppend if true write to end of file, otherwise overwrite the file - */ -FileWriter.prototype.writeAsText = function(file, text, bAppend) { - // Throw an exception if we are already writing a file - if (this.readyState === FileWriter.WRITING) { - throw FileError.INVALID_STATE_ERR; - } - - if (bAppend !== true) { - bAppend = false; // for null values - } - - this.fileName = file; - - // WRITING state - this.readyState = FileWriter.WRITING; - - var me = this; - - // If onwritestart callback - if (typeof me.onwritestart === "function") { - var evt = File._createEvent("writestart", me); - me.onwritestart(evt); - } - - // Write file - navigator.fileMgr.writeAsText(file, text, bAppend, - - // Success callback - function(r) { - var evt; - - // If DONE (cancelled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // Save result - me.result = r; - - // If onwrite callback - if (typeof me.onwrite === "function") { - evt = File._createEvent("write", me); - me.onwrite(evt); - } - - // DONE state - me.readyState = FileWriter.DONE; - - // If onwriteend callback - if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); - } - }, - - // Error callback - function(e) { - var evt; - - // If DONE (cancelled), then don't do anything - if (me.readyState === FileWriter.DONE) { - return; - } - - // Save error - me.error = e; - - // If onerror callback - if (typeof me.onerror === "function") { - evt = File._createEvent("error", me); - me.onerror(evt); - } - - // DONE state - me.readyState = FileWriter.DONE; - - // If onwriteend callback - if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); - } - } - ); -}; - /** * Writes data to the file * @@ -583,8 +459,7 @@ FileWriter.prototype.write = function(text) { // If onwritestart callback if (typeof me.onwritestart === "function") { - var evt = File._createEvent("writestart", me); - me.onwritestart(evt); + me.onwritestart({"type":"writestart", "target":me}); } // Write file @@ -605,8 +480,7 @@ FileWriter.prototype.write = function(text) { // If onwrite callback if (typeof me.onwrite === "function") { - evt = File._createEvent("write", me); - me.onwrite(evt); + me.onwrite({"type":"write", "target":me}); } // DONE state @@ -614,8 +488,7 @@ FileWriter.prototype.write = function(text) { // If onwriteend callback if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); + me.onwriteend({"type":"writeend", "target":me}); } }, @@ -633,8 +506,7 @@ FileWriter.prototype.write = function(text) { // If onerror callback if (typeof me.onerror === "function") { - evt = File._createEvent("error", me); - me.onerror(evt); + me.onerror({"type":"error", "target":me}); } // DONE state @@ -642,8 +514,7 @@ FileWriter.prototype.write = function(text) { // If onwriteend callback if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); + me.onwriteend({"type":"writeend", "target":me}); } } ); @@ -703,8 +574,7 @@ FileWriter.prototype.truncate = function(size) { // If onwritestart callback if (typeof me.onwritestart === "function") { - var evt = File._createEvent("writestart", me); - me.onwritestart(evt); + me.onwritestart({"type":"writestart", "target":this}); } // Write file @@ -724,8 +594,7 @@ FileWriter.prototype.truncate = function(size) { // If onwrite callback if (typeof me.onwrite === "function") { - evt = File._createEvent("write", me); - me.onwrite(evt); + me.onwrite({"type":"write", "target":me}); } // DONE state @@ -733,8 +602,7 @@ FileWriter.prototype.truncate = function(size) { // If onwriteend callback if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); + me.onwriteend({"type":"writeend", "target":me}); } }, @@ -751,8 +619,7 @@ FileWriter.prototype.truncate = function(size) { // If onerror callback if (typeof me.onerror === "function") { - evt = File._createEvent("error", me); - me.onerror(evt); + me.onerror({"type":"error", "target":me}); } // DONE state @@ -760,8 +627,7 @@ FileWriter.prototype.truncate = function(size) { // If onwriteend callback if (typeof me.onwriteend === "function") { - evt = File._createEvent("writeend", me); - me.onwriteend(evt); + me.onwriteend({"type":"writeend", "target":me}); } } ); From 7344964c05cdaa3598eaf72de68ceb8157241d7f Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Sun, 13 Mar 2011 22:36:09 -0500 Subject: [PATCH 3/3] Add support for setting sms body using uri "sms:#?body=text". --- framework/src/com/phonegap/DroidGap.java | 45 +++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 7953d8ad..470ed9f8 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -946,19 +946,38 @@ public class DroidGap extends PhonegapActivity { return true; } - // If sms:5551212 - else if (url.startsWith("sms:")) { - try { - Intent intent = new Intent(Intent.ACTION_VIEW); - intent.setData(Uri.parse(url)); - intent.putExtra("address", url.substring(4)); - intent.setType("vnd.android-dir/mms-sms"); - startActivity(intent); - } catch (android.content.ActivityNotFoundException e) { - System.out.println("Error sending sms "+url+":"+ e.toString()); - } - return true; - } + // If sms:5551212?body=This is the message + else if (url.startsWith("sms:")) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW); + + // Get address + String address = null; + int parmIndex = url.indexOf('?'); + if (parmIndex == -1) { + address = url.substring(4); + } + else { + address = url.substring(4, parmIndex); + + // If body, then set sms body + Uri uri = Uri.parse(url); + String query = uri.getQuery(); + if (query != null) { + if (query.startsWith("body=")) { + intent.putExtra("sms_body", query.substring(5)); + } + } + } + intent.setData(Uri.parse("sms:"+address)); + intent.putExtra("address", address); + intent.setType("vnd.android-dir/mms-sms"); + startActivity(intent); + } catch (android.content.ActivityNotFoundException e) { + System.out.println("Error sending sms "+url+":"+ e.toString()); + } + return true; + } // All else else {