Introduction

In this lecture we will describe about Android Touch Framework Overview,and also describe . After reading this lecture you will also able Understand Android Touch Framework Overview .

Prerequisite

If you not understand this lecture.Android Touch Framework Overview .You should also read my previous lectures How to Create Project – Material design and Toolbar in Android Material design .These lecture are interrelate to each other.

Android Touch Framework Overview

In this lecture we will learn about how we can handle click events of RecyclerView outside the Adpter.How we can perform touch on activity or fragment or item of activity.we will use three method.For more information about how can work Android Touch Framework Overview please click on Android Touch Framework Overview

  1. dispatch Touch Event
  2. on Intercept Touch event
  3. on Touch

 

Android Touch Framework Overview

First think that i explain about Touch is a Pointer.When your finger touch the specific item on Screen. What type of information is generated in x and y coordinate with index pointer id.In touch screen of android there is different type of pointer is uses and every pointer have x and y coordinate.You can tracked using pointer which finger is used and where. Reason android support multi-pal touch on screens that way they will find all the touches in same time.

How android handle Touches

Description user’s Current Action

  • Action_Down   (When you put  your finger on screen then Action_Down event working)
  • Action_up       (When you left the finger on screen  then Action_up event working)
  • Action_Move  (When Put you finger and action or move around all sides then Action_Move are working)
  • Action_Pointer_Down   (Action_Pointer_Down And Action_Pointer_up are secondary touches)
  • Action_Pointer_up
  • Action_Cancel    (When put finger on screen cancel the items then Action_Cancel working)

Events Meta data include

  • Touch Location (Touch Location Description the Position of X and y)
  • Number of Pointer(fingers)
  • Events Time

A “gesture” is define at the beginning with Action _Down ending with Action_upAndroid Touch Framework Overview

Whole touch framework are start from activity and end at activity.Two type of method is used dispatchTouchEvent() and on TouchEvent()

How android handle Touches

Activity.dispatchTouchEvent()

  • Always.dispatchTouchEvents
  • Send  events to root view that are attached to window
  • TouchEvent()
  • Called if no view
  • Always last to be called

Means first your dispatchTouchEvent() is working and last TouchEvent() working.

 

Android Touch Framework Overview

We will explain by a example consider we have three layout groupes ViewGroupA  name frame layout and ViewGroupB is relative layout and ViewC is a textview. ViewGroupB inside the ViewGroupA  and ViewC inside the ViewGroupeB .In simple word first there is a frame layout and  inside the frame layout there is a Relative layout and Relative layout consists of textview.ViewGroupA consists of on Intercept Touch event() method it is Boolean and return value true or false.If return true then onTuchEvent()method will be called  then this work is done “simply process touch the events” and go back to activity.But if return false then find all the children of ViewGroup A.And Jump the ViewGroupB and check again If return true then onTuchEvent()method will be called then this work is done simply  process” touch the events” and go back to activity.But if return false then find all the children of ViewGroupB.And Jump the ViewC .You also notice that ViewC have no Intercept Touch event() because parent is capable to teach events. ViewC is inside the the ViewGroupB ViewGroupe B is capable to teach events.OnTouchEvent() also B0olean if return true then simply  process” touch the events” if false then back to VewGroupB and again execute OnTouchEvent() if return true then simply  process” touch the events” if false then back to VewGroupA again execute OnTouchEvent() if return true then simply  process” touch the events”if false then back to Activity.

Algorithm

How a ViewGroup simple dispatch Touch

Conclusion

In this lecture we learned about how Android Touch Framework are work in android studio. . I hope you will understand this lecture. Thank you for reading this lecture Hope you got the idea.