package com.example.gpstest1;

import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.adapter.TongjiAdapter;
import com.example.bean.ChooseCarBean;
import com.example.bean.TongjiItem;
import com.example.util.Constant;
import com.example.util.SystemBarTintManager;

import java.util.ArrayList;

public class TongjiActivity extends Activity implements OnClickListener{
	private ListView mListView;
	private static MainActivity mActivity;
	private static Context mContext;
	private TongjiAdapter mAdapter;
	private ChooseCarBean mBean;
	private ArrayList<TongjiItem> mList = new ArrayList<TongjiItem>();//本界面需要用的list
	private TextView topTextView;
	private ImageView backImg;
	
	private String departCode;
	private String departName;
	private String strdeviceId;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    
	           setTranslucentStatus(true);    
	           SystemBarTintManager tintManager = new SystemBarTintManager(this);    
	           tintManager.setStatusBarTintEnabled(true);    
	           tintManager.setStatusBarTintResource(R.color.top_bg_color);//通知栏所需颜色  
	       }    
		setContentView(R.layout.activity_tongji);
		MainActivity.activityList.add(this);
		findViews();
		initData();
		
		
	}
	
	
	
	public void findViews()
	{
		mListView = (ListView)findViewById(R.id.typeList);
		topTextView = (TextView)findViewById(R.id.TitleText);
		backImg = (ImageView)findViewById(R.id.backImage);
		backImg.setOnClickListener(this);
		topTextView.setText(getResources().getString(R.string.Tongjifenxi));
		
		departCode = getIntent().getStringExtra("departCode");
		departName = getIntent().getStringExtra("departName");
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				//点击item
				int type =mList.get(position).getType();
				if(type==1)
				{
					OnlineTongjiActivity.actionStart(TongjiActivity.this,mActivity,departCode, departName);
				}else if(type ==2)
				{
					AlarmTongjiActivity.actionStart(TongjiActivity.this,mActivity, departCode, departName);
				}else if(type ==3)
				{
					MeliageActivity2.actionStart(TongjiActivity.this,mActivity, departCode, departName,Constant.MELIAGETONGJI);
				}else if(type ==4)
				{
					MeliageActivity2.actionStart(TongjiActivity.this,mActivity, departCode, departName,Constant.OVERMELIAGETONGJI);
				}
				
				
			}
		});
	}
	public void initData()
	{
		mList.clear();
		TongjiItem itme1 =new TongjiItem();
		itme1.setTypename("在线离线统计");
		itme1.setType(1);
		mList.add(itme1);
		
		TongjiItem itme2 =new TongjiItem();
		itme2.setTypename("报警统计");
		itme2.setType(2);
		mList.add(itme2);
		
		TongjiItem itme3 =new TongjiItem();
		itme3.setTypename("里程统计");
		itme3.setType(3);
		mList.add(itme3);
		
		TongjiItem itme4 =new TongjiItem();
		itme4.setTypename("超里程统计");
		itme4.setType(4);
		mList.add(itme4);
		
		showUI();
	}
	
	
	
	public void showUI()
	{
		
		if(mAdapter==null)
		{
			mAdapter = new TongjiAdapter(mContext, mList);
			mListView.setAdapter(mAdapter);
		}else{
			mAdapter.notifyList(mList);
		}
		

	}
	
	
	public  static void actionStart(Context context,String departCode,String departName)
	{
		mContext = context;
		mActivity = (MainActivity) context;
		Intent intent = new Intent(context,TongjiActivity.class);
		intent.putExtra("departCode", departCode);
		intent.putExtra("departName", departName);
		context.startActivity(intent);
		
	}


	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.backImage:
			finish();
			break;
		default:
			break;
		}
	}




	















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



@TargetApi(19)     
private void setTranslucentStatus(boolean on) {    
    Window win = getWindow();    
    WindowManager.LayoutParams winParams = win.getAttributes();    
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;    
    if (on) {    
        winParams.flags |= bits;    
    } else {    
        winParams.flags &= ~bits;    
    }    
    win.setAttributes(winParams);    
}

@Override
protected void onPause() {
	super.onPause();
	
}
    
@Override
protected void onRestart() {
	super.onRestart();
}
	
	
	
}
