incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdo...@apache.org
Subject [1/2] android commit: Merge in video tag changes and fix back button issue
Date Wed, 17 Oct 2012 18:24:35 GMT
Updated Branches:
  refs/heads/master d3ee322d7 -> a3a215a1b


Merge in video tag changes and fix back button issue


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/a3a215a1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/a3a215a1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/a3a215a1

Branch: refs/heads/master
Commit: a3a215a1bad456145a0c0a728fae5df0178067e8
Parents: d3ee322 06aafc9
Author: Simon MacDonald <simon.macdonald@gmail.com>
Authored: Tue Oct 16 15:47:42 2012 -0400
Committer: Simon MacDonald <simon.macdonald@gmail.com>
Committed: Wed Oct 17 10:14:30 2012 -0400

----------------------------------------------------------------------
 .../org/apache/cordova/CordovaChromeClient.java    |   51 +++++++-
 .../src/org/apache/cordova/CordovaWebView.java     |  113 ++++++++++++---
 framework/src/org/apache/cordova/DroidGap.java     |    6 +-
 3 files changed, 144 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/a3a215a1/framework/src/org/apache/cordova/CordovaChromeClient.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/CordovaChromeClient.java
index 2f4cdff,0a235a8..44b6bba
--- a/framework/src/org/apache/cordova/CordovaChromeClient.java
+++ b/framework/src/org/apache/cordova/CordovaChromeClient.java
@@@ -23,11 -23,19 +23,13 @@@ import org.apache.cordova.api.LOG
  import org.json.JSONArray;
  import org.json.JSONException;
  
 -//import android.app.Activity;
 +import android.annotation.TargetApi;
  import android.app.AlertDialog;
 -//import android.content.Context;
  import android.content.DialogInterface;
 -import android.util.Log;
+ import android.view.Gravity;
  import android.view.KeyEvent;
 -import android.view.LayoutInflater;
+ import android.view.View;
 -import android.view.ViewGroup;
+ import android.view.ViewGroup.LayoutParams;
 -import android.view.WindowManager;
 -//import android.view.View;
  import android.webkit.ConsoleMessage;
  import android.webkit.JsPromptResult;
  import android.webkit.JsResult;
@@@ -36,6 -44,11 +38,9 @@@ import android.webkit.WebStorage
  import android.webkit.WebView;
  import android.webkit.GeolocationPermissions.Callback;
  import android.widget.EditText;
 -import android.widget.FrameLayout;
+ import android.widget.LinearLayout;
+ import android.widget.ProgressBar;
+ import android.widget.RelativeLayout;
 -import android.widget.Toast;
  
  /**
   * This class is the WebChromeClient that implements callbacks for our web view.

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/a3a215a1/framework/src/org/apache/cordova/CordovaWebView.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/CordovaWebView.java
index 017c3d3,2257576..52ae6a9
--- a/framework/src/org/apache/cordova/CordovaWebView.java
+++ b/framework/src/org/apache/cordova/CordovaWebView.java
@@@ -30,28 -30,21 +30,29 @@@ import java.util.regex.Pattern
  import org.apache.cordova.api.CordovaInterface;
  import org.apache.cordova.api.LOG;
  import org.apache.cordova.api.PluginManager;
 +import org.apache.cordova.api.PluginResult;
- import org.json.JSONException;
  import org.xmlpull.v1.XmlPullParserException;
  
 +import android.annotation.SuppressLint;
 +import android.annotation.TargetApi;
 +import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
 +import android.content.IntentFilter;
  import android.content.res.XmlResourceParser;
- import android.net.ConnectivityManager;
- import android.net.NetworkInfo;
  import android.net.Uri;
 +import android.os.Build;
  import android.os.Bundle;
  import android.util.AttributeSet;
  import android.util.Log;
+ import android.view.Gravity;
  import android.view.KeyEvent;
+ import android.view.View;
+ import android.view.ViewGroup;
  import android.view.WindowManager;
 +import android.webkit.WebBackForwardList;
 +import android.webkit.WebHistoryItem;
+ import android.webkit.WebChromeClient;
  import android.webkit.WebSettings;
  import android.webkit.WebView;
  import android.webkit.WebSettings.LayoutAlgorithm;
@@@ -90,15 -83,22 +92,21 @@@ public class CordovaWebView extends Web
  
      private boolean bound;
  
--    private boolean volumedownBound;
--
--    private boolean volumeupBound;
--
      private boolean handleButton = false;
  
 +	NativeToJsMessageQueue jsMessageQueue;
 +	ExposedJsApi exposedJsApi;
 +
+     /** custom view created by the browser (a video player for example) */
+     private View mCustomView;
+     private WebChromeClient.CustomViewCallback mCustomViewCallback;
+     
+     static final FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER =
+             new FrameLayout.LayoutParams(
+             ViewGroup.LayoutParams.MATCH_PARENT,
+             ViewGroup.LayoutParams.MATCH_PARENT,
+             Gravity.CENTER);
+     
      /**
       * Constructor.
       *
@@@ -800,22 -749,28 +808,28 @@@
      {
          // If back key
          if (keyCode == KeyEvent.KEYCODE_BACK) {
-             // If back key is bound, then send event to JavaScript
-             if (this.bound) {
-                 this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
-                 return true;
-             } else {
-                 // If not bound
-                 // Go to previous page in webview if it is possible to go back
-                 if (this.backHistory()) {
-                     return true;
-                 }
-                 // If not, then invoke default behavior
-                 else {
-                     //this.activityState = ACTIVITY_EXITING;
-                     return false;
-                 }
-             }
 -        	// A custom view is currently displayed  (e.g. playing a video)
++            // A custom view is currently displayed  (e.g. playing a video)
+         	if(mCustomView != null) {
+         		this.hideCustomView();
+         	} else {
 -        	// The webview is currently displayed
++        	    // The webview is currently displayed
+ 	            // If back key is bound, then send event to JavaScript
+ 	            if (this.bound) {
+ 	                this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
+ 	                return true;
+ 	            } else {
+ 	                // If not bound
+ 	                // Go to previous page in webview if it is possible to go back
+ 	                if (this.backHistory()) {
+ 	                    return true;
+ 	                }
+ 	                // If not, then invoke default behaviour
+ 	                else {
+ 	                    //this.activityState = ACTIVITY_EXITING;
+ 	                    return false;
+ 	                }
+ 	            }
+         	}
          }
          // Legacy
          else if (keyCode == KeyEvent.KEYCODE_MENU) {
@@@ -945,36 -894,48 +959,89 @@@
          return handleButton;
      }
  
 +    // Wrapping these functions in their own class prevents warnings in adb like:
 +    // VFY: unable to resolve virtual method 285: Landroid/webkit/WebSettings;.setAllowUniversalAccessFromFileURLs
 +    @TargetApi(16)
 +    private static class Level16Apis {
 +        static void enableUniversalAccess(WebSettings settings) {
 +            settings.setAllowUniversalAccessFromFileURLs(true);
 +        }
 +    }
 +    
 +    public void printBackForwardList() {
 +    	WebBackForwardList currentList = this.copyBackForwardList();
 +    	int currentSize = currentList.getSize();
 +    	for(int i = 0; i < currentSize; ++i)
 +    	{
 +    		WebHistoryItem item = currentList.getItemAtIndex(i);
 +    		String url = item.getUrl();
 +    		LOG.d(TAG, "The URL at index: " + Integer.toString(i) + "is " + url );
 +    	}
 +    }
 +    
 +    
 +    //Can Go Back is BROKEN!
 +    public boolean startOfHistory()
 +    {
 +        WebBackForwardList currentList = this.copyBackForwardList();
 +        WebHistoryItem item = currentList.getItemAtIndex(0);
 +        String url = item.getUrl();
 +        String currentUrl = this.getUrl();
 +        LOG.d(TAG, "The current URL is: " + currentUrl);
 +        LOG.d(TAG, "The URL at item 0 is:" + url);
 +        return currentUrl.equals(url);
 +    }
+ 
+     public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
+     	// This code is adapted from the original Android Browser code, licensed under the
Apache License, Version 2.0
+     	Log.d(TAG, "showing Custom View");
+         // if a view already exists then immediately terminate the new one
+         if (mCustomView != null) {
+             callback.onCustomViewHidden();
+             return;
+         }
+         
+         // Store the view and its callback for later (to kill it properly)
+     	mCustomView = view;
+     	mCustomViewCallback = callback;
+     	
+         // Add the custom view to its container.
+     	ViewGroup parent = (ViewGroup) this.getParent();
+     	parent.addView(view, COVER_SCREEN_GRAVITY_CENTER);
+     	
+     	// Hide the content view.
+     	this.setVisibility(View.GONE);
+     	
+     	// Finally show the custom view container.
+     	parent.setVisibility(View.VISIBLE);
+     	parent.bringToFront();
+     }
+ 
+ 	public void hideCustomView() {
+     	// This code is adapted from the original Android Browser code, licensed under the
Apache License, Version 2.0
+     	Log.d(TAG, "Hidding Custom View");
+ 		if (mCustomView == null) return;
+ 
+ 		// Hide the custom view.
+ 		mCustomView.setVisibility(View.GONE);
+ 		
+ 		// Remove the custom view from its container.
+ 		ViewGroup parent = (ViewGroup) this.getParent();
+ 		parent.removeView(mCustomView);
+ 		mCustomView = null;
+ 		mCustomViewCallback.onCustomViewHidden();
+ 		
+         // Show the content view.
+         this.setVisibility(View.VISIBLE);
+ 	}
 -
++	
++	/**
++	 * if the video overlay is showing then we need to know 
++	 * as it effects back button handling
++	 * 
++	 * @return
++	 */
++	public boolean isCustomViewShowing() {
++	    return mCustomView != null;
++	}
  }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/a3a215a1/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/DroidGap.java
index 95e62c4,68dbe08..1176f69
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@@ -1002,40 -995,6 +1002,42 @@@ public class DroidGap extends Activity 
          this.runOnUiThread(runnable);
      }
  
 +    @Override
 +    public boolean onKeyUp(int keyCode, KeyEvent event)
 +    {
 +    	//Determine if the focus is on the current view or not
 +    	if (appView.getHitTestResult() != null && 
 +    	    appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE &&
 +    	    keyCode == KeyEvent.KEYCODE_BACK) {
 +    	    		return appView.onKeyUp(keyCode, event);
++        } else if (appView.isCustomViewShowing() && keyCode == KeyEvent.KEYCODE_BACK)
{
++            return appView.onKeyUp(keyCode, event);
++        } else {
++            return super.onKeyUp(keyCode, event);
 +    	}
-     	else
-     		return super.onKeyUp(keyCode, event);
 +    }
 +    
 +    /*
 +     * Android 2.x needs to be able to check where the cursor is.  Android 4.x does not
 +     * 
 +     * (non-Javadoc)
 +     * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent)
 +     */
 +    
 +    @Override
 +    public boolean onKeyDown(int keyCode, KeyEvent event)
 +    {
 +        //Determine if the focus is on the current view or not
 +        if (appView.getHitTestResult() != null && 
 +            appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE
&&
 +            keyCode == KeyEvent.KEYCODE_BACK) {
 +                    return appView.onKeyDown(keyCode, event);
 +        }
 +        else
 +            return super.onKeyDown(keyCode, event);
 +    }
 +    
 +    
      /**
       * Called when a message is sent to plugin.
       *


Mime
View raw message