|
|
package com.hh.xuetubao.activity.pratice;
|
|
|
|
|
|
import android.annotation.TargetApi;
|
|
|
import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
|
import android.support.annotation.RequiresApi;
|
|
|
import android.util.Log;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
import android.view.View;
|
|
|
import android.view.ViewGroup;
|
|
|
import android.view.WindowManager;
|
|
|
import android.widget.AdapterView;
|
|
|
import android.widget.GridView;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.ListView;
|
|
|
import android.widget.PopupWindow;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
import android.widget.Toast;
|
|
|
|
|
|
import com.hh.xuetubao.R;
|
|
|
import com.hh.xuetubao.Utils.SharedPrefrenceUtils;
|
|
|
import com.hh.xuetubao.adapter.AnswerSheetGridAdapter;
|
|
|
import com.hh.xuetubao.adapter.ListAnswerAdapter;
|
|
|
import com.hh.xuetubao.bean.AnswerBean;
|
|
|
import com.hh.xuetubao.model.ExerciseModel;
|
|
|
import com.hh.xuetubao.mvp.BaseMvpActivity;
|
|
|
import com.hh.xuetubao.mvp.CommonPresenter;
|
|
|
import com.hh.xuetubao.mvp.ICommonView;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
import butterknife.BindView;
|
|
|
import butterknife.ButterKnife;
|
|
|
|
|
|
/**
|
|
|
* 模拟考试答题界面
|
|
|
*/
|
|
|
public class AnswerActivity extends BaseMvpActivity<CommonPresenter, ExerciseModel> implements ICommonView, View.OnClickListener {
|
|
|
@BindView(R.id.list_answer)
|
|
|
ListView listAnswer;
|
|
|
@BindView(R.id.tv_radio)
|
|
|
TextView tvRadio;
|
|
|
@BindView(R.id.tv_max)
|
|
|
TextView tvMax;
|
|
|
@BindView(R.id.tv_current)
|
|
|
TextView tvCurrent;
|
|
|
@BindView(R.id.tv_title)
|
|
|
TextView tvTitle;
|
|
|
@BindView(R.id.tv_topic)
|
|
|
TextView tvTopic;
|
|
|
@BindView(R.id.rl_last)
|
|
|
RelativeLayout rlLast;
|
|
|
@BindView(R.id.rl_next)
|
|
|
RelativeLayout rlNext;
|
|
|
@BindView(R.id.commit)
|
|
|
LinearLayout commit;
|
|
|
@BindView(R.id.index)
|
|
|
TextView index;
|
|
|
@BindView(R.id.all)
|
|
|
TextView all;
|
|
|
@BindView(R.id.tv_right_num)
|
|
|
TextView tvRightNum;
|
|
|
@BindView(R.id.tv_wrong_num)
|
|
|
TextView tvWrongNum;
|
|
|
@BindView(R.id.lin_tab)
|
|
|
LinearLayout linTab;
|
|
|
@BindView(R.id.rl_card)
|
|
|
RelativeLayout rlCard;
|
|
|
|
|
|
private ListAnswerAdapter optionsAdapter;
|
|
|
private List<AnswerBean.QuestionLstBean> questionList = new ArrayList<>();
|
|
|
private List<Integer> sheetCard = new ArrayList<>();
|
|
|
private String catalogOid;
|
|
|
private PopupWindow popupWindow;
|
|
|
private int maxTopic=0; //题目总数量
|
|
|
private int unDone; //未完成题目数量
|
|
|
private double danxuan; //单选题分数 单个
|
|
|
private double duoxuan; //多选题分数 单个
|
|
|
private double panduan; //判断题分数 单个
|
|
|
private int danxuanCount;//单选题数量
|
|
|
private int duoxuanCount;//多选题数量
|
|
|
private int panduanCount;//判断题数量
|
|
|
private int currentIndex = 0; //当前题目下标
|
|
|
private String selectAnswer; //选择答案
|
|
|
private String rightAnswer; //正确答案
|
|
|
private double totalScore = 0; //获得分数
|
|
|
private String markType; //当前题目类型
|
|
|
private boolean isClickOnce = false;//是否是单选题 只能点击一次
|
|
|
private int rightCount;//答对题的数量
|
|
|
private int wrongCount;//答错题的数量
|
|
|
private int danxuanWrong;//单选做错的数量
|
|
|
private int duoxuanWrong;//多选做错的数量
|
|
|
private int panduanWrong;//判断做错的数量
|
|
|
private AnswerSheetGridAdapter sheetGridAdapter;
|
|
|
private String resumeOid;
|
|
|
|
|
|
|
|
|
// R.layout.pop_answer
|
|
|
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
resumeOid = SharedPrefrenceUtils.getString(this, "AccountOid");
|
|
|
catalogOid = getIntent().getStringExtra("catalogOid");
|
|
|
|
|
|
rlLast.setOnClickListener(this);
|
|
|
rlNext.setOnClickListener(this);
|
|
|
commit.setOnClickListener(this);
|
|
|
linTab.setOnClickListener(this);
|
|
|
rlCard.setOnClickListener(this);
|
|
|
|
|
|
listAnswer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
@Override
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
|
|
ImageView wrong = (ImageView) view.findViewById(R.id.img_wrong);
|
|
|
ImageView right = (ImageView) view.findViewById(R.id.img_right);
|
|
|
TextView option = (TextView) view.findViewById(R.id.option);
|
|
|
|
|
|
if (markType.contains("单选") || markType.contains("判断")) {
|
|
|
if (isClickOnce) {
|
|
|
isClickOnce = false;
|
|
|
try {
|
|
|
//选择答案
|
|
|
if (position == 0)
|
|
|
selectAnswer = "A";
|
|
|
if (position == 1)
|
|
|
selectAnswer = "B";
|
|
|
if (position == 2)
|
|
|
selectAnswer = "C";
|
|
|
if (position == 3)
|
|
|
selectAnswer = "D";
|
|
|
if (position == 4)
|
|
|
selectAnswer = "E";
|
|
|
if (position == 5)
|
|
|
selectAnswer = "F";
|
|
|
} catch (Exception e) {
|
|
|
Log.e("Exception:", e.toString());
|
|
|
}
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
} else if (markType.contains("多选")) {
|
|
|
try {
|
|
|
//选择答案
|
|
|
if (position == 0)
|
|
|
selectAnswer += "A";
|
|
|
if (position == 1)
|
|
|
selectAnswer += "B";
|
|
|
if (position == 2)
|
|
|
selectAnswer += "C";
|
|
|
if (position == 3)
|
|
|
selectAnswer += "D";
|
|
|
if (position == 4)
|
|
|
selectAnswer += "E";
|
|
|
if (position == 5)
|
|
|
selectAnswer += "F";
|
|
|
} catch (Exception e) {
|
|
|
Log.e("Exception:", e.toString());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
Log.e("zhangtao:rightAnswer", rightAnswer + "");
|
|
|
Log.e("zhangtao:selectAnswer", selectAnswer + "");
|
|
|
|
|
|
if (rightAnswer.contains(selectAnswer)) {
|
|
|
right.setVisibility(View.VISIBLE);
|
|
|
wrong.setVisibility(View.GONE);
|
|
|
option.setVisibility(View.GONE);
|
|
|
|
|
|
//答题成功 加分
|
|
|
if (markType.contains("单选")) {
|
|
|
totalScore += danxuan;
|
|
|
} else if (markType.contains("多选")) {
|
|
|
totalScore += duoxuan;
|
|
|
} else if (markType.contains("判断")) {
|
|
|
totalScore += panduan;
|
|
|
}
|
|
|
|
|
|
rightCount++;
|
|
|
tvRightNum.setText(String.valueOf(rightCount));
|
|
|
|
|
|
sheetCard.set(currentIndex, 1);
|
|
|
sheetGridAdapter.notifyDataSetChanged();
|
|
|
|
|
|
} else {
|
|
|
if (markType.contains("单选")) {
|
|
|
danxuanWrong++;
|
|
|
} else if (markType.contains("多选")) {
|
|
|
duoxuanWrong++;
|
|
|
} else if (markType.contains("判断")) {
|
|
|
panduanWrong++;
|
|
|
}
|
|
|
|
|
|
//答题失败
|
|
|
right.setVisibility(View.GONE);
|
|
|
wrong.setVisibility(View.VISIBLE);
|
|
|
option.setVisibility(View.GONE);
|
|
|
|
|
|
String questionOid = questionList.get(position).getQuestionOid();
|
|
|
mPresenter.getPresenter(4, 2, resumeOid, questionOid, String.valueOf(1));
|
|
|
|
|
|
wrongCount++;
|
|
|
tvWrongNum.setText(String.valueOf(wrongCount));
|
|
|
|
|
|
|
|
|
sheetCard.set(currentIndex, 2);
|
|
|
sheetGridAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void doRefresh() {
|
|
|
|
|
|
rightAnswer = questionList.get(currentIndex).getAnswer();
|
|
|
tvCurrent.setText(String.valueOf(currentIndex + 1));
|
|
|
tvRadio.setText(questionList.get(currentIndex).getQuestionTypeName());
|
|
|
markType = questionList.get(currentIndex).getQuestionTypeName();
|
|
|
if (markType.contains("单选") || markType.contains("判断")) {
|
|
|
isClickOnce = true;
|
|
|
} else {
|
|
|
isClickOnce = false;
|
|
|
}
|
|
|
tvTopic.setText(questionList.get(currentIndex).getQuestionTitle());
|
|
|
|
|
|
optionsAdapter = new ListAnswerAdapter(questionList.get(currentIndex).getOptionsLst(), this);
|
|
|
listAnswer.setAdapter(optionsAdapter);
|
|
|
optionsAdapter.notifyDataSetChanged();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public int initLayout() {
|
|
|
return R.layout.activity_answer;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void initData() {
|
|
|
// mPresenter.getPresenter(4, 1, catalogOid, "3E0E2A6B-6616-4CEE-B498-1F06A6F8D482");
|
|
|
mPresenter.getPresenter(4, 1, catalogOid,resumeOid);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public CommonPresenter getPresenter() {
|
|
|
return new CommonPresenter();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public ExerciseModel getModel() {
|
|
|
return new ExerciseModel();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void getData(Object o, int api, int intent) {
|
|
|
if (api == 4 && intent == 1) {
|
|
|
AnswerBean bean = (AnswerBean) o;
|
|
|
|
|
|
maxTopic = bean.getRadioCount() + bean.getMultipleCount() + bean.getJudgeCount();
|
|
|
danxuanCount = bean.getRadioCount();
|
|
|
duoxuanCount = bean.getMultipleCount();
|
|
|
panduanCount = bean.getJudgeCount();
|
|
|
|
|
|
all.setText(String.valueOf(maxTopic));
|
|
|
for (int i = 0; i < maxTopic; i++) {
|
|
|
sheetCard.add(0);
|
|
|
}
|
|
|
sheetGridAdapter = new AnswerSheetGridAdapter(sheetCard, this);
|
|
|
|
|
|
questionList.addAll(bean.getQuestionLst());
|
|
|
|
|
|
danxuan = bean.getRadioScore();
|
|
|
duoxuan = bean.getMultipleScore();
|
|
|
panduan = bean.getJudgeScore();
|
|
|
rightAnswer = bean.getQuestionLst().get(0).getAnswer();
|
|
|
|
|
|
if (bean.getExamType() != null) {
|
|
|
tvTitle.setText(bean.getExamType());
|
|
|
}
|
|
|
|
|
|
optionsAdapter = new ListAnswerAdapter(questionList.get(0).getOptionsLst(), this);
|
|
|
listAnswer.setAdapter(optionsAdapter);
|
|
|
|
|
|
tvCurrent.setText(String.valueOf(currentIndex + 1));
|
|
|
tvMax.setText(String.valueOf(maxTopic));
|
|
|
if (questionList.get(currentIndex).getQuestionTypeName() != null)
|
|
|
tvRadio.setText(questionList.get(currentIndex).getQuestionTypeName());
|
|
|
markType = questionList.get(currentIndex).getQuestionTypeName();
|
|
|
if (markType.contains("单选") || markType.contains("判断")) {
|
|
|
isClickOnce = true;
|
|
|
} else {
|
|
|
isClickOnce = false;
|
|
|
}
|
|
|
if (questionList.get(currentIndex).getQuestionTitle() != null)
|
|
|
tvTopic.setText(questionList.get(currentIndex).getQuestionTitle());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onComplete(int api) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onError(Throwable e, int api) {
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
|
// TODO: add setContentView(...) invocation
|
|
|
ButterKnife.bind(this);
|
|
|
}
|
|
|
|
|
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
switch (v.getId()) {
|
|
|
case R.id.rl_last:
|
|
|
if (currentIndex > 0) {
|
|
|
selectAnswer = "";
|
|
|
currentIndex--;
|
|
|
index.setText(String.valueOf(currentIndex + 1));
|
|
|
doRefresh();
|
|
|
} else {
|
|
|
Toast.makeText(this, "当前已是第一题", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
break;
|
|
|
case R.id.rl_next:
|
|
|
if (currentIndex < maxTopic - 1) {
|
|
|
if (selectAnswer == "" || selectAnswer == null) {
|
|
|
sheetCard.set(currentIndex, 0);
|
|
|
sheetGridAdapter.notifyDataSetChanged();
|
|
|
unDone++;
|
|
|
|
|
|
if (markType.contains("单选")) {
|
|
|
danxuanWrong++;
|
|
|
} else if (markType.contains("多选")) {
|
|
|
duoxuanWrong++;
|
|
|
} else if (markType.contains("判断")) {
|
|
|
panduanWrong++;
|
|
|
}
|
|
|
|
|
|
String questionOid = questionList.get(currentIndex).getQuestionOid();
|
|
|
mPresenter.getPresenter(4, 2, resumeOid, questionOid, String.valueOf(1));
|
|
|
}
|
|
|
currentIndex++;
|
|
|
index.setText(String.valueOf(currentIndex + 1));
|
|
|
doRefresh();
|
|
|
|
|
|
selectAnswer = "";
|
|
|
} else {
|
|
|
/* Intent intent = new Intent(this, AnswerMarkActivity.class);
|
|
|
intent.putExtra("catalogOid", catalogOid);
|
|
|
startActivity(intent);
|
|
|
Log.e("zhangtao:totalScore", totalScore + "");*/
|
|
|
Toast.makeText(this, "当前已是最后一题", Toast.LENGTH_SHORT).show();
|
|
|
}
|
|
|
break;
|
|
|
case R.id.commit:
|
|
|
showCommitCard(this, maxTopic - currentIndex - 1);
|
|
|
chageAlpha(0.5f);
|
|
|
break;
|
|
|
case R.id.lin_tab:
|
|
|
this.finish();
|
|
|
break;
|
|
|
case R.id.rl_card:
|
|
|
showAnswerCard(sheetCard, rightCount, wrongCount, currentIndex, maxTopic);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
|
|
|
private void showCommitCard(final Context context, int laveCount) {
|
|
|
View contentView = LayoutInflater.from(this).inflate(R.layout.pop_answer_commit, null);
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.activity_answer, null);
|
|
|
|
|
|
TextView count = (TextView) contentView.findViewById(R.id.tv_count);
|
|
|
TextView goOn = (TextView) contentView.findViewById(R.id.tv_continue);
|
|
|
TextView commit = (TextView) contentView.findViewById(R.id.tv_commit);
|
|
|
|
|
|
count.setText(String.valueOf(laveCount));
|
|
|
|
|
|
popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
|
|
popupWindow.setOutsideTouchable(false);
|
|
|
popupWindow.setTouchable(true);
|
|
|
popupWindow.showAtLocation(view, Gravity.CENTER, 0, 0);
|
|
|
|
|
|
goOn.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
popupWindow.dismiss();
|
|
|
}
|
|
|
});
|
|
|
|
|
|
commit.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
popupWindow.dismiss();
|
|
|
Intent intent = new Intent(context, TestScoreActivity.class);
|
|
|
intent.putExtra("catalogOid", catalogOid);
|
|
|
intent.putExtra("danxuanCount", danxuanCount);
|
|
|
intent.putExtra("duoxuanCount", duoxuanCount);
|
|
|
intent.putExtra("panduanCount", panduanCount);
|
|
|
intent.putExtra("danxuanWrong", danxuanWrong);
|
|
|
intent.putExtra("panduanWrong", panduanWrong);
|
|
|
intent.putExtra("duoxuanWrong", duoxuanWrong);
|
|
|
intent.putExtra("totalScore", totalScore);
|
|
|
Log.e("zhangtao",totalScore+"分");
|
|
|
startActivity(intent);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
|
|
|
@Override
|
|
|
public void onDismiss() {
|
|
|
chageAlpha(1f);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void showAnswerCard(List<Integer> sheetCard, int rightCount, int wrongCount, int currentIndex, int maxTopic) {
|
|
|
View contentView = LayoutInflater.from(this).inflate(R.layout.pop_answer_sheet, null);
|
|
|
View view = LayoutInflater.from(this).inflate(R.layout.activity_answer, null);
|
|
|
|
|
|
TextView tv_card = (TextView) contentView.findViewById(R.id.tv_card);
|
|
|
GridView gridView = (GridView) contentView.findViewById(R.id.grid_dati);
|
|
|
TextView index = (TextView) contentView.findViewById(R.id.index);
|
|
|
TextView total = (TextView) contentView.findViewById(R.id.total);
|
|
|
TextView right = (TextView) contentView.findViewById(R.id.tv_right_num);
|
|
|
TextView wrong = (TextView) contentView.findViewById(R.id.tv_wrong_num);
|
|
|
|
|
|
right.setText(String.valueOf(rightCount));
|
|
|
wrong.setText(String.valueOf(wrongCount));
|
|
|
index.setText(String.valueOf(currentIndex+1));
|
|
|
total.setText(String.valueOf(maxTopic));
|
|
|
|
|
|
// sheetGridAdapter = new AnswerSheetGridAdapter(sheetCard, this);
|
|
|
gridView.setAdapter(sheetGridAdapter);
|
|
|
|
|
|
popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
|
|
|
popupWindow.setOutsideTouchable(false);
|
|
|
popupWindow.setTouchable(true);
|
|
|
popupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
|
|
|
tv_card.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
if (popupWindow != null) {
|
|
|
popupWindow.dismiss();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
private void chageAlpha(float color) {
|
|
|
WindowManager.LayoutParams lp = this.getWindow().getAttributes();
|
|
|
lp.alpha = color;
|
|
|
this.getWindow().setAttributes(lp);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
|