package name.wanghwx.ehomework.presenter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import androidx.fragment.app.Fragment;
import com.onyx.android.sdk.pen.RawInputCallback;
import com.onyx.android.sdk.pen.TouchHelper;
import com.onyx.android.sdk.pen.data.TouchPoint;
import com.onyx.android.sdk.pen.data.TouchPointList;
import com.onyx.android.sdk.utils.CollectionUtils;
import com.onyx.android.sdk.utils.StringUtils;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import name.wanghwx.ehomework.common.constant.Category;
import name.wanghwx.ehomework.common.constant.MapKey;
import name.wanghwx.ehomework.common.constant.PreSuf;
import name.wanghwx.ehomework.common.pojo.DisplayItem;
import name.wanghwx.ehomework.common.pojo.DisplayOption;
import name.wanghwx.ehomework.common.pojo.DisplayQuestion;
import name.wanghwx.ehomework.common.pojo.EraserSetting;
import name.wanghwx.ehomework.common.pojo.HttpCallback;
import name.wanghwx.ehomework.common.pojo.PenSetting;
import name.wanghwx.ehomework.common.pojo.Result;
import name.wanghwx.ehomework.common.pojo.Step;
import name.wanghwx.ehomework.common.pojo.Stroke;
import name.wanghwx.ehomework.common.pojo.StrokeBoard;
import name.wanghwx.ehomework.common.util.GsonUtils;
import name.wanghwx.ehomework.model.HomeworkModel;
import name.wanghwx.ehomework.model.MistakeBookModel;
import name.wanghwx.ehomework.model.imodel.IHomeworkModel;
import name.wanghwx.ehomework.model.imodel.IMistakeBookModel;
import name.wanghwx.ehomework.pojo.Answer;
import name.wanghwx.ehomework.pojo.Choice;
import name.wanghwx.ehomework.pojo.Homework;
import name.wanghwx.ehomework.pojo.Item;
import name.wanghwx.ehomework.pojo.MistakeBook;
import name.wanghwx.ehomework.pojo.Option;
import name.wanghwx.ehomework.pojo.Question;
import name.wanghwx.ehomework.pojo.Review;
import name.wanghwx.ehomework.presenter.ipresenter.IHomeworkActivityPresenter;
import name.wanghwx.ehomework.view.fragment.AudioFragment;
import name.wanghwx.ehomework.view.fragment.CommentFragment;
import name.wanghwx.ehomework.view.fragment.EraserFragment;
import name.wanghwx.ehomework.view.fragment.ItemFragment;
import name.wanghwx.ehomework.view.fragment.PenFragment;
import name.wanghwx.ehomework.view.iactivity.IHomeworkActivity;
import okhttp3.MediaType;
import okhttp3.RequestBody;
public class HomeworkActivityPresenter extends IHomeworkActivityPresenter implements Serializable {
private static final Bundle bundles = new Bundle();
private Stack<Step<Stroke>> undoStack = new Stack<>();
private Stack<Step<Stroke>> redoStack = new Stack<>();
// 作业id
private int homeworkId;
// 查询得到的单次作业
private Homework homework;
// 题目序号
private int number;
private Handler handler = new Handler(message->{
if(message.what == number){
if(isViewAttached()) getView().renderDraw(true,false);
return true;
}else{
return false;
}
});
// 工具栏是否显示
private boolean showTool;
// 工具栏工具码
private int tool;
// 笔触设置
private PenSetting penSetting = new PenSetting();
// 橡皮设置
private EraserSetting eraserSetting = new EraserSetting();
private PenFragment penFragment = PenFragment.getInstance(penSetting);
private EraserFragment eraserFragment = EraserFragment.getInstance(eraserSetting);
// 指导栏是否显示
private boolean showGuidance;
// 指导栏指导码
private int guidance;
// 是否全屏显示
private boolean fullscreen;
// 是否显示草稿
private boolean showDraft;
// 是否显示答案
private boolean showReference;
// 手写范围定宽
private int fixedWidth;
// 当前滚动高度
private int scroll;
// 最大滚动高度
private int maxScroll;
private TouchHelper touchHelper;
// 当前笔画
private Stroke currentStroke;
// 滑动是否开启
private boolean slide;
// 滑动初始高度
private int initialY;
// 当前画布
private Canvas canvas;
// 当前位图
private Bitmap bitmap;
// 重绘线程
private Thread redraw;
// 题目展示数据
private List<DisplayItem> displayItems = new ArrayList<>();
// 答题区手写板
private List<StrokeBoard> answerBoards = new ArrayList<>();
// 草稿区手写板
private List<StrokeBoard> draftBoards = new ArrayList<>();
// 题目展示控件
private List<ItemFragment> itemFragments = new ArrayList<>();
// 评语展示控件
private List<CommentFragment> commentFragments = new ArrayList<>();
// 留言展示控件
private List<AudioFragment> audioFragments = new ArrayList<>();
private IHomeworkModel homeworkModel = HomeworkModel.getInstance();
private IMistakeBookModel mistakeBookModel = MistakeBookModel.getInstance();
public HomeworkActivityPresenter(IHomeworkActivity homeworkActivity){
attachView(homeworkActivity);
penFragment.setOnDecreaseClickListener(this::decreasePenWeight);
penFragment.setOnProgressChangeListener(this::setPenWeight);
penFragment.setOnIncreaseClickListener(this::increasePenWeight);
eraserFragment.setOnClearClickListener(this::emptyBoard);
}
private void decreasePenWeight(){
penSetting.weight--;
validatePenWeight();
}
private void setPenWeight(int progress){
penSetting.weight = (float)progress;
validatePenWeight();
}
private void increasePenWeight(){
penSetting.weight++;
validatePenWeight();
}
// 清空,支持撤销功能
private void emptyBoard(){
StrokeBoard strokeBoard = getStrokeBoard();
if(strokeBoard != null){
Step<Stroke> step = strokeBoard.clearBoard();
if(step != null){
redoStack.clear();
undoStack.push(step);
validateUndoRedo();
}
redraw();
}
}
private void validatePenWeight(){
if(penSetting.weight <= PenSetting.MIN_WEIGHT){
penSetting.weight = PenSetting.MIN_WEIGHT;
penFragment.disableDecrease();
}else{
penFragment.enableDecrease();
}
if(penSetting.weight >= PenSetting.MAX_WEIGHT){
penSetting.weight = PenSetting.MAX_WEIGHT;
penFragment.disableIncrease();
}else{
penFragment.enableIncrease();
}
if(touchHelper != null){
touchHelper.setStrokeWidth(penSetting.weight);
}
penFragment.renderPenSetting(penSetting);
}
@Override
public void getHomework(int homeworkId){
this.homeworkId = homeworkId;
homeworkModel.getHomework(new HttpCallback<Homework>(getView()){
@Override
public void success(Result<Homework> result){
Homework data = result.data();
if(data == null){
if(isViewAttached()) getView().nullData();
}else{
homework = data;
load();
}
}
},this.homeworkId);
}
private void load(){
Bundle bundle = bundles.getBundle(PreSuf.HOMEWORK_PREFIX + homeworkId);
List<Item> items = homework.getTask().getItems();
for(int i=0,il=items.size();i<il;i++){
int itemId = items.get(i).getItemId();
displayItems.
lsx202406
- 粉丝: 2845
- 资源: 5676
最新资源
- 【创新无忧】基于人工蜂鸟优化算法AHA优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于人工蜂群优化算法ABC优化相关向量机RVM实现数据多输入单输出回归预测附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化广义神经网络GRNN实现光伏预测附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化广义神经网络GRNN实现数据回归预测附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化相关向量机RVM实现北半球光伏数据预测附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化极限学习机ELM实现乳腺肿瘤诊断附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化极限学习机KELM实现故障诊断附matlab代码.rar
- 【创新无忧】基于三角测量拓扑聚合优化器TTAO优化相关向量机RVM实现数据多输入单输出回归预测附matlab代码.rar
- 【创新无忧】基于沙猫群优化算法SCSO优化广义神经网络GRNN实现电机故障诊断附matlab代码.rar
- 【创新无忧】基于沙猫群优化算法SCSO优化广义神经网络GRNN实现光伏预测附matlab代码.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈