<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>krishnaraj varma&#039;s blog</title>
	<atom:link href="http://www.krvarma.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.krvarma.com</link>
	<description></description>
	<lastBuildDate>Sun, 31 Oct 2010 15:47:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Custom CAR DOCK application in Android</title>
		<link>http://www.krvarma.com/2010/10/custom-car-dock-application-in-android/</link>
		<comments>http://www.krvarma.com/2010/10/custom-car-dock-application-in-android/#comments</comments>
		<pubDate>Sun, 31 Oct 2010 15:47:36 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=718</guid>
		<description><![CDATA[Download source code of this article. Car mode in Android is a UI mode that is invoked when the device is connected to the car dock. An application can programmatically switch to this mode by using UiModeManager.enterCarMode() method with UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME parameter. This a safer way to access the applications while driving. Android has introduced a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/CarDockSample" target="_blank">Download source code of this article.</a></p>
<p>Car mode in Android is a UI mode that is invoked when the device is connected to the car dock. An application can programmatically switch to this mode by using UiModeManager.enterCarMode() method with UiModeManager.ENABLE_CAR_MODE_GO_CAR_HOME parameter. This a safer way to access the applications while driving. Android has introduced a new application &#8220;Car Home&#8221; from 2.2 onwards. This is a default car mode application. Car Home application provides you a quick access to selected applications and supports customization also. You can add shortcuts of the application that supports car mode. To support car mode an application has to specify the category &#8220;android.intent.category.CAR_MODE&#8221; in AndroidManifest.xml file. By specifying this category we can tell the system that our application supports car mode and a user will be able to create shortcut of the application.</p>
<p>We can create our own custom car mode application by specifying the category &#8220;android.intent.category.CAR_DOCK&#8221; in AndroidManifest.xml file and thereby override the default &#8220;Car Home&#8221; application. But we have to take extra care to make it usable and safer while driving.</p>
<p>The sample application is a very simple and minimal that just shows information text and does nothing. If you press the BACK key the application will exit from the car mode by using UiModeManager.disableCarMode() with passing UiModeManager.DISABLE_CAR_MODE_GO_HOME as parameter.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/custom-car-dock-application-in-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multi-touch in Android</title>
		<link>http://www.krvarma.com/2010/10/multi-touch-in-android/</link>
		<comments>http://www.krvarma.com/2010/10/multi-touch-in-android/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 14:29:12 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=682</guid>
		<description><![CDATA[Download source code of this article. Multi-touch is the ability to detect touch events with 2 or more fingers. Android supports multi-touch from version 2.0 onwards. Most common multi-touch gesture is pinch zoom. With Pinch zoom, you can zoom in or out the content by squeezing or pull apart the fingers. We can implement multi-touch [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/multitouchsample" target="_blank">Download source code of this article</a>.</p>
<p>Multi-touch is the ability to detect touch events with 2 or more fingers. Android supports multi-touch from version 2.0 onwards. Most common multi-touch gesture is pinch zoom. With Pinch zoom, you can zoom in or out the content by squeezing or pull apart the fingers. We can implement multi-touch in Android using either <strong>onTouch events</strong> or <strong>ScaleGestureDetector</strong>.  </p>
<p><strong>To <strong>View.onTouchEven</strong>t is called when we touch the screen. This method has one MotionEvent</strong> parameter. This represents the touch event that occurred. The <strong>MotionEvent.getAction()</strong> method returns the event action. There are different event actions like <strong>ACTION_DOWN, ACTION_MOVE, ACTION_UP, ACTION_POINTER_DOWN, ACTION_POINTER_UP,</strong> etc. <strong>MotionEvent.getX()</strong> and <strong>MotionEvent.getY()</strong> returns x and y position of the event respectively.</p>
<p>ACTION_TOUCH will be generated whenever we touch the screen with one finger (primary pointer). ACTION_UP is generated when the finger has left the screen. This is for single touch. When we touch the screen with two fingers, the first touch detected is considered as the primary pointer and all others are considered as non-primary pointer. For the primary pointer (first touch detected) ACTION_TOUCH is generated and for the non-primary pointers (second touch onwards) ACTION_POINTER_DOWN is generated. When we move the fingers ACTION_MOVE will be generated. When the non-primary pointer left the screen, ACTION_POINTER_UP is generated.</p>
<p>To find now many pointers are there for an event, we can use <strong>MotionEvent.getPointerCount()</strong> method. This will return how many pointers are there for the event. The getX() and getY() methods has another variant which accepts a pointer id, i.e. <strong>MotionEvent.getX(pointerid)</strong> and <strong>MotionEvent.getY(pointerid)</strong> which returns the X and Y coordinates of the pointer with given pointerid. Note that we are passing pointer id not pointer index. The method <strong>MotionEvent.getPointerId(index)</strong> returns the pointer id of the pointer at the specified index. The index ranges from 0 to getPointerCount() – 1. Now we have X and Y coordinates of the different pointers involved in the multi-touch gesture and we can use this to implement actions like zoom-in, zoom-out, etc.</p>
<p><strong>Using ScaleGestureDetector</strong></p>
<p><strong>ScaleGestureDetector</strong> class detects gestures with more than two fingers. We use this class the same way we use the <strong><a href="http://www.krvarma.com/posts/android/gesture-detection-in-android-part-1-of-2/" target="_blank">GestureDetector</a></strong> class, i.e. we create and instance of the class and on <strong>View.onTouchEvent</strong> we call the <strong>ScaleGestureDetector.onTouchEvent</strong> method. The ScaleGestureDetector uses callback interface <strong>ScaleGestureDetector.OnScaleGestureListener</strong> to report the events occurred. This interface has following three methods:</p>
<pre language="java">boolean onScaleBegin(ScaleGestureDetector detector)
boolean onScale(ScaleGestureDetector detector)
void onScaleEnd(ScaleGestureDetector detector)</pre>
<p>The <strong>onScaleBegin</strong> method is called when two-finger gesture is detected. We have to return true to indicate we have handled this event and all the other methods should be called. If we return false then the <strong>ScaleGestureDetector</strong> will not call other methods.</p>
<p>The <strong>onScale</strong> method is called when we move the fingers. Note that this event will not be called when you return false from <strong>onScaleBegin</strong> callback method.</p>
<p>The <strong>onScaleEnd</strong> is called when the gesture is finished, i.e. then the fingers left the screen.</p>
<p>All these methods have one parameter ScaleGestureDetector which is instance of the ScaleGestureDetector reported the event.</p>
<p>The ScaleGestureDetector has different methods like, <strong>getCurrentSpan()</strong>, <strong>getFocusX()</strong>, <strong>getFocusY()</strong>, etc. The getCurrentSpan() method returns the current distance between the fingers. The getFocusX() and getFocusY() methods returns the focal point’s (middle point) X and Y coordinates respectively. Using this information we can implement the pinch-zoom gesture. Refer the reference links for more details.</p>
<p><strong>Sample Application</strong></p>
<p>The sample application is a simple one which draws a line between different pointers when you touch the screen with two fingers. The pinch-zoom is not implemented in this application but can be done with minimal effort. See the reference links for an example of pinch-zoom.</p>
<p><strong>Reference links</strong></p>
<p><a href="http://www.zdnet.com/blog/burnette/how-to-use-multi-touch-in-android-2/1747" target="_blank">How to use Multi-touch in Android 2</a><br />
<a href="http://developer.android.com/reference/android/view/MotionEvent.html" target="_blank">MotionEvent documentation</a><br />
<a href="http://developer.android.com/reference/android/view/ScaleGestureDetector.html" target="_blank">ScaleGestureDetector documentation</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/multi-touch-in-android/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Using hardware sensors in Android, part 1</title>
		<link>http://www.krvarma.com/2010/10/using-hardware-sensors-in-android-part-1/</link>
		<comments>http://www.krvarma.com/2010/10/using-hardware-sensors-in-android-part-1/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 20:41:50 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=676</guid>
		<description><![CDATA[Download source code of this article. Hardware sensors are present in almost all the modern mobile phone devices. Different types of sensors like accelerometer sensor, magnetic field sensor, orientation sensor, proximity sensor, etc. are present in these devices. Sensors that are present vary from device to device. In Android different types of sensors are supported. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/sensorsample" target="_blank">Download source code of this article</a>.</p>
<p>Hardware sensors are present in almost all the modern mobile phone devices. Different types of sensors like accelerometer sensor, magnetic field sensor, orientation sensor, proximity sensor, etc. are present in these devices. Sensors that are present vary from device to device. </p>
<p>In Android different types of sensors are supported. <strong>SensorManager</strong> class is used to access these sensors. Sensor Manager is a system service running in Android. We get an instance of this service by calling <strong>Context.getSystemService()</strong> method with <strong>SENSOR_MANAGER</strong> as the argument. Android supports different types of sensors, some of them are:</p>
<pre language="java">Sensor.TYPE_ACCELEROMETER - accelerometer sensor
Sensor.TYPE_GYROSCOPE - gyroscope sensor
Sensor.TYPE_LIGHT - light sensor
Sensor.TYPE_MAGNETIC_FIELD - magnetic field sensor
Sensor.TYPE_ORIENTATION - orientation sensor
Sensor.TYPE_PRESSURE - pressure sensor
Sensor.TYPE_PROXIMITY - proximity sensor
Sensor.TYPE_TEMPERATURE - temperature sensor</pre>
<p>Not all these will present in the target device, so before start using a particular type of sensor, we need to check whether the desired sensor is present in the device or not. We can check the presence using either <strong>SensorManager.getDefaultSensor()</strong> or <strong>ServiceManager.getSensorList()</strong>. Both methods accept sensor type parameter as an argument. In case of <strong>ServiceManager.getSensorList()</strong> method we can pass the <strong>Sensor. TYPE_ALL</strong> to get all the sensors present in the system. Once we confirm the desired sensor is present in the device, we can start getting the event updates from the sensor using <strong>SensorManager.registerListener()</strong> method. This method accepts one <strong>SensorEventListener</strong> callback interface. This is the interface that SensorManager uses to report the calling application whenever a sensor event occurred. This callback interface has following methods:</p>
<pre language="java">abstract void onAccuracyChanged(Sensor sensor, int accuracy)
abstract void onSensorChanged(SensorEvent event)</pre>
<p>The <strong>onAccuractChanged</strong> method is called when there is a change in the sensor accuracy. First parameter is the Sensor registered and second one is the accuracy value. This can be one of the following:</p>
<pre language="java">SensorManager.SENSOR_STATUS_ACCURACY_HIGH - high accuracy
SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM - medium accuracy
SensorManager.SENSOR_STATUS_ACCURACY_LOW - low accuracy
SensorManager.SENSOR_STATUS_UNRELIABLE - accuracy is unreliable and cannot be trusted</pre>
<p>The <strong>onSensorChanged</strong> is called when the sensor values are changed. The only argument SensorEvent is the sensor event occurred. This class holds the sensor values, accuracy of the sensor <strong>values, Sensor itself and a timestamp at which the event occurred.</p>
<p>SensorEvent.values</strong> contains the sensor values. This is an array of <em>float</em> values representing the sensor values. The length and content of this array depends on the type of sensor used. For example if the sensor is an accelerometer then it will be having three elements representing Azimuth angle, Pitch and Roll. Other sensors have different values. Sensor values are described in <a href="http://developer.android.com/reference/android/hardware/SensorEvent.html" target="_blank">this link</a>.</p>
<p><strong>Sample application</strong></p>
<p>Sample application for this article lists all the sensors present in the device and when you select a particular sensor, the application registers for sensor events and update the values on the screen. This application does not do anything with the values but just prints it on the screen. A real application should use these values to do something more meaning such as drawing a compass, counting steps while walking, etc. In the coming parts of this article I will try to explain different type of sensors in more detail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/using-hardware-sensors-in-android-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gesture detection in Android, part 2 of 2</title>
		<link>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-2-of-2/</link>
		<comments>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-2-of-2/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 16:45:06 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=668</guid>
		<description><![CDATA[Download source code of this article. In my previous article I tried to explain simple gesture detection in Android using GestureDetector. In this article I will explain complex gesture detection using GestureOverlayView. From Android 1.6 onwards includes a new package android.gesture which is used to for complex gesture recognition. This package includes APIs to store, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/gesturesample" target="_blank">Download source code of this article</a>.</p>
<p>In my previous article I tried to explain simple gesture detection in Android using <strong>GestureDetector</strong>. In this article I will explain complex gesture detection using <strong>GestureOverlayView</strong>.</p>
<p>From Android 1.6 onwards includes a new package <strong>android.gesture</strong> which is used to for complex gesture recognition. This package includes APIs to store, load, draw and recognize gestures. We can define our own pre-defined patterns in our application and store these gestures in a file and later on use this file to recognize the gesture.</p>
<p><strong>Gestures Builder application</strong></p>
<p>There is a handy sample application, Gestures Builder, which comes with the Android 1.6 and higher. This application is pre-installed in 1.6 and higher emulators. Here is a screenshot of the application:</p>
<div id="attachment_670" class="wp-caption alignnone" style="width: 170px"><a href="http://www.krvarma.com/wp-content/uploads/2010/10/gesturesbuilder.png"><img src="http://www.krvarma.com/wp-content/uploads/2010/10/gesturesbuilder.png" alt="Gesture Builder Sample application" title="Gesture Builder Sample application" width="160" height="240" class="size-full wp-image-670" /></a><p class="wp-caption-text">Gesture Builder Sample application</p></div>
<p>Using this application we can create our gesture library and save it to SD card. Once the file is created we can include this file in our application in <strong>/res/raw</strong> folder.</p>
<p><strong>Loading a gesture library</strong></p>
<p>To load the gesture file, we use the class <strong>GestureLibraries</strong> class. This class has functions to load from resource, SD card file or private file. GestureLibraries class has following methods: </p>
<pre language="java">
static GestureLibrary fromFile(String path)
static GestureLibrary fromFile(File path)
static GestureLibrary fromPrivateFile(Context context, String name)
static GestureLibrary fromRawResource(Context context, int resourceId)</pre>
<p>All these methods return a class <strong>GestureLibrary</strong>. This class is used to read gestures entries from file, save gestures entries to file, recognize the gestures, etc. Once the GestureLibraries return a GestureLibrary class that corresponds to the file specified, we read all the gesture entries using <strong>GestureLibrary.load</strong> method.<br />
<strong><br />
Drawing and recognize a gesture</strong></p>
<p>To draw and recognize gestures, we use the class <strong>GestureOverlayView</strong>. This view extends the <strong>FrameLayout</strong>, i.e. we can use it inside any other layout or use it as a parent layout to include other child views. This view acts as an overlay view and the user can draw gestures on it. This view uses three callback interfaces to report the actions performed, they are:</p>
<pre language="java">interface GestureOverlayView.OnGestureListener
interface GestureOverlayView.OnGesturePerformedListener
interface GestureOverlayView.OnGesturingListener</pre>
<p>The <strong>GestureOverlayView.OnGestureListener</strong> callback interface is used to handle the gesture operations in low-level. This interface has following methods: </p>
<pre language="java">
void onGestureStarted(GestureOverlayView overlay, MotionEvent event)
void onGesture(GestureOverlayView overlay, MotionEvent event)
void onGestureEnded(GestureOverlayView overlay, MotionEvent event)
void onGestureCancelled(GestureOverlayView overlay, MotionEvent event)</pre>
<p><strong><br />
All these methods have two parameters GestureOverlayView</strong> and <strong>MotionEvent</strong> and represent the overlay view and the event that occurred.</p>
<p>The GestureOverlayView.OnGesturingListener callback interface is used to find when the gesture is started and ended. The interface has following methods:</p>
<pre language="java">
void onGesturingStarted(GestureOverlayView overlay)
void onGesturingEnded(GestureOverlayView overlay)</pre>
<p>The <strong>onGestuingStarted</strong> will be called when gesture action is started and <strong>onGesturingEnded</strong> will be called when the gesture action ended. Both these methods contain the GestureOverlayView that is used.</p>
<p>Most important is the <strong>GestureOverlayView.OnGesturePerformedListener</strong> interface. This interface has only one method:</p>
<pre language="java">void onGesturePerformed(GestureOverlayView overlay, Gesture gesture)</pre>
<p>This method is called when the user performed the gesture and is processed by the GestureOverlayView. The first parameter is the overlay view that is used and the second is a class <strong>Gesture</strong> that represents the user performed gesture. <strong>Gesture</strong> class represents a hand drawn shape. This representation has one or more strokes; each stroke is a series of points. The GestureLibrary class uses this class to recognize gestures.</p>
<p>To recognize a gesture, we use GestureLibrary.recognize method. This method accepts a <strong>Gesture</strong> class. This method recognizes the gestures using internal recognizers and returns a list of predictions. The prediction is represented by <strong>Prediction</strong> class and contains two member variables <strong><em>name</em></strong> and <strong><em>score</em></strong>. The <em>name</em> variable represents the name of the gesture and <em>score</em> variable represents the score given by the gesture recognizer. This score member is used to choose the best matching prediction from the list. One of the common methods is to choose the first value that has score greater that one. Another method used is to choose the value that is inside a minimum and maximum threshold limit. Choosing this threshold limit is entirely depends on the implementation ranging from simple limits based on trial and error methods and more complex methods that may include leaning the user inputs and improve the recognition based on that.</p>
<p><strong>Sample application</strong></p>
<p>The sample application that accompanies this article includes 5 pre-defined gestures A, B, C, D and E. When the user draws these patterns the application lists the names and scores of all the predictions.</p>
<p>Hope this article helps you to understand complex gesture recognition in Android.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-2-of-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Gesture detection in Android, part 1 of 2</title>
		<link>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-1-of-2/</link>
		<comments>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-1-of-2/#comments</comments>
		<pubDate>Sun, 10 Oct 2010 14:24:27 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=659</guid>
		<description><![CDATA[Download the source code of this article. Gesture detection is one of the great features of all touch based mobile devices. Gestures are patterns drawn by the user on the screen. Simple gestures include tap, scroll, swipe, etc. Complex gestures are more complex patterns drawn on the screen. In Android we can detect simple gestures [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/gesturedetectorsample" target="_blank">Download the source code of this article</a>.</p>
<p>Gesture detection is one of the great features of all touch based mobile devices. Gestures are patterns drawn by the user on the screen. Simple gestures include tap, scroll, swipe, etc. Complex gestures are more complex patterns drawn on the screen. In Android we can detect simple gestures using <strong>GestureDetector</strong> class and complex gestures using <strong>GestureOverlayView</strong> class.</p>
<p>In part 1 of this 2 part article series, I will try to explain the simple gesture detection using GestureDetector class and in next part I will try to explain complex gesture detection using GestureOverlayView class. </p>
<p>GestureDetector is a class which is used to detect simple gestures like tap, scroll, swipe or fling, etc. This class detects gestures using the supplied MotionEvent class. We use this class along with the onTouchEvent, inside this method we call the GestureDetector.onTouchEvent. GestureDetector identify the gestures or events that occurred and report back to us using GestureDetector.OnGestureListener callback interface. We create an instance of the GestureDetector class by passing Context and GestureDetector.OnGestureListener listener.</p>
<p>The GestureDetector.OnGestureListener interface has following abstract methods:</p>
<pre language="java">
abstract boolean onDown(MotionEvent e)
abstract void onLongPress(MotionEvent e)
abstract boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
abstract void onShowPress(MotionEvent e)
abstract boolean onSingleTapUp(MotionEvent e)
abstract boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)</pre>
<p>The <strong>onDown</strong> method is called when the user first touch the screen, the MotionEvent parameter represents the event that corresponds to the touch event. </p>
<p>The <strong>onLongPress</strong> method is called when user touches the screen and holds it for a period of time. The MotionEvent parameter represents the event that corresponds to the touch event.</p>
<p>The <strong>onScroll</strong> method is called when the user touches the screen and moves to another location on the screen. This method has 4 parameters; first MotionEvent corresponds to the first touch event that occurred, second MotionEvent corresponds to the scroll that occurred, the distanceX parameter represents the scrolled distance along the X axis since the last call to onScroll and the forth parameter distanceY is the distance occurred along Y axis since the last call to onScroll. The third and forth parameters are little bit confusing and are not the distance between MotionEvent 1 and MotionEvent 2.</p>
<p>The <strong>onShowPress</strong> method is called when the user touches the phone and not moved yet. This event is mostly used for giving visual feedback to the user to show their action.</p>
<p>The <strong>onSingleTapUp</strong> method is called when a tap occurred, i.e. use taps the screen.</p>
<p>The <strong>onFling</strong> method is called whenever the user swipes the screen in any direction, i.e. the user touches the screen and immediately moves the finger in any direction.  The first parameter is the MotionEvent corresponds to the touch event that started the fling, second parameter is the MotionEvent that corresponds to the movement that triggered the fling, the third one corresponds to the velocity along X axis measured and the forth one corresponds to the velocity along Y axis measured. The use of this gesture depends on application to application. Some application starts the movement of some objects in the screens with velocity based on the X and Y velocity measured and gradually slows down the movement and settled the objects somewhere on the screen. Another use of this method is to move from one page to another within the application.</p>
<p><strong>Double-tap</strong></p>
<p>You should be noticed that the double-tap event is not present in the GestureDetector.onGestureListener callback interface. For some reason this event is reported using another callback interface GestureDetector.onDoubleTapListener. To use this callback interface we have to register for these events using GestureDetector.setOnDoubleTapListener passing the above listener. This interface has the following methods:</p>
<pre language="java">
abstract boolean onDoubleTap(MotionEvent e)
abstract boolean onDoubleTapEvent(MotionEvent e)
abstract boolean onSingleTapConfirmed(MotionEvent e)</pre>
<p>The <strong>onDoubleTap</strong> method is called when there is a double-tap event occurred. The only parameter MotionEvent corresponds to the double-tap event that occurred. </p>
<p>The <strong>onDoubleTapEvent</strong> is called for all events that occurred within the double-tap, i.e. down, move and up events.<br />
<strong><br />
The onSingleTapConfirmed</strong> method is called when there is a single tap occurred and confirmed, but this is not same as the single-tap event in the GestureDetector.onGestureListener. This is called when the GestureDetector detects and confirms that this tap does not lead to a double-tap.</p>
<p><strong>The MotionEvent class</strong></p>
<p>The MotionEvent class contains all the values correspond to a movement and touch event. This class holds values such as X and Y position at which the event occurred, timestamp at which the event occurred, mouse pointer index, etc. This class also contains the multi-touch information. Another interesting member is the pressure variable,  which reports the pressure of the touch and movement events. I am  experimenting with multi-touch and pressure and will be posting an article soon.</p>
<p><strong>Example application</strong></p>
<p>The example application accompanies this article is a simple one to show the use of these gestures. The application has 4 views and each view has different color. It has and 2 modes, SCROLL mode and FLIP mode. The application starts in FLIP mode. In this mode when you perform the swipe/fling gesture in left right, up and down direction, the view changes back and forth. When a long-press is detected, the application changes to SCROLL mode, in this mode you scroll the displayed view. While in this mode, you can double-tap on the screen to bring back the screen to its original position. Again when a long-press is detected the application changes to FLIP mode.</p>
<p>I hope this will give you an introduction to the simple gesture detection in Android. In the next part of this article I will try to explain complex gesture detection using GestureOverlayView class.</p>
<p>Happy gesture coding! <img src='http://www.krvarma.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/gesture-detection-in-android-part-1-of-2/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Security Permissions in Android</title>
		<link>http://www.krvarma.com/2010/10/security-permissions-in-android/</link>
		<comments>http://www.krvarma.com/2010/10/security-permissions-in-android/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 13:11:41 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=641</guid>
		<description><![CDATA[As we all know whenever we use a particular feature or API we need to request the permission in AndroidManifest.xml file with uses-permission element. If we don&#8217;t specify any permissions, then the application will not have any permission and application can do anything that does not require a permission. This link explains the permissions in [...]]]></description>
			<content:encoded><![CDATA[<p>As we all know whenever we use a particular feature or API we need to request the permission in AndroidManifest.xml file with <b>uses-permission</b> element. If we don&#8217;t specify any permissions, then the application will not have any permission and application can do anything that does not require a permission. <a href="http://developer.android.com/guide/topics/security/security.html" target="_blank">This link</a> explains the permissions in android in more detail and <a href="http://developer.android.com/reference/android/Manifest.permission.html" target="_blank">this link</a> lists the permissions in Android.</p>
<p>Permissions are granted to the application by package installer while installing. But not all the permissions will be granted to the system. There are some system permission which will not be granted to the user applications, but only to the system applications. Following are some of the permissions that may NOT be granted to the user application.</p>
<pre language="java">
android.permission.ACCESS_CHECKIN_PROPERTIES
android.permission.ACCESS_SURFACE_FLINGER
android.permission.ACCOUNT_MANAGER
android.permission.BIND_APPWIDGET
android.permission.BIND_DEVICE_ADMIN
android.permission.BIND_INPUT_METHOD
android.permission.BIND_WALLPAPER
android.permission.BRICK
android.permission.BROADCAST_PACKAGE_REMOVED
android.permission.BROADCAST_SMS
android.permission.BROADCAST_WAP_PUSH
android.permission.CALL_PRIVILEGED
android.permission.CHANGE_COMPONENT_ENABLED_STATE
android.permission.CLEAR_APP_USER_DATA
android.permission.CONTROL_LOCATION_UPDATES
android.permission.DELETE_CACHE_FILES
android.permission.DELETE_PACKAGES
android.permission.DEVICE_POWER
android.permission.DIAGNOSTIC
android.permission.FACTORY_TEST
android.permission.FORCE_BACK
android.permission.GLOBAL_SEARCH
android.permission.HARDWARE_TEST
android.permission.INJECT_EVENTS
android.permission.INSTALL_LOCATION_PROVIDER
android.permission.INSTALL_PACKAGES
android.permission.INTERNAL_SYSTEM_WINDOW
android.permission.MANAGE_APP_TOKENS
android.permission.MASTER_CLEAR
android.permission.READ_FRAME_BUFFER
android.permission.READ_INPUT_STATE
android.permission.REBOOT
android.permission.SET_ACTIVITY_WATCHER
android.permission.SET_ORIENTATION
android.permission.SET_PREFERRED_APPLICATIONS
android.permission.SET_TIME
android.permission.STATUS_BAR
android.permission.UPDATE_DEVICE_STATS
android.permission.WRITE_GSERVICES
android.permission.WRITE_SECURE_SETTINGS</pre>
<p>To get these permissions, the application must be signed with the key which used to sign the platform. This may be different for manufacturers. So it practically not possible to get these permissions granted to a user application.</p>
<p>Note: While playing with <code>PowerManager.reboot</code> I was so stupid I thought my application will be granted the permission <code>android.permission.REBOOT</code>, but it was not granted. Then I created an application requesting all the permissions and above list of permissions are not granted. Hope this will help you when you request a permission next time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/10/security-permissions-in-android/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Network Traffic Statistics in Android 2.2</title>
		<link>http://www.krvarma.com/2010/09/traffic-statistics-in-android-2-2/</link>
		<comments>http://www.krvarma.com/2010/09/traffic-statistics-in-android-2-2/#comments</comments>
		<pubDate>Sun, 19 Sep 2010 17:53:35 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=636</guid>
		<description><![CDATA[Download source code of this article Android API version 8 (Version 2.2) includes a convenient class, TrafficStats, to retrieve the traffic statistics of the device. This class provides traffic statistics of both Mobile Interface and All Network Interface. This class has following methods: static long getMobileRxBytes() static long getMobileRxPackets() static long getMobileTxBytes() static long getMobileTxPackets() [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/TrafficInfo">Download source code of this article</a></p>
<p>Android API version 8 (Version 2.2) includes a convenient class, TrafficStats, to retrieve the traffic statistics of the device. This class provides traffic statistics of both Mobile Interface and All Network Interface. This class has following methods:</p>
<pre language="java">static long getMobileRxBytes()
static long getMobileRxPackets()
static long getMobileTxBytes()
static long getMobileTxPackets()
static long getTotalRxBytes()
static long getTotalRxPackets()
static long getTotalTxBytes()
static long getTotalTxPackets()
static long getUidRxBytes(int uid)
static long getUidTxBytes(int uid)</pre>
<p>The function names explains its purpose. For more detailed documentation visit <a href="http://developer.android.com/reference/android/net/TrafficStats.html" target="_blank">this link</a>. Note that this class is only available from API version 8 onwards.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/09/traffic-statistics-in-android-2-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Detecting incoming and outgoing calls in Android</title>
		<link>http://www.krvarma.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/</link>
		<comments>http://www.krvarma.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/#comments</comments>
		<pubDate>Sun, 29 Aug 2010 16:54:48 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=633</guid>
		<description><![CDATA[Download source code of this article In one of my project, I wanted to detect incoming and outgoing calls. I used BroadcastReceiver with action android.intent.action.NEW_OUTGOING_CALL and android.intent.action.PHONE_STATE. The android.intent.action.NEW_OUTGOING_CALL will be broadcasted when an outgoing call is initiated. The receiving intent will have an extra string variable Intent.EXTRA_PHONE_NUMBER which contains the outgoing number. This requires [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/DetectCalls" target="_blank">Download source code of this article</a></p>
<p>In one of my project, I wanted to detect incoming and outgoing calls. I used BroadcastReceiver with action <code>android.intent.action.NEW_OUTGOING_CALL</code> and <code>android.intent.action.PHONE_STATE</code>.</p>
<p>The <code>android.intent.action.NEW_OUTGOING_CALL</code> will be broadcasted when an outgoing call is initiated. The receiving intent will have an extra string variable <code>Intent.EXTRA_PHONE_NUMBER</code> which contains the outgoing number. This requires the permission <code>android.permission.PROCESS_OUTGOING_CALLS</code>.</p>
<p>To detect the incoming call, we register a BroadcastReceiver for the action <code>android.intent.action.PHONE_STATE</code>. This will be broadcasted when there is a change in phone state. The receiving intent will have an extra string variable <code>TelephonyManager.EXTRA_STATE</code> which describes the phone state. If this state is <code>TelephonyManager.EXTRA_STATE_RINGING</code> then there will be another extra string variable <code>TelephonyManager.EXTRA_INCOMING_NUMBER</code>. This variable contains the incoming phone number. Note that this variable will not be present when the state is not <code>TelephonyManager.EXTRA_STATE_RINGING</code>. </p>
<p>The sample application is a simple one just for demonstration. The application registers for these actions and when the calls are detected it just displays a toast.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/08/detecting-incoming-and-outgoing-calls-in-android/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Android network connectivity BroadcastReceiver</title>
		<link>http://www.krvarma.com/2010/08/android-network-connectivity-broadcastreceiver/</link>
		<comments>http://www.krvarma.com/2010/08/android-network-connectivity-broadcastreceiver/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 17:41:36 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=612</guid>
		<description><![CDATA[Download source code of this article. Most of the time we need to connect to internet to download or upload data. If the downloading or uploading is a lengthy process, we need to know when the network connected or gone, so that we can temporarily pause the uploading or downloading and resume once the connection [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/ConnectionTest" target="_blank">Download source code of this article.</a></p>
<p>Most of the time we need to connect to internet to download or upload data. If the downloading or uploading is a lengthy process, we need to know when the network connected or gone, so that we can temporarily pause the uploading or downloading and resume once the connection is established. In Android we can register a <code>BroadcastReciver</code> with action <code>ConnectivityManager.CONNECTIVITY_ACTION</code>. System will broadcast this whenever a change in the network connectivity occurs.</p>
<p>Information regarding the connection will be there in the receiving intent. Some of them are:</p>
<pre language="java">ConnectivityManager.EXTRA_EXTRA_INFO
A string value indicating the network state.

ConnectivityManager.EXTRA_IS_FAILOVER
A boolean value indicates whether the connection manager is failing over or not.

ConnectivityManager.EXTRA_NETWORK_INFO
A NetworkInfo class with network information.

ConnectivityManager.EXTRA_NO_CONNECTIVITY
A boolean value indicating there is no internet connectivity.

ConnectivityManager.EXTRA_OTHER_NETWORK_INFO
A NetworkInfo class with network information of another network that may be connected.

ConnectivityManager.EXTRA_REASON
A String value about the reason of the connection failure.</pre>
<p>You can check either <code>ConnectivityManager.EXTRA_EXTRA_INFO</code> or NetworkInfo.State from the <code>ConnectivityManager.EXTRA_NETWORK_INFO key</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/08/android-network-connectivity-broadcastreceiver/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Android sample application: Simple logcat viewer</title>
		<link>http://www.krvarma.com/2010/08/simple-android-logcat-viewer/</link>
		<comments>http://www.krvarma.com/2010/08/simple-android-logcat-viewer/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 21:04:55 +0000</pubDate>
		<dc:creator>Krishnaraj Varma</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://www.krvarma.com/?p=604</guid>
		<description><![CDATA[Download source code of this article. Here is a sample application to view logcat messages on device. The application runs the command “logcat” using Runtime class, reads each log string and adds the string to a list view. Whenever you click on an item, an alert box is displayed with the corresponding log message.]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/p/krvarma-android-samples/source/browse/#svn/trunk/LogViewer" target="_blank">Download source code of this article.</a></p>
<p>Here is a sample application to view logcat messages on device. The application runs the command “logcat” using <code>Runtime</code> class, reads each log string and adds the string to a list view. Whenever you click on an item, an alert box is displayed with the corresponding log message.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.krvarma.com/2010/08/simple-android-logcat-viewer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

