Java Code Examples for com.blankj.utilcode.util.GsonUtils

The following examples show how to use com.blankj.utilcode.util.GsonUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: DoraemonKit   Source File: NetWorkMonitorFragment.java    License: Apache License 2.0 6 votes vote down vote up
private void initCustomView() {
    findViewById(R.id.btn_net_summary).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showContent(NetWorkMainPagerFragment.class);
        }
    });
    mHostRv = findViewById(R.id.host_list);
    mHostRv.setLayoutManager(new LinearLayoutManager(getActivity()));
    if (DokitConstant.WHITE_HOSTS.isEmpty()) {
        String whiteHostArray = FileIOUtils.readFile2String(whiteHostPath);
        if (TextUtils.isEmpty(whiteHostArray)) {
            mHostBeans.add(new WhiteHostBean("", true));
        } else {
            mHostBeans = GsonUtils.fromJson(whiteHostArray, GsonUtils.getListType(WhiteHostBean.class));
            DokitConstant.WHITE_HOSTS.clear();
            DokitConstant.WHITE_HOSTS.addAll(mHostBeans);
        }
    } else {
        mHostBeans.addAll(DokitConstant.WHITE_HOSTS);
    }

    mHostAdapter = new WhiteHostAdapter(R.layout.dk_item_white_host, mHostBeans);
    mHostRv.setAdapter(mHostAdapter);
}
 
Example 2
Source Project: DoraemonKit   Source File: NetWorkMonitorFragment.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    //保存白名单
    List<WhiteHostBean> hostBeans = mHostAdapter.getData();
    if (hostBeans.size() == 1 && TextUtils.isEmpty(hostBeans.get(0).getHost())) {
        DokitConstant.WHITE_HOSTS.clear();
        FileUtils.delete(whiteHostPath);
        return;
    }
    DokitConstant.WHITE_HOSTS.clear();
    DokitConstant.WHITE_HOSTS.addAll(hostBeans);
    String hostArray = GsonUtils.toJson(hostBeans);
    //保存到本地
    FileUtils.delete(whiteHostPath);
    FileIOUtils.writeFileFromString(whiteHostPath, hostArray);
    //ToastUtils.showShort("host白名单已保存");

}
 
Example 3
Source Project: DoraemonKit   Source File: TimeCounterManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * App 启动结束
 */
public void onAppCreateEnd() {
    mAppCounter.end();
    CounterInfo counterInfo = getAppSetupInfo();
    if (DokitPluginConfig.VALUE_METHOD_STRATEGY == DokitPluginConfig.STRATEGY_STACK) {
        StringBuilder startInfo = new StringBuilder();
        startInfo.append(MethodStackUtil.STR_APP_ATTACH_BASECONTEXT);
        startInfo.append("\n");
        startInfo.append(MethodStackUtil.STR_APP_ON_CREATE);
        AppHealthInfoUtil.getInstance().setAppStartInfo(counterInfo.totalCost, startInfo.toString(), new ArrayList<AppHealthInfo.DataBean.AppStartBean.LoadFuncBean>());
    } else {
        List<AppHealthMethodCostBean> appHealthMethodCostBeans = new ArrayList<>();
        AppHealthMethodCostBean onCreate = new AppHealthMethodCostBean();
        onCreate.setCostTime(mAppCounter.getStartCountTime() + "ms");
        onCreate.setFunctionName("Application onCreate");
        appHealthMethodCostBeans.add(onCreate);
        AppHealthMethodCostBean onAttach = new AppHealthMethodCostBean();
        onAttach.setCostTime(mAppCounter.getAttachCountTime() + "ms");
        onAttach.setFunctionName("Application attachBaseContext");
        appHealthMethodCostBeans.add(onAttach);

        AppHealthMethodCostBeanWrap appHealthMethodCostBeanWrap = new AppHealthMethodCostBeanWrap();
        appHealthMethodCostBeanWrap.setTitle("App启动耗时");
        appHealthMethodCostBeanWrap.setData(appHealthMethodCostBeans);
        AppHealthInfoUtil.getInstance().setAppStartInfo(counterInfo.totalCost, GsonUtils.toJson(appHealthMethodCostBeanWrap), new ArrayList<AppHealthInfo.DataBean.AppStartBean.LoadFuncBean>());

    }

}
 
Example 4
Source Project: DoraemonKit   Source File: DataPickManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 异常情况下保存到本地保存到本地
 */
public void saveData2Local() {
    if (events == null || events.size() == 0) {
        return;
    }
    dataPickBean.setEvents(events);
    //保存数据到本地
    FileIOUtils.writeFileFromString(filePath, GsonUtils.toJson(dataPickBean));
}