Monday, November 25, 2019

Android Internals - UI Events...



i know the way we started learning computer science almost three decades ago is absolutely different from the way students learn computer science these days. 

students these days probably start programming keeping AI, Robotics and similar stuffs in mind. 

However, it is also the fact that the basics have remained the same.

For example, the way event-handling works in different UI based OS is almost the same.

I remember when i studied Windows/ Visual C++ in 90's, i was really awed (rather scared)  by the MFC's dreaded 

DECLARE_MESSAGE_MAP

BEGIN_MESSAGE_MAP 

and 

END_MESSAGE_MAP 

macros... 

That's why i have made this video to throw lights on the way UI event handling is done in Android.

The video in the beginning is my investigation on the Android internals vis-a-vis an UI input event. 

i always wanted to get involved in my software job as an inquisitive engineer and not just as a programmer. 

Hence when Google made Android's framework code open-source, it became a boon for me. 

It opened the door for doing in-depth investigation... 

Hope you like the video...

Happy learning

Enjoy...

Here goes the source code of the Simulation Of the Android Button Click Event project.



package com.somitsolutions.java.SimulationOfAndroidButtonClickEvent;



public class View {

static class ListenerInfo {

OnClickListener mClickListener;

OnLongClickListener mLongClickListener;

}

ListenerInfo mListenerInfo;

//Lazy Initialization

ListenerInfo getListenerInfo() {

if (mListenerInfo != null) {

return mListenerInfo;

}

mListenerInfo = new ListenerInfo();

return mListenerInfo;

}


public void performClick() {

mListenerInfo.mClickListener.onClick(this);

}

public interface OnClickListener

{

public void onClick (View view);

}

public interface OnLongClickListener

{

public void onLongClick (View view);

}

public void setOnClickListner(OnClickListener li){

getListenerInfo().mClickListener = li;

}

public void setOnClickListner(OnLongClickListener li){

getListenerInfo().mLongClickListener = li;

}


}



package com.somitsolutions.java.SimulationOfAndroidButtonClickEvent;


public class Button extends View {

private String mButtonText;

public Button ()

{

}

public String getButtonText() {

return mButtonText;

}


public void setButtonText(String buttonText) {

this.mButtonText = buttonText;

}


}


package com.somitsolutions.java.SimulationOfAndroidButtonClickEvent;


public class Activity implements View.OnClickListener{

Button button;


public Activity() {

button = new Button();

button.setOnClickListner(this);

}

@Override

public void onClick(View view) {

// TODO Auto-generated method stub

if(view.equals(button)) {

button.setButtonText("You clicked me...");

System.out.println(button.getButtonText());

}

}


}



package com.somitsolutions.java.SimulationOfAndroidButtonClickEvent;


public class Main {


public static void main(String[] args) {

// TODO Auto-generated method stub

Activity activity = new Activity();

View view = (View)activity.button;

view.performClick();


}


}

No comments: