mList;
20 |
21 | public static void add(final Context context, String bookName) {
22 | //单词本名称转成对应内置数据库名称
23 | switch (bookName) {
24 | case "中考":
25 | bookName = "MiddleSchool.db";
26 | break;
27 | case "高考":
28 | bookName = "HighSchool.db";
29 | break;
30 | case "大学四级":
31 | bookName = "UniLv4.db";
32 | break;
33 | case "大学六级":
34 | bookName = "UniLv6.db";
35 | break;
36 | }
37 | //首先获取文件目录
38 | final String path = Assets2SQLiteUtils.getPath(context, bookName);
39 | //线程中做数据库获取等耗时操作
40 | new Thread(new Runnable() {
41 | @Override
42 | public void run() {
43 | SQLiteDatabase sqLiteDatabase = SQLiteDatabase.openOrCreateDatabase(path, null);
44 | mList = new ArrayList<>();
45 | WordsBean bean;
46 | @SuppressLint("Recycle") Cursor cursor = sqLiteDatabase.query(DictionaryHelper.TABLE_NAME, null, null, null, null, null, null);
47 | while (cursor.moveToNext()) {
48 | bean = new WordsBean();
49 | bean.setWord(cursor.getString(0));
50 | bean.setChinese(cursor.getString(1));
51 | mList.add(bean);
52 | }
53 | //整书单词插入数据库
54 | SQLiteUtils.insert(context, mList);
55 | }
56 | }).start();
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_person.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
17 |
18 |
23 |
24 |
37 |
38 |
51 |
52 |
53 |
54 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_dictionary_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
22 |
23 |
29 |
30 |
43 |
44 |
58 |
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/frag_person.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
18 |
19 |
26 |
27 |
33 |
34 |
41 |
42 |
47 |
48 |
49 |
50 |
51 |
57 |
58 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Home/Fragment/FragTranslate.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Home.Fragment;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.Button;
8 |
9 | import androidx.annotation.NonNull;
10 | import androidx.annotation.Nullable;
11 |
12 | import com.yjx.androidword.Activity.TranslationEnZhActivity;
13 | import com.yjx.androidword.Activity.TranslationMoreActivity;
14 | import com.yjx.androidword.Base.BaseFragment;
15 | import com.yjx.androidword.R;
16 | import com.yjx.androidword.Utils.DialogUtils;
17 | import com.yjx.androidword.Utils.JumpUtils;
18 | import com.yjx.androidword.Utils.NetWorkUtils;
19 |
20 | /**
21 | * @Time : 2020/5/17 18:06
22 | * @Author : Android_小黑
23 | * @File : FragReWords.java
24 | * @Software : Android Studio
25 | */
26 | public class FragTranslate extends BaseFragment implements View.OnClickListener {
27 |
28 | private Button mBtnTranslateEnzh;
29 | private Button mBtnTranslationMore;
30 |
31 | @Nullable
32 | @Override
33 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
34 | View view = inflater.inflate(R.layout.frag_translate, container, false);
35 | initView(view);
36 | mBtnTranslateEnzh.setOnClickListener(this);
37 | mBtnTranslationMore.setOnClickListener(this);
38 | return view;
39 | }
40 |
41 |
42 | @Override
43 | public void onClick(View v) {
44 | switch (v.getId()) {
45 | case R.id.btn_translate_enzh:
46 | if (NetWorkUtils.check(mContext))
47 | JumpUtils.To(mContext, TranslationEnZhActivity.class);
48 | else
49 | DialogUtils.show(mContext, "本功能为在线功能,请先连接网络再进行使用!", "去连接网络");
50 | break;
51 | case R.id.btn_translation_more:
52 | if (NetWorkUtils.check(mContext))
53 | JumpUtils.To(mContext, TranslationMoreActivity.class);
54 | else
55 | DialogUtils.show(mContext, "本功能为在线功能,请先连接网络再进行使用!", "去连接网络");
56 | break;
57 | }
58 | }
59 |
60 |
61 | private void initView(View view) {
62 | mBtnTranslateEnzh = view.findViewById(R.id.btn_translate_enzh);
63 | mBtnTranslationMore = view.findViewById(R.id.btn_translation_more);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_dictionary.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
19 |
20 |
26 |
27 |
33 |
34 |
35 |
36 |
39 |
40 |
48 |
49 |
57 |
58 |
59 |
60 |
61 |
65 |
66 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_modify.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
18 |
23 |
24 |
25 |
31 |
32 |
46 |
47 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_fill.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
26 |
27 |
36 |
37 |
43 |
44 |
56 |
57 |
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/PersonActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.text.TextUtils;
4 | import android.view.View;
5 |
6 | import com.yjx.androidword.Base.BaseActivity;
7 | import com.yjx.androidword.R;
8 | import com.yjx.androidword.Utils.SPUtils;
9 | import com.yjx.androidword.Utils.ToastUtils;
10 |
11 | /**
12 | * @Time : 2020/5/21 14:58
13 | * @Author : Android_小黑
14 | * @File : PersonActivity.java
15 | * @Software : Android Studio
16 | */
17 | public class PersonActivity extends BaseActivity implements View.OnClickListener {
18 |
19 | public static final String PERSON_NAME = "person_name";
20 | public static final String PERSON_MSG = "person_msg";
21 |
22 | private android.widget.ImageView mImvIcon;
23 | private android.widget.EditText mEditName;
24 | private android.widget.EditText mEditMsg;
25 | private com.yjx.androidword.MyView.MyFirstButton mBtnSave;
26 |
27 | @Override
28 | protected void initData() {
29 | getNameMsg();
30 | mBtnSave.setOnClickListener(this);
31 | mImvIcon.setOnClickListener(this);
32 | }
33 |
34 | private void getNameMsg() {
35 | // 获取设置的姓名和签名,如果没有就设置小黑默认值
36 | String strName = (String) SPUtils.get(mContext, PERSON_NAME, "Android_小黑");
37 | String strMsg = (String) SPUtils.get(mContext, PERSON_MSG, "励志做一个月入15K的Android软件攻城狮!");
38 | mEditName.setText(strName);
39 | mEditMsg.setText(strMsg);
40 | }
41 |
42 | @Override
43 | protected int initLayout() {
44 | return R.layout.layout_person;
45 | }
46 |
47 | @Override
48 | protected void initView() {
49 | mImvIcon = findViewById(R.id.imv_icon);
50 | mEditName = findViewById(R.id.edit_name);
51 | mEditMsg = findViewById(R.id.edit_msg);
52 | mBtnSave = findViewById(R.id.btn_save);
53 | }
54 |
55 | @Override
56 | public void onClick(View v) {
57 | switch (v.getId()) {
58 | case R.id.imv_icon:
59 | ToastUtils.show(mContext, "更换头像功能还在开发中噢!");
60 | break;
61 | case R.id.btn_save:
62 | if (!TextUtils.isEmpty(mEditName.getText().toString()) && !TextUtils.isEmpty(mEditMsg.getText().toString())) {
63 | //保存昵称和签名
64 | SPUtils.set(mContext, PERSON_NAME, mEditName.getText().toString());
65 | SPUtils.set(mContext, PERSON_MSG, mEditMsg.getText().toString());
66 | //重新获取一下
67 | getNameMsg();
68 | ToastUtils.show(mContext, "保存成功!");
69 | } else
70 | ToastUtils.show(mContext, "您的昵称和签名不能为空哟!");
71 | break;
72 | }
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/TranslationEnZhActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.text.TextUtils;
4 | import android.view.Gravity;
5 | import android.view.View;
6 | import android.widget.EditText;
7 | import android.widget.TextView;
8 |
9 | import com.yjx.androidword.Base.BaseActivity;
10 | import com.yjx.androidword.R;
11 | import com.yjx.androidword.Utils.BaiDuUtils;
12 | import com.yjx.androidword.Utils.CopyTextUtils;
13 | import com.yjx.androidword.Utils.DialogUtils;
14 | import com.yjx.androidword.Utils.NetWorkUtils;
15 | import com.yjx.androidword.Utils.ToastUtils;
16 |
17 | public class TranslationEnZhActivity extends BaseActivity implements View.OnClickListener {
18 |
19 | private EditText mEditFrom;
20 | private TextView mTxvTo;
21 | private com.yjx.androidword.MyView.MyFirstButton mBtnTranslate;
22 |
23 | @Override
24 | protected void initData() {
25 | mBtnTranslate.setOnClickListener(this);
26 | mTxvTo.setOnClickListener(this);
27 | }
28 |
29 | private void setText(final TextView txv, final String text) {
30 | runOnUiThread(new Runnable() {
31 | @Override
32 | public void run() {
33 | txv.setText(text);
34 | }
35 | });
36 | }
37 |
38 | //中译英
39 | private void translate() {
40 | if (TextUtils.isEmpty(mEditFrom.getText().toString()))
41 | ToastUtils.show(mContext, "需要翻译的内容不能为空噢!", Gravity.CENTER);
42 | else {
43 | new Thread(new Runnable() {
44 | @Override
45 | public void run() {
46 | String text = BaiDuUtils.translate(mEditFrom.getText().toString());
47 | setText(mTxvTo, text);
48 | }
49 | }).start();
50 | }
51 | }
52 |
53 | @Override
54 | public void onClick(View v) {
55 | switch (v.getId()) {
56 | case R.id.btn_translate:
57 | if (NetWorkUtils.check(mContext))
58 | translate();
59 | else
60 | DialogUtils.show(mContext, "本功能为在线功能,请先连接网络再进行使用!", "去连接网络");
61 | break;
62 | case R.id.txv_to:// 点击翻译结果框后复制内容到剪切板
63 | if (!TextUtils.isEmpty(mTxvTo.getText().toString()))
64 | CopyTextUtils.copy(mContext, mTxvTo);
65 | break;
66 | }
67 |
68 | }
69 |
70 | @Override
71 | protected int initLayout() {
72 | return R.layout.layout_translate_enzh;
73 | }
74 |
75 | @Override
76 | protected void initView() {
77 | mEditFrom = findViewById(R.id.edit_from);
78 | mTxvTo = findViewById(R.id.txv_to);
79 | mBtnTranslate = findViewById(R.id.btn_translate);
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/SPUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 |
7 | /**
8 | * @Time : 2020/5/18 18:04
9 | * @Author : Android_小黑
10 | * @File : SPUtils.java
11 | * @Software : Android Studio
12 | */
13 | // 轻量储存工具类
14 | public class SPUtils {
15 |
16 | /**
17 | * 存储数据
18 | *
19 | * 通过判断需要存储对象的类型
20 | * 来调用适当的put()方法
21 | *
22 | * @param context 上下文
23 | * @param key 键
24 | * @param object 值
25 | */
26 | public static void set(Context context, String key, Object object) {
27 | SharedPreferences sharedPreferences = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
28 | @SuppressLint("CommitPrefEdits") SharedPreferences.Editor edit = sharedPreferences.edit();
29 |
30 | if (object instanceof String) {
31 | edit.putString(key, (String) object);
32 | } else if (object instanceof Integer) {
33 | edit.putInt(key, (Integer) object);
34 | } else if (object instanceof Boolean) {
35 | edit.putInt(key, (Integer) object);
36 | } else if (object instanceof Float) {
37 | edit.putFloat(key, (Float) object);
38 | } else if (object instanceof Long) {
39 | edit.putLong(key, (Long) object);
40 | }
41 | // else if (object instanceof Set) {
42 | // edit.putStringSet(key, (Set) object);
43 | // }
44 | edit.apply();
45 | }
46 |
47 | /**
48 | * 获取数据
49 | *
50 | * 通过判断需要存储对象默认值的类型
51 | * 来调用适当的get()方法
52 | *
53 | * @param context 上下文
54 | * @param key 键
55 | * @param defValue 默认值
56 | */
57 | public static Object get(Context context, String key, Object defValue) {
58 | SharedPreferences sharedPreferences = context.getSharedPreferences("sp", Context.MODE_PRIVATE);
59 |
60 | if (defValue instanceof String) {
61 | return sharedPreferences.getString(key, (String) defValue);
62 | } else if (defValue instanceof Integer) {
63 | return sharedPreferences.getInt(key, (Integer) defValue);
64 | } else if (defValue instanceof Boolean) {
65 | return sharedPreferences.getBoolean(key, (Boolean) defValue);
66 | } else if (defValue instanceof Float) {
67 | return sharedPreferences.getFloat(key, (Float) defValue);
68 | } else if (defValue instanceof Long) {
69 | return sharedPreferences.getLong(key, (Long) defValue);
70 | }
71 | // else if (defValue instanceof Set) {
72 | // return sharedPreferences.getStringSet(key, (Set) defValue);
73 | // }
74 | return null;
75 | }
76 |
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
23 |
24 |
27 |
28 |
31 |
32 |
35 |
36 |
39 |
40 |
43 |
44 |
47 |
48 |
51 |
52 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
67 |
68 |
71 |
72 |
75 |
76 |
77 |
78 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_finish.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
17 |
18 |
30 |
31 |
39 |
40 |
45 |
46 |
57 |
58 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Base;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.os.Bundle;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.Button;
10 |
11 | import androidx.appcompat.app.AppCompatActivity;
12 |
13 | import com.yjx.androidword.Home.HomeActivity;
14 | import com.yjx.androidword.R;
15 | import com.yjx.androidword.Utils.DialogUtils;
16 |
17 | // Activity 基类
18 | public abstract class BaseActivity extends AppCompatActivity {
19 |
20 | protected Context mContext;
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | //进入动画
25 | overridePendingTransition(R.anim.base_enter, R.anim.base_exit);
26 | initWindow();
27 | super.onCreate(savedInstanceState);
28 | mContext = BaseActivity.this;
29 | setContentView(initLayout());
30 | //控件声明
31 | initView();
32 | //数据
33 | initData();
34 |
35 | }
36 |
37 | protected abstract void initData();
38 |
39 | protected void initWindow() {
40 | }
41 |
42 | protected abstract int initLayout();
43 |
44 | protected abstract void initView();
45 |
46 | @Override
47 | public void finish() {
48 | //退出动画
49 | overridePendingTransition(R.anim.base_exit, R.anim.base_enter);
50 | //重写finish事件,在主页面时返回需要确认
51 | if (mContext instanceof HomeActivity) {
52 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_finish, null);
53 | final Dialog dialog = DialogUtils.show(mContext, view);
54 | Button btnNo = view.findViewById(R.id.btn_no);
55 | Button btnYes = view.findViewById(R.id.btn_yes);
56 | btnNo.setOnClickListener(new View.OnClickListener() {
57 | @Override
58 | public void onClick(View v) {
59 | dialog.dismiss();
60 | }
61 | });
62 | btnYes.setOnClickListener(new View.OnClickListener() {
63 | @Override
64 | public void onClick(View v) {
65 | /**
66 | * 退出程序
67 | * finish() 结束当前Activity,不会立即释放内存。遵循Android内存管理机制
68 | * finish()是Activity类的方法,仅针对Activity,调用时只是把Activity推向后台,没有立刻释放内存
69 | * Systen.exit() java的方法:退出当前Activity并释放内存,但是此方法只会结束当前Activity,本APP的其他Activity或Service不会结束
70 | * System.exit(0); 参数是把退出原因返回给系统,0表示正常退出 1表示非正常
71 | * killProcess() 结束当前组件,并立刻释放当前Activity所占资源
72 | * 除了finish()以外,其他方法都不会调用Activity的生命周期
73 | * 但是可以手动调用,在方法之前或者之后
74 | * */
75 | android.os.Process.killProcess(android.os.Process.myPid());
76 | // System.exit(0);
77 | }
78 | });
79 | } else
80 | super.finish();
81 | }
82 |
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/OverWordsNumUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Context;
5 | import android.database.sqlite.SQLiteDatabase;
6 |
7 | import com.yjx.androidword.SQLiteHelper.OverWordsHelper;
8 |
9 | import java.util.Calendar;
10 | import java.util.Date;
11 | import java.util.HashMap;
12 | import java.util.Map;
13 |
14 | /**
15 | * @Time : 2020/5/18 18:38
16 | * @Author : Android_小黑
17 | * @File : OverWordsNumUtils.java
18 | * @Software : Android Studio
19 | */
20 | // 统计今日已背单词数量
21 | public class OverWordsNumUtils {
22 |
23 |
24 | public static void add(Context context) {
25 | // 今天和昨天的日期
26 | String strTo = getDateStr(0);
27 | String strYest = getDateStr(-1);
28 | // 判断是否是 新的一天(需要保存昨天的数量到数据库)
29 | if ((int) SPUtils.get(context, strTo, 0) == 0) {
30 | SPUtils.set(context, strTo, 1);
31 | int number = (int) SPUtils.get(context, strYest, 0);
32 | insertSQL(context, strYest, number + "");
33 | } else {
34 | int number = (int) SPUtils.get(context, strTo, 0);
35 | SPUtils.set(context, strTo, (number + 1));
36 | }
37 | }
38 |
39 |
40 | /**
41 | * 通过传入amount来获取日期
42 | *
43 | * @param amount 0=今天 -1=昨天 +1=明天
44 | */
45 | private static String getDateStr(int amount) {
46 | Calendar calendar = Calendar.getInstance();
47 | calendar.add(Calendar.DATE, amount);
48 | Date toDay = calendar.getTime();
49 | return getDate(toDay);
50 | }
51 |
52 |
53 | // 将Date数据转化成 xxxx.xx.xx 模式
54 | public static String getDate(Date date) {
55 | //Sun May 17 20:49:31 CST 2020
56 | String strDate = date.toString();
57 | // 由于每次Date的格式都一样,所以可以通过截取获取年月日
58 | String year = strDate.substring(24, 28);
59 | String mouth = getMonth(strDate.substring(4, 7));
60 | String day = strDate.substring(8, 10);
61 | return year + "." + mouth + "." + day;
62 | }
63 |
64 | // 添加数据进入数据库
65 | private static void insertSQL(Context context, String date, String number) {
66 | OverWordsHelper sHelper = new OverWordsHelper(context);
67 | SQLiteDatabase sDatabase = sHelper.getWritableDatabase();
68 |
69 | ContentValues cv = new ContentValues();
70 | cv.put(OverWordsHelper.DATE, date);
71 | cv.put(OverWordsHelper.NUMBER, number);
72 |
73 | sDatabase.insert(OverWordsHelper.TBNAME, null, cv);
74 | }
75 |
76 | //通过月份缩写获取对应的数据
77 | private static String getMonth(String month) {
78 | Map map = new HashMap<>();
79 | map.put("Jan", "01");
80 | map.put("Feb", "02");
81 | map.put("Mar", "03");
82 | map.put("Apr", "04");
83 | map.put("May", "05");
84 | map.put("Jun", "06");
85 | map.put("Jul", "07");
86 | map.put("Aug", "08");
87 | map.put("Sep", "09");
88 | map.put("Oct", "10");
89 | map.put("Nov", "11");
90 | map.put("Dec", "12");
91 | return map.get(month);
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/SQLiteUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.ContentValues;
5 | import android.content.Context;
6 | import android.database.Cursor;
7 | import android.database.SQLException;
8 | import android.database.sqlite.SQLiteDatabase;
9 | import android.util.Log;
10 |
11 | import com.yjx.androidword.Bean.WordsBean;
12 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper;
13 |
14 | import java.util.List;
15 |
16 | public class SQLiteUtils {
17 |
18 | private static DictionaryHelper sHelper;
19 | private static SQLiteDatabase sDatabase;
20 |
21 | //用事务插入数据库(批量)
22 | public static void insert(Context context, List list) {
23 | DictionaryHelper sHelper = new DictionaryHelper(context);
24 | sDatabase = sHelper.getWritableDatabase();
25 | //开始事务
26 | sDatabase.beginTransaction();
27 | Log.d("SQL", "insert: " + list.size());
28 | try {
29 | //多次插入
30 | for (int i = 0; i < list.size(); i++) {
31 | //原生语句执行效率更高
32 | sDatabase.execSQL("insert into words(word,chinese) values('" + list.get(i).getWord() + "','" + list.get(i).getChinese() + "')");
33 | // ContentValues cv = new ContentValues();
34 | // cv.put(DictionaryHelper.ENGLISH, list.get(i).getWord());
35 | // cv.put(DictionaryHelper.CHINESE, list.get(i).getChinese());
36 | // database.insert(DictionaryHelper.TABLE_NAME, null, cv);
37 | }
38 | //事务开始成功
39 | sDatabase.setTransactionSuccessful();
40 | } catch (SQLException e) {
41 | e.printStackTrace();
42 | Log.d("SQLiteUtils", "insert: IO错误");
43 | } finally {
44 | //最后要结束事务
45 | sDatabase.endTransaction();
46 | Log.d("SQLiteUtils", "插入成功");
47 | }
48 |
49 | }
50 |
51 | //数据库数据个数
52 | public static int cursorCount(Context context) {
53 | DictionaryHelper sHelper = new DictionaryHelper(context);
54 | sDatabase = sHelper.getWritableDatabase();
55 | @SuppressLint("Recycle") Cursor cursor = sDatabase.query(DictionaryHelper.TABLE_NAME, null, null, null, null, null, null);
56 | return cursor.getCount();
57 | }
58 |
59 |
60 | //删除数据
61 | public static void delete(Context context, String strDel) {
62 | DictionaryHelper sHelper = new DictionaryHelper(context);
63 | sDatabase = sHelper.getWritableDatabase();
64 | String clause = DictionaryHelper.ENGLISH + "=?";
65 | sDatabase.delete(DictionaryHelper.TABLE_NAME, clause, new String[]{strDel});
66 | }
67 |
68 | //清空数据
69 | public static int calern(Context context) {
70 | sHelper = new DictionaryHelper(context);
71 | sDatabase = sHelper.getWritableDatabase();
72 | return sDatabase.delete(DictionaryHelper.TABLE_NAME, null, null);
73 | }
74 |
75 | public static void upData(ContentValues cv, String oldEnglish) {
76 | sDatabase.update(DictionaryHelper.TABLE_NAME, cv, "word=?", new String[]{oldEnglish});
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_choose.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
21 |
22 |
23 |
30 |
31 |
38 |
39 |
46 |
47 |
54 |
55 |
61 |
62 |
73 |
74 |
75 |
76 |
86 |
87 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_translate_more.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
19 |
20 |
26 |
27 |
28 |
29 |
30 |
45 |
46 |
50 |
51 |
56 |
57 |
63 |
64 |
65 |
66 |
77 |
78 |
84 |
85 |
91 |
92 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_addwords.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
12 |
13 |
18 |
19 |
25 |
26 |
27 |
28 |
33 |
34 |
39 |
40 |
46 |
47 |
48 |
49 |
58 |
59 |
65 |
66 |
74 |
75 |
81 |
82 |
83 |
84 |
85 |
93 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/DescriptionUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.Button;
9 | import android.widget.TextView;
10 |
11 | import com.yjx.androidword.R;
12 |
13 | @SuppressLint("StaticFieldLeak")
14 | public class DescriptionUtils {
15 |
16 | private static TextView mTxvModeChoose;
17 | private static TextView mTxvModeFill;
18 | private static TextView mTxvDescription;
19 | private static TextView mTxvDictionary;
20 | private static TextView mTxvTranslate;
21 |
22 |
23 |
24 | //软件说明对话框
25 | public static void showDescription(Context context) {
26 | @SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.dialog_description, null);
27 | //软件说明
28 | Button btnDismiss = view.findViewById(R.id.btn_dismiss);
29 | mTxvModeChoose = view.findViewById(R.id.txv_mode_choose);
30 | mTxvModeFill = view.findViewById(R.id.txv_mode_fill);
31 | mTxvDescription = view.findViewById(R.id.txv_description);
32 | mTxvDictionary = view.findViewById(R.id.txv_dictionary);
33 | mTxvTranslate = view.findViewById(R.id.txv_translate);
34 | final Dialog dialog = DialogUtils.show(context, view);
35 | btnDismiss.setOnClickListener(new View.OnClickListener() {
36 | @Override
37 | public void onClick(View v) {
38 | //点击右上角 × 关闭弹窗
39 | dialog.dismiss();
40 | }
41 | });
42 | mTxvModeChoose.setOnClickListener(new View.OnClickListener() {
43 | @Override
44 | public void onClick(View v) {
45 | //点击选择模式
46 | mTxvModeChoose.setBackgroundResource(R.drawable.txv_stroke);
47 | mTxvModeFill.setBackground(null);
48 | mTxvDictionary.setBackground(null);
49 | mTxvTranslate.setBackground(null);
50 | mTxvDescription.setText(R.string.str_descrip_choose);
51 | }
52 | });
53 | mTxvModeFill.setOnClickListener(new View.OnClickListener() {
54 | @Override
55 | public void onClick(View v) {
56 | //点击填空模式
57 | mTxvModeFill.setBackgroundResource(R.drawable.txv_stroke);
58 | mTxvModeChoose.setBackground(null);
59 | mTxvDictionary.setBackground(null);
60 | mTxvTranslate.setBackground(null);
61 | mTxvDescription.setText(R.string.str_descrip_fill);
62 | }
63 | });
64 | mTxvDictionary.setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | mTxvDictionary.setBackgroundResource(R.drawable.txv_stroke);
68 | mTxvModeChoose.setBackground(null);
69 | mTxvModeFill.setBackground(null);
70 | mTxvTranslate.setBackground(null);
71 | mTxvDescription.setText(R.string.str_descrip_dictionary);
72 | }
73 | });
74 | mTxvTranslate.setOnClickListener(new View.OnClickListener() {
75 | @Override
76 | public void onClick(View v) {
77 | mTxvTranslate.setBackgroundResource(R.drawable.txv_stroke);
78 | mTxvModeChoose.setBackground(null);
79 | mTxvModeFill.setBackground(null);
80 | mTxvDictionary.setBackground(null);
81 | mTxvDescription.setText(R.string.str_descrip_translation);
82 | }
83 | });
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/TranslationMoreActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.text.TextUtils;
4 | import android.view.Gravity;
5 | import android.view.View;
6 | import android.widget.EditText;
7 | import android.widget.Spinner;
8 | import android.widget.TextView;
9 |
10 | import com.yjx.androidword.Base.BaseActivity;
11 | import com.yjx.androidword.R;
12 | import com.yjx.androidword.Utils.BaiDuUtils;
13 | import com.yjx.androidword.Utils.CopyTextUtils;
14 | import com.yjx.androidword.Utils.DialogUtils;
15 | import com.yjx.androidword.Utils.NetWorkUtils;
16 | import com.yjx.androidword.Utils.ToastUtils;
17 |
18 | public class TranslationMoreActivity extends BaseActivity implements View.OnClickListener {
19 |
20 | private EditText mEditFrom;
21 | private TextView mTxvTo;
22 | private com.yjx.androidword.MyView.MyFirstButton mBtnTranslate;
23 | private Spinner mSpinnerFrom;
24 | private Spinner mSpinnerTo;
25 |
26 | @Override
27 | protected void initData() {
28 | mBtnTranslate.setOnClickListener(this);
29 | mTxvTo.setOnClickListener(this);
30 | }
31 |
32 | private void setText(final TextView txv, final String text) {
33 | runOnUiThread(new Runnable() {
34 | @Override
35 | public void run() {
36 | txv.setText(text);
37 | }
38 | });
39 | }
40 |
41 | //判断原文语言和译文语言是否一样
42 | private boolean getSpinner(Spinner from, Spinner to) {
43 | String strFrom = from.getSelectedItem().toString();
44 | String strTo = to.getSelectedItem().toString();
45 | if (strFrom.equals(strTo)) {
46 | ToastUtils.show(mContext, "原文语言和译文语言不能是同一种语言噢!");
47 | return false;
48 | } else
49 | return true;
50 | }
51 |
52 | //中译英
53 | private void translate() {
54 | if (getSpinner(mSpinnerFrom, mSpinnerTo)) {
55 | if (TextUtils.isEmpty(mEditFrom.getText().toString()))
56 | ToastUtils.show(mContext, "需要翻译的内容不能为空噢!", Gravity.CENTER);
57 | else {
58 | new Thread(new Runnable() {
59 | @Override
60 | public void run() {
61 | String text = BaiDuUtils.translate(mEditFrom.getText().toString(),
62 | mSpinnerFrom.getSelectedItem().toString(), mSpinnerTo.getSelectedItem().toString());
63 | setText(mTxvTo, text);
64 | }
65 | }).start();
66 | }
67 | }
68 |
69 | }
70 |
71 | @Override
72 | public void onClick(View v) {
73 | switch (v.getId()) {
74 | case R.id.btn_translate:
75 | if (NetWorkUtils.check(mContext))
76 | translate();
77 | else
78 | DialogUtils.show(mContext, "本功能为在线功能,请先连接网络再进行使用!", "去连接网络");
79 | break;
80 | case R.id.txv_to:// 点击翻译结果框后复制内容到剪切板
81 | if (!TextUtils.isEmpty(mTxvTo.getText().toString()))
82 | CopyTextUtils.copy(mContext, mTxvTo);
83 | break;
84 | }
85 | }
86 |
87 | @Override
88 | protected int initLayout() {
89 | return R.layout.layout_translate_more;
90 | }
91 |
92 | @Override
93 | protected void initView() {
94 | mEditFrom = findViewById(R.id.edit_from);
95 | mTxvTo = findViewById(R.id.txv_to);
96 | mBtnTranslate = findViewById(R.id.btn_translate);
97 | mSpinnerFrom = findViewById(R.id.spinner_from);
98 | mSpinnerTo = findViewById(R.id.spinner_to);
99 | }
100 | }
101 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/dialog_description.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
12 |
13 |
27 |
28 |
35 |
36 |
37 |
38 |
43 |
44 |
53 |
54 |
62 |
63 |
71 |
72 |
80 |
81 |
82 |
83 |
87 |
88 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Home/HomeActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Home;
2 |
3 | import android.view.MenuItem;
4 |
5 | import androidx.annotation.NonNull;
6 | import androidx.fragment.app.Fragment;
7 | import androidx.viewpager.widget.ViewPager;
8 |
9 | import com.google.android.material.bottomnavigation.BottomNavigationView;
10 | import com.yjx.androidword.Base.BaseActivity;
11 | import com.yjx.androidword.Home.Adpater.HomeAdapter;
12 | import com.yjx.androidword.Home.Fragment.FragPerson;
13 | import com.yjx.androidword.Home.Fragment.FragReWords;
14 | import com.yjx.androidword.Home.Fragment.FragTranslate;
15 | import com.yjx.androidword.R;
16 |
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * @Time : 2020/5/17 17:50
22 | * @Author : Android_小黑
23 | * @File : HomeActivity.java
24 | * @Software : Android Studio
25 | */
26 | public class HomeActivity extends BaseActivity {
27 |
28 | private androidx.viewpager.widget.ViewPager mPagerContent;
29 | private com.google.android.material.bottomnavigation.BottomNavigationView mBnv;
30 |
31 | @Override
32 | protected void initData() {
33 | List list = new ArrayList<>();
34 | list.add(new FragReWords());
35 | list.add(new FragTranslate());
36 | list.add(new FragPerson());
37 |
38 | HomeAdapter adapter = new HomeAdapter(getSupportFragmentManager(), list);
39 |
40 | mPagerContent.setAdapter(adapter);
41 |
42 | //ViewPager和BotNaviView的联动
43 | setListener();
44 | }
45 |
46 | private void setListener() {
47 | // 点击下方按钮的时候,ViewPager跟着动
48 | mBnv.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
49 | @Override
50 | public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
51 | switch (menuItem.getItemId()) {
52 | case R.id.menu_rewords:
53 | mPagerContent.setCurrentItem(0);
54 | break;
55 | case R.id.menu_translate:
56 | mPagerContent.setCurrentItem(1);
57 | break;
58 | case R.id.menu_person:
59 | mPagerContent.setCurrentItem(2);
60 | break;
61 | }
62 | return true;
63 | }
64 | });
65 | // ViewPager滑动的时候,下面按钮跟着动
66 | mPagerContent.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
67 | @Override
68 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
69 | //滚动的时候
70 | }
71 |
72 | @Override
73 | public void onPageSelected(int position) {
74 | //选择的时候
75 | switch (position) {
76 | case 0:
77 | mBnv.setSelectedItemId(R.id.menu_rewords);
78 | break;
79 | case 1:
80 | mBnv.setSelectedItemId(R.id.menu_translate);
81 | break;
82 | case 2:
83 | mBnv.setSelectedItemId(R.id.menu_person);
84 | break;
85 | }
86 | }
87 |
88 | @Override
89 | public void onPageScrollStateChanged(int state) {
90 | //状态改变的时候
91 | }
92 | });
93 | }
94 |
95 | @Override
96 | protected int initLayout() {
97 | return R.layout.layout_home;
98 | }
99 |
100 | @Override
101 | protected void initView() {
102 | mPagerContent = findViewById(R.id.pager_content);
103 | mBnv = findViewById(R.id.bnv);
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/NotificationUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.app.Notification;
4 | import android.app.NotificationChannel;
5 | import android.app.NotificationManager;
6 | import android.app.PendingIntent;
7 | import android.content.Context;
8 | import android.content.Intent;
9 | import android.graphics.Color;
10 | import android.net.Uri;
11 | import android.os.Build;
12 |
13 | import androidx.core.app.NotificationManagerCompat;
14 |
15 | import com.yjx.androidword.R;
16 |
17 | import static android.content.Context.NOTIFICATION_SERVICE;
18 |
19 | /**
20 | * 通知栏消息工具类
21 | *
22 | * 适配安卓8.0+
23 | */
24 | public class NotificationUtils {
25 |
26 | private static final String ID = "smallDictionary";
27 | private static final String NAME = "小词典";
28 |
29 | public static void show(Context context, String title, String msg, Class> cla) {
30 |
31 | if (intent(context)) {
32 | NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);
33 | PendingIntent pi = PendingIntent.getActivity(context, 0, new Intent(context, cla), 0);
34 | Notification notification = null;
35 | if (Build.VERSION.SDK_INT >= 26) {//这里是API26以上的方法
36 | NotificationChannel channel = new NotificationChannel(ID, NAME, NotificationManager.IMPORTANCE_HIGH);
37 | manager.createNotificationChannel(channel);
38 | notification = new Notification.Builder(context, ID)
39 | .setContentTitle(title)
40 | .setContentText(msg)
41 | .setSmallIcon(R.mipmap.img_icon)
42 | .setTicker(msg)
43 | .setFullScreenIntent(pi, true)
44 | .setColor(Color.GREEN)
45 | .build();
46 | } else {//这里是API26以下
47 | notification = new Notification.Builder(context)
48 | .setContentTitle(title)
49 | .setContentText(msg)
50 | .setTicker(msg)
51 | .setSmallIcon(R.mipmap.img_icon)
52 | .setFullScreenIntent(pi, true)
53 | .setDefaults(Notification.DEFAULT_ALL)
54 | .setColor(Color.GREEN)
55 | .build();
56 | }
57 | manager.notify(1, notification);
58 | }
59 |
60 | }
61 |
62 | private static boolean intent(Context context) {
63 | if (!NotificationManagerCompat.from(context).areNotificationsEnabled()) {
64 | Intent localIntent = new Intent();
65 | //直接跳转到应用通知设置的代码:
66 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {//8.0及以上
67 | localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
68 | localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
69 | localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
70 | } else if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0以上到8.0以下
71 | localIntent.setAction("android.settings.APP_NOTIFICATION_SETTINGS");
72 | localIntent.putExtra("app_package", context.getPackageName());
73 | localIntent.putExtra("app_uid", context.getApplicationInfo().uid);
74 | } else {
75 | //4.4以下没有从app跳转到应用通知设置页面的Action,可考虑跳转到应用详情页面,
76 | localIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
77 | localIntent.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
78 | localIntent.setData(Uri.fromParts("package", context.getPackageName(), null));
79 | }
80 | context.startActivity(localIntent);
81 | ToastUtils.show(context, "请打开小词典的通知权限,否则会有很多重要消息漏掉噢!");
82 | return false;
83 | }
84 | return true;
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/MD5.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import java.io.File;
4 | import java.io.FileInputStream;
5 | import java.io.FileNotFoundException;
6 | import java.io.IOException;
7 | import java.io.InputStream;
8 | import java.io.UnsupportedEncodingException;
9 | import java.security.MessageDigest;
10 | import java.security.NoSuchAlgorithmException;
11 |
12 | /**
13 | * MD5编码相关的类
14 | *
15 | * @author wangjingtao
16 | *
17 | */
18 | public class MD5 {
19 | // 首先初始化一个字符数组,用来存放每个16进制字符
20 | private static final char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
21 | 'e', 'f' };
22 |
23 | /**
24 | * 获得一个字符串的MD5值
25 | *
26 | * @param input 输入的字符串
27 | * @return 输入字符串的MD5值
28 | *
29 | */
30 | public static String md5(String input) {
31 | if (input == null)
32 | return null;
33 |
34 | try {
35 | // 拿到一个MD5转换器(如果想要SHA1参数换成”SHA1”)
36 | MessageDigest messageDigest = MessageDigest.getInstance("MD5");
37 | // 输入的字符串转换成字节数组
38 | byte[] inputByteArray = new byte[0];
39 | try {
40 | inputByteArray = input.getBytes("utf-8");
41 | } catch (UnsupportedEncodingException e) {
42 | e.printStackTrace();
43 | }
44 | // inputByteArray是输入字符串转换得到的字节数组
45 | messageDigest.update(inputByteArray);
46 | // 转换并返回结果,也是字节数组,包含16个元素
47 | byte[] resultByteArray = messageDigest.digest();
48 | // 字符数组转换成字符串返回
49 | return byteArrayToHex(resultByteArray);
50 | } catch (NoSuchAlgorithmException e) {
51 | return null;
52 | }
53 | }
54 |
55 | /**
56 | * 获取文件的MD5值
57 | *
58 | * @param file
59 | * @return
60 | */
61 | public static String md5(File file) {
62 | try {
63 | if (!file.isFile()) {
64 | System.err.println("文件" + file.getAbsolutePath() + "不存在或者不是文件");
65 | return null;
66 | }
67 |
68 | FileInputStream in = new FileInputStream(file);
69 |
70 | String result = md5(in);
71 |
72 | in.close();
73 |
74 | return result;
75 |
76 | } catch (FileNotFoundException e) {
77 | e.printStackTrace();
78 | } catch (IOException e) {
79 | e.printStackTrace();
80 | }
81 |
82 | return null;
83 | }
84 |
85 | public static String md5(InputStream in) {
86 |
87 | try {
88 | MessageDigest messagedigest = MessageDigest.getInstance("MD5");
89 |
90 | byte[] buffer = new byte[1024];
91 | int read = 0;
92 | while ((read = in.read(buffer)) != -1) {
93 | messagedigest.update(buffer, 0, read);
94 | }
95 |
96 | in.close();
97 |
98 | String result = byteArrayToHex(messagedigest.digest());
99 |
100 | return result;
101 | } catch (NoSuchAlgorithmException e) {
102 | e.printStackTrace();
103 | } catch (FileNotFoundException e) {
104 | e.printStackTrace();
105 | } catch (IOException e) {
106 | e.printStackTrace();
107 | }
108 |
109 | return null;
110 | }
111 |
112 | private static String byteArrayToHex(byte[] byteArray) {
113 | // new一个字符数组,这个就是用来组成结果字符串的(解释一下:一个byte是八位二进制,也就是2位十六进制字符(2的8次方等于16的2次方))
114 | char[] resultCharArray = new char[byteArray.length * 2];
115 | // 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
116 | int index = 0;
117 | for (byte b : byteArray) {
118 | resultCharArray[index++] = hexDigits[b >>> 4 & 0xf];
119 | resultCharArray[index++] = hexDigits[b & 0xf];
120 | }
121 |
122 | // 字符数组组合成字符串返回
123 | return new String(resultCharArray);
124 |
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Home/Fragment/FragPerson.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Home.Fragment;
2 |
3 | import android.os.Bundle;
4 | import android.view.LayoutInflater;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.widget.LinearLayout;
8 | import android.widget.TextView;
9 |
10 | import androidx.annotation.NonNull;
11 | import androidx.annotation.Nullable;
12 | import androidx.recyclerview.widget.DefaultItemAnimator;
13 | import androidx.recyclerview.widget.DividerItemDecoration;
14 | import androidx.recyclerview.widget.LinearLayoutManager;
15 | import androidx.recyclerview.widget.RecyclerView;
16 |
17 | import com.yjx.androidword.Activity.PersonActivity;
18 | import com.yjx.androidword.Base.BaseFragment;
19 | import com.yjx.androidword.Home.Adpater.PersonMenuAdapter;
20 | import com.yjx.androidword.Home.Bean.MenuBean;
21 | import com.yjx.androidword.R;
22 | import com.yjx.androidword.Utils.JumpUtils;
23 | import com.yjx.androidword.Utils.SPUtils;
24 |
25 | import java.util.ArrayList;
26 | import java.util.List;
27 |
28 | /**
29 | * @Time : 2020/5/17 18:06
30 | * @Author : Android_小黑
31 | * @File : FragReWords.java
32 | * @Software : Android Studio
33 | */
34 | public class FragPerson extends BaseFragment {
35 |
36 | private RecyclerView mRecycleMenu;
37 | private List mList;
38 | private TextView mTxvName;
39 | private TextView mTxvMsg;
40 |
41 | @Nullable
42 | @Override
43 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
44 | View view = inflater.inflate(R.layout.frag_person, container, false);
45 | initView(view);
46 | initMenuData();
47 | LinearLayoutManager layoutManager = new LinearLayoutManager(mContext);
48 | layoutManager.setOrientation(RecyclerView.VERTICAL);
49 | PersonMenuAdapter adapter = new PersonMenuAdapter(mContext, mList);
50 | mRecycleMenu.setAdapter(adapter);
51 | mRecycleMenu.setLayoutManager(layoutManager);
52 | //子项动画
53 | mRecycleMenu.setItemAnimator(new DefaultItemAnimator());
54 | //子项分割线
55 | mRecycleMenu.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));
56 | return view;
57 | }
58 |
59 | @Override
60 | public void onStart() {
61 | // 获取设置的姓名和签名,如果没有就设置小黑默认值
62 | String strName = (String) SPUtils.get(mContext, PersonActivity.PERSON_NAME, "Android_小黑");
63 | String strMsg = (String) SPUtils.get(mContext, PersonActivity.PERSON_MSG, "励志做一个月入15K的Android软件攻城狮!");
64 | mTxvName.setText(strName);
65 | mTxvMsg.setText(strMsg);
66 | super.onStart();
67 | }
68 |
69 | private void initMenuData() {
70 | mList = new ArrayList<>();
71 |
72 | MenuBean bean = new MenuBean();
73 | bean.setIcon(R.mipmap.img_modify);
74 | bean.setText("修改每日目标");
75 | mList.add(bean);
76 |
77 | bean = new MenuBean();
78 | bean.setIcon(R.mipmap.img_add);
79 | bean.setText("添加单词");
80 | mList.add(bean);
81 |
82 | bean = new MenuBean();
83 | bean.setIcon(R.mipmap.img_suggest);
84 | bean.setText("意见反馈和功能建议");
85 | mList.add(bean);
86 |
87 | bean = new MenuBean();
88 | bean.setIcon(R.mipmap.img_help);
89 | bean.setText("软件使用帮助");
90 | mList.add(bean);
91 |
92 | bean = new MenuBean();
93 | bean.setIcon(R.mipmap.img_about);
94 | bean.setText("关于");
95 | mList.add(bean);
96 | }
97 |
98 | private void initView(View view) {
99 | mTxvName = view.findViewById(R.id.txv_name);
100 | mTxvMsg = view.findViewById(R.id.txv_msg);
101 | mRecycleMenu = view.findViewById(R.id.recycle_menu);
102 | LinearLayout llPerson = view.findViewById(R.id.ll_person);
103 | llPerson.setOnClickListener(new View.OnClickListener() {
104 | @Override
105 | public void onClick(View v) {
106 | JumpUtils.To(mContext, PersonActivity.class);
107 | }
108 | });
109 | }
110 |
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Home/Adpater/PersonMenuAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Home.Adpater;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.Context;
6 | import android.view.Gravity;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.Button;
11 | import android.widget.ImageView;
12 | import android.widget.NumberPicker;
13 | import android.widget.TextView;
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.recyclerview.widget.RecyclerView;
17 |
18 | import com.yjx.androidword.Activity.AddWordsActivity;
19 | import com.yjx.androidword.Activity.TxBugActivity;
20 | import com.yjx.androidword.Home.Bean.MenuBean;
21 | import com.yjx.androidword.R;
22 | import com.yjx.androidword.Utils.DescriptionUtils;
23 | import com.yjx.androidword.Utils.DialogUtils;
24 | import com.yjx.androidword.Utils.JumpUtils;
25 | import com.yjx.androidword.Utils.SPUtils;
26 | import com.yjx.androidword.Utils.ToastUtils;
27 |
28 | import java.util.List;
29 |
30 | /**
31 | * @Time : 2020/5/19 11:29
32 | * @Author : Android_小黑
33 | * @File : PersonMenuAdapter.java
34 | * @Software : Android Studio
35 | */
36 | public class PersonMenuAdapter extends RecyclerView.Adapter {
37 |
38 | private Context mContext;
39 | private List mList;
40 |
41 | public PersonMenuAdapter(Context context, List list) {
42 | mContext = context;
43 | mList = list;
44 | }
45 |
46 | @NonNull
47 | @Override
48 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
49 | View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_person_menu, parent, false);
50 | return new ViewHolder(view);
51 | }
52 |
53 | @Override
54 | public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
55 | holder.mImvIcon.setImageResource(mList.get(position).getIcon());
56 | holder.mTxvText.setText(mList.get(position).getText());
57 | holder.itemView.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | switch (position) {
61 | case 0:
62 | @SuppressLint("InflateParams") View view1 = LayoutInflater.from(mContext).inflate(R.layout.dialog_aims, null);
63 | String[] numbers = new String[50];
64 | for (int i = 0; i < 50; i++)
65 | numbers[i] = String.valueOf(i * 25);
66 | final NumberPicker mNumberPicker = view1.findViewById(R.id.number_picker);
67 | Button mBtnModify = view1.findViewById(R.id.btn_modify);
68 | final Dialog dialog = DialogUtils.show(mContext, view1);
69 | mNumberPicker.setMinValue(0);
70 | mNumberPicker.setMaxValue(45);
71 | mNumberPicker.setDisplayedValues(numbers);
72 | mNumberPicker.setValue((Integer) SPUtils.get(mContext, "everyday_aims", 0) / 25);
73 | mBtnModify.setOnClickListener(new View.OnClickListener() {
74 | @Override
75 | public void onClick(View v) {
76 | dialog.dismiss();
77 | SPUtils.set(mContext, "everyday_aims", mNumberPicker.getValue() * 25);
78 | ToastUtils.show(mContext, "修改成功!", Gravity.CENTER);
79 | }
80 | });
81 | break;
82 | case 1:
83 | JumpUtils.To(mContext, AddWordsActivity.class);
84 | break;
85 | case 2:
86 | JumpUtils.To(mContext, TxBugActivity.class);
87 | break;
88 | case 3:
89 | DescriptionUtils.showDescription(mContext);
90 | break;
91 | case 4:
92 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_about, null);
93 | DialogUtils.show(mContext, view);
94 | break;
95 | }
96 | }
97 | });
98 | }
99 |
100 | @Override
101 | public int getItemCount() {
102 | return mList.size();
103 | }
104 |
105 | class ViewHolder extends RecyclerView.ViewHolder {
106 | private ImageView mImvIcon;
107 | private TextView mTxvText;
108 |
109 | ViewHolder(@NonNull View itemView) {
110 | super(itemView);
111 | mImvIcon = itemView.findViewById(R.id.imv_icon);
112 | mTxvText = itemView.findViewById(R.id.txv_text);
113 | }
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/AddWordsActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.ContentValues;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.text.TextUtils;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.widget.Button;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import com.yjx.androidword.Base.BaseActivity;
15 | import com.yjx.androidword.R;
16 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper;
17 | import com.yjx.androidword.Utils.AddBookUtils;
18 | import com.yjx.androidword.Utils.DialogUtils;
19 | import com.yjx.androidword.Utils.NotificationUtils;
20 | import com.yjx.androidword.Utils.ToastUtils;
21 |
22 | public class AddWordsActivity extends BaseActivity implements View.OnClickListener {
23 | private android.widget.EditText mEditEnglish;
24 | private android.widget.EditText mEditChinese;
25 | private android.widget.Button mBtnAdd;
26 |
27 | DictionaryHelper mSQHelper;
28 | SQLiteDatabase mSQLiteDatabase;
29 | ContentValues mContentValues;
30 | private com.yjx.androidword.MyView.MyBookButton mBtnMschool;
31 | private com.yjx.androidword.MyView.MyBookButton mBtnHschool;
32 | private com.yjx.androidword.MyView.MyBookButton mBtnUni4;
33 | private com.yjx.androidword.MyView.MyBookButton mBtnUni6;
34 | private android.widget.Spinner mSpinnerPort;
35 |
36 | @Override
37 | protected void initData() {
38 | mSQHelper = new DictionaryHelper(mContext);
39 | mSQLiteDatabase = mSQHelper.getWritableDatabase();
40 |
41 | mBtnAdd.setOnClickListener(this);
42 | mBtnMschool.setOnClickListener(this);
43 | mBtnHschool.setOnClickListener(this);
44 | mBtnUni4.setOnClickListener(this);
45 | mBtnUni6.setOnClickListener(this);
46 | }
47 |
48 |
49 | @SuppressLint("SetTextI18n")
50 | private void showDialog(final String bookName) {
51 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_finish, null);
52 | final Dialog dialog = DialogUtils.show(mContext, view);
53 | TextView mTxvTitle = view.findViewById(R.id.txv_title);
54 | TextView mTxvText = view.findViewById(R.id.txv_text);
55 | Button mBtnYes = view.findViewById(R.id.btn_yes);
56 | Button mBtnNo = view.findViewById(R.id.btn_no);
57 | mTxvTitle.setText("确定添加");
58 | mTxvText.setText("确定添加" + bookName + "词汇书中所有单词吗?");
59 | mBtnYes.setOnClickListener(new View.OnClickListener() {
60 | @Override
61 | public void onClick(View v) {
62 | AddBookUtils.add(mContext, bookName);
63 | NotificationUtils.show(mContext,
64 | "添加成功!",
65 | bookName + "词汇已经添加到词库里面啦!赶快去背诵吧!"
66 | , ChooseE2CActivity.class);
67 | dialog.dismiss();
68 | }
69 | });
70 | mBtnNo.setOnClickListener(new View.OnClickListener() {
71 | @Override
72 | public void onClick(View v) {
73 | dialog.dismiss();
74 | }
75 | });
76 | }
77 |
78 | @Override
79 | public void onClick(View v) {
80 | switch (v.getId()) {
81 | case R.id.btn_mschool://添加初中
82 | showDialog("中考");
83 | break;
84 | case R.id.btn_hschool://添加高中
85 | showDialog("高考");
86 | break;
87 | case R.id.btn_uni4://添加大学四级
88 | showDialog("大学四级");
89 | break;
90 | case R.id.btn_uni6://添加大学六级
91 | showDialog("大学六级");
92 | break;
93 | case R.id.btn_add://添加单词
94 | String english = mEditEnglish.getText().toString();
95 | String chinese = mEditChinese.getText().toString();
96 | String port = mSpinnerPort.getSelectedItem().toString();
97 | if (!TextUtils.isEmpty(english) && !TextUtils.isEmpty(chinese)) {
98 | if (!port.equals("词性"))
99 | initSQLiteData(english, port + chinese);
100 | } else
101 | ToastUtils.show(mContext, "单词或翻译都不能为空噢!");
102 | break;
103 | }
104 | }
105 |
106 | private void initSQLiteData(String english, String chinese) {
107 | mContentValues = new ContentValues();
108 | mContentValues.put(DictionaryHelper.ENGLISH, english);
109 | mContentValues.put(DictionaryHelper.CHINESE, chinese);
110 | if (mSQLiteDatabase.insert(DictionaryHelper.TABLE_NAME, null, mContentValues) == -1) {
111 | Toast.makeText(mContext, "添加失败!", Toast.LENGTH_SHORT).show();
112 | } else {
113 | Toast.makeText(mContext, "添加成功!", Toast.LENGTH_SHORT).show();
114 | mEditEnglish.setText("");
115 | mEditChinese.setText("");
116 | }
117 | }
118 |
119 | @Override
120 | protected int initLayout() {
121 | return R.layout.layout_addwords;
122 | }
123 |
124 | @Override
125 | protected void initView() {
126 | mEditEnglish = findViewById(R.id.edit_english);
127 | mEditChinese = findViewById(R.id.edit_from);
128 | mBtnAdd = findViewById(R.id.btn_add);
129 | mBtnMschool = findViewById(R.id.btn_mschool);
130 | mBtnHschool = findViewById(R.id.btn_hschool);
131 | mBtnUni4 = findViewById(R.id.btn_uni4);
132 | mBtnUni6 = findViewById(R.id.btn_uni6);
133 | mSpinnerPort = findViewById(R.id.spinner_port);
134 | }
135 |
136 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Home/Fragment/FragReWords.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Home.Fragment;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.os.Bundle;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.LinearLayout;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 |
12 | import androidx.annotation.NonNull;
13 | import androidx.annotation.Nullable;
14 |
15 | import com.yjx.androidword.Activity.ChooseC2EActivity;
16 | import com.yjx.androidword.Activity.ChooseE2CActivity;
17 | import com.yjx.androidword.Activity.DictionaryActivity;
18 | import com.yjx.androidword.Activity.FillC2EActivity;
19 | import com.yjx.androidword.Activity.FillE2CActivity;
20 | import com.yjx.androidword.Base.BaseFragment;
21 | import com.yjx.androidword.MyView.MyFirstButton;
22 | import com.yjx.androidword.R;
23 | import com.yjx.androidword.Utils.DialogUtils;
24 | import com.yjx.androidword.Utils.JumpUtils;
25 | import com.yjx.androidword.Utils.OverWordsNumUtils;
26 | import com.yjx.androidword.Utils.SPUtils;
27 | import com.yjx.androidword.Utils.SQLiteUtils;
28 |
29 | import java.util.Calendar;
30 | import java.util.Date;
31 |
32 | /**
33 | * @Time : 2020/5/17 18:06
34 | * @Author : Android_小黑
35 | * @File : FragReWords.java
36 | * @Software : Android Studio
37 | */
38 | public class FragReWords extends BaseFragment implements View.OnClickListener {
39 |
40 | private TextView mTxvTodayAims;
41 | private TextView mTxvTodayCompleted;
42 | private ProgressBar mProgressRate;
43 | private TextView mTxvDictionaryWordsNumber;
44 | private MyFirstButton mBtnModeChoose;
45 | private MyFirstButton mBtnModeChoose2;
46 | private MyFirstButton mBtnModeFill;
47 | private MyFirstButton mBtnModeFill2;
48 | private LinearLayout mLlDictionary;
49 |
50 | @Nullable
51 | @Override
52 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
53 | View view = inflater.inflate(R.layout.frag_rewords, container, false);
54 | initView(view);
55 | mBtnModeChoose.setOnClickListener(this);
56 | mBtnModeChoose2.setOnClickListener(this);
57 | mBtnModeFill.setOnClickListener(this);
58 | mBtnModeFill2.setOnClickListener(this);
59 | mLlDictionary.setOnClickListener(this);
60 | return view;
61 | }
62 |
63 |
64 | // 根据Fragment的声明周期、这些需要实时更新的数据,放在onCreateView中不会刷新
65 | @SuppressLint("SetTextI18n")
66 | @Override
67 | public void onStart() {
68 | Calendar calendar = Calendar.getInstance();
69 | calendar.add(Calendar.DATE, 0);
70 | Date date = calendar.getTime();
71 | mTxvTodayCompleted.setText(SPUtils.get(mContext, OverWordsNumUtils.getDate(date), 0) + "");
72 | // 获取每日目标
73 | mTxvTodayAims.setText(String.valueOf(SPUtils.get(mContext, "everyday_aims", 0)));
74 | // 进度条比例计算
75 | int bili = (int) ((Float.valueOf(mTxvTodayCompleted.getText().toString()) / Float.valueOf(mTxvTodayAims.getText().toString())) * 100);
76 | mProgressRate.setProgress(bili);
77 | // 词库单词数获取
78 | mTxvDictionaryWordsNumber.setText(String.valueOf(SQLiteUtils.cursorCount(mContext)));
79 | super.onStart();
80 | }
81 |
82 | private void initView(View view) {
83 | mTxvTodayAims = view.findViewById(R.id.txv_today_aims);
84 | mTxvTodayCompleted = view.findViewById(R.id.txv_today_completed);
85 | mProgressRate = view.findViewById(R.id.progress_rate);
86 | mTxvDictionaryWordsNumber = view.findViewById(R.id.txv_dictionary_words_number);
87 | mBtnModeChoose = view.findViewById(R.id.btn_mode_choose);
88 | mBtnModeChoose2 = view.findViewById(R.id.btn_mode_choose2);
89 | mBtnModeFill = view.findViewById(R.id.btn_mode_fill);
90 | mBtnModeFill2 = view.findViewById(R.id.btn_mode_fill2);
91 | mLlDictionary = view.findViewById(R.id.ll_dictionary);
92 | }
93 |
94 | @Override
95 | public void onClick(View v) {
96 | switch (v.getId()) {
97 | //词库
98 | case R.id.ll_dictionary://查询词库
99 | if (SQLiteUtils.cursorCount(mContext) != 0)
100 | JumpUtils.To(mContext, DictionaryActivity.class);
101 | else
102 | DialogUtils.show(mContext, "词库内没有单词,请先添加!", "去添加单词");
103 | break;
104 | //四种模式
105 | case R.id.btn_mode_choose://选择 英-中
106 | if (SQLiteUtils.cursorCount(mContext) > 4)
107 | JumpUtils.To(mContext, ChooseE2CActivity.class);
108 | else
109 | DialogUtils.show(mContext, "词库内单词低于5个,无法进入此模式!请先添加!", "去添加单词");
110 | break;
111 |
112 | case R.id.btn_mode_choose2://选择 中-英
113 | if (SQLiteUtils.cursorCount(mContext) > 4)
114 | JumpUtils.To(mContext, ChooseC2EActivity.class);
115 | else
116 | DialogUtils.show(mContext, "词库内单词低于5个,无法进入此模式!请先添加!", "去添加单词");
117 | break;
118 |
119 | case R.id.btn_mode_fill://填写 英-中
120 | if (SQLiteUtils.cursorCount(mContext) != 0)
121 | JumpUtils.To(mContext, FillE2CActivity.class);
122 | else
123 | DialogUtils.show(mContext, "词库内没有单词,请先添加!", "去添加单词");
124 | break;
125 |
126 | case R.id.btn_mode_fill2://填写 中-英
127 | if (SQLiteUtils.cursorCount(mContext) != 0)
128 | JumpUtils.To(mContext, FillC2EActivity.class);
129 | else
130 | DialogUtils.show(mContext, "词库内没有单词,请先添加!", "去添加单词");
131 | break;
132 | }
133 | }
134 | }
135 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/FillC2EActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.graphics.Color;
6 | import android.text.TextUtils;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import com.yjx.androidword.Base.BaseActivity;
12 | import com.yjx.androidword.Bean.WordsBean;
13 | import com.yjx.androidword.R;
14 | import com.yjx.androidword.Utils.DialogUtils;
15 | import com.yjx.androidword.Utils.NotificationUtils;
16 | import com.yjx.androidword.Utils.OverWordsNumUtils;
17 | import com.yjx.androidword.Utils.SQLiteUtils;
18 | import com.yjx.androidword.Utils.WordsUtils;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | public class FillC2EActivity extends BaseActivity implements View.OnClickListener {
24 |
25 | private TextView mTxvWord;
26 | private com.yjx.androidword.MyView.MyEditText mEditAnswer;
27 | private com.yjx.androidword.MyView.MyFirstButton mBtnNext;
28 | private TextView mTxvGrasp;
29 | private List mList = new ArrayList<>();
30 | private TextView mTxvAnswer;
31 | //当前单词标记
32 | private int index = 0;
33 |
34 | @Override
35 | protected void initData() {
36 | mBtnNext.setOnClickListener(this);
37 | mTxvGrasp.setOnClickListener(this);
38 | mBtnNext.setText("确定");
39 | //进入时获取词库
40 | mList = WordsUtils.get(mContext);
41 | setData();
42 | }
43 |
44 | //答案判断
45 | @SuppressLint("SetTextI18n")
46 | private void getJudg(String answer) {
47 |
48 | // 每次选完就可以加一个数量
49 | OverWordsNumUtils.add(mContext);
50 |
51 | if (answer.equals(mList.get(index).getWord())) {
52 | mEditAnswer.setTextColor(Color.GREEN);
53 | } else {
54 | mEditAnswer.setTextColor(Color.RED);
55 | mTxvAnswer.setText("正确答案:" + mList.get(index).getWord());
56 | }
57 |
58 | }
59 |
60 | //把获取到的单词传到TextView上
61 | private void setData() {
62 | //防止背到最后一个单词导致IndexOutOfBoundsException
63 | if (index == SQLiteUtils.cursorCount(mContext) - 1) {
64 | index = 0;
65 | } else {
66 | index++;
67 | }
68 | //传入一个单词
69 | mTxvWord.setText(mList.get(index).getChinese());
70 | mTxvAnswer.setText("");
71 | mEditAnswer.setTextColor(Color.BLACK);
72 | mEditAnswer.setText("");
73 | }
74 |
75 | @Override
76 | protected int initLayout() {
77 | return R.layout.layout_fill;
78 | }
79 |
80 | @Override
81 | protected void initView() {
82 | mTxvWord = findViewById(R.id.txv_word);
83 | mEditAnswer = findViewById(R.id.edit_answer);
84 | mBtnNext = findViewById(R.id.btn_next);
85 | mTxvGrasp = findViewById(R.id.txv_grasp);
86 | mTxvAnswer = findViewById(R.id.txv_answer);
87 | }
88 |
89 | @SuppressLint("SetTextI18n")
90 | @Override
91 | public void onClick(View v) {
92 | switch (v.getId()) {
93 | case R.id.btn_next:
94 | if (mBtnNext.getText().equals("确定")) {
95 | if (!TextUtils.isEmpty(mEditAnswer.getText().toString()))
96 | getJudg(mEditAnswer.getText().toString());
97 | else
98 | mTxvAnswer.setText("正确答案:" + mList.get(index).getWord());
99 | mBtnNext.setText(R.string.str_next);
100 | } else {
101 | mBtnNext.setText("确定");
102 | setData();
103 | }
104 |
105 | break;
106 |
107 | case R.id.txv_grasp://掌握了单词
108 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_dictionary_menu, null);
109 | TextView txvEnglish = view.findViewById(R.id.edit_english);
110 | TextView txvChinese = view.findViewById(R.id.edit_from);
111 | TextView txvDel = view.findViewById(R.id.txv_del);
112 | TextView txvModify = view.findViewById(R.id.txv_modify);
113 | txvEnglish.setText(mList.get(index).getWord());
114 | txvChinese.setText(mList.get(index).getChinese());
115 | txvDel.setText("掌握(删除)");
116 | txvModify.setText("取消");
117 | final Dialog dialog = DialogUtils.show(mContext, view);
118 | txvDel.setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | //数据库删除此单词
122 | SQLiteUtils.delete(mContext, mList.get(index).getWord());
123 | //当词库单词量不足1时,返回主页面并提示
124 | if (SQLiteUtils.cursorCount(mContext) == 0) {
125 | NotificationUtils.show(mContext,
126 | "温馨提示",
127 | "词库中没有单词,无法继续此模式,请添加单词!"
128 | , AddWordsActivity.class);
129 | finish();
130 | } else {
131 | //删除了单词以后需要重新获取词库
132 | mList = WordsUtils.get(mContext);
133 | setData();
134 | }
135 | dialog.dismiss();
136 | }
137 | });
138 | txvModify.setOnClickListener(new View.OnClickListener() {
139 | @Override
140 | public void onClick(View v) {
141 | dialog.dismiss();
142 | }
143 | });
144 | break;
145 | }
146 | }
147 |
148 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/FillE2CActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.graphics.Color;
6 | import android.text.TextUtils;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.TextView;
10 |
11 | import com.yjx.androidword.Base.BaseActivity;
12 | import com.yjx.androidword.Bean.WordsBean;
13 | import com.yjx.androidword.R;
14 | import com.yjx.androidword.Utils.DialogUtils;
15 | import com.yjx.androidword.Utils.NotificationUtils;
16 | import com.yjx.androidword.Utils.OverWordsNumUtils;
17 | import com.yjx.androidword.Utils.SQLiteUtils;
18 | import com.yjx.androidword.Utils.WordsUtils;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 |
23 | public class FillE2CActivity extends BaseActivity implements View.OnClickListener {
24 |
25 | private android.widget.TextView mTxvWord;
26 | private com.yjx.androidword.MyView.MyEditText mEditAnswer;
27 | private com.yjx.androidword.MyView.MyFirstButton mBtnNext;
28 | private android.widget.TextView mTxvGrasp;
29 | private List mList = new ArrayList<>();
30 | private android.widget.TextView mTxvAnswer;
31 | //当前单词标记
32 | private int index = 0;
33 |
34 | @Override
35 | protected void initData() {
36 | mBtnNext.setOnClickListener(this);
37 | mTxvGrasp.setOnClickListener(this);
38 | mBtnNext.setText("确定");
39 | //进入时获取词库
40 | mList = WordsUtils.get(mContext);
41 | setData();
42 | }
43 |
44 | //答案判断
45 | @SuppressLint("SetTextI18n")
46 | private void getJudg(String answer) {
47 |
48 | // 每次选完就可以加一个数量
49 | OverWordsNumUtils.add(mContext);
50 |
51 | if (answer.equals(mList.get(index).getChinese())) {
52 | mEditAnswer.setTextColor(Color.GREEN);
53 | } else {
54 | mEditAnswer.setTextColor(Color.RED);
55 | mTxvAnswer.setText("正确答案:" + mList.get(index).getChinese());
56 | }
57 |
58 | }
59 |
60 | //把获取到的单词传到TextView上
61 | private void setData() {
62 | //防止背到最后一个单词导致IndexOutOfBoundsException
63 | if (index == SQLiteUtils.cursorCount(mContext) - 1) {
64 | index = 0;
65 | } else {
66 | index++;
67 | }
68 | //传入一个单词
69 | mTxvWord.setText(mList.get(index).getWord());
70 | mTxvAnswer.setText("");
71 | mEditAnswer.setTextColor(Color.BLACK);
72 | mEditAnswer.setText("");
73 | }
74 |
75 | @Override
76 | protected int initLayout() {
77 | return R.layout.layout_fill;
78 | }
79 |
80 | @Override
81 | protected void initView() {
82 | mTxvWord = findViewById(R.id.txv_word);
83 | mEditAnswer = findViewById(R.id.edit_answer);
84 | mBtnNext = findViewById(R.id.btn_next);
85 | mTxvGrasp = findViewById(R.id.txv_grasp);
86 | mTxvAnswer = findViewById(R.id.txv_answer);
87 | }
88 |
89 | @SuppressLint("SetTextI18n")
90 | @Override
91 | public void onClick(View v) {
92 | switch (v.getId()) {
93 | case R.id.btn_next:
94 | if (mBtnNext.getText().equals("确定")) {
95 | if (!TextUtils.isEmpty(mEditAnswer.getText().toString()))
96 | getJudg(mEditAnswer.getText().toString());
97 | else
98 | mTxvAnswer.setText("正确答案:" + mList.get(index).getChinese());
99 | mBtnNext.setText(R.string.str_next);
100 | } else {
101 | mBtnNext.setText("确定");
102 | setData();
103 | }
104 |
105 | break;
106 |
107 | case R.id.txv_grasp://掌握了单词
108 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_dictionary_menu, null);
109 | TextView txvEnglish = view.findViewById(R.id.edit_english);
110 | TextView txvChinese = view.findViewById(R.id.edit_from);
111 | TextView txvDel = view.findViewById(R.id.txv_del);
112 | TextView txvModify = view.findViewById(R.id.txv_modify);
113 | txvEnglish.setText(mList.get(index).getWord());
114 | txvChinese.setText(mList.get(index).getChinese());
115 | txvDel.setText("掌握(删除)");
116 | txvModify.setText("取消");
117 | final Dialog dialog = DialogUtils.show(mContext, view);
118 | txvDel.setOnClickListener(new View.OnClickListener() {
119 | @Override
120 | public void onClick(View v) {
121 | //数据库删除此单词
122 | SQLiteUtils.delete(mContext, mList.get(index).getWord());
123 | //当词库单词量不足1时,返回主页面并提示
124 | if (SQLiteUtils.cursorCount(mContext) == 0) {
125 | NotificationUtils.show(mContext,
126 | "温馨提示",
127 | "词库中没有单词,无法继续此模式,请添加单词!"
128 | , AddWordsActivity.class);
129 | finish();
130 | } else {
131 | //删除了单词以后需要重新获取词库
132 | mList = WordsUtils.get(mContext);
133 | setData();
134 | }
135 | dialog.dismiss();
136 | }
137 | });
138 | txvModify.setOnClickListener(new View.OnClickListener() {
139 | @Override
140 | public void onClick(View v) {
141 | dialog.dismiss();
142 | }
143 | });
144 | break;
145 | }
146 | }
147 |
148 | }
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/DictionaryActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.text.TextUtils;
8 | import android.view.Gravity;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.widget.Button;
12 | import android.widget.TextView;
13 |
14 | import androidx.recyclerview.widget.DividerItemDecoration;
15 | import androidx.recyclerview.widget.LinearLayoutManager;
16 | import androidx.recyclerview.widget.RecyclerView;
17 |
18 | import com.yjx.androidword.Adapter.DictionaryAdapter;
19 | import com.yjx.androidword.Base.BaseActivity;
20 | import com.yjx.androidword.Bean.WordsBean;
21 | import com.yjx.androidword.R;
22 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper;
23 | import com.yjx.androidword.Utils.DialogUtils;
24 | import com.yjx.androidword.Utils.NotificationUtils;
25 | import com.yjx.androidword.Utils.SQLiteUtils;
26 | import com.yjx.androidword.Utils.ToastUtils;
27 |
28 | import java.util.ArrayList;
29 | import java.util.List;
30 |
31 | public class DictionaryActivity extends BaseActivity implements View.OnClickListener {
32 |
33 | private androidx.recyclerview.widget.RecyclerView mRecycleWords;
34 | private List mList;
35 | private SQLiteDatabase mSQLiteDatabase;
36 |
37 | private android.widget.Button mBtnDelete;
38 | private LinearLayoutManager mManager;
39 | private com.yjx.androidword.MyView.MyEditText mEditSearchWord;
40 | private Button mBtnSearch;
41 | private DictionaryAdapter mAdapter;
42 |
43 | @Override
44 | protected void initData() {
45 | mBtnSearch.setOnClickListener(this);
46 | mBtnDelete.setOnClickListener(this);
47 | DictionaryHelper SQWordsHelper = new DictionaryHelper(mContext);
48 | mSQLiteDatabase = SQWordsHelper.getWritableDatabase();
49 |
50 | //获取数据库中的数据,传入List
51 | getData();
52 |
53 | mAdapter = new DictionaryAdapter(mContext, mList);
54 | mRecycleWords.setAdapter(mAdapter);
55 | //布局管理器
56 | mManager = new LinearLayoutManager(mContext);
57 | mManager.setOrientation(RecyclerView.VERTICAL);
58 | mRecycleWords.setLayoutManager(mManager);
59 | //子项分割线
60 | mRecycleWords.addItemDecoration(new DividerItemDecoration(mContext, DividerItemDecoration.VERTICAL));
61 | }
62 |
63 | private void searchData(String str) {
64 | for (int i = 0; i < mList.size(); i++) {
65 | if (TextUtils.equals(str, mList.get(i).getWord())) {
66 | moveToPosition(i);
67 | break;
68 | } else if (i == mList.size() - 1)
69 | ToastUtils.show(mContext, "词库中查无此“词”!", Gravity.CENTER);
70 | }
71 | }
72 |
73 | //根据 position 跳转至RecycleView的某个子项位置
74 | private void moveToPosition(int position) {
75 | //高亮显示
76 | mAdapter.setItem(position);
77 | // mRecycleWords.scrollToPosition(position);
78 | mManager.scrollToPositionWithOffset(position, 0);
79 | mManager.setStackFromEnd(true);
80 | }
81 |
82 | //获取词库数据
83 | private void getData() {
84 | mList = new ArrayList<>();
85 | @SuppressLint("Recycle") Cursor cursor = mSQLiteDatabase.query(DictionaryHelper.TABLE_NAME, null, null, null, null, null, null);
86 | while (cursor.moveToNext()) {
87 | WordsBean wordsBean = new WordsBean();
88 | wordsBean.setWord(cursor.getString(0));
89 | wordsBean.setChinese(cursor.getString(1));
90 | mList.add(wordsBean);
91 | }
92 | }
93 |
94 | @Override
95 | public void onClick(View v) {
96 | switch (v.getId()) {
97 | case R.id.btn_search://按单词查找
98 | if (!TextUtils.isEmpty(mEditSearchWord.getText().toString()))
99 | searchData(mEditSearchWord.getText().toString());
100 | else
101 | ToastUtils.show(mContext, "查找的单词不能为空噢!", Gravity.CENTER);
102 | break;
103 | case R.id.btn_delete://清空词库
104 | showDialog();
105 | break;
106 | }
107 | }
108 |
109 | //清空单词确定对话框
110 | @SuppressLint("SetTextI18n")
111 | private void showDialog() {
112 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_finish, null);
113 | final Dialog dialog = DialogUtils.show(mContext, view);
114 | TextView mTxvTitle = view.findViewById(R.id.txv_title);
115 | TextView mTxvText = view.findViewById(R.id.txv_text);
116 | Button mBtnYes = view.findViewById(R.id.btn_yes);
117 | Button mBtnNo = view.findViewById(R.id.btn_no);
118 | mTxvTitle.setText("确定删除");
119 | mTxvText.setText("确定删除词库中所有单词吗?");
120 | mBtnYes.setOnClickListener(new View.OnClickListener() {
121 | @Override
122 | public void onClick(View v) {
123 | NotificationUtils.show(mContext,
124 | "温馨提示",
125 | "整整删除了:" + SQLiteUtils.calern(mContext) + "个单词!词库中没有单词了哦!"
126 | , AddWordsActivity.class);
127 | dialog.dismiss();
128 | finish();
129 | }
130 | });
131 | mBtnNo.setOnClickListener(new View.OnClickListener() {
132 | @Override
133 | public void onClick(View v) {
134 | dialog.dismiss();
135 | }
136 | });
137 | }
138 |
139 | @Override
140 | protected int initLayout() {
141 | return R.layout.layout_dictionary;
142 | }
143 |
144 | @Override
145 | protected void initView() {
146 | mRecycleWords = findViewById(R.id.recycle_words);
147 | mBtnDelete = findViewById(R.id.btn_delete);
148 | mEditSearchWord = findViewById(R.id.edit_search_word);
149 | mBtnSearch = findViewById(R.id.btn_search);
150 | }
151 |
152 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 小词典
3 |
4 |
5 | 选择模式
6 | 选择模式(中-英)
7 | 选择模式(英-中)
8 | 填空模式
9 | 填空模式(英-中)
10 | 填空模式(中-英)
11 | 添加单词
12 | 词库
13 | 中英互译
14 | 在线翻译
15 | 多语言翻译
16 | 软件使用说明
17 |
18 |
19 | 清空词库
20 | 单词
21 | 翻译
22 | 翻译结果
23 | 删除
24 | 修改
25 | 取消
26 | 查找
27 | 完全掌握这个单词了
28 | 下一个
29 | 确定退出
30 | 确定退出软件?
31 | 确定
32 | 取消
33 | 中文/英文
34 | 请输入需要翻译的文本
35 | 个人中心
36 | 背单词
37 |
38 |
39 | 大学四级\n5197词
40 | 大学六级\n2581词
41 | 中考词汇\n2729词
42 | 高考词汇\n2327词
43 |
44 |
45 | 本软件由\n Android_小黑 \n独立开发,仅供学习交流!小黑微信:yu1563782588
46 |
47 | 注意:由于模式特性,你的词库内单词数超过五个才能进入。\n\n
48 | 进入选择模式后,页面将会随机给出一个单词(或中文),四个选项中有一个选项为正确选项,其余三个为词库中随机获取的非正确选项。\n\n
49 | 选择任意选项后,除正确答案外,其余选项都将提示出对应的翻译;并且选择正确时所选选项将变为绿色;选择错误时所选选项将变为红色,并且正确答案将会用绿色标出。\n
50 | 选择完成后,选项右下方会出现一个“下一个”按钮,点击按钮即可刷新当前单词。\n\n
51 | 点击屏幕下方“完全掌握这个单词了”,可以对本单词进行“掌握(删除)”,词库中将删除此单词。
52 |
53 |
54 | 进入填空模式后,页面将随机给出一个单词(或中文),只有在输出框中输入正确答案,并点击输入框右下方的“确定”按钮,才会进行答案的判断。\n\n
55 | 当填写答案正确时:填写的内容将变为绿色;\n\n
56 | 当填写答案错误时:填写的内容将变为绿色,并会提示出正确答案;\n\n
57 | 答案判断完可以点击输入框右下方的“下一个”,刷新当前单词。\n\n
58 | 点击输入框下侧“完全掌握这个单词了”,可以对本单词进行“掌握(删除)”,词库中将删除此单词。
59 |
60 |
61 | 词库列表显示词库内所有单词\n
62 | 搜索:在顶部搜索框中输入想要搜索的单词,点击“查找”按钮,即可找到所查找单词的位置\n\n
63 | 清空:点击右上角“清空词库”按钮即可清空词库所有单词(不可恢复,谨慎处理!)\n\n
64 | 长按任意单词行弹出对话框,通过对话框可所选单词进行删除或更改
65 |
66 |
67 | 注意:中英互译功能为网络功能(需要数据连接)\n\n
68 | 在输入框内输入需要翻译的中文(或英文),点击“翻译”按钮即可得到对应的翻译\n\n
69 | 网络连接较慢时,请耐心等候翻译结果,无需多次点击“翻译”按钮
70 |
71 |
72 | 修改每日目标
73 | ]]>
74 | 原文的语言类型:
75 | 译文的语言类型:
76 | Tip:点击翻译结果框可复制翻译结果至手机剪切板!
77 | 保存修改
78 | 昵称最长为13个字符
79 | 签名最长为40个字符
80 | 今日目标
81 | 今日已完成
82 |
83 |
84 |
85 | - 自动检测
86 | - 中文
87 | - 英文
88 | - 粤语
89 | - 文言文
90 | - 日语
91 | - 韩语
92 | - 法语
93 | - 西班牙语
94 | - 泰语
95 | - 阿拉伯语
96 | - 俄语
97 | - 葡萄牙语
98 | - 德语
99 | - 意大利语
100 | - 希腊语
101 | - 荷兰语
102 | - 波兰语
103 | - 保加利亚语
104 | - 爱沙尼亚语
105 | - 丹麦语
106 | - 芬兰语
107 | - 捷克语
108 | - 罗马尼亚语
109 | - 斯洛文尼亚语
110 | - 瑞典语
111 | - 匈牙利语
112 | - 繁体中文
113 | - 越南语
114 |
115 |
116 |
117 | - 中文
118 | - 英文
119 | - 粤语
120 | - 文言文
121 | - 日语
122 | - 韩语
123 | - 法语
124 | - 西班牙语
125 | - 泰语
126 | - 阿拉伯语
127 | - 俄语
128 | - 葡萄牙语
129 | - 德语
130 | - 意大利语
131 | - 希腊语
132 | - 荷兰语
133 | - 波兰语
134 | - 保加利亚语
135 | - 爱沙尼亚语
136 | - 丹麦语
137 | - 芬兰语
138 | - 捷克语
139 | - 罗马尼亚语
140 | - 斯洛文尼亚语
141 | - 瑞典语
142 | - 匈牙利语
143 | - 繁体中文
144 | - 越南语
145 |
146 |
147 |
148 |
149 | - 词性
150 | - n.
151 | - prep.
152 | - adj.
153 | - adv.
154 | - num.
155 | - v.
156 | - vt.
157 | - vi.
158 | - pron.
159 | - conj.
160 | - int.
161 | - art.
162 |
163 |
164 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Utils/BaiDuUtils.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Utils;
2 |
3 | import android.util.Log;
4 |
5 | import com.alibaba.fastjson.JSON;
6 | import com.alibaba.fastjson.JSONArray;
7 | import com.alibaba.fastjson.JSONObject;
8 |
9 | import java.io.IOException;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.Random;
13 |
14 | import okhttp3.FormBody;
15 | import okhttp3.OkHttpClient;
16 | import okhttp3.Request;
17 | import okhttp3.RequestBody;
18 | import okhttp3.Response;
19 |
20 | /**
21 | * @Time : 2020/5/16 22:44
22 | * @Author : Android_小黑
23 | * @File : BaiDuUtils.java
24 | * @Software : Android Studio
25 | */
26 | public class BaiDuUtils {
27 | // 请求地址
28 | private static final String URL = "https://fanyi-api.baidu.com/api/trans/vip/translate";
29 | // 应用id
30 | private static final String APP_ID = "";
31 | // 密钥
32 | private static final String KEY = "";
33 | // 随机数对象
34 | private static Random sRandom = new Random();
35 |
36 | /**
37 | * 中英互译(自动检测)
38 | *
39 | * @param q 待翻译文本
40 | */
41 | public static String translate(String q) {
42 | // 源语言
43 | String from = "";
44 | // 译文语言
45 | String to = "";
46 | // 字符长度和字符的字节长度相等,则说明没有中文
47 | if (q.length() == q.getBytes().length) {
48 | from = "en";
49 | to = "zh";
50 | } else {
51 | from = "zh";
52 | to = "en";
53 | }
54 | // 翻译结果
55 | String result = "";
56 | // 随机数
57 | String salt = String.valueOf(sRandom.nextInt(100));
58 | // 合成签名
59 | String strSign = APP_ID + q + salt + KEY;
60 | // 将sign串转化成MD5
61 | String sign = MD5Utils.MD5(strSign);
62 | // 实例化OkHttpClient对象
63 | OkHttpClient client = new OkHttpClient();
64 | RequestBody requestBody = new FormBody.Builder()
65 | .add("q", q)
66 | .add("from", from)
67 | .add("to", to)
68 | .add("appid", APP_ID)
69 | .add("salt", salt)
70 | .add("sign", sign)
71 | .build();
72 | Request request = new Request.Builder()
73 | .url(URL)
74 | .post(requestBody)
75 | .build();
76 | Response response = null;
77 | try {
78 | response = client.newCall(request).execute();
79 | JSONObject jsonObject = JSON.parseObject(response.body().string());
80 | JSONArray array = jsonObject.getJSONArray("trans_result");
81 | for (int i = 0; i < array.size(); i++) {
82 | JSONObject object = (JSONObject) array.get(i);
83 | result = object.getString("dst");
84 | return result;
85 | }
86 | } catch (IOException e) {
87 | Log.d("BaiDuUtils", "translate: 失败!");
88 | return "请求错误";
89 | }
90 | return result;
91 | }
92 |
93 | /**
94 | * 多语言翻译
95 | *
96 | * @param q 待翻译文本
97 | * @param from 源语言类型
98 | * @param to 目标语言类型
99 | */
100 | public static String translate(String q, String from, String to) {
101 | // 从Spinner获取过来的是中文,所以需要转化成代码
102 | from = getLanguage(from);
103 | to = getLanguage(to);
104 | // 翻译结果
105 | String result = "";
106 | // 随机数
107 | String salt = String.valueOf(sRandom.nextInt(100));
108 | // 合成签名
109 | String strSign = APP_ID + q + salt + KEY;
110 | // 将sign串转化成MD5
111 | String sign = MD5Utils.MD5(strSign);
112 | // 实例化OkHttpClient对象
113 | OkHttpClient client = new OkHttpClient();
114 | RequestBody requestBody = new FormBody.Builder()
115 | .add("q", q)
116 | .add("from", from)
117 | .add("to", to)
118 | .add("appid", APP_ID)
119 | .add("salt", salt)
120 | .add("sign", sign)
121 | .build();
122 | Request request = new Request.Builder()
123 | .url(URL)
124 | .post(requestBody)
125 | .build();
126 | Response response = null;
127 | try {
128 | response = client.newCall(request).execute();
129 | JSONObject jsonObject = JSON.parseObject(response.body().string());
130 | JSONArray array = jsonObject.getJSONArray("trans_result");
131 | for (int i = 0; i < array.size(); i++) {
132 | JSONObject object = (JSONObject) array.get(i);
133 | result = object.getString("dst");
134 | return result;
135 | }
136 | } catch (IOException e) {
137 | Log.d("BaiDuUtils", "translate: 失败!");
138 | return "请求错误";
139 | }
140 | return result;
141 | }
142 |
143 |
144 | // 通过传入中文,返回对应的语言代码
145 | private static String getLanguage(String key) {
146 | Map map = new HashMap<>();
147 | map.put("自动检测", "auto");
148 | map.put("中文", "zh");
149 | map.put("英文", "en");
150 | map.put("粤语", "yue");
151 | map.put("文言文", "wyw");
152 | map.put("日语", "jp");
153 | map.put("韩语", "kor");
154 | map.put("法语", "fra");
155 | map.put("西班牙语", "spa");
156 | map.put("泰语", "th");
157 | map.put("阿拉伯语", "ara");
158 | map.put("俄语", "ru");
159 | map.put("葡萄牙语", "pt");
160 | map.put("德语", "de");
161 | map.put("意大利语", "it");
162 | map.put("希腊语", "el");
163 | map.put("荷兰语", "nl");
164 | map.put("波兰语", "pl");
165 | map.put("保加利亚语", "bul");
166 | map.put("爱沙尼亚语", "est");
167 | map.put("丹麦语", "dan");
168 | map.put("芬兰语", "fin");
169 | map.put("捷克语", "cs");
170 | map.put("罗马尼亚语", "rom");
171 | map.put("斯洛文尼亚语", "slo");
172 | map.put("瑞典语", "swe");
173 | map.put("匈牙利语", "hu");
174 | map.put("繁体中文", "cht");
175 | map.put("越南语", "vie");
176 | return map.get(key);
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/frag_rewords.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
29 |
30 |
33 |
34 |
39 |
40 |
45 |
46 |
47 |
48 |
51 |
52 |
59 |
60 |
67 |
68 |
69 |
70 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
90 |
91 |
99 |
100 |
106 |
107 |
114 |
115 |
116 |
117 |
118 |
119 |
125 |
126 |
132 |
133 |
140 |
141 |
142 |
143 |
149 |
150 |
156 |
157 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Adapter/DictionaryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Adapter;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.content.ContentValues;
6 | import android.content.Context;
7 | import android.text.TextUtils;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.LinearLayout;
12 | import android.widget.TextView;
13 |
14 | import androidx.annotation.NonNull;
15 | import androidx.recyclerview.widget.RecyclerView;
16 |
17 | import com.yjx.androidword.Bean.WordsBean;
18 | import com.yjx.androidword.MyView.MyEditText;
19 | import com.yjx.androidword.R;
20 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper;
21 | import com.yjx.androidword.Utils.DialogUtils;
22 | import com.yjx.androidword.Utils.SQLiteUtils;
23 | import com.yjx.androidword.Utils.ToastUtils;
24 |
25 | import java.util.List;
26 |
27 | public class DictionaryAdapter extends RecyclerView.Adapter {
28 |
29 | private Context mContext;
30 | private List mList;
31 |
32 | // 对话框View
33 | private TextView mTxvDel;
34 | private TextView mTxvEnglish;
35 | private TextView mTxvChinese;
36 | private TextView mTxvModify;
37 | private MyEditText mEditEnglish;
38 | private MyEditText mEditChinese;
39 | private TextView mTxvCancel;
40 |
41 | public DictionaryAdapter(Context context, List wordsBeanList) {
42 | mContext = context;
43 | mList = wordsBeanList;
44 | }
45 |
46 | @NonNull
47 | @Override
48 | public Viewholder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
49 | View mView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_dictionary, parent, false);
50 | return new Viewholder(mView);
51 | }
52 |
53 | //在Activity中调用方法,实现搜索并高亮显示
54 | private int posit = -1;
55 | public void setItem(int position) {
56 | this.posit = position;
57 | notifyItemChanged(position);
58 | }
59 |
60 | @Override
61 | public void onBindViewHolder(@NonNull final Viewholder holder, final int position) {
62 | holder.mTxvEnglish.setText(mList.get(position).getWord());
63 | holder.mTxvChinese.setText(mList.get(position).getChinese());
64 |
65 | if (posit == position) {
66 | holder.mItemView.setBackgroundResource(R.color.btn_blue);
67 | } else {
68 | holder.mItemView.setBackground(null);
69 | }
70 |
71 | //子项长按事件 单词管理 删除 & 修改
72 | holder.mItemView.setOnLongClickListener(new View.OnLongClickListener() {
73 | @Override
74 | public boolean onLongClick(View v) {
75 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_dictionary_menu, null);
76 | final Dialog dialog = DialogUtils.show(mContext, view);
77 | mTxvDel = view.findViewById(R.id.txv_del);
78 | mTxvEnglish = view.findViewById(R.id.edit_english);
79 | mTxvChinese = view.findViewById(R.id.edit_from);
80 | mTxvModify = view.findViewById(R.id.txv_modify);
81 | mTxvEnglish.setText(mList.get(position).getWord());
82 | mTxvChinese.setText(mList.get(position).getChinese());
83 | mTxvDel.setOnClickListener(new View.OnClickListener() {
84 | @Override
85 | public void onClick(View v) {
86 | dialog.dismiss();
87 | removeData(position, mList.get(position).getWord());
88 | }
89 | });
90 | mTxvModify.setOnClickListener(new View.OnClickListener() {
91 | @Override
92 | public void onClick(View v) {
93 | dialog.dismiss();
94 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_modify, null);
95 | final Dialog dialog = DialogUtils.show(mContext, view);
96 | mEditEnglish = view.findViewById(R.id.edit_english);
97 | mEditChinese = view.findViewById(R.id.edit_from);
98 | mTxvModify = view.findViewById(R.id.txv_modify);
99 | mTxvCancel = view.findViewById(R.id.txv_cancel);
100 | mEditEnglish.setText(mList.get(position).getWord());
101 | mEditChinese.setText(mList.get(position).getChinese());
102 | mTxvCancel.setOnClickListener(new View.OnClickListener() {
103 | @Override
104 | public void onClick(View v) {
105 | dialog.dismiss();
106 | }
107 | });
108 | mTxvModify.setOnClickListener(new View.OnClickListener() {
109 | @Override
110 | public void onClick(View v) {
111 | if (!TextUtils.isEmpty(mEditEnglish.getText().toString()) && !TextUtils.isEmpty(mEditChinese.getText().toString())) {
112 | modifyData(mList.get(position).getWord(), mEditEnglish.getText().toString(), mEditChinese.getText().toString());
113 | ToastUtils.show(mContext, "修改成功!");
114 | dialog.dismiss();
115 | mList.get(position).setWord(mEditEnglish.getText().toString());
116 | mList.get(position).setChinese(mEditChinese.getText().toString());
117 | notifyItemChanged(position);
118 | } else {
119 | ToastUtils.show(mContext, "修改后的单词或翻译不能为空噢!");
120 | }
121 | }
122 | });
123 | }
124 | });
125 | return true;
126 | }
127 | });
128 |
129 | }
130 |
131 | //删除单词
132 | private void removeData(int position, String str_del) {
133 | //当前List删除
134 | mList.remove(position);
135 | //RecycleView移除
136 | notifyItemRemoved(position);
137 | //调用局部刷新.防止position错乱
138 | notifyItemRangeChanged(position, mList.size() - position);
139 | //数据库同步删除
140 | SQLiteUtils.delete(mContext, str_del);
141 | }
142 |
143 | //修改单词
144 | private void modifyData(String oldEnglish, String newEnglish, String newChinese) {
145 | ContentValues cv = new ContentValues();
146 | cv.put(DictionaryHelper.ENGLISH, newEnglish);
147 | cv.put(DictionaryHelper.CHINESE, newChinese);
148 | SQLiteUtils.upData(cv, oldEnglish);
149 | }
150 |
151 | @Override
152 | public int getItemCount() {
153 | return mList.size();
154 | }
155 |
156 | class Viewholder extends RecyclerView.ViewHolder {
157 | private LinearLayout mItemView;
158 | private TextView mTxvEnglish;
159 | private TextView mTxvChinese;
160 |
161 | Viewholder(@NonNull View itemView) {
162 | super(itemView);
163 | mItemView = itemView.findViewById(R.id.item_view);
164 | mTxvEnglish = itemView.findViewById(R.id.edit_english);
165 | mTxvChinese = itemView.findViewById(R.id.edit_from);
166 | }
167 | }
168 |
169 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/yjx/androidword/Activity/ChooseC2EActivity.java:
--------------------------------------------------------------------------------
1 | package com.yjx.androidword.Activity;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Dialog;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.TextView;
9 |
10 | import com.yjx.androidword.Base.BaseActivity;
11 | import com.yjx.androidword.Bean.WordsBean;
12 | import com.yjx.androidword.R;
13 | import com.yjx.androidword.Utils.DialogUtils;
14 | import com.yjx.androidword.Utils.NotificationUtils;
15 | import com.yjx.androidword.Utils.OverWordsNumUtils;
16 | import com.yjx.androidword.Utils.RandomUtils;
17 | import com.yjx.androidword.Utils.SQLiteUtils;
18 | import com.yjx.androidword.Utils.WordsUtils;
19 |
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import java.util.Random;
23 |
24 | public class ChooseC2EActivity extends BaseActivity implements View.OnClickListener {
25 |
26 | private TextView mTxvWord;
27 | private Button mBtnA;
28 | private Button mBtnB;
29 | private Button mBtnC;
30 | private Button mBtnD;
31 | private TextView mTxvGrasp;
32 | private Button mBtnNext;
33 | //词库
34 | private List mListWords = new ArrayList<>();
35 | //当前考核的 单词和翻译
36 | private String mString_English = "";
37 | private String mString_Chinese = "";
38 | //利用随机数把答案放入选项
39 | private Random mRandom = new Random();
40 | //背诵标记
41 | private int index = 0;
42 | private int index2, index3, index4;
43 |
44 | @Override
45 | protected void initData() {
46 | mBtnA.setOnClickListener(this);
47 | mBtnB.setOnClickListener(this);
48 | mBtnC.setOnClickListener(this);
49 | mBtnD.setOnClickListener(this);
50 | mBtnNext.setOnClickListener(this);
51 | mTxvGrasp.setOnClickListener(this);
52 | //获取打乱顺序的词库
53 | mListWords = WordsUtils.get(mContext);
54 | //首次进入设置一个单词
55 | setData();
56 | }
57 |
58 | @Override
59 | public void onClick(View v) {
60 | switch (v.getId()) {
61 | case R.id.btn_a://A选项
62 | getJudg(mBtnA, mBtnA.getText().toString());
63 | break;
64 | case R.id.btn_b://B选项
65 | getJudg(mBtnB, mBtnB.getText().toString());
66 | break;
67 | case R.id.btn_c://C选项
68 | getJudg(mBtnC, mBtnC.getText().toString());
69 | break;
70 | case R.id.btn_d://D选项
71 | getJudg(mBtnD, mBtnD.getText().toString());
72 | break;
73 | case R.id.btn_next://下一个
74 | reSetButton();
75 | setData();
76 | break;
77 | case R.id.txv_grasp://掌握了单词
78 | @SuppressLint("InflateParams") View view = LayoutInflater.from(mContext).inflate(R.layout.dialog_dictionary_menu, null);
79 | TextView txvEnglish = view.findViewById(R.id.edit_english);
80 | TextView txvChinese = view.findViewById(R.id.edit_from);
81 | TextView txvDel = view.findViewById(R.id.txv_del);
82 | TextView txvModify = view.findViewById(R.id.txv_modify);
83 | txvEnglish.setText(mString_English);
84 | txvChinese.setText(mString_Chinese);
85 | txvDel.setText("掌握(删除)");
86 | txvModify.setText("取消");
87 | final Dialog dialog = DialogUtils.show(mContext, view);
88 | txvDel.setOnClickListener(new View.OnClickListener() {
89 | @Override
90 | public void onClick(View v) {
91 | SQLiteUtils.delete(mContext, mString_English);
92 | if (SQLiteUtils.cursorCount(mContext) < 5) {
93 | NotificationUtils.show(mContext,
94 | "温馨提示",
95 | "词库中单词数量过低,无法继续此模式,请选择填空模式或添加单词!"
96 | , AddWordsActivity.class);
97 | finish();
98 | } else {
99 | //删除了单词以后,List需要重新获取一下词库数据
100 | mListWords = WordsUtils.get(mContext);
101 | reSetButton();
102 | setData();
103 | }
104 | dialog.dismiss();
105 | }
106 | });
107 | txvModify.setOnClickListener(new View.OnClickListener() {
108 | @Override
109 | public void onClick(View v) {
110 | dialog.dismiss();
111 | }
112 | });
113 | break;
114 | }
115 | }
116 |
117 | //获取需要测试的单词和翻译
118 | private void setData() {
119 | //防止背到最后一个单词导致IndexOutOfBoundsException
120 | if (index == SQLiteUtils.cursorCount(mContext) - 1) {
121 | index = 0;
122 | } else {
123 | index++;
124 | }
125 | //需要测试的组赋值
126 | mString_English = mListWords.get(index).getWord();
127 | mString_Chinese = mListWords.get(index).getChinese();
128 | //单词发送到TextView上
129 | mTxvWord.setText(mString_Chinese);
130 | //获取三个随机非正确答案的下标
131 | List list3Random = RandomUtils.get3Random(mContext, index);
132 | index2 = list3Random.get(0);
133 | index3 = list3Random.get(1);
134 | index4 = list3Random.get(2);
135 | //随机选取一个按钮放中文答案,其他按钮放上获取的随机非正确答案
136 | switch (mRandom.nextInt(4) % (4) + 1) {
137 | case 1:
138 | mBtnA.setText(mString_English);
139 | mBtnB.setText(mListWords.get(index2).getWord());
140 | mBtnC.setText(mListWords.get(index3).getWord());
141 | mBtnD.setText(mListWords.get(index4).getWord());
142 | break;
143 | case 2:
144 | mBtnB.setText(mString_English);
145 | mBtnA.setText(mListWords.get(index2).getWord());
146 | mBtnC.setText(mListWords.get(index3).getWord());
147 | mBtnD.setText(mListWords.get(index4).getWord());
148 | break;
149 | case 3:
150 | mBtnC.setText(mString_English);
151 | mBtnA.setText(mListWords.get(index2).getWord());
152 | mBtnB.setText(mListWords.get(index3).getWord());
153 | mBtnD.setText(mListWords.get(index4).getWord());
154 | break;
155 | case 4:
156 | mBtnD.setText(mString_English);
157 | mBtnA.setText(mListWords.get(index2).getWord());
158 | mBtnB.setText(mListWords.get(index3).getWord());
159 | mBtnC.setText(mListWords.get(index4).getWord());
160 | break;
161 | }
162 | }
163 |
164 | //选择判断
165 | @SuppressLint("SetTextI18n")
166 | private void getJudg(Button btn, String str_btn) {
167 |
168 | // 每次选完就可以加一个数量
169 | OverWordsNumUtils.add(mContext);
170 |
171 | if (str_btn.equals(mString_English)) {
172 |
173 | //选择正确
174 | btn.setBackgroundResource(R.drawable.btn_green);
175 |
176 | if (btn == mBtnA) {
177 | mBtnB.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
178 | mBtnC.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
179 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
180 | } else if (btn == mBtnB) {
181 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
182 | mBtnC.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
183 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
184 | } else if (btn == mBtnC) {
185 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
186 | mBtnB.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
187 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
188 | } else if (btn == mBtnD) {
189 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
190 | mBtnB.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
191 | mBtnC.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
192 | }
193 |
194 | } else {
195 |
196 | //选择错误
197 | btn.setBackgroundResource(R.drawable.btn_red);
198 |
199 | if (btn != mBtnA && mBtnA.getText().toString().equals(mString_English)) {
200 | mBtnA.setBackgroundResource(R.drawable.btn_green2);
201 | mBtnB.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
202 | mBtnC.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
203 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
204 | } else if (btn != mBtnB && mBtnB.getText().toString().equals(mString_English)) {
205 | mBtnB.setBackgroundResource(R.drawable.btn_green2);
206 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
207 | mBtnC.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
208 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
209 | } else if (btn != mBtnC && mBtnC.getText().toString().equals(mString_English)) {
210 | mBtnC.setBackgroundResource(R.drawable.btn_green2);
211 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
212 | mBtnB.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
213 | mBtnD.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
214 | } else if (btn != mBtnD && mBtnD.getText().toString().equals(mString_English)) {
215 | mBtnD.setBackgroundResource(R.drawable.btn_green2);
216 | mBtnA.setText(mListWords.get(index2).getWord() + " : " + mListWords.get(index2).getChinese());
217 | mBtnB.setText(mListWords.get(index3).getWord() + " : " + mListWords.get(index3).getChinese());
218 | mBtnC.setText(mListWords.get(index4).getWord() + " : " + mListWords.get(index4).getChinese());
219 | }
220 |
221 | }
222 | //选择完以后设置按钮不可点击
223 | mBtnA.setEnabled(false);
224 | mBtnB.setEnabled(false);
225 | mBtnC.setEnabled(false);
226 | mBtnD.setEnabled(false);
227 | //选择完以后把右下角 下一个 按钮显示出来
228 | mBtnNext.setVisibility(View.VISIBLE);
229 | }
230 |
231 | //重置按钮
232 | private void reSetButton() {
233 | //隐藏“下一个”按钮
234 | mBtnNext.setVisibility(View.GONE);
235 | //重置背景
236 | mBtnA.setBackgroundResource(R.drawable.btn_first_bg);
237 | mBtnB.setBackgroundResource(R.drawable.btn_first_bg);
238 | mBtnC.setBackgroundResource(R.drawable.btn_first_bg);
239 | mBtnD.setBackgroundResource(R.drawable.btn_first_bg);
240 | //重置状态
241 | mBtnA.setEnabled(true);
242 | mBtnB.setEnabled(true);
243 | mBtnC.setEnabled(true);
244 | mBtnD.setEnabled(true);
245 | }
246 |
247 | @Override
248 | protected int initLayout() {
249 | return R.layout.layout_choose;
250 | }
251 |
252 | @Override
253 | protected void initView() {
254 | mTxvWord = findViewById(R.id.txv_word);
255 | mBtnA = findViewById(R.id.btn_a);
256 | mBtnB = findViewById(R.id.btn_b);
257 | mBtnC = findViewById(R.id.btn_c);
258 | mBtnD = findViewById(R.id.btn_d);
259 | mTxvGrasp = findViewById(R.id.txv_grasp);
260 | mBtnNext = findViewById(R.id.btn_next);
261 | }
262 |
263 | }
--------------------------------------------------------------------------------