How to detect Swipe in a PlayN app - playn

I'm trying to detect a swipe gesture on a game developed with PlayN and Tripleplay libraries.
I did some experiment using tripleplay.gesture package but I don't understand how to use it.
Is there any example?
Thank you
Giovanni

I found a solution that works well. I hope it can be useful to someone (although I think that unfortunately there are few of us still using PlayN)
if (touch().hasTouch()) {
platform().setPropagateEvents(true);
final Swipe swipe = new Swipe(Gesture.Direction.LEFT);
swipe.completed().connect(new UnitSlot() {
#Override
public void onEmit() {
PlayN.log().info("Swipe");
UIController.getInstance().toggleScreen();
}
});
Touch.LayerListener tll = new GestureDirector(
new Rectangle(
0,
0,
layerWidth,
layerHeigth
), UIController.getTimer()).add(swipe);
layer.addListener(tll);
}

Related

JavaFX not available, what now?

I have a JavaFX application, but when people try to run it nothing happens because they got no JavaFX on their system, because they are using OpenJDK for example.
What can I do to inform people about the problem?
Best way would be to have an Alert informing the user about that, is there a way to do this with basic Java functionality?
You can use a Swing App to start and check if Java FX is avalaible like this:
private static boolean isJavaFxAvalaible() {
try {
ClassLoader.getSystemClassLoader().loadClass("javafx.application.Application");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
If this is true, just load your Main JavaFX, here's an example:
Launch JavaFX application from another class
hope this can help you.

Creating a "toast"

I have been trying to get similar functionality to an Android "toast" using Xamarin forms. After looking around, I found what I think is a good solution. The general approach appears to be to make a new Absolute layout, and make it appear for a set time, then disappear. While I think I generally understand what is being done, I can't seem to get it to work. Can anyone suggest how I would use this class if I want to make a toast appear in my MainPage? Should I be adding an AbsoluteLayout in the XAML file? Sorry, I'm sure this is a simple question, but I can't really figure out what to do...
Any help would be greatly appreciated!
public static class Popper
{
public async static Task Pop (string message, AbsoluteLayout attachLayout, int showforMilliseconds = 1500)
{
var container = new StackLayout
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
BackgroundColor = Color.FromHex ("#DDEFEFEF"),
Padding = 10
};
var label = new Label
{
Text = message,
FontAttributes = FontAttributes.Bold,
Style = (Style)Application.Current.Resources["PopupText"]
};
container.Children.Add (label);
container.Scale = 0;
container.Opacity = 0;
attachLayout.Children.Add (container, attachLayout.Bounds, AbsoluteLayoutFlags.PositionProportional);
container.ScaleTo (1.0f, 100);
container.FadeTo (1.0f, 100);
await Task.Delay (showforMilliseconds);
container.ScaleTo (0.0f, 250);
await container.FadeTo (0.0f, 250);
attachLayout.Children.Remove (container);
}
}
On Android you don't have to reinvent the wheel since Toast exists natively. On other platforms there is no such thing like Toast, therefor there is no silver-bullet solution here. This problem have been solved by multiple people in multiple ways, thats why I left a comment that your question might be a duplicate of existing thread with multiple examples.
Now about your idea. Your implementation is working, however it will show Toast only on an AbsoluteLayout. Why to set such a restriction? If you will recheck the link I shared in comments you will find a more appropriate and elegant solutions.
I can't seem to get it to work.
All you need is a an AbsoluteLayout on your page so you could call your method:
await Popper.Pop("Hello world", referenceToYourAbsoluteLayout, 5000);
If you still for some reason want to stick to this exact solution, maybe it will make sense to have an extension method instead. However this solution just does not make sense for the average user.
P.S: Once again, please check the existing thread for more information and details.
P.S.S: Usage example of your code snippet
<!-- XXXPage.xaml -->
<?xml version="1.0" encoding="utf-8"?>
<ContentPage
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XXX"
x:Class="XXX.XXXPage">
<AbstractLayout x:name="myLayout />
</ContentPage>
// XXXPage.xaml.cs
public partial class XXXPage : ContentPage
{
public Test999Page()
{
InitializeComponent();
}
async protected override void OnAppearing()
{
base.OnAppearing();
await Popper.Pop("Hello world", myLayout, 5000);
}
}

How to migrate a clickable Frame with ripple touch to Xamarin.Forms 2.5?

I have implemented a clickable Frame in Xamarin.Forms 2.3.4 with a custom FrameRenderer that set Clickable (and LongPressable FWIW) to true, subscribed the respective events and set the FrameRenderers foreground
TypedValue typedValue = new TypedValue();
this.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true);
this.Foreground = this.Resources.GetDrawable(typedValue.ResourceId, this.Context.Theme);
to achieve Material motion (ripple touch).
After updating to XF 2.5 (most likely as of 2.3.5, since fast renderers have been introduced with that release) my touch events have ceased to work. My custom renderer is assigned correctly, so are the Clickable and LongPressable properties, but nothing happens. Partially I have been able to work around the issue - at least for the moment - by subscribing to FrameRenderer.Touch and call OnClick from that event handler. This renders the app usable, but unfortunately lacks the visual feedback in form of the ripple touch effect.
Is there any way I can restore the original behavior? Is there any way to implement a clickable frame with ripple touch in XF 2.5?
With the help of this answer I have figured out a solution. Here's a draft of it:
First of all I store a local reference to my RippleDrawable (see documentation)
private void SetMaterialMotion()
{
TypedValue typedValue = new TypedValue();
this.Context.Theme.ResolveAttribute(Android.Resource.Attribute.SelectableItemBackground, typedValue, true);
this.Foreground = this.Resources.GetDrawable(typedValue.ResourceId, this.Context.Theme);
this._layerDrawable = this.Foreground as RippleDrawable;
}
then I have to subscribe to the Touch event
private void SubscribeClickEvent()
{
if (this.ClickableFrame.IsClickable)
{
this.Touch += ClickableFrameRenderer_Touch;
}
}
In my ClickableFrameRenderer_Touch I set the Pressed property and the hotspot of the RippleDrawable
private void ClickableFrameRenderer_Touch(object sender, TouchEventArgs e)
{
if(e.Event.Action == Android.Views.MotionEventActions.Down)
{
this.Pressed = true;
}
if(e.Event.Action == Android.Views.MotionEventActions.Up)
{
this._layerDrawable.SetHotspot(e.Event.GetX(), e.Event.GetY());
this.Pressed = false;
}
}
This will show the ripple touch motion (more or less) as expected. Of course this does not handle long presses, yet, but I'm on a way.
Anyway, this is not a solution I like very much. I still think that there has to be a supported way on making FastRenderers.FrameRenderer clickable. If anyone knows it: Please share your knowledge.

How to disable right click in jxbrowser

I am loading a webpage in jxbrowser in java swing, I want to block or disable right click on that page, I searched but not got the answer, please let me know if any one has any suggestion.
Thanks
After a long search, finally I have a working solution for disabling right click
final Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
view.setMouseEventsHandler(new InputEventsHandler<MouseEvent>() {
#Override
public boolean handle(MouseEvent arg0) {
if(arg0.getButton() == MouseEvent.BUTTON3)
return true;
return false;
}
});
The latest JxBrowser has major API changes. If you are using 7.* or above the approach is as follows.
browser.set(MoveMouseWheelCallback.class, params -> Response.suppress());
Available Callbacks
EnterMouseCallback
ExitMouseCallback
MoveMouseCallback
MoveMouseWheelCallback
PressKeyCallback
PressMouseCallback
ReleaseKeyCallback
ReleaseMouseCallback
TypeKeyCallback
Links
What's New
API Documentation

Eclipse Rap no focus on a button

I have a problem with Focusable Buttons on Eclipse Rap. I have defined some Toogle buttons with some css style when your mouse is over it, with it is selected and when it is not. The thing is the focus on the button is making it look odd.
I have tried
btnAnimals = new Button(panel, SWT.TOGGLE | SWT.NO_FOCUS);
with no exit. And finally I decided to implement a FocusAdapter for the buttons:
FocusListener focusListener = new FocusAdapter() {
#Override
public void focusGained(FocusEvent event) {
txtStreet.setFocus();
}
};
btnAnimals.addFocusListener(focusListener);
The strange issue that this listener is only called ONCE. Do you know what I am doing wrong? Is it a bug?
Thanks in advance
After asking in Eclipse Rap Forum, they give me the propper answer and it is to use RWT Theming:
Button-FocusIndicator {
border: none;
}
Hope that helps ;)

Resources