Commit 26ea9322 by chengxiuhong

test main

parent 3daae609
package com.oo.eye.activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
......@@ -24,16 +24,19 @@ import com.oo.eye.manager.DaemonSender;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import static com.oo.eye.bean.Eye.getLineSumByIndex;
/**
*/
public class EyeTestActivity extends BaseActivity{
public class EyeTestActivity extends BaseActivity {
static final int TOP = 0;
static final int RIGHT = 1;
......@@ -93,10 +96,10 @@ public class EyeTestActivity extends BaseActivity{
private int test_dis = 0;
private ArrayList<ArrayList<Eye.E>> mList = new ArrayList<>();
private ArrayList<ArrayList<E>> mList = new ArrayList<>();
private int mLocation;
private int mLevelIndex = -1;
private LinkedHashMap<Integer, List<Eye.E>> mCollect = new LinkedHashMap<>();
private LinkedHashMap<Integer, List<E>> mCollect = new LinkedHashMap<>();
private EyeHistroyBean mHistroyBean;
//是否是右眼训练
private boolean isSecondTest;
......@@ -147,7 +150,7 @@ public class EyeTestActivity extends BaseActivity{
continueTest();
}
private void continueTest(){
private void continueTest() {
if (!isStartTest) {
isStartTest = true;
resetView(true);
......@@ -156,6 +159,7 @@ public class EyeTestActivity extends BaseActivity{
/**
* 开始测试
*
* @param isNewTest true 代表测试的第一只眼 代表左眼 false代表测量另一只眼 右眼
*/
private void resetView(final boolean isNewTest) {
......@@ -165,7 +169,7 @@ public class EyeTestActivity extends BaseActivity{
String eye = isNewTest ? "右" : "左";
if (isNewTest) {
if(mHistroyBean != null) {
if (mHistroyBean != null) {
mLeftEye = mHistroyBean.getLeft_eye();
mRightEye = mHistroyBean.getRight_eye();
}
......@@ -176,20 +180,20 @@ public class EyeTestActivity extends BaseActivity{
eLayout2.setVisibility(View.GONE);
maskView1.setVisibility(View.GONE);
maskView2.setVisibility(View.GONE);
new CountDownTimer(totalTime,intervalTime){
new CountDownTimer(totalTime, intervalTime) {
@Override
public void onTick(long millisUntilFinished) {
long time = millisUntilFinished / 1000;
timeText1.setText(time+"");
timeText2.setText(time+"");
float f = millisUntilFinished*1.0f/totalTime;
if(isSecondTest){
maskView1.setAlpha(1-f);
timeText1.setText(time + "");
timeText2.setText(time + "");
float f = millisUntilFinished * 1.0f / totalTime;
if (isSecondTest) {
maskView1.setAlpha(1 - f);
maskView1.setVisibility(View.VISIBLE);
maskView2.setVisibility(View.GONE);
}else{
maskView2.setAlpha(1-f);
} else {
maskView2.setAlpha(1 - f);
maskView1.setVisibility(View.GONE);
maskView2.setVisibility(View.VISIBLE);
}
......@@ -206,7 +210,7 @@ public class EyeTestActivity extends BaseActivity{
double e = 5.0;
//如果是左眼次测试
if (isNewTest) {
if(mHistroyBean != null) {
if (mHistroyBean != null) {
e = mHistroyBean.getLeft_eye();
}
maskView1.setVisibility(View.GONE);
......@@ -215,7 +219,7 @@ public class EyeTestActivity extends BaseActivity{
} else {
//右眼测试
if (isSecondTest) {
if(mHistroyBean != null) {
if (mHistroyBean != null) {
e = mHistroyBean.getRight_eye();
}
}
......@@ -223,7 +227,7 @@ public class EyeTestActivity extends BaseActivity{
maskView1.setVisibility(View.VISIBLE);
maskView2.setVisibility(View.GONE);
}
mLevelIndex = Eye.getIndexByValue(e,true) - 1;
mLevelIndex = Eye.getIndexByValue(e, true) - 1;
next(true);
}
}.start();
......@@ -231,14 +235,16 @@ public class EyeTestActivity extends BaseActivity{
mCollect.clear();
}
private void speak(String text){
DaemonSender.sendDBTTS(this,text);
private void speak(String text) {
DaemonSender.sendDBTTS(this, text);
}
/**
* 描画E字
*
* @param e
*/
private void drewE(Eye.E e) {
private void drewE(E e) {
//视力等级
float level = e.getLevel();
//视标边长
......@@ -369,14 +375,13 @@ public class EyeTestActivity extends BaseActivity{
/**
* 下一个测试
*
*/
private void next(boolean isNextLine) {
if (isNextLine) {
mLevelIndex++;
mLocation = 0;
eyeVision1.setText(""+Eye.getLevelByIndex(mLevelIndex,true));
eyeVision2.setText(""+Eye.getLevelByIndex(mLevelIndex,true));
eyeVision1.setText("" + Eye.getLevelByIndex(mLevelIndex, true));
eyeVision2.setText("" + Eye.getLevelByIndex(mLevelIndex, true));
count1.setText("");
count2.setText("");
allow1.setText("");
......@@ -385,7 +390,7 @@ public class EyeTestActivity extends BaseActivity{
right2.setText("");
error1.setText("");
error2.setText("");
}else{
} else {
mLocation++;
}
......@@ -395,11 +400,12 @@ public class EyeTestActivity extends BaseActivity{
/**
* 选择的方向
*
* @param direct
*/
private void userChoose(int direct) {
LogUtil.e("direct:"+direct);
LogUtil.e("mLevelIndex:"+mLevelIndex);
LogUtil.e("direct:" + direct);
LogUtil.e("mLevelIndex:" + mLevelIndex);
//获取当前行答过的e
List<E> list = mCollect.get(mLevelIndex);
if (null == list || list.size() == 0) {
......@@ -407,7 +413,7 @@ public class EyeTestActivity extends BaseActivity{
}
mSelectE.setUserChoose(direct);
list.add(mSelectE);
mCollect.put(mLevelIndex,list);
mCollect.put(mLevelIndex, list);
judge();
// int verifyErrorCount = 0;
// //获取每行有多少个e
......@@ -478,7 +484,7 @@ public class EyeTestActivity extends BaseActivity{
// next(isNextLine);
}
private void judge(){
private void judge() {
int verifyErrorCount = 0;
//获取每行有多少个e
int lineSum = getLineSumByIndex(mLevelIndex);
......@@ -492,22 +498,22 @@ public class EyeTestActivity extends BaseActivity{
rightAnswerCount++;
}
}
LogUtil.e("rightAnswerCount:"+rightAnswerCount);
LogUtil.e("rightAnswerCount:" + rightAnswerCount);
//当前行答错的数
int errorCount = list.size() - rightAnswerCount;
LogUtil.e("errorCount:"+errorCount);
LogUtil.e("errorCount:" + errorCount);
//判断是否满足答对的要求
boolean isNextLine = rightAnswerCount >= leastAnswerCount;
LogUtil.e("isNextLine:"+isNextLine);
LogUtil.e("isNextLine:" + isNextLine);
mCollect.put(mLevelIndex, list);
if(isNextLine){
if(mLevelIndex == 13){
if (isNextLine) {
if (mLevelIndex == 13) {
showResult();
return;
}else {
} else {
List<E> nextList = mCollect.get(mLevelIndex + 1);
if(nextList != null && nextList.size() > 0){
if (nextList != null && nextList.size() > 0) {
showResult();
return;
}
......@@ -520,28 +526,28 @@ public class EyeTestActivity extends BaseActivity{
} else {
verifyErrorCount = 0;
}
count1.setText("总共:"+lineSum);
count2.setText("总共:"+lineSum);
allow1.setText("正确数:"+leastAnswerCount);
allow2.setText("正确数:"+leastAnswerCount);
right1.setText("答对数:"+rightAnswerCount);
right2.setText("答对数:"+rightAnswerCount);
error1.setText("错误数:"+errorCount);
error2.setText("错误数:"+errorCount);
count1.setText("总共:" + lineSum);
count2.setText("总共:" + lineSum);
allow1.setText("正确数:" + leastAnswerCount);
allow2.setText("正确数:" + leastAnswerCount);
right1.setText("答对数:" + rightAnswerCount);
right2.setText("答对数:" + rightAnswerCount);
error1.setText("错误数:" + errorCount);
error2.setText("错误数:" + errorCount);
//必须答对一半才往下走一行的
//如果错误次数超过一半 (默认位置时上一行没有数据时候)回退一行
if (errorCount > verifyErrorCount) {
//如果上一行数据不为空 结束测试
if (mLevelIndex == 0 || (mCollect.containsKey(mLevelIndex - 1) &&
mCollect.get(mLevelIndex - 1) != null && mCollect.get(mLevelIndex - 1).size() > 0)) {
if(isSecondTest){
if (isSecondTest) {
mRightLine = leastAnswerCount;
}else{
} else {
mLeftLine = leastAnswerCount;
}
showResult();
return;
}else {
} else {
backLastLine();
return;
}
......@@ -553,7 +559,7 @@ public class EyeTestActivity extends BaseActivity{
* 答错
*/
private void userChooseError() {
int direct = mSelectE.getDirect()+1;
int direct = mSelectE.getDirect() + 1;
//获取当前行答过的e
List<E> list = mCollect.get(mLevelIndex);
if (null == list || list.size() == 0) {
......@@ -561,7 +567,7 @@ public class EyeTestActivity extends BaseActivity{
}
mSelectE.setUserChoose(direct);
list.add(mSelectE);
mCollect.put(mLevelIndex,list);
mCollect.put(mLevelIndex, list);
judge();
// int verifyErrorCount = 0;
// int lineSum = getLineSumByIndex(mLevelIndex);
......@@ -635,7 +641,7 @@ public class EyeTestActivity extends BaseActivity{
//返回到上一行
private void backLastLine() {
mLevelIndex = mLevelIndex-2;
mLevelIndex = mLevelIndex - 2;
next(true);
}
......@@ -657,28 +663,28 @@ public class EyeTestActivity extends BaseActivity{
private void showStudentTestDialog() {
int selectId = PreferencesUtils.getInt(EyeConfig.EYE_SETTING_KEY,0);
String text = ("测视结束左眼视力"+mLeftEye+"右眼视力"+mRightEye).replace(".","点");
if(selectId == 1){
text = ("测视结束左眼视力"+Eye.transformSmall(mLeftEye)+"右眼视力"+
Eye.transformSmall(mRightEye)).replace(".","点");
int selectId = PreferencesUtils.getInt(EyeConfig.EYE_SETTING_KEY, 0);
String text = ("测视结束左眼视力" + mLeftEye + "右眼视力" + mRightEye).replace(".", "点");
if (selectId == 1) {
text = ("测视结束左眼视力" + Eye.transformSmall(mLeftEye) + "右眼视力" +
Eye.transformSmall(mRightEye)).replace(".", "点");
}
speak(text);
Intent intent = new Intent(this,AfterEyeTestActivity.class);
intent.putExtra("leftEye",mLeftEye);
intent.putExtra("rightEye",mRightEye);
intent.putExtra("leftLine",mLeftLine);
intent.putExtra("rightLine",mRightLine);
Intent intent = new Intent(this, AfterEyeTestActivity.class);
intent.putExtra("leftEye", mLeftEye);
intent.putExtra("rightEye", mRightEye);
intent.putExtra("leftLine", mLeftLine);
intent.putExtra("rightLine", mRightLine);
startActivity(intent);
finish();
}
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_UP){
if (event.getAction() == KeyEvent.ACTION_UP) {
//两次点击大于1秒
long currentTime = System.currentTimeMillis();
if (mLastOnKeyTime > 0&&currentTime - mLastOnKeyTime < 500) {
if (mLastOnKeyTime > 0 && currentTime - mLastOnKeyTime < 500) {
return true;
}
mLastOnKeyTime = currentTime;
......@@ -720,9 +726,9 @@ public class EyeTestActivity extends BaseActivity{
private double getResult() {
if (null == mCollect || mCollect.size() == 0) {
if(test_dis == 0) {
if (test_dis == 0) {
return 4.0;
}else{
} else {
return 3.8;
}
}
......@@ -730,17 +736,33 @@ public class EyeTestActivity extends BaseActivity{
for (LinkedHashMap.Entry<Integer, List<E>> entry : mCollect.entrySet()) {
result = entry.getKey();
}
final String levelByIndex = ""+Eye.getLevelByIndex(result,test_dis == 0);
final String levelByIndex = "" + Eye.getLevelByIndex(result, test_dis == 0);
return Double.parseDouble(levelByIndex);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
if (keyCode == KeyEvent.KEYCODE_BACK) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// TODO: add setContentView(...) invocation
ButterKnife.bind(this);
}
@OnClick({R.id.next_left, R.id.next_right})
public void onClick(View view) {
switch (view.getId()) {
case R.id.next_left:
break;
case R.id.next_right:
break;
}
}
}
......@@ -12,6 +12,24 @@
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_marginTop="@dimen/dp_16"
android:layout_centerHorizontal="true"
android:id="@+id/title_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5.0 -3"
android:textColor="@color/text_color"
android:textSize="@dimen/sp_22" />
<TextView
android:layout_marginTop="@dimen/dp_16"
android:id="@+id/next_left"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X 放弃当前,跳到下一位"
android:textColor="@color/text_color"
android:textSize="@dimen/sp_16" />
<RelativeLayout
android:id="@+id/rl_eye_test_center1"
android:layout_width="match_parent"
......@@ -175,7 +193,24 @@
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:layout_marginTop="@dimen/dp_16"
android:layout_centerHorizontal="true"
android:id="@+id/title_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5.0 -3"
android:textColor="@color/text_color"
android:textSize="@dimen/sp_22" />
<TextView
android:layout_marginTop="@dimen/dp_16"
android:id="@+id/next_right"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="X 放弃当前,跳到下一位"
android:textColor="@color/text_color"
android:textSize="@dimen/sp_16" />
<RelativeLayout
android:id="@+id/rl_eye_test_center2"
android:layout_width="match_parent"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment