incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [5/17] git commit: Moving LinearLayoutSoftKeyboardDetect out into its own class and making it more plugin-like
Date Mon, 23 Jan 2012 23:05:54 GMT
Moving LinearLayoutSoftKeyboardDetect out into its own class and making it more plugin-like


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/c7e3b46e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/c7e3b46e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/c7e3b46e

Branch: refs/heads/master
Commit: c7e3b46e2ed2a6128a91a8536216c2041962e4bc
Parents: 490a13d
Author: Joe Bowser <bowserj@apache.org>
Authored: Mon Jan 23 13:49:55 2012 -0800
Committer: Joe Bowser <bowserj@apache.org>
Committed: Mon Jan 23 13:49:55 2012 -0800

----------------------------------------------------------------------
 framework/res/xml/plugins.xml                      |    1 +
 framework/src/com/phonegap/DroidGap.java           |   82 -------------
 framework/src/com/phonegap/KeyboardHandler.java    |   34 ++++++
 .../phonegap/LinearLayoutSoftKeyboardDetect.java   |   92 +++++++++++++++
 4 files changed, 127 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c7e3b46e/framework/res/xml/plugins.xml
----------------------------------------------------------------------
diff --git a/framework/res/xml/plugins.xml b/framework/res/xml/plugins.xml
index 7316937..4d84f59 100644
--- a/framework/res/xml/plugins.xml
+++ b/framework/res/xml/plugins.xml
@@ -16,4 +16,5 @@
     <plugin name="FileTransfer" value="com.phonegap.FileTransfer"/>
     <plugin name="Capture" value="com.phonegap.Capture"/>
     <plugin name="Battery" value="com.phonegap.BatteryListener"/>
+    <plugin name="Keyboard" value="com.phonegap.KeyboardHandler" />
 </plugins>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c7e3b46e/framework/src/com/phonegap/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java
index 59e4a15..1d13e59 100755
--- a/framework/src/com/phonegap/DroidGap.java
+++ b/framework/src/com/phonegap/DroidGap.java
@@ -1774,88 +1774,6 @@ public class DroidGap extends PhonegapActivity {
          });
      }
      
-     /**
-      * We are providing this class to detect when the soft keyboard is shown 
-      * and hidden in the web view.
-      */
-     class LinearLayoutSoftKeyboardDetect extends LinearLayout {
-
-            private static final String TAG = "SoftKeyboardDetect";
-            
-            private int oldHeight = 0;  // Need to save the old height as not to send redundant
events
-            private int oldWidth = 0; // Need to save old width for orientation change  
       
-            private int screenWidth = 0;
-            private int screenHeight = 0;
-                        
-            public LinearLayoutSoftKeyboardDetect(Context context, int width, int height)
{
-                super(context);     
-                screenWidth = width;
-                screenHeight = height;                  
-            }
-
-            @Override
-            /**
-             * Start listening to new measurement events.  Fire events when the height 
-             * gets smaller fire a show keyboard event and when height gets bigger fire 
-             * a hide keyboard event.
-             * 
-             * Note: We are using callbackServer.sendJavascript() instead of 
-             * this.appView.loadUrl() as changing the URL of the app would cause the 
-             * soft keyboard to go away.
-             * 
-             * @param widthMeasureSpec
-             * @param heightMeasureSpec
-             */
-            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
-                super.onMeasure(widthMeasureSpec, heightMeasureSpec);       
-                
-                LOG.v(TAG, "We are in our onMeasure method");
-
-                // Get the current height of the visible part of the screen.
-                // This height will not included the status bar.
-                int height = MeasureSpec.getSize(heightMeasureSpec);
-                int width = MeasureSpec.getSize(widthMeasureSpec);
-
-                LOG.v(TAG, "Old Height = %d", oldHeight);
-                LOG.v(TAG, "Height = %d", height);             
-                LOG.v(TAG, "Old Width = %d", oldWidth);
-                LOG.v(TAG, "Width = %d", width);
-
-                // If the oldHeight = 0 then this is the first measure event as the app starts
up.
-                // If oldHeight == height then we got a measurement change that doesn't affect
us.
-                if (oldHeight == 0 || oldHeight == height) {
-                    LOG.d(TAG, "Ignore this event");
-                }
-                // Account for orientation change and ignore this event/Fire orientation
change
-                else if(screenHeight == width)
-                {
-                    int tmp_var = screenHeight;
-                    screenHeight = screenWidth;
-                    screenWidth = tmp_var;
-                    LOG.v(TAG, "Orientation Change");
-                }
-                // If the height as gotten bigger then we will assume the soft keyboard has

-                // gone away.
-                else if (height > oldHeight) {
-                    if (callbackServer != null) {
-                        LOG.v(TAG, "Throw hide keyboard event");
-                        callbackServer.sendJavascript("PhoneGap.fireDocumentEvent('hidekeyboard');");
-                    }
-                } 
-                // If the height as gotten smaller then we will assume the soft keyboard
has 
-                // been displayed.
-                else if (height < oldHeight) {
-                    if (callbackServer != null) {
-                        LOG.v(TAG, "Throw show keyboard event");
-                        callbackServer.sendJavascript("PhoneGap.fireDocumentEvent('showkeyboard');");
-                    }
-                }
-
-                // Update the old height for the next event
-                oldHeight = height;
-                oldWidth = width;
-            }
-    }
      
     /**
      * Load PhoneGap configuration from res/xml/phonegap.xml.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c7e3b46e/framework/src/com/phonegap/KeyboardHandler.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/KeyboardHandler.java b/framework/src/com/phonegap/KeyboardHandler.java
new file mode 100644
index 0000000..953ac71
--- /dev/null
+++ b/framework/src/com/phonegap/KeyboardHandler.java
@@ -0,0 +1,34 @@
+package com.phonegap;
+
+import org.json.JSONArray;
+
+import com.phonegap.api.Plugin;
+import com.phonegap.api.PluginResult;
+
+public class KeyboardHandler extends Plugin {
+
+    
+    /*
+     * This will never be called! 
+     * (non-Javadoc)
+     * @see com.phonegap.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
+     */
+    @Override
+    public PluginResult execute(String action, JSONArray args, String callbackId) {
+        // TODO Auto-generated method stub
+        return null;
+    }
+
+    @Override
+    public void onMessage(String id, Object data)
+    {
+        if(id.equals("keyboardHidden"))
+        {
+            super.sendJavascript("PhoneGap.fireDocumentEvent('hidekeyboard');");
+        }
+        else if(id.equals("keyboardVisible"))
+        {
+            super.sendJavascript("PhoneGap.fireDocumentEvent('showkeyboard');");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/c7e3b46e/framework/src/com/phonegap/LinearLayoutSoftKeyboardDetect.java
----------------------------------------------------------------------
diff --git a/framework/src/com/phonegap/LinearLayoutSoftKeyboardDetect.java b/framework/src/com/phonegap/LinearLayoutSoftKeyboardDetect.java
new file mode 100644
index 0000000..32a7f6e
--- /dev/null
+++ b/framework/src/com/phonegap/LinearLayoutSoftKeyboardDetect.java
@@ -0,0 +1,92 @@
+package com.phonegap;
+import com.phonegap.api.LOG;
+
+import android.content.Context;
+import android.view.View.MeasureSpec;
+import android.widget.LinearLayout;
+
+
+public class LinearLayoutSoftKeyboardDetect extends LinearLayout {
+
+    private static final String TAG = "SoftKeyboardDetect";
+    
+    private int oldHeight = 0;  // Need to save the old height as not to send redundant events
+    private int oldWidth = 0; // Need to save old width for orientation change          
+    private int screenWidth = 0;
+    private int screenHeight = 0;
+    private DroidGap app = null;
+                
+    public LinearLayoutSoftKeyboardDetect(Context context, int width, int height) {
+        super(context);     
+        screenWidth = width;
+        screenHeight = height;
+        if(context.getClass().getSimpleName().equals("DroidGap"))
+            app = (DroidGap) app;
+    }
+
+    @Override
+    /**
+     * Start listening to new measurement events.  Fire events when the height 
+     * gets smaller fire a show keyboard event and when height gets bigger fire 
+     * a hide keyboard event.
+     * 
+     * Note: We are using callbackServer.sendJavascript() instead of 
+     * this.appView.loadUrl() as changing the URL of the app would cause the 
+     * soft keyboard to go away.
+     * 
+     * @param widthMeasureSpec
+     * @param heightMeasureSpec
+     */
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);       
+        
+        LOG.v(TAG, "We are in our onMeasure method");
+
+        // Get the current height of the visible part of the screen.
+        // This height will not included the status bar.
+        int height = MeasureSpec.getSize(heightMeasureSpec);
+        int width = MeasureSpec.getSize(widthMeasureSpec);
+
+        LOG.v(TAG, "Old Height = %d", oldHeight);
+        LOG.v(TAG, "Height = %d", height);             
+        LOG.v(TAG, "Old Width = %d", oldWidth);
+        LOG.v(TAG, "Width = %d", width);
+
+        // If the oldHeight = 0 then this is the first measure event as the app starts up.
+        // If oldHeight == height then we got a measurement change that doesn't affect us.
+        if (oldHeight == 0 || oldHeight == height) {
+            LOG.d(TAG, "Ignore this event");
+        }
+        // Account for orientation change and ignore this event/Fire orientation change
+        else if(screenHeight == width)
+        {
+            int tmp_var = screenHeight;
+            screenHeight = screenWidth;
+            screenWidth = tmp_var;
+            LOG.v(TAG, "Orientation Change");
+        }
+        // If the height as gotten bigger then we will assume the soft keyboard has 
+        // gone away.
+        else if (height > oldHeight) {
+            if(app != null)
+                app.postMessage("hideKeyboard", null);
+        } 
+        // If the height as gotten smaller then we will assume the soft keyboard has 
+        // been displayed.
+        else if (height < oldHeight) {
+            if(app != null)
+                app.postMessage("keyboardVisible", null);
+            /*
+            if (callbackServer != null) {
+                LOG.v(TAG, "Throw show keyboard event");
+                callbackServer.sendJavascript("PhoneGap.fireDocumentEvent('showkeyboard');");
+            }
+            */
+        }
+
+        // Update the old height for the next event
+        oldHeight = height;
+        oldWidth = width;
+    }
+
+}


Mime
View raw message