scnViewGesture.Plugin.Droid for xamarin forms - xamarin

I using scnViewGesture.Plugin for xamarin forms. LongTap is working as expected in iOS, but in the Android the LongTap event is not working. please share your inputs.

Why do you need a plugin to do this? Just handle the touch event, start a timer on the down event, clear the timer on the up event, and whenever a specified amount of time has passed on the timer, do whatever you wanted to do with the long touch on a separate thread.
For the record, I can't give you a better example because you've provided no code, and your question is extremely broad because of that.

Related

Xamarin Android Activities and Disposing of Disposables

I've found that whilst there are a lot of tutorials on Xamarin Android, there does not seem to be a great deal on how to dispose of resources. More particularly, when they are disposed of.
For example, in the OnCreate handler of an activity, I am making several Rx subscriptions, each of which returns an IDisposable. I have tried to dispose of those in various other handlers (e.g. OnDestroy), but those handlers never get invoked. But the subscriptions seem to pile up because OnCreate runs every time the activity is navigated to.
In addition to those subscriptions, there's all the UI controls (TextViews, Buttons etc.) which I am assigning to class-level variables (fields). And those also implement IDisposable.
For all I know, I've got memory leaks all over the place.
Is there a guidance on this anywhere?
#SushiHangover is correct (thanks Sushi). OnPause and OnResume were the events I was after. I also had a bit of a challenge in that when I clicked my custom "Back to Start" button, I needed to go right back to the start screen (skipping the intermediate screen along the way).
The way to do that is use the ClearTop ActivityFlag (Android.Content.ActivityFlags.ClearTop) when starting the Home screen activity. Raw Android code version of this can be seen here https://stackoverflow.com/a/5794572/540156
When you do that, you can clean things up on the activities which get popped off the back-stack as they get popped (in the OnDestroy handler, from recollection).

Xamarin.Forms equivalent to overriding iOS's SendEvent

I'm working on inactivity detection.
I have successfully done so in iOS by subclassing UIApplication and overriding SendEvent as outlined here.
I know I could implement this separately for both iOS and Android, but I'd rather have a cross-platform Forms approach by intercepting all touch events and resetting my timers. I'd rather not have to add a touch event handler to all my pages either.
I was unable to find a cross platform approach. I was able to accomplish this by leaving the timer related information in core Forms project and implement the touch event handlers separately for iOS and Android. I handled the iOS touch events as outlined in the link in the OP, but for Android I took the approach of subclassing Activity due to the presence of the OnUserInteraction() method.
Initially I thought I would have to force Xamarin to use my subclassed Activity for all pages that I use in Xamarin, but I was mistaken. AdamMeaney over on the Xamarin forums was able to help with providing a solution for the Android side of things with regards to subclassing an Android activity. As it turns out, Xamarin only uses one Activity which inherits from Xamarin.Forms.Platform.Android.FormsAppCompatActivity. I used the MainAcitivty provided by Xamarin in the Droid project. From there, overriding the OnUserInteraction() proved to be quite simple:
public override void OnUserInteraction()
{
base.OnUserInteraction();
//Do other stuff
}
It would seem to me that all you really have to do on the platform side is get notified whenever a new touch event occurs. Unless I am missing something it seems you can do all of the timer stuff in the PCL core Forms project and call that code from the platform specific code that runs when a touch is detected.
So if on Android ( I did not verify, but I would assume so) there is a similar way to handle any touch, device wide, then it would seem that all you have to do is implement that event handler, as you did for iOS, and call into your Forms core code to handle the timer(s).
To clarify: On the platform side, just handle the touch events globally and then call into code in the Forms core thus only having to implement the timer functionality once. Or so it would seem unless I am missing something.
If you want to make a feature request for Xamarin Form, please do so at Xamarin's user voice page: xamarin.uservoice.com
I suspect Forms would just have to do as outlined above... handle device wide touches on each platform and then have a virtual method in Forms core code that is called whenever a touch occurs.

Appcelerator controller appear/disapear methods

I'm pretty new to Appcelerator and was wondering what the listeners for the view life cycle are?
For example, if I wanted to detect the iOS viewWillAppear and viewDidDisappear methods, or Androids OnResume, OnPause methods, then how would I do this the "Appcelerator" way?
I've searched around on the web, but only able to find in the Titanium documentation info about the application state such as Active, Suspended, ect. I need a controller, or window, specific listener to react to.
Thanks!
Titanium abstracts those events for you - so you don't have to worry about writing them for iOS/Android each.
Check out the Titanium.App documentation (http://docs.appcelerator.com/platform/latest/#!/api/Titanium.App). You can see what events are available at the app level (of course, each Titanium components has it's own events - but those are at app level).
If I understand your question, the relevant events for you are paused and resumed - when the app goes in the background and then back to foreground.

Time or duration control?

In my application the users needs to be able to enter a duration, consisting of minutes and seconds.
I am thinking of something like the control used in Windows to change the time, though I only need minutes and seconds and also the arrows would be nice, but are not necessary.
Is there already a control for this in JavaFX 2?
If not, how can I create such a control?
A screenshot of the mentioned Windows control:
Thanks for any hint!
Unfortunately there is no such control in standard JavaFX 2.
Although you can try to look at Spinner control from JFXtras project: http://jfxtras.org/
And intergrate it with TextEdit filtering approach described here: What is the recommended way to make a numeric TextField in JavaFX?
Nice implementation of spinner, though you need to adjust it to handle time inputs.
JavaFX NumberTextField and Spinner Control.

Tap and Hold (Long Press)

Has anyone implemented Tap & Hold in a Windows Phone 7 App yet? I can see a couple of possible approaches KeyDown/KeyUp and a timer or ManipulationStarted/manipulationCompleted and a timer.
However it strikes me that this is a less than idea approach because different apps would have different timer settings leading to inconsistency.
Am I missing something? I was hoping for a TapAndHold event
For all views Hold method is there.
It will handle long press function.
Silverlight Toolkit for Windows Phone adds easy to use gestures support, including On Hold gestures
I'm in the same situation, and I'm looking for "the recommended way". In the meantime, Mike Francis posted a solution on his blog, using Microsoft.Xna.Framework.Input.TouchPanel's gesture recognition within a Silverlight app. I didn't try it.
Start the Timer on Hold Event of GestureLister
and stop it on GestureCompleted event this is really a trick see detail answer on following link
How do I detect when toolkit:GestureListener Hold has stopped?
Button b = new Button();
b.Hold += new EventHandler<System.Windows.Input.GestureEventArgs>(HoldEventHandler);
The above code should work for touch and hold event

Resources