diff --git a/app/src/main/java/me/bello/rkenword/activity/CharEngActivity.java b/app/src/main/java/me/bello/rkenword/activity/CharEngActivity.java
index 571896d..f5dae30 100644
--- a/app/src/main/java/me/bello/rkenword/activity/CharEngActivity.java
+++ b/app/src/main/java/me/bello/rkenword/activity/CharEngActivity.java
@@ -18,6 +18,9 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -27,11 +30,12 @@
import me.bello.rkenword.adapter.ChineseAdapter;
import me.bello.rkenword.data.ChineseData;
import me.bello.rkenword.data.MainData;
+import me.bello.rkenword.util.PreferenceUtils;
public class CharEngActivity extends AppCompatActivity {
private Context context;
private TextView doingText, errText, wordText;
- private ImageView soundImg;
+ private ImageView soundImg, eyeImg;
private ListView mListView;
private Button preBtn, nextBtn, closeBtn;
private LinearLayout arrow_layout;
@@ -49,6 +53,9 @@
private boolean noSound;
// 方向键是否在右侧
private boolean arrowIsLeft;
+ // 显示单词
+ private boolean displayWord = true;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -58,7 +65,7 @@
// 获取传值
mainData = (MainData) getIntent().getSerializableExtra("info");
if (mainData == null) finish();
- level = getIntent().getIntExtra("level",0);
+ level = getIntent().getIntExtra("level", 0);
doingText = findViewById(R.id.doing_text);
doingText.setOnClickListener(new View.OnClickListener() {
@@ -104,7 +111,7 @@
@Override
public boolean onLongClick(View v) {
noSound = !noSound;
- if (noSound){
+ if (noSound) {
soundImg.setImageResource(R.drawable.ic_sound_off);
} else {
soundImg.setImageResource(R.drawable.ic_sound_on);
@@ -112,6 +119,20 @@
return true;
}
});
+ eyeImg = findViewById(R.id.eye_image);
+ eyeImg.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ displayWord = !displayWord;
+ if (displayWord || mainData.getCharList().get(currentPosition).get("o").equals("1")) {
+ eyeImg.setImageResource(R.drawable.ic_eye_yes);
+ wordText.setText(mainData.getCharList().get(currentPosition).get("w"));
+ } else {
+ eyeImg.setImageResource(R.drawable.ic_eye_no);
+ wordText.setText("");
+ }
+ }
+ });
mListView = findViewById(R.id.chinese_list_view);
closeBtn = findViewById(R.id.close_btn);
closeBtn.setOnClickListener(new View.OnClickListener() {
@@ -124,9 +145,9 @@
preBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (currentPosition != 0){
+ if (currentPosition != 0) {
currentPosition -= 1;
- doingText.setText((currentPosition+1) + " / " + mainDataLen);
+ doingText.setText((currentPosition + 1) + " / " + mainDataLen);
startExam(currentPosition);
}
}
@@ -135,9 +156,9 @@
nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- if (currentPosition != mainDataLen - 1){
+ if (currentPosition != mainDataLen - 1) {
currentPosition += 1;
- doingText.setText((currentPosition+1) + " / " + mainDataLen);
+ doingText.setText((currentPosition + 1) + " / " + mainDataLen);
startExam(currentPosition);
}
}
@@ -146,7 +167,7 @@
mainDataLen = mainData.getCharList().size();
doingText.setText("1 / " + mainDataLen);
- errText.setText(Html.fromHtml(""+aswRgt+" / "+aswErr+""));
+ errText.setText(Html.fromHtml("" + aswRgt + " / " + aswErr + ""));
startExam(currentPosition);
}
@@ -172,7 +193,7 @@
mediaPlayer = new MediaPlayer();
if (level == 0) {
mediaPlayer.setDataSource(getAssets().openFd("word/" + word));
- } else if (level == 1){
+ } else if (level == 1) {
mediaPlayer.setDataSource(getAssets().openFd("rkword/" + word));
}
@@ -189,7 +210,7 @@
});
- } catch (Exception e){
+ } catch (Exception e) {
System.out.println(e);
}
}
@@ -200,16 +221,19 @@
String simple = mainData.getCharList().get(position).get("s");
String cn = mainData.getCharList().get(position).get("c");
String open = mainData.getCharList().get(position).get("o");
- if (simple != null && !simple.equals("") ){
+ if (simple != null && !simple.equals("")) {
word = word + "(" + simple + ")";
}
- wordText.setText(word);
-
+ if (displayWord || mainData.getCharList().get(position).get("o").equals("1")) {
+ wordText.setText(word);
+ } else {
+ wordText.setText("");
+ }
// 生成4个选项
ArrayList chineseList = new ArrayList<>();
int[] rd;
- if (mainDataLen < 4){
- rd = randomNums(mainDataLen, position, mainDataLen-1);
+ if (mainDataLen < 4) {
+ rd = randomNums(mainDataLen, position, mainDataLen - 1);
} else {
rd = randomNums(mainDataLen, position, 3);
}
@@ -217,11 +241,11 @@
ChineseData data = new ChineseData();
data.setChineseStr(mainData.getCharList().get(rd[i]).get("c"));
data.setAnswer(false);
- data.setOpen("1".equals(open)?true:false);
+ data.setOpen("1".equals(open) ? true : false);
chineseList.add(data);
}
// 添加正确选项
- chineseList.add(new ChineseData(cn, true, "1".equals(open)?true:false));
+ chineseList.add(new ChineseData(cn, true, "1".equals(open) ? true : false));
// 乱序处理
Collections.shuffle(chineseList);
@@ -231,51 +255,67 @@
// adapter.notifyDataSetChanged();
}
- private int[] randomNums(int maxLen, int excludeNum, int count){
+ private int[] randomNums(int maxLen, int excludeNum, int count) {
int[] intRandom = new int[count];
List list = new ArrayList();
Random rd = new Random();
- while (list.size() < count){
+ while (list.size() < count) {
int num = new Random().nextInt(maxLen);
- if (!list.contains(num) && num != excludeNum){
+ if (!list.contains(num) && num != excludeNum) {
list.add(num);
}
}
for (int i = 0; i < list.size(); i++) {
intRandom[i] = (int) list.get(i);
- System.out.println("================"+maxLen+"========="+excludeNum+"======"+intRandom[i]+"===");
+ System.out.println("================" + maxLen + "=========" + excludeNum + "======" + intRandom[i] + "===");
}
return intRandom;
}
- Handler mHandler = new Handler(){
+ private void saveErrToPref(int position) {
+ try {
+ String p = PreferenceUtils.readPreference(context);
+ if (p != null) {
+ JSONObject obj = new JSONObject(p);
+ obj.getJSONObject("word");
+
+ }
+ } catch (JSONException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ Handler mHandler = new Handler() {
@Override
public void handleMessage(@NonNull Message msg) {
super.handleMessage(msg);
- switch (msg.what){
+ switch (msg.what) {
case 999:
// 判断对错
// if (page == currentPosition) {
- int isRight = msg.arg1;
- if (isRight == 666) {
- aswRgt += 1;
- } else {
- aswErr += 1;
- }
+ int isRight = msg.arg1;
+ if (isRight == 666) {
+ aswRgt += 1;
+ } else {
+ aswErr += 1;
+ saveErrToPref(currentPosition);
+ }
- mainData.getCharList().get(currentPosition).put("o", "1");
+ mainData.getCharList().get(currentPosition).put("o", "1");
-; errText.setText(Html.fromHtml("" + aswRgt + " / " + aswErr + ""));
-// }
+ errText.setText(Html.fromHtml("" + aswRgt + " / " + aswErr + ""));
+ if (!displayWord) {
+ wordText.setText(mainData.getCharList().get(currentPosition).get("w"));
+ }
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
- if (currentPosition == mainDataLen - 1){
+ if (currentPosition == mainDataLen - 1) {
closeBtn.setVisibility(View.VISIBLE);
} else {
currentPosition += 1;
- doingText.setText((currentPosition+1) + " / " + mainDataLen);
+ doingText.setText((currentPosition + 1) + " / " + mainDataLen);
startExam(currentPosition);
}
}