WMSApplication.java 2.05 KB
package com.huaheng.wms;

import android.app.Application;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.RemoteException;

import com.huaheng.wms.util.CrashHandler;
import com.huaheng.wms.util.SoundUtils;
import com.huaheng.wms.util.SpeechUtil;
import com.huaheng.wms.util.WMSUtils;
import com.huaheng.wms.wmsgreendao.DaoMaster;
import com.huaheng.wms.wmsgreendao.DaoSession;

import org.xutils.x;


public class WMSApplication extends Application {

    private static String cookie;
    //  greenDao
    private  DaoMaster.DevOpenHelper mHelper;
    private  SQLiteDatabase db;
    private  DaoMaster mDaoMaster;
    private  DaoSession mDaoSession;
    private static Context mContext;
    private static WMSApplication instance;

    @Override
    public void onCreate() {
        super.onCreate();
        initData();
    }

    public static WMSApplication getInstance() {
        if(instance == null) {
            instance = new WMSApplication();
        }
        return instance;
    }

    public  void initData() {
        mContext = this;
        SoundUtils.getInstance(this);
        setupDataBase();
        CrashHandler.getInstance().init(this);

        x.Ext.init(this);
        x.Ext.setDebug(BuildConfig.DEBUG); // 是否输出debug日志, 开启debug会影响性能.
        SpeechUtil.getInstance(mContext).initSpeech();
    }

    public static String getOkhttpCookie() {
        return cookie;
    }

    public static void setOkhttpCookie(String result) {
        cookie = result;
    }

    /**
     * 初始化数据库
     */
    private void setupDataBase() {
        mHelper = new DaoMaster.DevOpenHelper(this, "WMSApplication", null);
        db = mHelper.getWritableDatabase();
        mDaoMaster = new DaoMaster(db);
        mDaoSession = mDaoMaster.newSession();
        WMSLog.d("setupDataBase");
    }


    public DaoSession getDaoSession() {
        return mDaoSession;
    }

    public SQLiteDatabase getDb() {
        return db;
    }

    public static Context getContext() {
        return mContext;
    }


}