package com.gh.common.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.RelativeLayout;


public class Gh_RelativeLayout extends RelativeLayout {

	private GestureDetector mGestureDetector;
	private OnSingleTapListener listener;

	public Gh_RelativeLayout(Context context) {
		this(context, null);
	}

	public Gh_RelativeLayout(Context context, AttributeSet attrs) {
		super(context, attrs);
		
		mGestureDetector = new GestureDetector(context,
				new GestureDetector.SimpleOnGestureListener() {

					@Override
					public boolean onSingleTapUp(MotionEvent e) {
						if (listener != null) {
							listener.onSingleTap();
						}
						return super.onSingleTapUp(e);
					}

				});
	}

	public void setOnSingleTapListener(OnSingleTapListener listener) {
		this.listener = listener;
	}

	public interface OnSingleTapListener {
		void onSingleTap();
	}

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		mGestureDetector.onTouchEvent(event);
		return super.dispatchTouchEvent(event);
	}
}
