| | |
| | | package com.hdl.photovoltaic.ui.test; |
| | | |
| | | |
| | | import android.content.Intent; |
| | | import android.net.Uri; |
| | | import android.os.Bundle; |
| | | import android.text.Spannable; |
| | | import android.text.SpannableStringBuilder; |
| | | import android.text.TextUtils; |
| | | import android.text.style.ForegroundColorSpan; |
| | | import android.view.View; |
| | | |
| | | import androidx.core.content.FileProvider; |
| | | |
| | | import com.hdl.photovoltaic.R; |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | |
| | | import com.hdl.photovoltaic.widget.ConfirmationCancelDialog; |
| | | import com.hdl.photovoltaic.widget.ListStaticDialog; |
| | | |
| | | import java.io.File; |
| | | import java.util.IdentityHashMap; |
| | | import java.util.Map; |
| | | |
| | |
| | | * 监听器初始化 |
| | | */ |
| | | private void initEvent() { |
| | | viewBinding.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | finish(); |
| | |
| | | |
| | | } |
| | | }); |
| | | |
| | | viewBinding.clickToBottomTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | // int offset = (viewBinding.sv.getChildAt(0).getMeasuredHeight() - viewBinding.sv.getHeight()); // 计算需要滚动的距离 |
| | | // if (offset > 0) { |
| | | // viewBinding.sv.smoothScrollTo(0, offset); // 平滑地滚动到底部位置 |
| | | // } else { |
| | | // viewBinding.sv.fullScroll(View.FOCUS_DOWN); // 直接滚动到最后一行 |
| | | // } |
| | | viewBinding.sv.fullScroll(View.FOCUS_DOWN); // 直接滚动到最后一行 |
| | | } |
| | | }); |
| | | //上传日志到云端上 |
| | | viewBinding.uploadingLogTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //todo 需要调云端的接口 |
| | | HdlThreadLogic.toast(_mActivity, "还没有支持上传日志."); |
| | | // HdlThreadLogic.toast(_mActivity, "还没有支持上传日志."); |
| | | |
| | | // Intent sendIntent = new Intent(); |
| | | // sendIntent.setAction(Intent.ACTION_SEND); |
| | | // sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); |
| | | // sendIntent.setType("text/plain"); |
| | | // startActivity(Intent.createChooser(sendIntent, "Share via")); |
| | | try { |
| | | // 在Activity中创建分享Intent |
| | | Intent shareIntent = new Intent(Intent.ACTION_SEND); |
| | | shareIntent.setType("application/pdf"); // 根据要分享的文件类型设置MIME类型 |
| | | File file = new File(HdlFileLogic.getInstance().getLogFileNamePath()); // 指定文件路径 |
| | | Uri fileUri = FileProvider.getUriForFile(_mActivity, "com.hdl.photovoltaic.dc.fileprovider", file); |
| | | shareIntent.putExtra(Intent.EXTRA_STREAM, fileUri); |
| | | shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); |
| | | startActivity(Intent.createChooser(shareIntent, "Share file using")); |
| | | } catch (Exception ignored) { |
| | | HdlThreadLogic.toast(_mActivity, "分享失败"); |
| | | } |
| | | } |
| | | }); |
| | | |
| | |
| | | * 初始化界面 |
| | | */ |
| | | private void initView() { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | String homeId = "日志住宅ID=" + UserConfigManage.getInstance().getHomeId(); |
| | | String homeName = "日志住宅名称=" + UserConfigManage.getInstance().getHomeName(); |
| | | viewBinding.homeIdTv.setText(homeId); |
| | | viewBinding.homeNameTv.setText(homeName); |
| | | showLoading(); |
| | | HdlThreadLogic.runSubThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | |
| | | String homeId = "测试住宅ID=" + UserConfigManage.getInstance().getHomeId(); |
| | | String homeName = "测试住宅名称=" + UserConfigManage.getInstance().getHomeName(); |
| | | viewBinding.homeIdTv.setText(homeId); |
| | | viewBinding.homeNameTv.setText(homeName); |
| | | |
| | | HdlFileLogic.getInstance().delFileLien(HdlFileLogic.getInstance().getLogFileNamePath(), 2); |
| | | // HdlFileLogic.getInstance().delFileLien(HdlFileLogic.getInstance().getLogFileNamePath(), 2); |
| | | String content = HdlLogLogic.readLog(); |
| | | int startIndex = 0; |
| | | int endIndex; |
| | | Map<Integer, Integer> map = new IdentityHashMap<>(); |
| | | String[] s = content.split("\r\n"); |
| | | for (int i = 0; i < s.length; i++) { |
| | | if (i == 0) { |
| | | endIndex = s[i].indexOf("s%"); |
| | | } else { |
| | | startIndex = 2 + startIndex + s[i - 1].length();//2换行符长度 |
| | | endIndex = 2 + startIndex + s[i].indexOf("s%");//2换行符长度 |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | hideLoading(); |
| | | if (TextUtils.isEmpty(content)) { |
| | | return; |
| | | } |
| | | int startIndex = 0; |
| | | int endIndex; |
| | | Map<Integer, Integer> map = new IdentityHashMap<>(); |
| | | String[] newArray = content.split("\r\n"); |
| | | // String[] newArray = new String[oldArray.length];//倒序 |
| | | // for (int i = oldArray.length - 1, j = 0; i >= 0; i--, j++) { |
| | | // newArray[j] = oldArray[i]; |
| | | // } |
| | | // StringBuilder stringBuilder = new StringBuilder(); |
| | | // for (String s : newArray) { |
| | | // stringBuilder.append(s).append("\r\n"); |
| | | // } |
| | | // content = stringBuilder.toString(); |
| | | for (int i = 0; i < newArray.length; i++) { |
| | | if (i == 0) { |
| | | endIndex = newArray[i].indexOf("s%"); |
| | | } else { |
| | | startIndex = 2 + startIndex + newArray[i - 1].length();//2换行符长度 |
| | | endIndex = 2 + startIndex + newArray[i].indexOf("s%");//2换行符长度 |
| | | } |
| | | map.put(startIndex, endIndex); |
| | | } |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(content.replace("s%", " "));//注意s%是两个字符,所以占两位 |
| | | for (Map.Entry<Integer, Integer> entry : map.entrySet()) { |
| | | int start = entry.getKey(); |
| | | int end = entry.getValue(); |
| | | //设置时间体验是另一种颜色 |
| | | spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | } |
| | | viewBinding.replyContentTv.setText(spannable); |
| | | |
| | | } |
| | | map.put(startIndex, endIndex); |
| | | } |
| | | SpannableStringBuilder spannable = new SpannableStringBuilder(content.replace("s%", " "));//注意s%是两个字符,所以占两位 |
| | | for (Map.Entry<Integer, Integer> entry : map.entrySet()) { |
| | | int start = entry.getKey(); |
| | | int end = entry.getValue(); |
| | | //设置时间体验是另一种颜色 |
| | | spannable.setSpan(new ForegroundColorSpan(getColor(R.color.text_245EC3)), start, end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); |
| | | } |
| | | viewBinding.replyContentTv.setText(spannable); |
| | | }); |
| | | } |
| | | }, null, null); |
| | | }); |
| | | |
| | | } |
| | | } |