FangTangApplication.java 3.36 KB
package com.xgimi.gimicinema.application;

import android.util.Log;
import android.widget.Toast;
import com.gimi.common.cinema.utils.LogUtils;
import com.gimi.common.cinema.utils.Utils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.qnbar.smc.application.MySampleAdvanceStrategy;
import com.qnbar.smc.service.TelinkLightService;
import com.telink.TelinkApplication;
import com.telink.bluetooth.light.AdvanceStrategy;
import com.telink.bluetooth.light.model.Mesh;

public class FangTangApplication extends TelinkApplication {
    private Mesh mesh;
    private String currentPlayUrl;

    @Override
    public void onCreate() {
        super.onCreate();
        AdvanceStrategy.setDefault(new MySampleAdvanceStrategy());
//		CrashHandler crashHandler = CrashHandler.getInstance();
//		crashHandler.init(getApplicationContext());initLog\\
        initLog();
    }

    @Override
    public void doInit() {
//        String fileName = "telink-";
//        fileName += System.currentTimeMillis();
//        fileName += ".log";
//        TelinkLog.LOG2FILE_ENABLE = false;
//        TelinkLog.onCreate(fileName);
        super.doInit();
        //AES.Security = true;
        /**
         *
         *@see com.telink.bluetooth.light.model.Mesh#saveOrUpdate
         */
        //save by json string
        try {
            String string = Utils.getString(this, "mesh-config");
            this.mesh = new Gson().fromJson(string, Mesh.class);
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }

        if (mesh == null) {
            Toast.makeText(this, "没有配置智能灯光,请配置", Toast.LENGTH_SHORT).show();
//            return;
        }

        Log.d("SMCService", "doInit");
        //启动LightService
        this.startLightService(TelinkLightService.class);
    }

    public Mesh getMesh() {
        return this.mesh;
    }

    public void setMesh(Mesh mesh) {
        this.mesh = mesh;
    }

    public boolean isEmptyMesh() {
        return this.mesh == null;
    }

    public String getCurrentPlayUrl() {
        return currentPlayUrl;
    }

    public void setCurrentPlayUrl(String currentPlayUrl) {
        this.currentPlayUrl = currentPlayUrl;
    }

    public static void initLog() {
        LogUtils.Builder builder = new LogUtils.Builder()
                .setLogSwitch(true)// 设置log总开关,包括输出到控制台和文件,默认开
                .setConsoleSwitch(true)// 设置是否输出到控制台开关,默认开
                .setGlobalTag(null)// 设置log全局标签,默认为空
                // 当全局标签不为空时,我们输出的log全部为该tag,
                // 为空时,如果传入的tag为空那就显示类名,否则显示tag
                .setLogHeadSwitch(true)// 设置log头信息开关,默认为开
                .setLog2FileSwitch(true)// 打印log时是否存到文件的开关,默认关
                .setDir("/sdcard/ft_log/")// 当自定义路径为空时,写入应用的/cache/log/目录中
                .setBorderSwitch(true)// 输出日志是否带边框开关,默认开
                .setConsoleFilter(LogUtils.V)// log的控制台过滤器,和logcat过滤器同理,默认Verbose
                .setFileFilter(LogUtils.V);// log文件过滤器,和logcat过滤器同理,默认Verbose
        LogUtils.d(builder.toString());
    }

}