package com.zhou.mobilesafe.activity;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Toast;
/**
 * ÉèÖÃÒýµÀÒ³µÄ»ùÀà£¬²»ÐèÒªÔÙÇåµ¥ÎÄ¼þÖÐ×¢²á£¬ÒòÎª²»ÐèÒª½çÃæÕ¹Ê¾
 * @author zhouzuo
 *
 */
public abstract class BaseSetupActivity extends Activity {
	private GestureDetector mDectecteor;
	public SharedPreferences mPref;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		mPref = getSharedPreferences("config", MODE_PRIVATE);
		
		mDectecteor = new GestureDetector(this, new SimpleOnGestureListener(){

			//¼àÌýÊÖÊÆ»¬¶¯ÊÂ¼þ
			/**
			 * e1±íÊ¾»¬¶¯ÆðÊ¼µã£¬e2±íÊ¾»¬¶¯ÖÕµã
			 * velocityX±íÊ¾Ë®Æ½ËÙ¶È
			 * velocityY±íÊ¾´¹Ö±ËÙ¶È 
			 */
			@Override
			public boolean onFling(MotionEvent e1, MotionEvent e2,
					float velocityX, float velocityY) {
				//ÅÐ¶Ï×ÝÏò»¬¶¯·ù¶ÈÊÇ·ñ¹ý´ó£¬¹ý´ó²»ÔÊÐíÇÐ»»½çÃæ
				if(Math.abs(e2.getRawY()-e1.getRawY())>100){
					Toast.makeText(BaseSetupActivity.this, "Äã»¹Êú×Å»®£¿ÄæÌì£¿", 0).show();
					return true;
				}
				
				if(Math.abs(velocityX)<100){
					Toast.makeText(BaseSetupActivity.this, "Ê³ÊºÁË£¬»®ÕâÃ´Âý", 0).show();
					return true;
				}
				
				//ÏòÓÒ»®£¬ÉÏÒ»Ò³
				if((e2.getRawX()-e1.getRawX())>100){
					showPreviousPage();
					return true;
				}
				
				if((e1.getRawX()-e2.getRawX())>100){
					showNextPage();
					return true;
				}
				
				return super.onFling(e1, e2, velocityX, velocityY);
			}
		});
	}
	
	//Õ¹Ê¾ÉÏÒ»Ò³
		public abstract void showPreviousPage();
		
		public abstract void showNextPage();
		
		//ÏÂÒ»Ò³
		public void next(View v){
			showNextPage();//½øÈëºÍÍË³ö¶¯»­
		}
		//ÉÏÒ»Ò³
		public void previous(View v){
			showPreviousPage();
		}
		
		@Override
		public boolean onTouchEvent(MotionEvent event) {
			mDectecteor.onTouchEvent(event);//Î¯ÍÐÊÖÊÆÊ¶±ðÆ÷´¦Àí´¥ÃþÊÂ¼þ
			
			return super.onTouchEvent(event);
			
		}
}
