package cc.winboll.studio.powerbell;

import android.content.Context;
import android.os.Environment;
import android.view.Gravity;
import cc.winboll.studio.libappbase.GlobalApplication;
import cc.winboll.studio.libappbase.ToastUtils;
import cc.winboll.studio.powerbell.receivers.GlobalApplicationReceiver;
import cc.winboll.studio.powerbell.utils.AppCacheUtils;
import cc.winboll.studio.powerbell.utils.AppConfigUtils;
import java.io.File;

public class App extends GlobalApplication {

    public static final String TAG = "GlobalApplication";
	
	public static final String COMPONENT_EN1 = "cc.winboll.studio.powerbell.MainActivityEN1";
	public static final String COMPONENT_CN1 = "cc.winboll.studio.powerbell.MainActivityCN1";
	public static final String COMPONENT_CN2 = "cc.winboll.studio.powerbell.MainActivityCN2";
	public static final String ACTION_SWITCHTO_EN1 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_EN1";
	public static final String ACTION_SWITCHTO_CN1 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_CN1";
	public static final String ACTION_SWITCHTO_CN2 = "cc.winboll.studio.powerbell.App.ACTION_SWITCHTO_CN2";
	
    // 数据配置存储工具
    static AppConfigUtils _mAppConfigUtils;
    static AppCacheUtils _mAppCacheUtils;
    GlobalApplicationReceiver mReceiver;
    static String szTempDir = "";

    public static String getTempDirPath() {
        return szTempDir;
    }

    @Override
    public void onCreate() {
        super.onCreate();
		setIsDebugging(BuildConfig.DEBUG);

        // 临时文件夹方案1
        // 获取Pictures文件夹路径（Android 10及以上推荐使用MediaStore，此处为传统方式）
        File picturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
        // 定义目标文件路径（在Pictures目录下创建"PowerBell"子文件夹及文件）
        File powerBellDir = new File(picturesDir, "PowerBell");
        
        // 临时文件夹方案2 <图片保存失败>
        // 获取Pictures文件夹路径（Android 10及以上推荐使用MediaStore，此处为传统方式）
        //File powerBellDir = getExternalFilesDir("TempDir");

        // 先创建文件夹（如果不存在）
        if (!powerBellDir.exists()) {
            powerBellDir.mkdirs();
        }
        szTempDir = powerBellDir.getAbsolutePath();


        // 初始化 Toast 框架
        ToastUtils.init(this);
        // 设置 Toast 布局样式
        //ToastUtils.setView(R.layout.toast_custom_view);
        //ToastUtils.setStyle(new WhiteToastStyle());
        //ToastUtils.setGravity(Gravity.BOTTOM, 0, 200);

        // 设置数据配置存储工具
        _mAppConfigUtils = getAppConfigUtils(this);
        _mAppCacheUtils = getAppCacheUtils(this);

        mReceiver = new GlobalApplicationReceiver(this);
        mReceiver.registerAction();
    }

    public static AppConfigUtils getAppConfigUtils(Context context) {
        if (_mAppConfigUtils == null) {
            _mAppConfigUtils = AppConfigUtils.getInstance(context);
        }
        return _mAppConfigUtils;
    }

    public static AppCacheUtils getAppCacheUtils(Context context) {
        if (_mAppCacheUtils == null) {
            _mAppCacheUtils = AppCacheUtils.getInstance(context);
        }
        return _mAppCacheUtils;
    }

    public void clearBatteryHistory() {
        _mAppCacheUtils.clearBatteryHistory();
    }

	@Override
	public void onTerminate() {
		super.onTerminate();
		ToastUtils.release();
	}
	
	
}

