package com.jicheng.android.project.ui.activity;
import java.util.ArrayList;
import java.util.List;
import com.jicheng.android.project.R;
import com.jicheng.android.project.db.JC_DbHelper;
import com.jicheng.android.project.db.responsevo.AnswerColumns;
import com.jicheng.android.project.db.responsevo.DBManager;
import com.jicheng.android.project.db.responsevo.ErrorColumns;
import com.jicheng.android.project.db.responsevo.JC_BaseColumns;
import com.jicheng.android.project.db.responsevo.JC_CauseInfo;
import com.jicheng.android.project.preferences.ConfigPreferences;
import com.jicheng.android.project.ui.adapter.JC_AnswerSheetAdapter;
import com.jicheng.android.project.ui.base.BaseFragmentActivity;
import com.jicheng.android.project.ui.widget.JCGridView;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
/**
*
* @Title: JC_ChapterExaminationActivity.java
* @Package : com.jicheng.android.project.ui.activity
* @Description: TODO(章节考试)
* @author : xiezhenggen
* @date : 2015年12月29日 下午3:09:20
* @version V1.0
*/
public class JC_ExaminationActivity extends BaseFragmentActivity implements OnClickListener, OnItemClickListener {
/**
* 答题卡
*/
private JCGridView jc_answer_sheet_gv;
private JC_AnswerSheetAdapter mAnswerSheetAdapter;
private List<String> mAnswerSheetList;
/**
* 考试数据
*/
private ArrayList<JC_CauseInfo> list;
/**
* 标题名称
*/
private TextView titlebar_title;
/**
* 已做题目数量和总题目数量
*/
private TextView jc_has_been_done_tv;
/**
* 题目内容标题
*/
private TextView jc_unit_title_content_tv; // jc_unit_title_content_tv;title
/**
* 题目类型
*/
private TextView jc_unit_type;
/**
* A选项背景
*/
private RelativeLayout jc_unit_relOne;
/**
* A选项图标
*/
private ImageView jc_unit_imageOne_A_img;
/**
* A选项内容
*/
private TextView jc_unit_selectOne_tv;
/**
* B选项背景
*/
private RelativeLayout jc_unit_relTwo;
/**
* B选项图标
*/
private ImageView jc_unit_imageTwo_B_img;
/**
* B选项内容
*/
private TextView jc_unit_selectTwo_tv;
/**
* C选项背景
*/
private RelativeLayout jc_unit_relThree;
/**
* C选项图标
*/
private ImageView jc_unit_imageThree_C_img;
/**
* C选项内容
*/
private TextView jc_selectThree_tv;
/**
* D选项背景
*/
private RelativeLayout jc_unit_relFour;
/**
* D选项图标
*/
private ImageView jc_unit_imageFour_D_img;
/**
* D选项内容
*/
private TextView jc_unit_selectFour_tv;
/**
* 查看成绩
*/
private Button jc_view_results_bt;
DBManager dbManager;
/**
* 数据库管理器
*/
private JC_DbHelper downloadManager;
/**
* 点击主题选择
*/
private boolean isClickSelectSubject;
/**
* 触摸事件
*/
private GestureDetector mGestureDetector;
@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.jc_unit_test_questions);
mAnswerSheetList = new ArrayList<String>();
for (int i = 1; i <= 16; i++) {
mAnswerSheetList.add("A");
}
downloadManager = JC_DbHelper.getInstance(this);// DownloadService.getDownloadManager(this);
dbManager = downloadManager.getInstance();
mGestureDetector = new GestureDetector(this, mSimpleOnGestureListener);
// 先读取数据库中的缓存, 数据量较多比较耗时,应使用AsyncTask
new QueryTask().execute();
mAnswerSheetAdapter = new JC_AnswerSheetAdapter(this, (ArrayList<String>) mAnswerSheetList);
jc_answer_sheet_gv = (JCGridView) findViewById(R.id.jc_answer_sheet_gv);
jc_answer_sheet_gv.setAdapter(mAnswerSheetAdapter);
jc_answer_sheet_gv.setFocusable(false);
jc_answer_sheet_gv.setOnItemClickListener(this);
titlebar_title = (TextView) findViewById(R.id.titlebar_title);
jc_has_been_done_tv = (TextView) findViewById(R.id.jc_has_been_done_tv);
jc_unit_title_content_tv = (TextView) findViewById(R.id.jc_unit_title_content_tv);
jc_unit_type = (TextView) findViewById(R.id.jc_unit_type);
jc_unit_relOne = (RelativeLayout) findViewById(R.id.jc_unit_relOne);
jc_unit_relOne.setOnClickListener(this);
jc_unit_imageOne_A_img = (ImageView) findViewById(R.id.jc_unit_imageOne);
jc_unit_selectOne_tv = (TextView) findViewById(R.id.jc_unit_selectOne_tv);
jc_unit_selectOne_tv.setOnClickListener(this);
jc_unit_relTwo = (RelativeLayout) findViewById(R.id.jc_unit_relTwo);
jc_unit_relTwo.setOnClickListener(this);
jc_unit_imageTwo_B_img = (ImageView) findViewById(R.id.jc_unit_imageTwo);
jc_unit_selectTwo_tv = (TextView) findViewById(R.id.jc_unit_selectTwo);
jc_unit_selectTwo_tv.setOnClickListener(this);
jc_unit_relThree = (RelativeLayout) findViewById(R.id.jc_unit_relThree);
jc_unit_relThree.setOnClickListener(this);
jc_unit_imageThree_C_img = (ImageView) findViewById(R.id.jc_unit_imageThree);
jc_selectThree_tv = (TextView) findViewById(R.id.jc_selectThree);
jc_selectThree_tv.setOnClickListener(this);
jc_unit_relFour = (RelativeLayout) findViewById(R.id.jc_unit_relFour);
jc_unit_relFour.setOnClickListener(this);
jc_unit_imageFour_D_img = (ImageView) findViewById(R.id.jc_unit_imageFour);
jc_unit_selectFour_tv = (TextView) findViewById(R.id.jc_unit_selectFour);
jc_unit_selectFour_tv.setOnClickListener(this);
jc_view_results_bt = (Button) findViewById(R.id.jc_view_results_bt);
}
private int i = 0;
/**
* 单选多选判断
*/
private boolean isSelectA;
private boolean isSelectB;
private boolean isSelectC;
private boolean isSelectD;
private class QueryTask extends AsyncTask<Void, Void, ArrayList<JC_CauseInfo>> {
@Override
protected ArrayList<JC_CauseInfo> doInBackground(Void... params) {
list = DBManager.getInstance(JC_ExaminationActivity.this).queryExam(AnswerColumns.TABLE_NAME);
return list;
}
@Override
protected void onPostExecute(ArrayList<JC_CauseInfo> list) {
if (list.size() == 0) {
jc_has_been_done_tv.setText("0/0");
jc_unit_selectOne_tv.setText("");
jc_unit_selectTwo_tv.setText("");
jc_selectThree_tv.setText("");
jc_unit_selectFour_tv.setText("");
return;
}
int lastSelect = ConfigPreferences.getInstance(JC_ExaminationActivity.this).isLastSelectExam();
i = lastSelect - 1;
JC_CauseInfo myData = list.get(lastSelect - 1);
jc_unit_title_content_tv.setText(lastSelect + "." + myData.getProblem());
jc_unit_type.setText("题型:" + myData.getOption_types());
jc_has_been_done_tv.setText(lastSelect + "/" + list.size());
if ("单选".equals(myData.getOption_types())) {
jc_unit_relThree.setVisibility(View.VISIBLE);
jc_unit_relFour.setVisibility(View.VISIBLE);
jc_unit_selectOne_tv.setText("A." + myData.getOption_a());
jc_unit_selectTwo_tv.setText("B." + myData.getOption_b());
jc_selectThree_tv.setText("C." + myData.getOption_c());
jc_unit_selectFour_tv.setText("D." + myData.getOption_d());
} else if ("多选".equals(myData.getOption_types())) {
jc_unit_relThree.setVisibility(View.VISIBLE);
jc_unit_relFour.setVisibility(View.VISIBLE);
jc_unit_selectOne_tv.setText("A." + myData.getOption_a());
jc_unit_selectTwo_tv.setText("B." + myData.getOption_b());
jc_selectThree_tv.setText("C." + myData.getOption_c());
jc_unit_selectFour_tv.setText("D." + myData.getOption_d());
} else if ("判断".equals(myData.getOption_types())) {
jc_unit_relThree.setVisibility(View.GONE);
jc_unit_relFour.setVisibility(View.GONE);
jc_unit_selectOne_tv.setText(myData.getOption_a());
jc_unit_selectTwo_tv.setText(myData.getOption_b());
}
}
}
@Override
public void onDownloadStateChanged(String info) {
// TODO Auto-generated method stub
}
@Override
public void onDownloadProgressed(String result) {
// TODO Auto-generated method stub
}
@Override
public String getAccessNetworkData(String networkData) {
// TODO Auto-generated method stub
return null;
}
@Override
public String addGequestURL() {
// TODO Auto-generated method stub
return null;
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
ChoiceQuestions(position);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (list.size() == 0) {
return;
}
JC_CauseInfo myData = list.get(i);
String types = myData.getOption_types();
String daan_one = myData.getDaan_one();
String daan_tow = myData.getDaan_tow();
String daan_three = myData.getDaan_three();
String daan_four = myData.getDaan_four();
switch (v.getId()) {
case R.id.jc_unit_selectOne_tv:
if ("单选".equals(types)) {
DefaultConfigurationImg();
myData.setReply(JC_BaseColumns.A);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_one)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_tow)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_three)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_four)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
}
}
} else if ("多选".equals(types)) {
isSelectA = !isSelectA;
if (isSelectA) {
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
} else {
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
}
} else if ("判断".equals(types)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_selectThree_tv.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
if (!TextUtils.isEmpty(daan_one)) {
myData.setReply(JC_BaseColumns.TRUE);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
myData.setReply(JC_BaseColumns.TRUE);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
}
}
break;
case R.id.jc_unit_selectTwo:
if ("单选".equals(types)) {
DefaultConfigurationImg();
myData.setReply(JC_BaseColumns.B);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_tow)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_one)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_three)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_four)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
}
}
} else if ("多选".equals(types)) {
isSelectB = !isSelectB;
if (isSelectB) {
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
} else {
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
}
} else if ("判断".equals(types)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_selectThree_tv.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
if (!TextUtils.isEmpty(daan_tow)) {
myData.setReply(JC_BaseColumns.FALSE);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
myData.setReply(JC_BaseColumns.FALSE);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
}
}
break;
case R.id.jc_selectThree:
if ("单选".equals(types)) {
DefaultConfigurationImg();
myData.setReply(JC_BaseColumns.C);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_three)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_up);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_one)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_up);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_tow)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_up);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_four)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_up);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
}
}
} else if ("多选".equals(types)) {
isSelectC = !isSelectC;
if (isSelectC) {
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_up);
} else {
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
}
}
break;
case R.id.jc_unit_selectFour:
if ("单选".equals(types)) {
DefaultConfigurationImg();
myData.setReply(JC_BaseColumns.D);
DBManager.getInstance(this).update(AnswerColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_four)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_up);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
} else {
DBManager.getInstance(this).insert(ErrorColumns.TABLE_NAME, myData);
if (!TextUtils.isEmpty(daan_one)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_up);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_tow)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_up);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
} else if (!TextUtils.isEmpty(daan_three)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_up);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
}
}
} else if ("多选".equals(types)) {
isSelectD = !isSelectD;
if (isSelectD) {
jc_unit_relFour.setBackgroundResource(R.color.select_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_up);
} else {
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
}
}
break;
}
}
/**
* @Description: TODO(切换到下一题)
* @param
* @return void 返回类型
* @date: 2015年12月30日 上午11:16:26
* @Author xiezhenggen
*/
void switchNextQuestion() {
if (i >= list.size() - 1) {
return;
}
// answer.setText("");
if (isClickSelectSubject) {
i = ConfigPreferences.getInstance(this).isLastSelectExam() - 1;
i += 1;
isClickSelectSubject = false;
} else {
i += 1;
}
ChoiceQuestions(i);
}
/**
* @Description: TODO(上一题)
* @param
* @return void 返回类型
* @date: 2015年12月30日 下午5:05:55
* @Author xiezhenggen
*/
void back_last_question() {
if (i <= 0) {
return;
}
isSelectA = false;
isSelectB = false;
isSelectC = false;
isSelectD = false;
DefaultConfigurationImg();
if (isClickSelectSubject) {
i = ConfigPreferences.getInstance(this).isLastSelectExam() - 1;
i -= 1;
isClickSelectSubject = false;
} else {
i -= 1;
}
ChoiceQuestions(i);
}
/**
* @Description: TODO(选择问题)
* @param: i
* @return: void 返回类型
* @date: 2016年1月4日 上午10:45:05
* @Author: xiezhenggen
*/
private void ChoiceQuestions(int i) {
isSelectA = false;
isSelectB = false;
isSelectC = false;
isSelectD = false;
DefaultConfigurationImg();
ConfigPreferences.getInstance(this).setLastSelectExam(i + 1);
JC_CauseInfo myDataForward = list.get(i);
jc_has_been_done_tv.setText((i + 1) + "/" + list.size());
if ("单选".equals(myDataForward.getOption_types())) {
jc_unit_relThree.setVisibility(View.VISIBLE);
jc_unit_relFour.setVisibility(View.VISIBLE);
} else if ("多选".equals(myDataForward.getOption_types())) {
jc_unit_relThree.setVisibility(View.VISIBLE);
jc_unit_relFour.setVisibility(View.VISIBLE);
} else if ("判断".equals(myDataForward.getOption_types())) {
jc_unit_relThree.setVisibility(View.GONE);
jc_unit_relFour.setVisibility(View.GONE);
}
int replyForward = myDataForward.getReply();
switch (replyForward) {
case JC_BaseColumns.NULL:
SelectTopicContent(myDataForward);
break;
case JC_BaseColumns.A:
if (myDataForward.daan_one.equals("A")) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
} else {
if (!TextUtils.isEmpty(myDataForward.daan_tow)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_three)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_four)) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
}
}
SelectTopicContent(myDataForward);
break;
case JC_BaseColumns.B:
if (myDataForward.daan_tow.equals("B")) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
} else {
if (!TextUtils.isEmpty(myDataForward.daan_one)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_three)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_four)) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
}
}
SelectTopicContent(myDataForward);
break;
case JC_BaseColumns.C:
if (myDataForward.daan_three.equals("C")) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_selectThree_tv.setBackgroundResource(R.color.select_select);
} else {
if (!TextUtils.isEmpty(myDataForward.daan_one)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_tow)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_four)) {
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
}
}
SelectTopicContent(myDataForward);
break;
case JC_BaseColumns.D:
if (myDataForward.daan_four.equals("D")) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
} else {
if (!TextUtils.isEmpty(myDataForward.daan_one)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_tow)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
} else if (!TextUtils.isEmpty(myDataForward.daan_three)) {
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
}
}
SelectTopicContent(myDataForward);
break;
case JC_BaseColumns.AB:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectB = true;
break;
case JC_BaseColumns.AC:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectC = true;
break;
case JC_BaseColumns.AD:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectD = true;
break;
case JC_BaseColumns.BC:
MultiplechoiceContent(myDataForward);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
isSelectB = true;
isSelectC = true;
break;
case JC_BaseColumns.BD:
MultiplechoiceContent(myDataForward);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectB = true;
isSelectD = true;
break;
case JC_BaseColumns.CD:
MultiplechoiceContent(myDataForward);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectC = true;
isSelectD = true;
break;
case JC_BaseColumns.ABC:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectB = true;
isSelectC = true;
break;
case JC_BaseColumns.ABD:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectB = true;
isSelectD = true;
break;
case JC_BaseColumns.ACD:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectC = true;
isSelectD = true;
break;
case JC_BaseColumns.BCD:
MultiplechoiceContent(myDataForward);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectB = true;
isSelectC = true;
isSelectD = true;
break;
case JC_BaseColumns.ABCD:
MultiplechoiceContent(myDataForward);
jc_unit_imageOne_A_img.setImageResource(R.drawable.more_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.more_select);
jc_unit_imageThree_C_img.setImageResource(R.drawable.more_select);
jc_unit_imageFour_D_img.setImageResource(R.drawable.more_select);
isSelectA = true;
isSelectB = true;
isSelectC = true;
isSelectD = true;
break;
case JC_BaseColumns.TRUE:
if (myDataForward.daan_one.equals("A")) {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
} else {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_up);
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
}
JudgmentQuestion(myDataForward);
break;
case JC_BaseColumns.FALSE:
if (myDataForward.daan_tow.equals("B")) {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
} else {
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_up);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
}
JudgmentQuestion(myDataForward);
break;
default:
break;
}
}
/**
* @Description: TODO(选择颜色)
* @param i
* @param @return
* @return String 返回类型
* @date: 2015年12月30日 上午11:55:58
* @Author xiezhenggen
*/
private String selectColor(int i) {
String str = "";
switch (i) {
case 5:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
break;
case 6:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
break;
case 7:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 8:
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
break;
case 9:
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 10:
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 11:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
break;
case 12:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 13:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 14:
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
case 15:
jc_unit_relOne.setBackgroundResource(R.color.select_select);
jc_unit_relTwo.setBackgroundResource(R.color.select_select);
jc_unit_relThree.setBackgroundResource(R.color.select_select);
jc_unit_relFour.setBackgroundResource(R.color.select_select);
break;
default:
break;
}
return str;
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
mGestureDetector.onTouchEvent(ev); // 让GestureDetector响应触碰事件
super.dispatchTouchEvent(ev); // 让Activity响应触碰事件
return super.dispatchTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
mGestureDetector.onTouchEvent(event);
return super.onTouchEvent(event);
}
/**
* 每次滑动只有一个跳动的滑动事件
*/
GestureDetector.SimpleOnGestureListener mSimpleOnGestureListener = new GestureDetector.SimpleOnGestureListener() {
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.i("EEE", "e2=" + (e2.getX() - e1.getX()));
// 控制只右滑
if (e2.getX() - e1.getX() > 0 && (e1.getX() >= 0 && e1.getX() >= 300)) {
Log.i("HHH", "下一题 左往右=" + (e2.getX() - e1.getX()));
switchNextQuestion();// 下一题
} else if (e1.getX() - e2.getX() > 0 && (e2.getX() >= 0 && e2.getX() <= 300)) {
Log.i("HHH", "上一题 右往左=" + (e1.getX() - e2.getX()));
back_last_question();// 上一题
}
return false;
};
};
/**
* @Description: TODO(选择题默认配置)
* @param:
* @return: void 返回类型
* @date: 2016年1月4日 上午11:21:35
* @Author: xiezhenggen
*/
void DefaultConfigurationImg() {
jc_unit_imageOne_A_img.setImageResource(R.drawable.jc_option_a_in);
jc_unit_imageTwo_B_img.setImageResource(R.drawable.jc_option_b_in);
jc_unit_imageThree_C_img.setImageResource(R.drawable.jc_option_c_in);
jc_unit_imageFour_D_img.setImageResource(R.drawable.jc_option_d_in);
jc_unit_relOne.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relTwo.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relThree.setBackgroundResource(R.color.jc_select_default_color);
jc_unit_relFour.setBackgroundResource(R.color.jc_select_default_color);
}
/**
* @Description: TODO(选择题内容)
* @param: @param
* myDataForward
* @return: void 返回类型
* @date: 2016年1月4日 上午11:55:29
* @Author: xiezhenggen
*/
void SelectTopicContent(JC_CauseInfo myDataForward) {
String timu_title = myDataForward.getProblem();
String timu_one = myDataForward.getOption_a();
String timu_tow = myDataForward.getOption_b();
String timu_three = myDataForward.getOption_c();
String timu_four = myDataForward.getOption_d();
jc_unit_type.setText("题型:" + myDataForward.getOption_types());
jc_unit_title_content_tv.setText((i + 1) + "." + timu_title);
if ("单选".equals(myDataForward.getOption_types())) {
jc_unit_selectOne_tv.setText("A." + timu_one);
jc_unit_selectTwo_tv.setText("B." + timu_tow);
jc_selectThree_tv.setText("C." + timu_three);
jc_unit_selectFour_tv.setText("D." + timu_four);
} else if ("多选".equals(myDataForward.getOption_types())) {
jc_unit_selectOne_tv.setText("A." + timu_one);
jc_unit_selectTwo_tv.setText("B." + timu_tow);
jc_selectThree_tv.setText("C." + timu_three);
jc_unit_selectFour_tv.setText("D." + timu_four);
} else if ("判断".equals(myDataForward.getOption_types())) {
jc_unit_selectOne_tv.setText(timu_one);
jc_unit_selectTwo_tv.setText(timu_tow);
}
jc_unit_selectOne_tv.setClickable(true);
jc_unit_selectTwo_tv.setClickable(true);
jc_selectThree_tv.setClickable(true);
jc_unit_selectFour_tv.setClickable(true);
}
/**
* @Description: TODO(多选题内容)
* @param: @param
* myDataForward
* @return: void 返回类型
* @date: 2016年1月4日 上午11:56:26
* @Author: xiezhenggen
*/
void MultiplechoiceContent(JC_CauseInfo myDataForward) {
String timu_title = myDataForward.getProblem();
String timu_one = myDataForward.getOption_a();
String timu_tow = myDataForward.getOption_b();
String timu_three = myDataForward.getOption_c();
String timu_four = myDataForward.getOption_d();
jc_unit_type.setText("题型:" + myDataForward.getOption_types());
jc_unit_title_content_tv.setText((i + 1) + "." + timu_title);
jc_unit_selectOne_tv.setText("A." + timu_one);
jc_unit_selectTwo_tv.setText("B." + timu_tow);
jc_selectThree_tv.setText("C." + timu_three);
jc_unit_selectFour_tv.setText("D." + timu_four);
selectColor(myDataForward.getReply());
}
/**
* Judgment question
*
* @Description: TODO(判断题对错)
* @param: @param
* myDataForward
* @return: void 返回类型
* @date: 2016年1月4日 下午1:49:31
* @Author: xiezhenggen
*/
void JudgmentQuestion(JC_CauseInfo myDataForward) {
String timu_title = myDataForward.getProblem();
String timu_one = myDataForward.getOption_a();
String timu_tow = myDataForward.getOption_b();
jc_unit_type.setText("题型:" + myDataForward.getOption_types());
jc_unit_title_content_tv.setText((i + 1) + "." + timu_title);
jc_unit_selectOne_tv.setText(timu_one);
jc_unit_selectTwo_tv.setText(timu_tow);
jc_unit_selectOne_tv.setClickable(false);
jc_unit_selectTwo_tv.setClickable(false);
jc_selectThree_tv.setClickable(false);
jc_unit_selectFour_tv.setClickable(false);
}
}