-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added fullscreen-video support #892
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,7 @@ Licensed to the Apache Software Foundation (ASF) under one | |
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
|
@@ -18,12 +16,14 @@ Licensed to the Apache Software Foundation (ASF) under one | |
*/ | ||
package org.apache.cordova.inappbrowser; | ||
|
||
import android.app.Activity; | ||
import android.annotation.SuppressLint; | ||
import android.annotation.TargetApi; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.pm.PackageManager; | ||
import android.content.pm.ResolveInfo; | ||
import android.content.pm.ActivityInfo; | ||
import android.os.Parcelable; | ||
import android.provider.Browser; | ||
import android.content.res.Resources; | ||
|
@@ -34,6 +34,7 @@ Licensed to the Apache Software Foundation (ASF) under one | |
import android.net.Uri; | ||
import android.os.Build; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.text.InputType; | ||
import android.util.TypedValue; | ||
import android.view.Gravity; | ||
|
@@ -132,8 +133,10 @@ public class InAppBrowser extends CordovaPlugin { | |
private boolean mediaPlaybackRequiresUserGesture = false; | ||
private boolean shouldPauseInAppBrowser = false; | ||
private boolean useWideViewPort = true; | ||
private ValueCallback<Uri[]> mUploadCallback; | ||
private ValueCallback<Uri> mUploadCallback; | ||
private ValueCallback<Uri[]> mUploadCallbackLollipop; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing code that handles API < 21 should also eliminate the need to have two different class members to handle different API levels. |
||
private final static int FILECHOOSER_REQUESTCODE = 1; | ||
private final static int FILECHOOSER_REQUESTCODE_LOLLIPOP = 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here; see comment above. |
||
private String closeButtonCaption = ""; | ||
private String closeButtonColor = ""; | ||
private boolean leftToRight = false; | ||
|
@@ -264,10 +267,7 @@ else if (action.equals("loadAfterBeforeload")) { | |
@Override | ||
public void run() { | ||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O) { | ||
currentClient.waitForBeforeload = false; | ||
inAppWebView.setWebViewClient(currentClient); | ||
} else { | ||
((InAppBrowserClient)inAppWebView.getWebViewClient()).waitForBeforeload = false; | ||
} | ||
inAppWebView.loadUrl(url); | ||
} | ||
|
@@ -716,6 +716,8 @@ public String showWebPage(final String url, HashMap<String, String> features) { | |
|
||
// Create dialog in new thread | ||
Runnable runnable = new Runnable() { | ||
|
||
private boolean inFullScreen = false; | ||
/** | ||
* Convert our DIP units to Pixels | ||
* | ||
|
@@ -773,6 +775,38 @@ public void onClick(View v) { | |
return _close; | ||
} | ||
|
||
private void enableFullScreen(Activity activity, Window window) { | ||
inFullScreen = true; | ||
WindowManager.LayoutParams attrs = window.getAttributes(); | ||
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; | ||
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; | ||
window.setAttributes(attrs); | ||
if (android.os.Build.VERSION.SDK_INT >= 14) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of cordova-android@9, our supported min SDK is 22. We don't need to have defensive checks here, and can assume that the SDK will be at least 22. |
||
{ | ||
//noinspection all | ||
int flags = View.SYSTEM_UI_FLAG_LOW_PROFILE; | ||
if (android.os.Build.VERSION.SDK_INT >= 16) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same situation above. |
||
{ | ||
flags = View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE; | ||
} | ||
window.getDecorView().setSystemUiVisibility(flags); | ||
} | ||
|
||
} | ||
|
||
private void disableFullScreen(Activity activity, Window window) { | ||
inFullScreen = false; | ||
WindowManager.LayoutParams attrs = window.getAttributes(); | ||
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; | ||
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON; | ||
window.setAttributes(attrs); | ||
if (android.os.Build.VERSION.SDK_INT >= 14) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above |
||
{ | ||
//noinspection all | ||
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); | ||
} | ||
} | ||
|
||
@SuppressLint("NewApi") | ||
public void run() { | ||
|
||
|
@@ -785,13 +819,30 @@ public void run() { | |
dialog = new InAppBrowserDialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar); | ||
dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog; | ||
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
final View decor = dialog.getWindow().getDecorView(); | ||
decor.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { | ||
public void onSystemUiVisibilityChange(int visibility) { | ||
new Handler().postDelayed(new Runnable() { | ||
public void run(){ | ||
if (inFullScreen) | ||
{ | ||
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE); | ||
} | ||
} | ||
}, 3000); | ||
} | ||
}); | ||
if (fullscreen) { | ||
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); | ||
} | ||
dialog.setCancelable(true); | ||
dialog.setInAppBroswer(getInAppBrowser()); | ||
|
||
// Main container layout | ||
RelativeLayout fsmain = new RelativeLayout(cordova.getActivity()); | ||
RelativeLayout fullScreenMain = new RelativeLayout(cordova.getActivity()); | ||
fullScreenMain.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); | ||
LinearLayout browserMain = new LinearLayout(cordova.getActivity()); | ||
LinearLayout main = new LinearLayout(cordova.getActivity()); | ||
main.setOrientation(LinearLayout.VERTICAL); | ||
|
||
|
@@ -917,26 +968,73 @@ public boolean onKey(View v, int keyCode, KeyEvent event) { | |
inAppWebView.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); | ||
inAppWebView.setId(Integer.valueOf(6)); | ||
// File Chooser Implemented ChromeClient | ||
inAppWebView.setWebChromeClient(new InAppChromeClient(thatWebView) { | ||
InAppChromeClient inAppChromeClient = new InAppChromeClient(thatWebView, browserMain, fullScreenMain) { | ||
// For Android 5.0+ | ||
public boolean onShowFileChooser (WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) | ||
{ | ||
LOG.d(LOG_TAG, "File Chooser 5.0+"); | ||
// If callback exists, finish it. | ||
if(mUploadCallback != null) { | ||
mUploadCallback.onReceiveValue(null); | ||
if(mUploadCallbackLollipop != null) { | ||
mUploadCallbackLollipop.onReceiveValue(null); | ||
} | ||
mUploadCallback = filePathCallback; | ||
mUploadCallbackLollipop = filePathCallback; | ||
|
||
// Create File Chooser Intent | ||
Intent content = new Intent(Intent.ACTION_GET_CONTENT); | ||
content.addCategory(Intent.CATEGORY_OPENABLE); | ||
content.setType("*/*"); | ||
|
||
// Run cordova startActivityForResult | ||
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE); | ||
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE_LOLLIPOP); | ||
return true; | ||
} | ||
|
||
// For Android 4.1+ | ||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to support android 4.x |
||
{ | ||
LOG.d(LOG_TAG, "File Chooser 4.1+"); | ||
// Call file chooser for Android 3.0+ | ||
openFileChooser(uploadMsg, acceptType); | ||
} | ||
|
||
// For Android 3.0+ | ||
public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to support android 3.x |
||
{ | ||
LOG.d(LOG_TAG, "File Chooser 3.0+"); | ||
mUploadCallback = uploadMsg; | ||
Intent content = new Intent(Intent.ACTION_GET_CONTENT); | ||
content.addCategory(Intent.CATEGORY_OPENABLE); | ||
|
||
// run startActivityForResult | ||
cordova.startActivityForResult(InAppBrowser.this, Intent.createChooser(content, "Select File"), FILECHOOSER_REQUESTCODE); | ||
} | ||
|
||
}; | ||
|
||
inAppChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback() { | ||
@Override | ||
public void toggledFullscreen(boolean fullscreenV) | ||
{ | ||
// Your code to handle the full-screen change, for example showing and hiding the title bar. Example: | ||
|
||
Activity activity = cordova.getActivity(); | ||
Window window = dialog.getWindow(); | ||
if (fullscreenV) | ||
{ | ||
enableFullScreen(activity, window); | ||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); | ||
} | ||
else | ||
{ | ||
if (!fullscreen) | ||
{ | ||
disableFullScreen(activity, window); | ||
} | ||
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); | ||
} | ||
} | ||
}); | ||
inAppWebView.setWebChromeClient(inAppChromeClient); | ||
currentClient = new InAppBrowserClient(thatWebView, edittext, beforeload); | ||
inAppWebView.setWebViewClient(currentClient); | ||
WebSettings settings = inAppWebView.getSettings(); | ||
|
@@ -1031,8 +1129,11 @@ public void postMessage(String data) { | |
lp.width = WindowManager.LayoutParams.MATCH_PARENT; | ||
lp.height = WindowManager.LayoutParams.MATCH_PARENT; | ||
|
||
fsmain.addView(main); | ||
fsmain.addView(fullScreenMain); | ||
|
||
if (dialog != null) { | ||
dialog.setContentView(main); | ||
dialog.setContentView(fsmain); | ||
dialog.show(); | ||
dialog.getWindow().setAttributes(lp); | ||
} | ||
|
@@ -1083,12 +1184,12 @@ private void sendUpdate(JSONObject obj, boolean keepCallback, PluginResult.Statu | |
public void onActivityResult(int requestCode, int resultCode, Intent intent) { | ||
LOG.d(LOG_TAG, "onActivityResult"); | ||
// If RequestCode or Callback is Invalid | ||
if(requestCode != FILECHOOSER_REQUESTCODE || mUploadCallback == null) { | ||
if(requestCode != FILECHOOSER_REQUESTCODE_LOLLIPOP || mUploadCallbackLollipop == null) { | ||
super.onActivityResult(requestCode, resultCode, intent); | ||
return; | ||
} | ||
mUploadCallback.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent)); | ||
mUploadCallback = null; | ||
mUploadCallbackLollipop.onReceiveValue(WebChromeClient.FileChooserParams.parseResult(resultCode, intent)); | ||
mUploadCallbackLollipop = null; | ||
} | ||
|
||
/** | ||
|
@@ -1098,7 +1199,6 @@ public class InAppBrowserClient extends WebViewClient { | |
EditText edittext; | ||
CordovaWebView webView; | ||
String beforeload; | ||
boolean waitForBeforeload; | ||
|
||
/** | ||
* Constructor. | ||
|
@@ -1110,7 +1210,6 @@ public InAppBrowserClient(CordovaWebView webView, EditText mEditText, String bef | |
this.webView = webView; | ||
this.edittext = mEditText; | ||
this.beforeload = beforeload; | ||
this.waitForBeforeload = beforeload != null; | ||
} | ||
|
||
/** | ||
|
@@ -1171,7 +1270,7 @@ public boolean shouldOverrideUrlLoading(String url, String method) { | |
} | ||
|
||
// On first URL change, initiate JS callback. Only after the beforeload event, continue. | ||
if (useBeforeload && this.waitForBeforeload) { | ||
if (useBeforeload) { | ||
if(sendBeforeLoad(url, method)) { | ||
return true; | ||
} | ||
|
@@ -1266,9 +1365,6 @@ else if (!url.startsWith("http:") && !url.startsWith("https:") && url.matches("^ | |
} | ||
} | ||
|
||
if (useBeforeload) { | ||
this.waitForBeforeload = true; | ||
} | ||
return override; | ||
} | ||
|
||
|
@@ -1459,4 +1555,4 @@ public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, Str | |
super.onReceivedHttpAuthRequest(view, handler, host, realm); | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deletion of these lines will probably cause problems with our release process where it checks for proper license headers. Please revert these deletions