Touch and Gestures with Xamarin Forms

Slides:



Advertisements
Similar presentations
Windows Basic and Dynamic Disk Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator Marian Marinov CEO of 1H Ltd.
Advertisements

Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
HTML Forms, GET, POST Methods Tran Anh Tuan Edit from Telerik Academy
Make swiftly iOS development Telerik Academy Telerik Academy Plus.
Amazon S 3, App Engine Blobstore, Google Cloud Storage, Azure Blobs Svetlin Nakov Telerik Software Academy academy.telerik.com.
RPN and Shunting-yard algorithm Ivaylo Kenov Telerik Software Academy academy.telerik.com Technical Assistant
Shortest paths in edge-weighted digraph Krasin Georgiev Technical University of Sofia g.krasin at gmail com Assistant Professor.
Telerik Software Academy Telerik School Academy.
Asynchronous Programming with C# and WinRT
Unleash the Power of JavaScript Tooling Telerik Software Academy End-to-end JavaScript Applications.
Telerik School Academy ASP.NET MVC.
Character sequences, C-strings and the C++ String class, Working with Strings Learning & Development Team Telerik Software Academy.
Hybrid or Native?! Doncho Minkov Telerik Software Academy Senior Technical Trainer
Done already for your convenience! Telerik School Academy Unity 2D Game Development.
Processing Sequences of Elements Telerik School Academy C# Fundamentals – Part 1.
With Mocha and Karma Telerik Academy Telerik Software Academy.
C# Fundamentals – Part I
Welcome to the JSON-stores world Telerik Software Academy Databases.
The Business Plan and the Business Model Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System Analyst Telerik Corporation.
What are ADTs, STL Intro, vector, list, queue, stack Learning & Development Team Telerik Software Academy.
Making JavaScript code by template! Learning & Development Team Telerik Software Academy.
Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training Who, What, Why?
Marketing Mix, SWOT Analysis and Stages of Developing an Idea Margarita Antonova Volunteer Telerik Academy academy.telerik.com Business System.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Processing Matrices and Multidimensional Tables Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Learning & Development Telerik Software Academy.
Reading and Writing Text Files Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Telerik Software Academy ASP.NET Web Forms.
Classical OOP in JavaScript Classes and stuff Telerik Software Academy
Optimization problems, Greedy Algorithms, Optimal Substructure and Greedy choice Learning & Development Team Telerik Software.
Using Selenium for Mobile Web Testing Powered by KendoUI Telerik QA Academy Atanas Georgiev Senior QA Engineer KendoUI Team.
NoSQL Concepts, Redis, MongoDB, CouchDB Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
New features: classes, generators, iterators, etc. Telerik Academy Plus JavaScript.Next.
Throwing and Catching Exceptions Tran Anh Tuan Edit from Telerik Software Academy
Loops, Conditional Statements, Functions Tran Anh Tuan Edit from Telerik Academy
With C# or “JavaScript” Telerik School Academy Unity 2D Game Development.
Concerned with communication (interaction) between the objects Telerik Software Academy High-Quality Code.
Private/Public fields, Module, Revealing Module Learning & Development Team Telerik Software Academy.
Building Data-Driven ASP.NET Web Forms Apps Telerik Software Academy ASP.NET Web Forms.
Telerik Software Academy End-to-end JavaScript Applications.
General and reusable solutions to common problems in software design Vasil Dininski Telerik Software Academy academy.telerik.com Intern at Telerik Academy.
Planning and Tracking Software Quality Yordan Dimitrov Telerik Corporation Team Leader, Team Pulse, Team Leader, Team Pulse, Telerik Corporation,
What you need to know Ivaylo Kenov Telerik Corporation Telerik Academy Student.
Data binding concepts, Bindings in WinJS George Georgiev Telerik Software Academy academy.telerik.com Technical Trainer itgeorge.net.
Pavel Kolev Telerik Software Academy Senior.Net Developer and Trainer
Objects, Properties, Primitive and Reference Types Learning & Development Team Telerik Software Academy.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Free Training and Job for Software Engineers Svetlin Nakov, PhD Manager Technical Training Telerik Corp. Telerik Software Academy.
Access to known folders, using pickers, writing to and reading from files, caching files for future access George Georgiev Telerik Software Academy academy.telerik.com.
Doing the Canvas the "easy way"! Learning & Development Telerik Software Academy.
Creating and Running Your First C# Program Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical Training
Course Overview Doncho Minkov Telerik Software Academy Technical Trainer
Data Types, Primitive Types in C++, Variables – Declaration, Initialization, Scope Telerik Software Academy academy.telerik.com Learning and Development.
The past, the present, the future Learning & Development Team Telerik Software Academy.
Learn to Design Error Steady Code Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
Connecting, Queries, Best Practices Tran Anh Tuan Edit from Telerik Software Academy
Processing Sequences of Elements Telerik Software Academy C# Fundamentals – Part 2.
Telerik JavaScript Framework Telerik Software Academy Hybrid Mobile Applications.
Telerik Software Academy Databases.
Things start to get serious Telerik Software Academy JavaScript OOP.
Learning & Development Mobile apps for iPhone & iPad.
Processing Matrices and Multidimensional Tables Telerik Software Academy C# Fundamentals – Part 2.
Nikolay Kostov Telerik Software Academy academy.telerik.com Team Lead, Senior Developer and Trainer
Functions and Function Expressions Closures, Function Scope, Nested Functions Telerik Software Academy
Implementing Control Logic in C# Svetlin Nakov Telerik Software Academy academy.telerik.com Manager Technical trainer
Inheritance, Abstraction, Encapsulation, Polymorphism Telerik Software Academy Mobile apps for iPhone & iPad.
Mocking tools for easier unit testing Telerik Software Academy High Quality Code.
What why and how? Telerik School Academy Unity 2D Game Development.
Windows Security Model Borislav Varadinov Telerik Software Academy academy.telerik.com System Administrator
Presentation transcript:

Touch and Gestures with Xamarin Forms Tap, Pinch and so on Xamarin apps for iOS, Android & WinPhone Telerik School Academy http://schoolacademy.telerik.com

Table of Contents Gestures overview Types of gestures Pinch, rotate, swipe, double tap, long press, tap, fling Using TapGestureRecognizer Adding support for other gestures

Touch and Gestures Overview

Touch & Gestures Touch is the main form of input used on mobile devices Every view is capable of handling Touch events Touches are actions the users perform with their fingers or stylus pen One-finger touches and multi-finger touches A gesture is a predefined combination of touch actions i.e. touch down and then touch move is called a Pan gesture

Types of Gestures Tap gesture Double tap gesture Long press gesture Like click but with a finger on a touch device Double tap gesture Like a double click but with a finger on a touch device Long press gesture Put a finger on the screen and hold it for a brief time

Types of Gestures Scroll gesture Pan gesture Flick/Swipe gesture Put a finger on the screen and move it up and down Pan gesture Put a finger on the screen and move it Flick/Swipe gesture Put a finger on the screen and move it really fast

Types of Gestures Pinch-in gesture Pinch-out/Zoom gesture Put two fingers on the screen and move them closer Pinch-out/Zoom gesture Put two fingers on the screen and move them further Rotate gesture Put two fingers on the screen and move one of them in a circle

Types of Gestures Every mobile platform supports these gestures Their names can vary Zoom is Scale on Android /WP8 and Pinch on iOS A good visual on the gestures can be found in Wikipedia: http://en.wikipedia.org/wiki/Multi-touch#Multi- touch_gestures

Gestures in Xamarin Forms Lets get practical

Gestures in Xamarin Forms Every Control in Xamarin form can handle gestures Labels, Buttons, StackLayouts, etc… Everything that descends from Xamarin.Forms.View Yet, as of December 2014, Xamarin Forms supports only Tap gestures Tap, Double tap, Triple tap, etc.. Other gestures must be implemented OS specific

INSERT XAML CODE HERE Handling Tap Gestures To handle a tap gesture in Xamarin forms, use TapGestureRecognizer Can be defined in code //other code var tapGesture = new TapGestureRecognizer(); tapGesture.Tapped += this.HandleTapGesture; view.GestureRecognizers.Add(tapGesture); Or with XAML INSERT XAML CODE HERE

Handling Tap Gestures Live Demo

Handling Other Gestures Like Long press, Pan and Pinch

Handle Other Gestures in Xamarin Forms To handle other gestures in Xamarin Forms: Inherit the control you need the gestures on i.e. if you want to add gestures to Label, create GesturedLabel Expose public events for the needed gestures Create a Renderer for each platform In the Renderer, handle the gestures and bubble them to your control

Handle Pinch on WP8 Inherit the Label in the SAP or PCL and expose public events public class GesturedLabel: Label { public event EventHandler<PinchEventArgs> Pinch; public void OnPinch(PinchEventArgs args); } Create a PinchEventArgs to hold the state of the gesture public class PinchEventArgs: EventArgs { public double ScaleFactor {get; set;} }

Handle Pinch on WP8 Create a Renderer for each platform Export it public class GesturedLabelWPRenderer : LabelRenderer { } Export it [assembly: ExportRenderer(typeof(GesturedLabel), typeof(GesturedLabelWPRenderer))] Override the OnElementChanged() method public override OnElementChanged(… e) { base.OnElementChanged(e); this.Control.ManipulationDelta += this.HandlePinch; }

Handle Pinch on WP8 In the Pinch handler: Get the scale factor And fire the OnPinch event we created on the GesturedLabel private void HandleManipulationDelta(object sender, ManipulationDeltaEventArgs e) { var gesturedLabel = this.Element as GesturedLabel; if (gesturedLabel == null) { return; } var pinchEventArgs = new PinchEventArgs { ScaleFactor = e.DeltaManipulation.Scale.X}; gesturedLabel.OnPinched(pinchEventArgs); }

Pinch Gesture on WindowsPhone Live Demo

Handle Long Press on Android Configuring gestures on Android is a little harder than on WindowsPhone A specific gesture listener must be created, to handle the events class GestureLabelListener :GestureDetector. SimpleOnGestureListener { public override void OnLongPress(MotionEvent e) var args = new TapEventEvents(e.GetX(), e.GetY()); this.Element.OnLongPress(args); base.OnLongPress(e); }

Handle Long Press on Android Then in the GesturedLabelAndroidRenderer: class GesturedLabelAndroidRenderer : LabelRenderer { readonly GestureDetector detector; readonly GesturedLabelListener listener; public GesturedLabelAndroidRenderer() { this.listener = new GesturedLabelListener(); this.detector = new GestureDetector(this.listener); } override void OnElementChanged(…) { // unregister events if e.NewElement is null var element = this.Element as GesturedLabel; this.listener.Element = element; this.GenericMotion += (snd, e) => this.detector.OnTouchEvent(e.Event); this.Touch += (snd, e) => this.detector.OnTouchEvent(e.Event);

LongPress Gesture on Android Live Demo

Handle Swipe Gesture on iOS

Swipe Gesture on iOS Live Demo

Touch and Gestures with Xamarin Forms http://academy.telerik.com