Technical Article

Windows Phone 7™ Gestures Compared

Lab version: 1.0.0

Last updated: August 25, 2014

Contents

Overview 3

Objectives 3

Introduction to Gestures 3

Phone Operating System Flavors 4

Creating a Gesture-Aware Application 7

Raw Touch Information 9

Summary 10

Overview

Windows Phone 7 introduces gestures as part of the operating system.

This technical article compares ideas about gestures and their implementation across several phone operating systems, focusing on Windows Phone 7 as a reference.

Objectives

When you’ve finished the article, you will have:

· A high-level of understanding about gestures used by phone operating systems.

· A clear view of the ways that gesture implementations differ across resistive and capacitive touch screens, and across various phone operating systems.

· A knowledge of  how to implement gesture-aware applications in Windows Phone 7.

Introduction to Gestures

Handheld devices and, in particular, smart–phone devices, have evolved over the years to use touch screen interaction. The primary user interface evolved from stylus-operated devices—with or without the need for additional hardware buttons—to finger-based touch screens over resistive touch screen hardware by using the human finger as a "big stylus." Since resistive screens rely on the application of firm pressure, these input devices had to settle for press/long press/release operations, and had little use for drag-and-drop actions.

Dragging an object with a finger over a resistive touch screen is a frustrating task. Why? Because during the drag operation we instinctively tend to release some of the pressure from the screen and drop the dragged object too soon.  Moreover, resistive touch screens are capable of detecting only a single touch point, thereby limiting the possible actions the user can perform.

Capacitive touch screens

The recent use of capacitive touch screen hardware in phones has allowed the user to have better control over the location of the selecting finger. The hardware detects the touch location—regardless of the amount of pressure applied to the screen—by applying a tiny amount of electrical current through the finger, and then by calculating the position accordingly.

Because of their hardware implementation, capacitive screens, unlike older resistive touch screens, support multiple touch locations. Capacitive screens provide for a multitouch experience and unlock a wide range of innovative gestures that users can apply to control applications.

New interaction possibilities

In addition to using an input method to select and then drag an object on the screen, we can use capacitive touch screens to hold, pinch, rotate, enlarge, and throw away an object, and so on.

These input methods, known as gestures, are virtual actions that the user applies to the phone screen. The hardware determines the type of gesture based on the location, velocity, and direction of each finger touching the screen.

Phone Operating System Flavors

As of today, three major phone operating systems employ gestures: Apple iOS™, Google Android™, and Microsoft Windows Phone 7.

Because there is no uniform standard for gestures, each operating system has its own set of gestures.  Some gestures conform to other operating systems, some gestures do not.

Next is a review of the differences among operating systems with regard to gesture support.

Apple iOS gesture set

Apple iOS, used mainly on iPhone™, iPad™, and iPod touch™ devices, supports the following gestures:

Tap – Press or select a screen object–a brief touch within a bounded area on the screen.

Double tap – Two rapid sequential taps on the same object.

Swipe – Move a finger across the screen and raise it without stopping.

Drag/pan – Hold the finger over a screen object and move it around.

Pinch – Hold two fingers on the screen, and in a relatively straight, virtual line move toward (pinch in) or away from (pinch out) each other.

Rotate – Hold two fingers on the screen and move them in opposite directions on different virtual lines; one finger acts as a center while the other circles around it.

Apple iOS 4 introduces two new gestures:

Long press – Touch a screen object without releasing.

Three-finger tap

Google Android™ gesture set

Google Android™ takes a different approach to gestures. The basic set is limited, but the operating system also enables you to create new gestures into gesture sets that can be used later within applications.

The basic set includes:

Single tap – Press or select a screen object.

Double tap – Two rapid sequential taps on the same object.

Down – Touch a spot on the screen with a finger. This is the first phase of a tap, fling, or another gesture.

Up – Finger no longer touches the screen. This is the last phase of a tap, fling, or another gesture.

Fling – Move a finger across the screen and raise the finger without stopping.

Long press – Touch a screen object without releasing it.

Scroll – Hold the finger over a screen object, and then move the finger.

Windows Phone 7 gesture set

Windows Phone 7 supports the following gestures:

Tap – Press or select a screen object—a brief touch within a bounded area on the screen.

Double tap – Two rapid sequential taps on the same object.

Pan – Hold a finger on the screen and move it around.

Flick – Move a finger across the screen and raise the finger without stopping (in-motion). This gesture may be used to create kinetic movements, and can follow a pan gesture.

Touch and hold – Touch a screen object for a defined time.

Also, the following gestures are supported for multitouch:

Pinch – Hold two fingers on the screen,  and move the fingers toward each other.

Stretch – Hold two fingers on the screen, and move the fingers away from each other.

Similarities and differences

Windows Phone 7 gestures are compared to the gestures of the other two operating systems in the following table.

Table 1. Gesture comparison

Gesture

name

 

Illustration

Windows Phone 7 usage

Apple iOS equivalent

Google Android equivalent

Tap

Select an object

-  or -

Stop any content from moving on the screen

Tap

Tap

Double tap

Toggle between in and out zoom states

Double tap

Double tap

Pan

Move ("drag") an object on the screen to a different location

Drag/pan

Scroll

Flick

Move the whole canvas in any direction

Swipe

Fling

Touch and hold

Display context menu or option page for an item

Long press

Long press

Pinch

Zoom out

- or –

Diminish an object

(depending on the application)

Pinch

No standard gesture

Stretch

Zoom in

- or –

Enlarge an object

(depending on the application)

Pinch

No standard gesture

Creating a Gesture-Aware Application

In order to create a gesture-aware application in Windows Phone 7 under XNA, we first must know how Windows Phone 7 exposes gestures to the programmer. Once we know how gestures are exposed,  we used programmable gestures to define which gestures are allowed for our application, to sample incoming gestures, and to react to them.

Programmable gestures

Windows Phone 7 breaks the above logical gestures into more elaborate programmable gestures, as follows:

Table 2. Logical vs. programmable gestures

Logical gesture

Programmable gestures

Notes

Tap

Tap

Double tap

Double tap

Pan

FreeDrag (holding and moving in any direction), or HorizontalDrag (as the name implies), or VerticalDrag (as the name implies) gesture, followed by a DragComplete gesture.

Pan is achieved by starting with the detection of a drag gesture and ending with the detection of the DragComplete gesture.

An application may limit the user to horizontal only, to vertical only, to both horizontal and vertical, or to free drag types.

Flick

Flick

A flick may be detected following a drag gesture set, and should be treated accordingly.

Touch And Hold

Hold

Pinch

Pinch gesture followed by a PinchComplete gesture.

Both pinch and stretch logical gestures are achieved by programmable Pinch/PinchComplete gesture set, where the changing deltas between the touch points allow the programmer to determine if a pinch or a stretch is being performed.

Stretch

Pinch gesture followed by a PinchComplete gesture.

Both pinch and stretch logical gestures are achieved by programmable Pinch/PinchComplete gesture set, where the changing deltas between the touch points allow the programmer to determine if a pinch or a stretch is being performed.

Enabling desired gestures

Assuming we already have an XNA Windows Phone 7 Game project open in Visual Studio 2010, we should instruct the framework to enable the desired gestures in our application.
As described in the previous section, XNA allows the programmer to define which gestures the application is capable of consuming, thus allowing the user to perform those gestures. There might be a case, for example, where you would like to disallow FreeDrag/VerticalDrag gestures in your application.  You may, however, want to allow HorizontalDrag or to support the Flick gesture.

In order to define the above instruction, we would use the namespace Microsoft.Xna.Framework.Input.Touch to access the static class TouchPanel. Within this static class, we then would access the static (Flags enumeration) property EnableGestures and set it to the desired set of enabled gestures.

Gestures must be enabled before we can use them. Thus, TouchPanel.EnabledGestures must be set to the appropriate set of gesture types before calling TouchPanel.IsGestureAvailable or TouchPanel.ReadGesture (both are described later in the article) for the first time.

The following example shows how to allow Tap, DoubleTap, and Hold touch gestures, and to disallow all the rest:

C#

TouchPanel.EnabledGestures = GestureType.Tap |

GestureType.DoubleTap |
                             GestureType.Hold;

Waiting for a gesture and reacting accordingly

We now want to detect and react to incoming gestures. To do this, we sample the current gestures from within the XNA project Update override method. We test if new gestures are available by checking the Boolean property TouchPanel.IsGestureAvailable. Next, we sample the gestures, and then react accordingly.

When true is returned, we know that there are new gestures waiting to be sampled.  We then call the TouchPanel.ReadGesture method, which returns an instance of the GestureSample class. The returned GestureSample class instance holds a sample of the detected gesture, supplying various information such as the type and location of the gesture, and identification of the deltas between touch points (for multitouch gestures). In the following code example, the Boolean property is tested, a sample is acquired, and information is collected into a string for later display:

C#

string infoMessage = "";

while (TouchPanel.IsGestureAvailable)

{

GestureSample gestureSample = TouchPanel.ReadGesture();

infoMessage += String.Format("Type: {0}\nFirst touch point position: {1},{2};

Delta: {3},{4}\nSecond touch point position: {5},{6}; Delta: {7}, {8}\n",

gestureSample.GestureType,

gestureSample.Position.X, gestureSample.Position.Y,

gestureSample.Delta.X, gestureSample.Delta.Y,

gestureSample.Position2.X, gestureSample.Position2.Y,

gestureSample.Delta2.X, gestureSample.Delta2.Y);

}

Special considerations

A single gesture on the screen will create a few subsequent gestures to sample. For example, a DoubleTap gesture always will be preceded by a Tap gesture located near the succeeding DoubleTap gesture. When coding against gestures in XNA Framework, such subsequent gestures must be considered when reacting to incoming gestures.

Raw Touch Information

Gestures are not always required in our applications. Sometimes we only need to know where user’s fingers are on the screen at any given moment.

This could be compared to registering a MouseClick event on a standard Windows application, or registering MouseDown and MouseUp events.

A MouseClick event represents the combination of subsequent MouseDown and MouseUp events at the same location. Registering to the raw MouseDown or MouseUp events allows us to make our own decisions about what the user is trying to do.

Reading raw touch information

In order to react to raw user activities, we call the static method TouchPanel.GetState from within the project's Update override method. The static method returns an instance of the TouchCollection structure, holding a collection of touch locations (each represented by the TouchLocationstructure). The collection holds one instance of the structure for each finger touching the screen.

Using the raw method requires the programmer to watch closely for touch screen changes, and to interpret them accordingly.

The following code example runs within the Update override method, gets the current touch state, tests if there are any current touched positions, and collects the information into a string for later display:

C#

string infoMessage = "";

TouchCollection touchLocations = TouchPanel.GetState();

if (touchLocations.Count > 0)

{

infoMessage = String.Format("Detected {0} touch points at the following locations:\n",

touchLocations.Count);

for (int i = 0; i < touchLocations.Count; i++)

infoMessage += string.Format("{0}. {3} at {1}, {2};\n", i, touchLocations

[i].Position.X, touchLocations [i].Position.Y, touchLocations [i].State);

}

Summary

Gestures are an exciting new way for applications to interact with the user under Windows Phone 7, employing the power of capacitive touch screen hardware.

Programming gesture-aware applications against the XNA Framework is quite simple and straightforward.

Instead of having to interpret and calculate touch locations over time, the programmer may rely on the XNA Framework to do the major part of the work interpreting standard gestures, leaving the special application logic to implement. Nevertheless, the programmer may still use the raw touch input detection method when required, and combine these two methods where needed.

Gestures_Article_4_0的更多相关文章

随机推荐

  1. uva 437 巴比伦塔(DAG上dp)

    巴比伦塔 紫书P269 看完紫书,终于可以自己写一个dp了 :) [题目链接]巴比伦塔 [题目类型]DAG上dp &题意: 有n种立方体 n<=30,每种有无穷个,要求选一些立方体摞成一 ...

  2. C#(类)

    一.String类 string s = " abCDefgb ";int a = s.Length;//获取长度 Console.WriteLine(s.Length); Con ...

  3. 转--2014年最新810多套android源码2.46GB免费一次性打包下载

    转载自:http://www.eoeandroid.com/thread-497046-1-1.html 感谢该博客主人无私奉献~~ 下面的源码是从今年3月份开始不断整理源码区和其他网站上的安卓例子源 ...

  4. ylbtech-dbs-m-QQ邮箱

    ylbtech-dbs:ylbtech-dbs-m-QQ邮箱 -- =============================================-- DatabaseName:QQ-Em ...

  5. 微信支付开发若干问题总结,API搞死人(谢谢ζั͡ޓއއއ๓http://www.thinkphp.cn/code/1620.html)血淋淋的教训,第二次栽这里了

    近日,我研究了微信支付的API,我是用简化版的API,首先简述一下流程: 1.通过APP_ID,APP_SCRECT获取网页授权码code, 2.利用code获取用户openid/userinfo 3 ...

  6. GC之一--GC 的算法分析、垃圾收集器、内存分配策略介绍

    一.概述 垃圾收集 Garbage Collection 通常被称为“GC”,它诞生于1960年 MIT 的 Lisp 语言,经过半个多世纪,目前已经十分成熟了. jvm 中,程序计数器.虚拟机栈.本 ...

  7. 不容错过错的xcode 插件 转至于cocoachina

    古人云“工欲善其事必先利其器”,打造一个强大的开发环境,是立即提升自身战斗力的绝佳途径!以下是搜集的一些有力的XCode插件.   1.全能搜索家CodePilot 2.0 你要找的是文件?是文件夹? ...

  8. vi命令的使用

    <转:http://linux.vbird.org/linux_basic/0310vi.php> 基本上 vi 共分为三种模式,分别是『一般模式』.『编辑模式』与『指令列命令模式』. 圖 ...

  9. 【在线】Actionbar Style Generator:ActionBar风格生成器

    这个ActionBar风格生成器可以让你轻松地创建一个简洁.有吸引力且无漏洞的自定义actionbar.它会生成所有9种必须的patch assets以及相关XML的drawables和styles文 ...

  10. LeetCode 67. Add Binary

    Given two binary strings, return their sum (also a binary string). For example,a = "11"b = ...