From 05e233bf1d6a1c5350a73a427485a49c1294a83a Mon Sep 17 00:00:00 2001 From: macdonst Date: Wed, 23 Nov 2011 03:39:27 +0800 Subject: [PATCH 1/7] Fix for issue #281 of phonegap/phonegap-android: Detect for localStorage if Java has disabled it --- framework/assets/js/storage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/assets/js/storage.js b/framework/assets/js/storage.js index cb741a92..47858c93 100755 --- a/framework/assets/js/storage.js +++ b/framework/assets/js/storage.js @@ -431,7 +431,7 @@ PhoneGap.addConstructor(function() { }; } - if (typeof window.localStorage === "undefined") { + if ((typeof window.localStorage == "undefined") || (window.localStorage == null)) { navigator.localStorage = window.localStorage = new CupcakeLocalStorage(); PhoneGap.waitForInitialization("cupcakeStorage"); } From 80d0a0cb4c801e4e5fb2f74534ba9351946b5969 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 22 Nov 2011 14:36:00 -0600 Subject: [PATCH 2/7] Change API to postMessage() to call a plugin's onMessage() method. --- framework/src/com/phonegap/Device.java | 6 +-- framework/src/com/phonegap/DroidGap.java | 10 ++-- .../src/com/phonegap/NetworkManager.java | 2 +- .../com/phonegap/api/PhonegapActivity.java | 2 +- .../src/com/phonegap/api/PluginManager.java | 48 ++++++------------- 5 files changed, 24 insertions(+), 44 deletions(-) diff --git a/framework/src/com/phonegap/Device.java b/framework/src/com/phonegap/Device.java index 4202ef62..f752a8db 100755 --- a/framework/src/com/phonegap/Device.java +++ b/framework/src/com/phonegap/Device.java @@ -136,15 +136,15 @@ public class Device extends Plugin { String extraData = intent.getStringExtra(TelephonyManager.EXTRA_STATE); if (extraData.equals(TelephonyManager.EXTRA_STATE_RINGING)) { LOG.i(TAG, "Telephone RINGING"); - myctx.onMessage("telephone", "ringing"); + myctx.postMessage("telephone", "ringing"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) { LOG.i(TAG, "Telephone OFFHOOK"); - myctx.onMessage("telephone", "offhook"); + myctx.postMessage("telephone", "offhook"); } else if (extraData.equals(TelephonyManager.EXTRA_STATE_IDLE)) { LOG.i(TAG, "Telephone IDLE"); - myctx.onMessage("telephone", "idle"); + myctx.postMessage("telephone", "idle"); } } } diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 812cb0e5..97c62b31 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -840,10 +840,10 @@ public class DroidGap extends PhonegapActivity { * @param id The message id * @param data The message data */ - public void onMessage(String id, Object data) { + public void postMessage(String id, Object data) { // Forward to plugins - this.pluginManager.onMessage(id, data); + this.pluginManager.postMessage(id, data); } /** @@ -1835,21 +1835,21 @@ public class DroidGap extends PhonegapActivity { @Override public boolean onCreateOptionsMenu(Menu menu) { - this.onMessage("onCreateOptionsMenu", menu); + this.postMessage("onCreateOptionsMenu", menu); return super.onCreateOptionsMenu(menu); } @Override public boolean onPrepareOptionsMenu(Menu menu) { - this.onMessage("onPrepareOptionsMenu", menu); + this.postMessage("onPrepareOptionsMenu", menu); return super.onPrepareOptionsMenu(menu); } @Override public boolean onOptionsItemSelected(MenuItem item) { - this.onMessage("onOptionsItemSelected", item); + this.postMessage("onOptionsItemSelected", item); return true; } } diff --git a/framework/src/com/phonegap/NetworkManager.java b/framework/src/com/phonegap/NetworkManager.java index aadac661..2be55d1a 100755 --- a/framework/src/com/phonegap/NetworkManager.java +++ b/framework/src/com/phonegap/NetworkManager.java @@ -201,7 +201,7 @@ public class NetworkManager extends Plugin { this.success(result, this.connectionCallbackId); // Send to all plugins - this.ctx.onMessage("networkconnection", type); + this.ctx.postMessage("networkconnection", type); } /** diff --git a/framework/src/com/phonegap/api/PhonegapActivity.java b/framework/src/com/phonegap/api/PhonegapActivity.java index fc5f5e27..cb3c8714 100755 --- a/framework/src/com/phonegap/api/PhonegapActivity.java +++ b/framework/src/com/phonegap/api/PhonegapActivity.java @@ -76,5 +76,5 @@ public abstract class PhonegapActivity extends Activity { * @param id The message id * @param data The message data */ - abstract public void onMessage(String id, Object data); + abstract public void postMessage(String id, Object data); } diff --git a/framework/src/com/phonegap/api/PluginManager.java b/framework/src/com/phonegap/api/PluginManager.java index db10d637..6bf9f66f 100755 --- a/framework/src/com/phonegap/api/PluginManager.java +++ b/framework/src/com/phonegap/api/PluginManager.java @@ -287,13 +287,9 @@ public final class PluginManager { * @param multitasking Flag indicating if multitasking is turned on for app */ public void onPause(boolean multitasking) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onPause(multitasking); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onPause(multitasking); + } } /** @@ -302,26 +298,18 @@ public final class PluginManager { * @param multitasking Flag indicating if multitasking is turned on for app */ public void onResume(boolean multitasking) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onResume(multitasking); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onResume(multitasking); + } } /** * The final call you receive before your activity is destroyed. */ public void onDestroy() { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onDestroy(); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onDestroy(); + } } /** @@ -330,12 +318,8 @@ public final class PluginManager { * @param id The message id * @param data The message data */ - public void onMessage(String id, Object data) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); + public void postMessage(String id, Object data) { + for (IPlugin plugin : this.plugins.values()) { plugin.onMessage(id, data); } } @@ -344,13 +328,9 @@ public final class PluginManager { * Called when the activity receives a new intent. */ public void onNewIntent(Intent intent) { - java.util.Set> s = this.plugins.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - IPlugin plugin = entry.getValue(); - plugin.onNewIntent(intent); - } + for (IPlugin plugin : this.plugins.values()) { + plugin.onNewIntent(intent); + } } /** From 035ad08c69f0a150a24589c2604f7e5f0923a36f Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 22 Nov 2011 14:36:24 -0600 Subject: [PATCH 3/7] Optimize enumerations as suggested by @plowman. --- framework/src/com/phonegap/AudioHandler.java | 22 +++++++------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/framework/src/com/phonegap/AudioHandler.java b/framework/src/com/phonegap/AudioHandler.java index dc672569..6259496a 100755 --- a/framework/src/com/phonegap/AudioHandler.java +++ b/framework/src/com/phonegap/AudioHandler.java @@ -130,13 +130,9 @@ public class AudioHandler extends Plugin { * Stop all audio players and recorders. */ public void onDestroy() { - java.util.Set> s = this.players.entrySet(); - java.util.Iterator> it = s.iterator(); - while(it.hasNext()) { - Entry entry = it.next(); - AudioPlayer audio = entry.getValue(); + for (AudioPlayer audio : this.players.values()) { audio.destroy(); - } + } this.players.clear(); } @@ -154,26 +150,22 @@ public class AudioHandler extends Plugin { // If phone ringing, then pause playing if ("ringing".equals(data) || "offhook".equals(data)) { - // Get all audio players and pause then - java.util.Set> s = this.players.entrySet(); - java.util.Iterator> it = s.iterator(); - while (it.hasNext()) { - Entry entry = it.next(); - AudioPlayer audio = entry.getValue(); + // Get all audio players and pause them + for (AudioPlayer audio : this.players.values()) { if (audio.getState() == AudioPlayer.MEDIA_RUNNING) { this.pausedForPhone.add(audio); audio.pausePlaying(); } } + } // If phone idle, then resume playing those players we paused else if ("idle".equals(data)) { - for (int i=0; i(); + this.pausedForPhone.clear(); } } } From 5ceb6e2cfada8c1d52c3007eb43589c77ca2fa0d Mon Sep 17 00:00:00 2001 From: William Shen Date: Thu, 3 Nov 2011 18:41:08 -0700 Subject: [PATCH 4/7] Changed createCaptureFile to explicitly check for PNG and to throw an IllegalArgumentException if it is not a JPEG nor a PNG --- framework/src/com/phonegap/CameraLauncher.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/framework/src/com/phonegap/CameraLauncher.java b/framework/src/com/phonegap/CameraLauncher.java index 9dd5d0c1..dd619a24 100755 --- a/framework/src/com/phonegap/CameraLauncher.java +++ b/framework/src/com/phonegap/CameraLauncher.java @@ -180,8 +180,10 @@ public class CameraLauncher extends Plugin { File photo = null; if (encodingType == JPEG) { photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.jpg"); - } else { + } else if (encodingType == PNG) { photo = new File(DirectoryManager.getTempDirectoryPath(ctx), "Pic.png"); + } else { + throw new IllegalArgumentException("Invalid Encoding Type: " + encodingType); } return photo; } From e77e55229338bc1797567fdeb245387b35ab7d95 Mon Sep 17 00:00:00 2001 From: macdonst Date: Fri, 25 Nov 2011 05:28:15 +0800 Subject: [PATCH 5/7] Fix for Issue #33: onReceivedError incorrectly sets openExternal to true --- framework/src/com/phonegap/DroidGap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 97c62b31..ae0490de 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -1592,7 +1592,7 @@ public class DroidGap extends PhonegapActivity { // Load URL on UI thread me.runOnUiThread(new Runnable() { public void run() { - me.showWebPage(errorUrl, true, true, null); + me.showWebPage(errorUrl, false, true, null); } }); } From 784044813350fe57464ead0d704fc55ba3920bb4 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 25 Nov 2011 14:01:50 -0800 Subject: [PATCH 6/7] Work-around Feature for Classic PhoneGap 320x480 resolution --- framework/res/xml/phonegap.xml | 1 + framework/src/com/phonegap/DroidGap.java | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/framework/res/xml/phonegap.xml b/framework/res/xml/phonegap.xml index 97f31ea1..f57d9ab5 100644 --- a/framework/res/xml/phonegap.xml +++ b/framework/res/xml/phonegap.xml @@ -2,4 +2,5 @@ + diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index ae0490de..276ac87d 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -219,6 +219,8 @@ public class DroidGap extends PhonegapActivity { // when another application (activity) is started. protected boolean keepRunning = true; + private boolean clasicRender; + /** * Called when the activity is first created. * @@ -280,7 +282,17 @@ public class DroidGap extends PhonegapActivity { this.appView.setWebChromeClient(new GapClient(DroidGap.this)); this.setWebViewClient(this.appView, new GapViewClient(this)); - this.appView.setInitialScale(100); + //14 is Ice Cream Sandwich! + if(android.os.Build.VERSION.SDK_INT < 14) + this.appView.setInitialScale(100); + else if(this.clasicRender) + { + //This hack fixes legacy PhoneGap apps + //We should be using real pixels, not pretend pixels + final float scale = getResources().getDisplayMetrics().density; + int initialScale = (int) (scale * 100); + this.appView.setInitialScale(initialScale); + } this.appView.setVerticalScrollBarEnabled(false); this.appView.requestFocusFromTouch(); @@ -1750,6 +1762,14 @@ public class DroidGap extends PhonegapActivity { LOG.setLogLevel(level); } } + else if(strNode.equals("render")) { + String enabled = xml.getAttributeValue(null, "enabled"); + if(enabled != null) + { + this.clasicRender = enabled.equals("true"); + } + + } } try { eventType = xml.next(); From 71ea25f40aabca3929e48b7f58e3810bb745e0de Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Fri, 25 Nov 2011 14:31:53 -0800 Subject: [PATCH 7/7] Fixing scale, setting legacy scale --- framework/src/com/phonegap/DroidGap.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 276ac87d..af2762bb 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -219,7 +219,7 @@ public class DroidGap extends PhonegapActivity { // when another application (activity) is started. protected boolean keepRunning = true; - private boolean clasicRender; + private boolean classicRender; /** * Called when the activity is first created. @@ -283,9 +283,7 @@ public class DroidGap extends PhonegapActivity { this.setWebViewClient(this.appView, new GapViewClient(this)); //14 is Ice Cream Sandwich! - if(android.os.Build.VERSION.SDK_INT < 14) - this.appView.setInitialScale(100); - else if(this.clasicRender) + if(android.os.Build.VERSION.SDK_INT < 14 && this.classicRender) { //This hack fixes legacy PhoneGap apps //We should be using real pixels, not pretend pixels @@ -293,6 +291,10 @@ public class DroidGap extends PhonegapActivity { int initialScale = (int) (scale * 100); this.appView.setInitialScale(initialScale); } + else + { + this.appView.setInitialScale(0); + } this.appView.setVerticalScrollBarEnabled(false); this.appView.requestFocusFromTouch(); @@ -1766,7 +1768,7 @@ public class DroidGap extends PhonegapActivity { String enabled = xml.getAttributeValue(null, "enabled"); if(enabled != null) { - this.clasicRender = enabled.equals("true"); + this.classicRender = enabled.equals("true"); } }