Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Working with LongTapDetector API - S60 Touch UI

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibility
Platform(s):
S60 5th Edition
Article
Created: kiran10182 (02 Nov 2008)
Last edited: hamishwillee (08 Feb 2012)

Contents

Overview

The S60 5th edition includes Long Tap detector concept to handle long tap events. Long tap event occurs when the stylus is held down for a specific time on the screen or on the item on the screen.

What is Long Tap Detector API

The S60 5th edition platform includes CAknLongTapDetector to receive long tap events. When the stylus is held down in the same position, an animation starts after a default set time of 0.15 seconds to show that the long tap functionality has started. The animation is provided by AVKON and cannot be changed by the application or control. However, animation can be turned off through the EnableLongTapAnimation from the CAknLongTapDetector class.


LongTapDetector.png

Implementing Long Tap Detector functionality

LongTapDetectorAppView.h

  • We will inherit our class from MAknLongTapDetectorCallBack interface and implement its pure virtual method HandleLongTapEventL() method to receive long tap events.
  • Declare object of CAknLongTapDetector and use it to set observer for this class and handle long tap detection pointer events.
....
#include <aknlongtapdetector.h>
....
// CLASS DECLARATION
class CLongTapDetectorAppView : public CCoeControl, MAknLongTapDetectorCallBack
{
.....
// From MAknLongTapDetectorCallBack
virtual void HandleLongTapEventL(const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation);
.....
private:
CAknLongTapDetector* iLongTapDetector;
......
};

LongTapDetectorAppView.cpp

  • Set "this" class to receive long tap detection events in the ConstructL() as shown below.
// -----------------------------------------------------------------------------
// CLongTapDetectorAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CLongTapDetectorAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
......
......
iLongTapDetector = CAknLongTapDetector::NewL(this);
.....
}
  • You can change Long tap delay as per your requirements. By default it is 0.8 seconds.
void CLongTapDetectorAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
......
......
iLongTapDetector = CAknLongTapDetector::NewL(this);
iLongTapDetector->SetLongTapDelay(5000000); // Long tap delay is set to 5 seconds in this example. Defualt is 0.8 seconds
.....
}
  • You can change delay before animation as per your requirements. By default it is 0.15 seconds.
void CLongTapDetectorAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
......
......
iLongTapDetector = CAknLongTapDetector::NewL(this);
iLongTapDetector->SetTimeDelayBeforeAnimation(2000000); // Delay before animation is set to 2 seconds in this example. Defualt is 0.15 seconds
.....
}
  • Handle pointer events in HandlePointerEventL as shown below.
// -----------------------------------------------------------------------------
// CLongTapDetectorAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// -----------------------------------------------------------------------------
//
void CLongTapDetectorAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Pass the pointer event to Long tap detector component
iLongTapDetector->PointerEventL(aPointerEvent);
 
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
  • Long tap events should be handled in the HandleLongTapEventL() callback function from MAknLongTapDetectorCallBack
  • Both the arguments in the HandleLongTapEventL will give points of the event occurrence with respect to the following points:
    • aPenEventLocation gives Long tap event location relative to parent control.
    • aPenEventScreenLocation gives Long tap event location relative to screen.
void CLongTapDetectorAppView::HandleLongTapEventL(const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation)
{
// Here in this example a simple information note is displayed
CAknInformationNote* info = new (ELeave) CAknInformationNote;
info->ExecuteLD(_L("Really Long one"));
}
  • Make sure to delete iLongTapDetector in the destructor of the class.
 
// -----------------------------------------------------------------------------
// CLongTapDetectorAppView::~CLongTapDetectorAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CLongTapDetectorAppView::~CLongTapDetectorAppView()
{
.....
.....
if(iLongTapDetector)
delete iLongTapDetector, iLongTapDetector = NULL;
.....
}

Things to keep in mind with Carbide and its UI designer

When using Carbide in UI designer mode, a few things must be kept in mind:

VERY IMPORTANT: WHEN USING THIS IN COMBINATION WITH A CARBIDE-GENERATED UI SYSTEM, BY ALL MEANS CHECK WHICH CLASS IS DERIVED FROM CCOECONTROL! This tutorial tells you to do it with the View class, but in your example, it will likely be the Container!

Furthermore, the popup menu event will probably not work out well as any Carbide-created List Box Selected commands will fire immediately afterwards, possibly voiding whatever you want to achieve (especially if its a popup menu).

To prevent this, create a global variable TBool, and set it to false on ConstructL.

Then, set it to true on Long Tap:

 void foo::HandleLongTapEventL(const TPoint& aPenEventLocation, const TPoint& aPenEventScreenLocation)
{
//
long_tap=true;
}

In list selector, add the following:

 void CLocaNoteListView::HandleLstFilesItemClickedL( CEikListBox* aListBox, TListBoxEvent anEventType )
{
// TODO: implement itemClicked event handler (if an item gets clicked)
if(long_tap==true)
{
long_tap=false;
return;
}
//rest of code
...
}

If you have multiple selected routines, make one bool variable each!

Things to keep in mind when implementing a list item popup

In case you want to implement this as a per-item popup of a list (think rightclick/context menu on Windows), you will face an issue if the list is not full: the user can tap in list space where no item is and still bring up the contect menu.

To prevent this, change the code routine as follows:

void CLocaNoteListView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
// Pass the pointer event to Long tap detector component
if( aPointerEvent.iPosition.iY < (Rect().iTl.iY + LstFiles()->ItemHeight() * LstFiles()->Model()->ItemTextArray()->MdcaCount() ))
iLongTapDetector->PointerEventL(aPointerEvent);
}
 
....

Useful functions

CAknLongTapDetector

  • PointerEventL()
  • EnableLongTapAnimation()
  • SetLongTapDelay()
  • SetTimeDelayBeforeAnimation()

MAknLongTapDetectorCallBack

  • HandleLongTapEventL()

Keywords

Headers

  • #include <aknlongtapdetector.h>

Classes

  • CAknLongTapDetector
  • MAknLongTapDetectorCallBack

Libraries

  • avkon.lib

Example Application

Related links

Reference list

This page was last modified on 8 February 2012, at 04:25.
41 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×