mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Merge in video tag changes and fix back button issue
This commit is contained in:
commit
a3a215a1ba
@ -20,14 +20,16 @@ package org.apache.cordova;
|
|||||||
|
|
||||||
import org.apache.cordova.api.CordovaInterface;
|
import org.apache.cordova.api.CordovaInterface;
|
||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.apache.cordova.api.PluginResult;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.webkit.ConsoleMessage;
|
import android.webkit.ConsoleMessage;
|
||||||
import android.webkit.JsPromptResult;
|
import android.webkit.JsPromptResult;
|
||||||
import android.webkit.JsResult;
|
import android.webkit.JsResult;
|
||||||
@ -36,6 +38,9 @@ import android.webkit.WebStorage;
|
|||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.GeolocationPermissions.Callback;
|
import android.webkit.GeolocationPermissions.Callback;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is the WebChromeClient that implements callbacks for our web view.
|
* This class is the WebChromeClient that implements callbacks for our web view.
|
||||||
@ -47,6 +52,9 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
private CordovaInterface cordova;
|
private CordovaInterface cordova;
|
||||||
private CordovaWebView appView;
|
private CordovaWebView appView;
|
||||||
|
|
||||||
|
// the video progress view
|
||||||
|
private View mVideoProgressView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -316,4 +324,45 @@ public class CordovaChromeClient extends WebChromeClient {
|
|||||||
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
super.onGeolocationPermissionsShowPrompt(origin, callback);
|
||||||
callback.invoke(origin, true, false);
|
callback.invoke(origin, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// API level 7 is required for this, see if we could lower this using something else
|
||||||
|
@Override
|
||||||
|
public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
|
||||||
|
this.appView.showCustomView(view, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onHideCustomView() {
|
||||||
|
this.appView.hideCustomView();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* Ask the host application for a custom progress view to show while
|
||||||
|
* a <video> is loading.
|
||||||
|
* @return View The progress view.
|
||||||
|
*/
|
||||||
|
public View getVideoLoadingProgressView() {
|
||||||
|
|
||||||
|
if (mVideoProgressView == null) {
|
||||||
|
// Create a new Loading view programmatically.
|
||||||
|
|
||||||
|
// create the linear layout
|
||||||
|
LinearLayout layout = new LinearLayout(this.appView.getContext());
|
||||||
|
layout.setOrientation(LinearLayout.VERTICAL);
|
||||||
|
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT);
|
||||||
|
layout.setLayoutParams(layoutParams);
|
||||||
|
// the proress bar
|
||||||
|
ProgressBar bar = new ProgressBar(this.appView.getContext());
|
||||||
|
LinearLayout.LayoutParams barLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||||
|
barLayoutParams.gravity = Gravity.CENTER;
|
||||||
|
bar.setLayoutParams(barLayoutParams);
|
||||||
|
layout.addView(bar);
|
||||||
|
|
||||||
|
mVideoProgressView = layout;
|
||||||
|
}
|
||||||
|
return mVideoProgressView;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import org.apache.cordova.api.CordovaInterface;
|
|||||||
import org.apache.cordova.api.LOG;
|
import org.apache.cordova.api.LOG;
|
||||||
import org.apache.cordova.api.PluginManager;
|
import org.apache.cordova.api.PluginManager;
|
||||||
import org.apache.cordova.api.PluginResult;
|
import org.apache.cordova.api.PluginResult;
|
||||||
import org.json.JSONException;
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
@ -41,20 +40,23 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.res.XmlResourceParser;
|
import android.content.res.XmlResourceParser;
|
||||||
import android.net.ConnectivityManager;
|
|
||||||
import android.net.NetworkInfo;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.webkit.WebBackForwardList;
|
import android.webkit.WebBackForwardList;
|
||||||
import android.webkit.WebHistoryItem;
|
import android.webkit.WebHistoryItem;
|
||||||
|
import android.webkit.WebChromeClient;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
public class CordovaWebView extends WebView {
|
public class CordovaWebView extends WebView {
|
||||||
|
|
||||||
@ -90,15 +92,21 @@ public class CordovaWebView extends WebView {
|
|||||||
|
|
||||||
private boolean bound;
|
private boolean bound;
|
||||||
|
|
||||||
private boolean volumedownBound;
|
|
||||||
|
|
||||||
private boolean volumeupBound;
|
|
||||||
|
|
||||||
private boolean handleButton = false;
|
private boolean handleButton = false;
|
||||||
|
|
||||||
NativeToJsMessageQueue jsMessageQueue;
|
NativeToJsMessageQueue jsMessageQueue;
|
||||||
ExposedJsApi exposedJsApi;
|
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.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -800,22 +808,28 @@ public class CordovaWebView extends WebView {
|
|||||||
{
|
{
|
||||||
// If back key
|
// If back key
|
||||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
// If back key is bound, then send event to JavaScript
|
// A custom view is currently displayed (e.g. playing a video)
|
||||||
if (this.bound) {
|
if(mCustomView != null) {
|
||||||
this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
|
this.hideCustomView();
|
||||||
return true;
|
} else {
|
||||||
} else {
|
// The webview is currently displayed
|
||||||
// If not bound
|
// If back key is bound, then send event to JavaScript
|
||||||
// Go to previous page in webview if it is possible to go back
|
if (this.bound) {
|
||||||
if (this.backHistory()) {
|
this.loadUrl("javascript:cordova.fireDocumentEvent('backbutton');");
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
// If not, then invoke default behavior
|
// If not bound
|
||||||
else {
|
// Go to previous page in webview if it is possible to go back
|
||||||
//this.activityState = ACTIVITY_EXITING;
|
if (this.backHistory()) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
// If not, then invoke default behaviour
|
||||||
|
else {
|
||||||
|
//this.activityState = ACTIVITY_EXITING;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Legacy
|
// Legacy
|
||||||
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
else if (keyCode == KeyEvent.KEYCODE_MENU) {
|
||||||
@ -977,4 +991,57 @@ public class CordovaWebView extends WebView {
|
|||||||
LOG.d(TAG, "The URL at item 0 is:" + url);
|
LOG.d(TAG, "The URL at item 0 is:" + url);
|
||||||
return currentUrl.equals(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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1010,9 +1010,11 @@ public class DroidGap extends Activity implements CordovaInterface {
|
|||||||
appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE &&
|
appView.getHitTestResult().getType() == WebView.HitTestResult.EDIT_TEXT_TYPE &&
|
||||||
keyCode == KeyEvent.KEYCODE_BACK) {
|
keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
return appView.onKeyUp(keyCode, event);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user