package com.example.mountaintravel.base;

import java.util.ArrayList;
import java.util.Iterator;

import com.example.mountaintravel.view.TitleBarView;
import com.smart.gtstrvl.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;



public class BaseActivity extends Activity {
	protected static ArrayList<BaseActivity> activityLists = new ArrayList<BaseActivity>();

	
	public static void finishAll() {
	
		Iterator<BaseActivity> it = activityLists.iterator();
		while (it.hasNext()) {
			it.next().finish();
		}
	}

	public void initTitleBar(int leftIconId, int rightIconId, String text,
			View.OnClickListener l) {
		TitleBarView v = (TitleBarView) findViewById(R.id.titleBarView1);
		if (v != null) {
			v.initTitleBar(leftIconId, rightIconId, text, l);
		}
	}

	public void initTitleBar(String text,int rightIconId) {
		TitleBarView v = (TitleBarView) findViewById(R.id.titleBarView1);
		if (v != null) {
			v.initTitleBar(R.drawable.zuoback,rightIconId, text,
					new View.OnClickListener() {
						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (v.getId() == R.id.left_icon) {
								finish();
							}
						}
					});
		}
	}
	public void initTitleBar(String text) {
		TitleBarView v = (TitleBarView) findViewById(R.id.titleBarView1);
		if (v != null) {
			v.initTitleBar(R.drawable.zuoback, -1, text,
					new View.OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if (v.getId() == R.id.left_icon) {
								finish();

							}
						}
					});
		}
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		activityLists.add(this);
	}

	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
		

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onRestart() {
		// TODO Auto-generated method stub
		super.onRestart();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		activityLists.remove(this);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	// ��ת��
	protected void startActivity(Class<?> targetClass, int enterAnimID,
			int exitAnimId) {
		Intent intent = new Intent(this, targetClass);
		startActivity(intent);
		overridePendingTransition(enterAnimID, exitAnimId);

	}

	
	protected void startActivity(Class<?> targetClass) {
		Intent intent = new Intent(this, targetClass);
		startActivity(intent);
	}

	protected void startActivity(Class<?> targetClass, Bundle bundle) {
		Intent intent = new Intent(this, targetClass);
		intent.putExtras(bundle);
		startActivity(intent);
	}

	protected void finish(int enterAnimID, int exitAnimId) {
		finish();
		overridePendingTransition(enterAnimID, exitAnimId);
	}
}
