package com.qiyou.mb.android.ui;

import android.annotation.TargetApi;
import android.app.ActionBar;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.qiyou.mb.android.Activity_qiyouBase;
import com.qiyou.mb.android.R;
import com.qiyou.mb.android.utils.Utils;
import com.qiyou.mb.android.utils.log.QLog;

public class Welcome extends Activity_qiyouBase {
	public static final String TAG ="com.qiyou.Welcome";
	public static final String dTAG ="com.qiyou";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		 updateActionBar();
		app.isUIactive = true;
		Intent intent =this.getIntent();
		
		setContentView(R.layout.welcomelogo);
		
//		    app.restoreLastTracking(); 
//			app.getStaticsTracks();//异步获取track statistics 
 		
			if(intent.hasExtra("noani")){
				startMainActivity();			
			}
		
			
			
		//寰楀埌ImageView鎺т欢
        ImageView logo = (ImageView) findViewById(R.id.logo2);
         Animation logo_animation = AnimationUtils.loadAnimation(Welcome.this, 
        		R.anim.push_left_in);
        logo.setAnimation(logo_animation);
        
//        app.syncStatistics();
//        app.startNetworkLocationRequest(true);	
//        workingInBackground();
        app.restoreLastTracking(); 
//		  QLog.getLogger().dLog(TAG,  "   restoreLastTracking cost time:" +(System.currentTimeMillis()-st)); 
//		  st=System.currentTimeMillis(); 
//		app.getStaticsTracks();//异步获取track statistics
		
        logo_animation.setAnimationListener(new AnimationListener() {
		
			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub
//				workingInBackground();
				
			}
			
			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void onAnimationEnd(Animation animation) {
//				if(Utils.getAndroidSDKVersion()>=Build.VERSION_CODES.HONEYCOMB)
//				((ImageView) findViewById(R.id.logo2)).setAlpha(50f);
//				((TextView)findViewById(R.id.i7lv)).setVisibility(View.VISIBLE);
				// TODO Auto-generated method stub
		        workingInBackground();

				startMainActivity();
			}
		});
        
       
	}
	 
	 @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
	public void updateActionBar(){
			
			if(Utils.getAndroidSDKVersion()<Build.VERSION_CODES.HONEYCOMB)return;
		  
			ActionBar ab =getActionBar();
			  if(ab!=null){
//				  ab.setDisplayShowHomeEnabled(enable);
				  ab.setDisplayHomeAsUpEnabled(false) ;
				  ab.setLogo(R.drawable.icon_ablogo);
 
			  }
	 } 
	 
	void startMainActivity(){
		Intent it = new Intent(Welcome.this,MainActivity.class);
		startActivity(it);
//		overridePendingTransition(android.R.anim.slide_in_left,android.R.anim.slide_out_right);
		Welcome.this.finish();
	}
	/*@Override 
    public boolean onKeyUp(int keyCode, KeyEvent event) { 
        if (keyCode == KeyEvent.KEYCODE_BACK) {
        	startMainActivity(); 
        }
        return true;
        }*/
	
	void workingInBackground(){
		long  st=System.currentTimeMillis(); 
		
		/*app.restoreLastTracking(); 
		  QLog.getLogger().dLog(TAG,  "   restoreLastTracking cost time:" +(System.currentTimeMillis()-st)); 
		  st=System.currentTimeMillis(); 
		app.getStaticsTracks();//异步获取track statistics
*/		 
		QLog.getLogger().dLog(TAG,  "   getStaticsTracks cost time:" +(System.currentTimeMillis()-st));  
		 st=System.currentTimeMillis(); 
//		 app.initMapview(this);
		app.startNetworkLocationRequest(true);	
		  QLog.getLogger().dLog(TAG,  "   startNetworkLocationRequest cost time:" +(System.currentTimeMillis()-st));  
			 st=System.currentTimeMillis(); 
		/*app.syncStatistics();
		  QLog.getLogger().dLog(TAG,  "   syncStatistics cost time:" +(System.currentTimeMillis()-st));  
			 st=System.currentTimeMillis(); */
		
	}
}
