Monthly Archives: September 2012

Set up Objective C development environment in Ubuntu


I want to learning something new to keep my brain busy a little bit. Today, I’m gonna write  out some simple steps to set up environment for Objective C in Ubuntu (mine is 12.04 LTS )

Here is some commands  that you just need to type in terminal.

sudo apt-get -y install build-essential
sudo apt-get -y install gnustep
sudo apt-get install gobjc
sudo apt-get install gnustep-make
sudo apt-get install libgnustep-base-dev

Then, add the following line into profile ( /etc/profile)

export GNUSTEP_MAKEFILES=/usr/share/GNUstep/Makefiles

Restart/log off for get our environment into effect.

That’s all.


[ANDROID] Set title of app to be centered

Use this:

((TextView)((FrameLayout)((LinearLayout)((ViewGroup) getWindow().getDecorView()).getChildAt(0)).getChildAt(0)).getChildAt(0)).setGravity(Gravity.CENTER);

Comment: This will help your app crash in ICS ( >= 4.0)

[ANDROID] FlingGesture Listener


Today topic is about Fling Gesture in Android.

As you might notice that, some apps on Android like Music or Photo are implemented Fling gesture, so that if you fling you finger from left to right or from right to left, you will have your songs or images changed.

So, what was happened under the hook?

Let’s dive into these little snippet of code. (This is not my code, I just collect them from somewhere on the internet that I can not remember now, sorry for this, just I think you can try to Google them).


public class FlingGestureDetector extends SimpleOnGestureListener {
public static final int SWIPE_MIN_DISTANCE = 120;
public static final int SWIPE_MAX_OFF_PATH = 250;
public static final int SWIPE_THRESHOLD_VELOCITY = 200;
public onAction mOnL2RAction;
public onAction mOnR2LAction;

public FlingGestureDetector(Context context, View v){

public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
try {
if (Math.abs(e1.getY() – e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if (e1.getX() – e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} else if (e2.getX() – e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
} catch (Exception e) {
// nothing
return false;

public interface onAction{
void doAction();

private void onL2RDoAction(){

private void onR2LDoAction(){



The main component here is the way to determine that the action of flinging has happened.
By defining the constants of minimum distance and minimum velocity that calculated from 2 points: touching point and releasing point

The demo that uses this snippet of code can be found here

One SMALL notice when applying the gesture listener on some kinds of view is  that view must be set to be clickable ( clickable = true)