Commit 26ea9322 by chengxiuhong

test main

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