Contents |
Tactile Feedback API is a new feature offered by S60 5th edition Touch UI concept for giving a feeling of touch on the screen. The device will respond to the touch inputted by the end user. The Feedback could be in the form of sound or vibration or both. In this article we will learn how to play with Tactile Feedback API with different methods.
Tactile Feedback works in two ways, when the user touches the screen or when the user touches any control on the screen. On S60 5th edition platform, most of the UI components has inbuilt feature of Tactile feedback.
From the user experience perspective, care should be taken while implementing Tactile Feedback functionality in the applications.
In the above figure, we will be sending feedback when the pointer event occurs inside the label control's hit region.
...
...
#include <touchfeedback.h>
#include <eiklabel.h> // For label component
// CLASS DECLARATION
class CTactileFeedbackAppView : public CCoeControl, MCoeControlHitTest
{
....
....
//For label control
TInt CountComponentControls() const;
CCoeControl* ComponentControl(TInt aIndex) const;
//From MCoeControlHitTest
TBool HitRegionContains( const TPoint& aPoint, const CCoeControl& /*aControl*/ ) const;
private:
....
....
MTouchFeedback* iTouchFeedback; // For Tactile feedback
CEikLabel* iLabel; // For Label Control
};
// -----------------------------------------------------------------------------
// CTactileFeedbackAppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CTactileFeedbackAppView::ConstructL(const TRect& aRect)
{
// Create a window for this application view
CreateWindowL();
_LIT(KTextHelloWorld, "hello world");
iLabel = new (ELeave) CEikLabel;
iLabel->SetContainerWindowL( *this );
iLabel->SetTextL(KTextHelloWorld);
iLabel->SetHitTest(this);
// Set the windows size
SetRect(aRect);
iTouchFeedback = MTouchFeedback::Instance();
}
// ---------------------------------------------------------------------------
// From class MCoeControlHitTest.
// Check if a pointer event occurred inside the label region
// ---------------------------------------------------------------------------
//
TBool CTactileFeedbackAppView::HitRegionContains( const TPoint& aPoint, const CCoeControl& /*aControl*/ ) const
{
return iLabel->Rect().Contains( aPoint );
}
// -----------------------------------------------------------------------------
// CTactileFeedbackAppView::HandlePointerEventL()
// Called by framework to handle pointer touch events.
// -----------------------------------------------------------------------------
//
void CTactileFeedbackAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent)
{
TPoint point = aPointerEvent.iPosition;
if(aPointerEvent.iType == TPointerEvent::EButton1Down)
{
if( HitRegionContains( point, *iLabel ))
iTactileFeedback->InstantFeedback(ETouchFeedbackBasic);
}
// Call base class HandlePointerEventL()
CCoeControl::HandlePointerEventL(aPointerEvent);
}
// -----------------------------------------------------------------------------
// CTactileFeedbackAppView::SizeChanged()
// Called by framework when the view size is changed.
// -----------------------------------------------------------------------------
//
void CTactileFeedbackAppView::SizeChanged()
{
iLabel->SetExtent( TPoint(0,0), iLabel->MinimumSize());
}
TInt CTactileFeedbackAppView::CountComponentControls() const
{
return 1; // return number of controls inside this container
}
CCoeControl* CTactileFeedbackAppView::ComponentControl(TInt aIndex) const
{
switch ( aIndex )
{
case 0:
return iLabel;
default:
return NULL;
}
}
// -----------------------------------------------------------------------------
// CTactileFeedbackAppView::~CTactileFeedbackAppView()
// Destructor.
// -----------------------------------------------------------------------------
//
CTactileFeedbackAppView::~CTactileFeedbackAppView()
{
if(iLabel)
delete iLabel, iLabel = NULL;
}
No related wiki articles found