You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2017/01/09 17:47:33 UTC

[3/8] cordova-plugin-inappbrowser git commit: Add Support for input[type=file] File Chooser

Add Support for input[type=file] File Chooser


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/commit/ad28a0ec
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/tree/ad28a0ec
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/diff/ad28a0ec

Branch: refs/heads/master
Commit: ad28a0ec68b49078821a61bb54e81f261bb6460e
Parents: fa70a64
Author: \ubc15\uad00\uc601 <ja...@naver.com>
Authored: Tue Jan 3 14:20:50 2017 +0900
Committer: Joe Bowser <bo...@apache.org>
Committed: Mon Jan 9 09:27:53 2017 -0800

----------------------------------------------------------------------
 src/android/InAppBrowser.java | 82 ++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser/blob/ad28a0ec/src/android/InAppBrowser.java
----------------------------------------------------------------------
diff --git a/src/android/InAppBrowser.java b/src/android/InAppBrowser.java
index b7a463c..a02743d 100644
--- a/src/android/InAppBrowser.java
+++ b/src/android/InAppBrowser.java
@@ -409,7 +409,7 @@ public class InAppBrowser extends CordovaPlugin {
             intent.putExtra(Browser.EXTRA_APPLICATION_ID, cordova.getActivity().getPackageName());
             this.cordova.getActivity().startActivity(intent);
             return "";
-        // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
+            // not catching FileUriExposedException explicitly because buildtools<24 doesn't know about it
         } catch (java.lang.RuntimeException e) {
             LOG.d(LOG_TAG, "InAppBrowser: Error loading url "+url+":"+ e.toString());
             return e.toString();
@@ -571,7 +571,7 @@ public class InAppBrowser extends CordovaPlugin {
             }
             Boolean wideViewPort = features.get(USER_WIDE_VIEW_PORT);
             if (wideViewPort != null ) {
-		            useWideViewPort = wideViewPort.booleanValue();
+                useWideViewPort = wideViewPort.booleanValue();
             }
         }
 
@@ -586,8 +586,8 @@ public class InAppBrowser extends CordovaPlugin {
              */
             private int dpToPixels(int dipValue) {
                 int value = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP,
-                                                            (float) dipValue,
-                                                            cordova.getActivity().getResources().getDisplayMetrics()
+                        (float) dipValue,
+                        cordova.getActivity().getResources().getDisplayMetrics()
                 );
 
                 return value;
@@ -695,8 +695,8 @@ public class InAppBrowser extends CordovaPlugin {
                     public boolean onKey(View v, int keyCode, KeyEvent event) {
                         // If the event is a key-down event on the "enter" button
                         if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
-                          navigate(edittext.getText().toString());
-                          return true;
+                            navigate(edittext.getText().toString());
+                            return true;
                         }
                         return false;
                     }
@@ -893,6 +893,42 @@ public class InAppBrowser extends CordovaPlugin {
     }
 
     /**
+     * Receive File Data from File Chooser
+     *
+     * @param requestCode the requested code from chromeclient
+     * @param resultCode the result code returned from android system
+     * @param intent the data from android file chooser
+     */
+    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
+        // For Android >= 5.0
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
+            Log.i("mytag", "onActivityResult (For Android >= 5.0)");
+            // If RequestCode or Callback is Invalid
+            if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
+                super.onActivityResult(requestCode, resultCode, intent);
+                return;
+            }
+            mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
+            mUploadCallbackLollipop = null;
+        }
+        // For Android < 5.0
+        else {
+            Log.i("mytag", "onActivityResult (For Android < 5.0)");
+            // If RequestCode or Callback is Invalid
+            if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
+                super.onActivityResult(requestCode, resultCode, intent);
+                return;
+            }
+
+            if (null == mUploadCallback) return;
+            Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();
+
+            mUploadCallback.onReceiveValue(result);
+            mUploadCallback = null;
+        }
+    }
+
+    /**
      * The webview client receives notifications about appView
      */
     public class InAppBrowserClient extends WebViewClient {
@@ -999,7 +1035,7 @@ public class InAppBrowser extends CordovaPlugin {
             // Update the UI if we haven't already
             if (!newloc.equals(edittext.getText().toString())) {
                 edittext.setText(newloc);
-             }
+            }
 
             try {
                 JSONObject obj = new JSONObject();
@@ -1087,35 +1123,5 @@ public class InAppBrowser extends CordovaPlugin {
             // By default handle 401 like we'd normally do!
             super.onReceivedHttpAuthRequest(view, handler, host, realm);
         }
-
-        @Override
-        public void onActivityResult(int requestCode, int resultCode, Intent intent) {
-            // For Android >= 5.0
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-                Log.i("mytag", "onActivityResult (For Android >= 5.0)");
-                // If RequestCode or Callback is Invalid
-                if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) {
-                    super.onActivityResult(requestCode, resultCode, intent);
-                    return;
-                }
-                mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent));
-                mUploadCallbackLollipop = null;
-            }
-            // For Android < 5.0
-            else {
-                Log.i("mytag", "onActivityResult (For Android < 5.0)");
-                // If RequestCode or Callback is Invalid
-                if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) {
-                    super.onActivityResult(requestCode, resultCode, intent);
-                    return;
-                }
-
-                if (null == mUploadCallback) return;
-                Uri result = intent == null || resultCode != cordova.getActivity().RESULT_OK ? null : intent.getData();
-
-                mUploadCallback.onReceiveValue(result);
-                mUploadCallback = null;
-            }
-        }
     }
-}
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org