Monthly Archives: September 2012

Set up Objective C development environment in Ubuntu

Hi,

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

Hi,

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).

[CODE]

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){
}

@Override
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) {
onR2LDoAction();
} else if (e2.getX() – e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
onL2RDoAction();
}
} catch (Exception e) {
// nothing
}
return false;
}

public interface onAction{
void doAction();
}

private void onL2RDoAction(){
mOnL2RAction.doAction();
}

private void onR2LDoAction(){
mOnR2LAction.doAction();
}

}

[/CODE]

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
http://www.mediafire.com/?secs6gsy73aw9zo

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