Blocking/disabling JavaFX 2 WebView LEFT click - webview

I have searched the web but can't get any information about this.
There is a lot of information about disabling right click***, but how to disable left click?
***example:
WebView webview = new WebView();
webview.setContextMenuEnabled(false);

Answer - Blocking/disabling LEFT and right click:
stage.addEventFilter(MouseEvent.MOUSE_RELEASED, new EventHandler<MouseEvent>() {
public void handle(MouseEvent event) {
if (event.getButton() == MouseButton.SECONDARY ||
event.getButton() == MouseButton.PRIMARY) {
event.consume();
}
}
});

Related

Is there a way to conditionally disable the swipe to go back gesture in react native iOS?

I'm looking for a way to conditionally disable the swipe to go back gesture in react native iOS. I'm using the react-navigation library to control navigation. For Android, I am able to do it using BackHandler. Is it possible to do something similar in iOS?
componentDidMount() {
BackHandler.addEventListener("hardwareBackPress", this.handleBackButton);
}
handleBackButton = () => {
if (this.props.creating) {
return true; // Disables the back button in Android
}
};
componentWillUnmount() {
BackHandler.removeEventListener(
"hardwareBackPress",
this.handleBackButton
);
}
Yes, there is an option to disable gestures:
screen: ExampleView
navigationOptions: {
gesturesEnabled: false,
},
Check for more details here: https://github.com/react-navigation/react-navigation/issues/1063
But I'm trying to only disable gestures when this.props.creating is
true.
Try adding this static method to your component.
static navigationOptions = props => {
return {
gesturesEnabled: this.props.creating ? false : true
}
};
StackNavigator takes navigationOptions representing the "Default navigation options to use for screens"
Example:
const RootStackNavigator = StackNavigator(
{
Login: {
screen: LoginScreen
},
Main: {
screen: MainScreen
}
},
{
initialRouteName: 'Login',
navigationOptions: {
gesturesEnabled: false // <- add this line
}
}
);

How to stop video playing in WebView

I work on a Xamarin.Forms app (UWP!). It has a Master-Details architecture. The Master page has a ListView, and each item in it opens a corresponding Detail page. The first Detail page has only a WebView that plays a YouTube video upon loading. The second Detail view has just a placeholder label for now.
Where I switch from first Detail page to the second, the sound of the video from the first Detail page is still heard. And when I switch back to the first Detail page, the video loads again, and now I hear two voices. How can I stop the video upon switching to the second Detail page and resume when going back? If this is not possible, how can I just stop the video upon leaving its Detail page?
I guess I could do something in an overridden OnDisappearing() method of the detail page:
protected override void OnDisappearing()
{
MyWebView.NavigateToString(""); // This does not work, as NavigateToString() is not part of WebView.
base.OnDisappearing();
}
What can I use to stop playing video in WebView?
Could you please tell what I can use to stop playing video in WebView?
For your requirement, you could approach with injecting Eval java script.
private void Button_Clicked(object sender, EventArgs e)
{
string pausefunctionString = #"
var videos = document.querySelectorAll('video');
[].forEach.call(videos, function(video) { video.pause(); });
";
MyWebView.Eval(pausefunctionString);
}
Update
I have re-checked your issue, when you navigate to another page, the WebView has not be released correctly. If you want to stop the WebView video play, you could make it navigate to blank page via custom WebViewRenderer.
[assembly: ExportRenderer(typeof(WebView), typeof(CustomWebViewRender))]
namespace App4.UWP
{
class CustomWebViewRender : WebViewRenderer
{
private Windows.UI.Xaml.Controls.WebView _WebView;
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
var source = Element.Source as UrlWebViewSource;
_WebView = new Windows.UI.Xaml.Controls.WebView();
SetNativeControl(_WebView);
}
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == WebView.SourceProperty.PropertyName)
{
var source = Element.Source as UrlWebViewSource;
if (source.Url == string.Empty)
{
_WebView.NavigateToString(string.Empty);
}
}
}
}
}
Usage
protected override void OnAppearing()
{
base.OnAppearing();
MyWebView.Source = "https://www.youtube.com";
}
protected override void OnDisappearing()
{
MyWebView.Source = string.Empty;
base.OnDisappearing();
}
Xaml
<WebView HeightRequest="500" WidthRequest="500" x:Name="MyWebView"/>

UWP: WebView using the Mouse Forward and Backward Buttons

I'm developing a UWP-App with a WebView inside. At the WebView I want to use the forward and backward buttons of the mouse to navigate forward and backward. At default the WebView doesn't support it. (a normal browser does)
So I've found the PointerPressed Event and in this event I can check if the pointer-device is the mouse and if the pointer-properties are IsXButton1Pressed or IsXButton2Pressed. If I implement it on other usercontrols it works perfectly. But on the WebView usercontrol it doesn't work.
That's how I implemented it on other usercontrols:
private void Page_PointerPressed(object sender, PointerRoutedEventArgs e)
{
PointerPoint currentPoint = e.GetCurrentPoint(this);
if(currentPoint.PointerDevice.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
{
PointerPointProperties pointerProperties = currentPoint.Properties;
if(pointerProperties.IsXButton2Pressed)
{
if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
{
Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];
e.Handled = iWebNav.GoForward();
}
}
else if(pointerProperties.IsXButton1Pressed)
{
if (grd_content.Children.Count == 1 && grd_content.Children[0] is Interfaces.IWebNavigation)
{
Interfaces.IWebNavigation iWebNav = (Interfaces.IWebNavigation)grd_content.Children[0];
e.Handled = iWebNav.GoBackward();
}
}
}
}
How can I implement the mouse forward and backward button on a WebView usercontrol?

AngularStrap datepicker doesn't disappear on blur of trigger event in the IOS Safari browser

My datepicker can disappear on blur of trigger event in the windows Chrome, windows Safari, mac Safari, android Chrome except IOS Safari browser.
My code:
<input class="title-menu-left-input form-control"
name="birthday" data-date-format="yyyy-MM-dd"
data-date-type="string" data-autoclose="1"
ng-model="dateFrom" placeholder="date" data-trigger="focus"
bs-datepicker>
Anyone can help me to find why it doesn't disappear on blur of trigger event in IOS safari browser? Thanks in advance!
There are some background which maybe help you to know more about my question. you can visit this page http://mgcrea.github.io/angular-strap/#/datepickers or plunker: http://plnkr.co/edit/lUtYyIqD4ETCG5zbKrNC?p=preview. my code is the same as it. I don't know why it can disappear on blur of trigger event in the windows Chrome, windows Safari, mac Safari, android Chrome except IOS Safari browser. I wonder whether i do special process in IOS Safari. Anyone has come with this quesiton?
What about the another source code ?, it should have a button to open date picker popup, and some from controller
The problem is that 'blur' event is not fired on iPad. So when user touches screen outside of calendar input and dropdown I fire that event by this manually.
controller: ['$scope', function ($scope) {
function isiPadiPhone () {
return ((navigator.userAgent.match(/iPad/i) != null) ||
(navigator.platform.indexOf("iPhone") != -1) ||
(navigator.platform.indexOf("iPod") != -1));
}
if (isiPadiPhone()) {
document.body.addEventListener("touchend", handleTouchEnd, false);
$scope.$on('$destroy', function () {
document.body.removeEventListener("touchend", handleTouchEnd, false);
});
}
function handleTouchEnd(event) {
var dateInput = document.getElementById('your_input_id');
var nextSibling = dateInput.nextSibling;
if (!nextSibling || !nextSibling.classList || !nextSibling.classList.contains('dropdown-menu')) {
//no calendar dropdown is shown now
return;
}
if (isParent(event.target, nextSibling)) {
return;
}
if (isParent(event.target, dateInput)) {
return;
}
//we have to fire 'blur' event manually on iPad
dateInput.blur();
}
function isParent(element, parent) {
while (element != null) {
if (element === parent) {
return true;
}
element = element.parentNode;
}
return false;
}
}

Disable eventlistener temporarily till animation completes

I'm working on a basic flash fight game. I'm not a developer so i'm new to actionscript except that i have some background knowledge about coding from my course.
The problem is-
There are about 6 fighting moves and i want to disable all 6 key_down events till the animation completes. And all 6 animations have different time frames. Can some1 just help me out with this?
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterKeyHandler);
function enterKeyHandler(event:KeyboardEvent):void {
if (event.keyCode == Keyboard.B) {
gotoAndPlay(252);}
if (event.keyCode == Keyboard.V) {
gotoAndPlay(259);}
I have put down only 2 of them but there 6 in total.
I would use a public static flag , ex:
keyboardDisabled:Boolean = false;
While you play your animations you could set this to true, and inside the function which listens to keyboard events just check if keyboard is disabled and return right away.
Some code would look like
public static var keyboardDisabled:Boolean = false;
stage.addEventListener(KeyboardEvent.KEY_DOWN, enterKeyHandler);
function enterKeyHandler(event:KeyboardEvent):void {
if ( keyboardDisabled )
return;
if (event.keyCode == Keyboard.B) {
gotoAndPlay(252);}
if (event.keyCode == Keyboard.V) {
gotoAndPlay(259);
}
Then in the frame where your animation begin
keyboardDisabled = true;
And on animation end
keyboardDisabled = false;

Resources