package com.graduate.secret;

import android.app.Application;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.text.TextUtils;

public class GlobalApplication extends Application {
	/**
	 * 自定义全局获取context的方法类
	 */
	LockScreenReceiver receiver;
	IntentFilter filter;
	public boolean isLocked = false;
	private static Context context;

	@Override
	public void onCreate() {
		context = getApplicationContext();
		receiver = new LockScreenReceiver();
		filter = new IntentFilter();
		filter.addAction(Intent.ACTION_SCREEN_OFF);
		this.registerReceiver(receiver, filter);
	}

	public static Context getContext() {
		return context;
	}

	@Override
	public void onTerminate() {
		super.onTerminate();
		this.unregisterReceiver(receiver);
	}

	// 内部类

	class LockScreenReceiver extends BroadcastReceiver {
		@Override
		public void onReceive(Context context, Intent intent) {
			/* 在这里处理广播 */
			String gesture_pass = Config
					.getCacheSpString(Config.SP_GESTURE_PASS);
			Boolean open_gesture = Config
					.getCacheSpBoolean(Config.SP_OPEN_GESTURE);
			// 如果打开密码锁，且屏幕锁定
			if (!TextUtils.isEmpty(gesture_pass) && open_gesture)
				if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
					isLocked = true;
				}
		}
	}

}
