package com.wasu.cs.ui;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.KeyEvent;
import android.widget.Toast;

import com.wasu.module.log.WLog;

import cn.com.wasu.main.R;

/**
 * 停服页面
 * 
 * @author yuanjr@wasu.com
 * 
 */
public class ActivityServiceStop extends Activity {

	private String TAG = "ActivityServiceStop";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		WLog.i(TAG,"onCreate()");

		setContentView(R.layout.activity_service_stop);

	}

	public int backKeyDownCount = 0;
	private final static int First_KeyDown_Back = 10010;
	private Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {

			switch (msg.what) {
			case First_KeyDown_Back:
				backKeyDownCount = 0;
				break;
			}
		}
	};

	/**
	 * 覆盖onKeyDown 添加首页连续点击两次返回键退出应用
	 */
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			if (backKeyDownCount == 1) {
				finish();
			} else {
				Toast.makeText(this, R.string.exit_message, Toast.LENGTH_SHORT)
						.show();
				backKeyDownCount++;
				mHandler.sendEmptyMessageDelayed(First_KeyDown_Back, 2000);
			}

			return true;
		}

		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();

		System.exit(0);
	}
}
