Bulk Emailing

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Wednesday, 4 August 2010

Region Handling in Android Canvas

Posted on 22:44 by Unknown
In my previous post I have shared an Image Geo Tagging application for Android. A very important concept of Canvas Region handling was used in that application and thought lets discuss more on that concept. The concept of Region can be used in User Click event handling for any Canvas based drawing and Custom View.

Region is a section of Canvas area- its shape can be rectangular or non rectangular (i.e. circle, triangles, multi-phased polygons etc.). Android provides android.graphics.Region class, which has a very important and useful method contains(int x, int y);which easily detects whether your click event on the screen falls within the region or not. x and y are the co-ordinate position on the Screen.

How I can use it-
Suppose you have created a custom View and want to do specific operations depending upon which portion of screen user has clicked. Lets explain this with following screen shot-

Above screen is from my application (Image Geo Tagging for Android). Each Pin and its associated image thumbnail popups are part of a single Custom Overlay. Each Custom Overlay instance needs to detect when user has clicked on Pin and Popup, so that it can take appropriate action.

To handle this, we have to define 2 regions-
Region pinRegion = new Region (x1, y1, x1 + pinIcon.getWidth, y1 + pinIcon.getHeight());
Region popupRegion = new Region (x2, y2, x2 + popUpWidth, y2 + popUpHeight);

You need to now overwrite onTouchEvent( MotionEvent e, MapView mapView) method to get user Click events. Get the (x, y) co-ordinates from MotionEvent instance and use the magic function contains(x, y) e.g. pinRegion.contains(x, y) and popupRegion.contains(x, y).

This is really an important concept, if you are planning to control user Click events on specific sections of your Custom View or any Canvas based drawing. For complete code bases please refer my previous post
Email ThisBlogThis!Share to XShare to Facebook
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • Weekend at Yeouido (Han River Cruise)
    Yeouido is one of the Han River Cruise boarding points. It has a wonderful river side park (Yeouido P...
  • CityWeather
    Update: Release 1.1 has been uploaded. It will now provide weekly forecast of your selected cities. Download   CityWeather is an Android...
  • Few Multi-Threading Implementations
    Sequential Producer & Consumer In my first example, I will demonstrate an implementation to solve ...
  • Accessing Yahoo Finance API
    Since last few days I was wondering the right set of Web Service to read Country wise Stock Exchange index information . I found a bunch of ...
  • Regular Expression in JavaScript
    I was struggling to get familiar with JavaScript's Regular expression handling and thought my learning might help others. Here I'll...
  • Alphanumeric Random Number
    Sometime basic things becomes tricky :-) Was trying to find out ways to generate some alphanumeric random number whose size (i.e. number of ...
  • Binary Search Tree in Java
    This post is a part of my continuous effort to just implement few of the important data structures in ...
  • QuickSort in Java
    This post is a part of my continuous effort to just implement few of the important data structures in Java. Please find my previous post on ...
  • InDroid- Access to Android's Hidden API
    I have started one project " InDroid " to expose and share Hidden and Internal methods and variables of Android platform which are...
  • Image Geo Tagging for Android
    " onMap " is an Image Geo Tagging application, which can read EXIF header of images stored in your Android device and Map them ov...

Blog Archive

  • ►  2013 (6)
    • ►  September (2)
    • ►  May (1)
    • ►  April (1)
    • ►  February (1)
    • ►  January (1)
  • ►  2012 (4)
    • ►  July (2)
    • ►  March (1)
    • ►  January (1)
  • ►  2011 (11)
    • ►  November (1)
    • ►  October (2)
    • ►  August (1)
    • ►  June (1)
    • ►  April (2)
    • ►  March (3)
    • ►  January (1)
  • ▼  2010 (27)
    • ►  December (2)
    • ►  November (3)
    • ►  September (2)
    • ▼  August (4)
      • Overlay on Android Layout
      • Overlay on Android ListView
      • Region Handling in Android Canvas
      • Image Geo Tagging for Android
    • ►  July (4)
    • ►  June (7)
    • ►  May (5)
Powered by Blogger.

About Me

Unknown
View my complete profile