├── app ├── .gitignore ├── libs │ ├── volley.jar │ └── gson-2.8.0.jar ├── src │ ├── main │ │ ├── assets │ │ │ ├── UniLv4.db │ │ │ ├── UniLv6.db │ │ │ ├── HighSchool.db │ │ │ └── MiddleSchool.db │ │ ├── res │ │ │ ├── mipmap-hdpi │ │ │ │ ├── img_add.png │ │ │ │ ├── img_about.png │ │ │ │ ├── img_book.png │ │ │ │ ├── img_help.png │ │ │ │ ├── img_icon.png │ │ │ │ ├── img_modify.png │ │ │ │ ├── img_person.png │ │ │ │ ├── img_suggest.png │ │ │ │ ├── img_book_small.png │ │ │ │ ├── img_translate.png │ │ │ │ └── img_translate_enzh.png │ │ │ ├── drawable │ │ │ │ ├── img_error.9.png │ │ │ │ ├── img_yellowback.9.png │ │ │ │ ├── btn_red.xml │ │ │ │ ├── btn_green.xml │ │ │ │ ├── btn_green2.xml │ │ │ │ ├── txv_stroke.xml │ │ │ │ ├── edit_stroke.xml │ │ │ │ ├── bg_stroke.xml │ │ │ │ ├── btn_first_bg.xml │ │ │ │ ├── btn_finish_yes.xml │ │ │ │ ├── btn_finish_no.xml │ │ │ │ └── progress_style.xml │ │ │ ├── anim │ │ │ │ ├── base_enter.xml │ │ │ │ └── base_exit.xml │ │ │ ├── color │ │ │ │ └── navi_view_bg.xml │ │ │ ├── values │ │ │ │ ├── styles.xml │ │ │ │ ├── colors.xml │ │ │ │ └── strings.xml │ │ │ ├── layout │ │ │ │ ├── layout_tx_bug.xml │ │ │ │ ├── item_dictionary.xml │ │ │ │ ├── dialog_about.xml │ │ │ │ ├── layout_home.xml │ │ │ │ ├── dialog_aims.xml │ │ │ │ ├── frag_translate.xml │ │ │ │ ├── item_person_menu.xml │ │ │ │ ├── layout_translate_enzh.xml │ │ │ │ ├── layout_person.xml │ │ │ │ ├── dialog_dictionary_menu.xml │ │ │ │ ├── frag_person.xml │ │ │ │ ├── layout_dictionary.xml │ │ │ │ ├── dialog_modify.xml │ │ │ │ ├── layout_fill.xml │ │ │ │ ├── dialog_finish.xml │ │ │ │ ├── layout_choose.xml │ │ │ │ ├── layout_translate_more.xml │ │ │ │ ├── layout_addwords.xml │ │ │ │ ├── dialog_description.xml │ │ │ │ └── frag_rewords.xml │ │ │ └── menu │ │ │ │ └── menu_home.xml │ │ ├── java │ │ │ └── com │ │ │ │ └── yjx │ │ │ │ └── androidword │ │ │ │ ├── Utils │ │ │ │ ├── JumpUtils.java │ │ │ │ ├── NetWorkUtils.java │ │ │ │ ├── CopyTextUtils.java │ │ │ │ ├── RandomUtils.java │ │ │ │ ├── MD5Utils.java │ │ │ │ ├── WordsUtils.java │ │ │ │ ├── ToastUtils.java │ │ │ │ ├── Assets2SQLiteUtils.java │ │ │ │ ├── SystemUtils.java │ │ │ │ ├── DialogUtils.java │ │ │ │ ├── AddBookUtils.java │ │ │ │ ├── SPUtils.java │ │ │ │ ├── OverWordsNumUtils.java │ │ │ │ ├── SQLiteUtils.java │ │ │ │ ├── DescriptionUtils.java │ │ │ │ ├── NotificationUtils.java │ │ │ │ ├── MD5.java │ │ │ │ └── BaiDuUtils.java │ │ │ │ ├── Home │ │ │ │ ├── Bean │ │ │ │ │ └── MenuBean.java │ │ │ │ ├── Adpater │ │ │ │ │ ├── HomeAdapter.java │ │ │ │ │ └── PersonMenuAdapter.java │ │ │ │ ├── Fragment │ │ │ │ │ ├── FragTranslate.java │ │ │ │ │ ├── FragPerson.java │ │ │ │ │ └── FragReWords.java │ │ │ │ └── HomeActivity.java │ │ │ │ ├── Base │ │ │ │ ├── BaseFragment.java │ │ │ │ └── BaseActivity.java │ │ │ │ ├── Bean │ │ │ │ └── WordsBean.java │ │ │ │ ├── SQLiteHelper │ │ │ │ ├── DictionaryHelper.java │ │ │ │ └── OverWordsHelper.java │ │ │ │ ├── MyView │ │ │ │ ├── MyEditText.java │ │ │ │ ├── MyBookButton.java │ │ │ │ ├── MyFirstButton.java │ │ │ │ └── MyTranslateButton.java │ │ │ │ ├── Activity │ │ │ │ ├── TxBugActivity.java │ │ │ │ ├── PersonActivity.java │ │ │ │ ├── TranslationEnZhActivity.java │ │ │ │ ├── TranslationMoreActivity.java │ │ │ │ ├── AddWordsActivity.java │ │ │ │ ├── FillC2EActivity.java │ │ │ │ ├── FillE2CActivity.java │ │ │ │ ├── DictionaryActivity.java │ │ │ │ └── ChooseC2EActivity.java │ │ │ │ └── Adapter │ │ │ │ └── DictionaryAdapter.java │ │ └── AndroidManifest.xml │ ├── test │ │ └── java │ │ │ └── com │ │ │ └── yjx │ │ │ └── androidword │ │ │ └── ExampleUnitTest.java │ └── androidTest │ │ └── java │ │ └── com │ │ └── yjx │ │ └── androidword │ │ └── ExampleInstrumentedTest.java ├── proguard-rules.pro └── build.gradle ├── settings.gradle ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .idea ├── encodings.xml ├── vcs.xml ├── render.experimental.xml ├── misc.xml ├── inspectionProfiles │ └── Project_Default.xml ├── runConfigurations.xml └── gradle.xml ├── .gitignore ├── gradle.properties ├── README.md ├── gradlew.bat └── gradlew /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /app/libs/volley.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/libs/volley.jar -------------------------------------------------------------------------------- /app/libs/gson-2.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/libs/gson-2.8.0.jar -------------------------------------------------------------------------------- /app/src/main/assets/UniLv4.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/assets/UniLv4.db -------------------------------------------------------------------------------- /app/src/main/assets/UniLv6.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/assets/UniLv6.db -------------------------------------------------------------------------------- /app/src/main/assets/HighSchool.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/assets/HighSchool.db -------------------------------------------------------------------------------- /app/src/main/assets/MiddleSchool.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/assets/MiddleSchool.db -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_add.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_error.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/drawable/img_error.9.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_about.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_about.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_book.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_book.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_help.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_icon.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_modify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_modify.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_person.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_person.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_suggest.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_suggest.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/img_yellowback.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/drawable/img_yellowback.9.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_book_small.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_book_small.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_translate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_translate.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/img_translate_enzh.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YJX666666/MyDictionary/HEAD/app/src/main/res/mipmap-hdpi/img_translate_enzh.png -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/render.experimental.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_red.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_green.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_green2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | -------------------------------------------------------------------------------- /app/src/main/res/anim/base_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/anim/base_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Apr 19 16:19:49 CST 2020 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/txv_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/color/navi_view_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/edit_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/JumpUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | 6 | public class JumpUtils { 7 | 8 | public static void To(Context context, Class cla) { 9 | Intent sIntent = new Intent(context, cla); 10 | context.startActivity(sIntent); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_tx_bug.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/Project_Default.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_stroke.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/test/java/com/yjx/androidword/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_first_bg.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/menu/menu_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 13 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Home/Bean/MenuBean.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Home.Bean; 2 | 3 | /** 4 | * @Time : 2020/5/19 11:35 5 | * @Author : Android_小黑 6 | * @File : MenuBean.java 7 | * @Software : Android Studio 8 | */ 9 | public class MenuBean { 10 | private int icon; 11 | private String text; 12 | 13 | public int getIcon() { 14 | return icon; 15 | } 16 | 17 | public void setIcon(int icon) { 18 | this.icon = icon; 19 | } 20 | 21 | public String getText() { 22 | return text; 23 | } 24 | 25 | public void setText(String text) { 26 | this.text = text; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Base; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.annotation.NonNull; 6 | import androidx.fragment.app.Fragment; 7 | 8 | /** 9 | * @Time : 2020/5/17 18:02 10 | * @Author : Android_小黑 11 | * @File : BaseFragment.java 12 | * @Software : Android Studio 13 | */ 14 | // Fragment 基类 15 | public abstract class BaseFragment extends Fragment { 16 | 17 | public Context mContext; 18 | 19 | @Override 20 | public void onAttach(@NonNull Context context) { 21 | super.onAttach(context); 22 | this.mContext = context; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Bean/WordsBean.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Bean; 2 | 3 | public class WordsBean { 4 | String word; 5 | String chinese; 6 | String sound; 7 | 8 | public String getSound() { 9 | return sound; 10 | } 11 | 12 | public void setSound(String sound) { 13 | this.sound = sound; 14 | } 15 | 16 | public String getWord() { 17 | return word; 18 | } 19 | 20 | public void setWord(String word) { 21 | this.word = word; 22 | } 23 | 24 | public String getChinese() { 25 | return chinese; 26 | } 27 | 28 | public void setChinese(String chinese) { 29 | this.chinese = chinese; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_finish_yes.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 11 | 14 | 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/NetWorkUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | /** 8 | * @Time : 2020/5/17 13:32 9 | * @Author : Android_小黑 10 | * @File : NetWorkUtils.java 11 | * @Software : Android Studio 12 | */ 13 | //网络连接判断工具类 14 | public class NetWorkUtils { 15 | 16 | //返回一个boolean值,true代表有网络连接,false代表无网络连接 17 | public static boolean check(Context context) { 18 | ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 19 | NetworkInfo info = cm.getActiveNetworkInfo(); 20 | if (info != null) 21 | return info.isConnected(); 22 | return false; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/CopyTextUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.ClipData; 4 | import android.content.ClipboardManager; 5 | import android.content.Context; 6 | import android.widget.TextView; 7 | 8 | /** 9 | * @Time : 2020/5/18 17:01 10 | * @Author : Android_小黑 11 | * @File : CopyTextUtils.java 12 | * @Software : Android Studio 13 | */ 14 | // 复制内容到剪切板工具类 15 | public class CopyTextUtils { 16 | 17 | // 复制内容至剪切板 18 | public static void copy(Context context, TextView txv) { 19 | //剪切板管理器 20 | ClipboardManager cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); 21 | 22 | cm.setPrimaryClip(ClipData.newPlainText(null, String.valueOf(txv.getText()))); 23 | 24 | ToastUtils.show(context, "复制成功!"); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_dictionary.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 15 | 16 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_finish_no.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/yjx/androidword/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword; 2 | 3 | import android.content.Context; 4 | 5 | import androidx.test.InstrumentationRegistry; 6 | import androidx.test.runner.AndroidJUnit4; 7 | 8 | import org.junit.Test; 9 | import org.junit.runner.RunWith; 10 | 11 | import static org.junit.Assert.*; 12 | 13 | /** 14 | * Instrumented test, which will execute on an Android device. 15 | * 16 | * @see Testing documentation 17 | */ 18 | @RunWith(AndroidJUnit4.class) 19 | public class ExampleInstrumentedTest { 20 | @Test 21 | public void useAppContext() { 22 | // Context of the app under test. 23 | Context appContext = InstrumentationRegistry.getTargetContext(); 24 | 25 | assertEquals("com.yjx.androidword", appContext.getPackageName()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/progress_style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/SQLiteHelper/DictionaryHelper.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.SQLiteHelper; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | public class DictionaryHelper extends SQLiteOpenHelper { 8 | 9 | public static final String ENGLISH = "word"; 10 | public static final String CHINESE = "chinese"; 11 | public static final String DB_NAME = "words.db"; 12 | public static final String TABLE_NAME = "words"; 13 | 14 | public DictionaryHelper(Context context) { 15 | super(context, DB_NAME, null, 1); 16 | } 17 | 18 | @Override 19 | public void onCreate(SQLiteDatabase db) { 20 | db.execSQL("create table " + TABLE_NAME + "(" + ENGLISH + " text," + CHINESE + " text)"); 21 | } 22 | 23 | @Override 24 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_about.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 13 | 14 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/RandomUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.util.ArrayList; 6 | import java.util.HashSet; 7 | import java.util.List; 8 | import java.util.Random; 9 | import java.util.Set; 10 | 11 | public class RandomUtils { 12 | 13 | //获取三个随机非正确答案的下标 14 | public static List get3Random(Context context, int index) { 15 | Random random = new Random(); 16 | List list = new ArrayList<>(); 17 | Set set = new HashSet<>(); 18 | 19 | int max = SQLiteUtils.cursorCount(context); 20 | while (set.size() < 3) { 21 | // [0,max] 22 | int i = random.nextInt(max); 23 | //不能和当前的单词相同 24 | if (i != index) 25 | set.add(i); 26 | } 27 | Object[] numbers = set.toArray(); 28 | for (Object object : numbers) { 29 | list.add((Integer) object); 30 | } 31 | return list; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Home/Adpater/HomeAdapter.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Home.Adpater; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.fragment.app.Fragment; 5 | import androidx.fragment.app.FragmentManager; 6 | import androidx.fragment.app.FragmentPagerAdapter; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @Time : 2020/5/17 18:14 12 | * @Author : Android_小黑 13 | * @File : HomeAdapter.java 14 | * @Software : Android Studio 15 | */ 16 | public class HomeAdapter extends FragmentPagerAdapter { 17 | 18 | private List mList; 19 | 20 | public HomeAdapter(@NonNull FragmentManager fm, List list) { 21 | super(fm); 22 | mList = list; 23 | notifyDataSetChanged(); 24 | } 25 | 26 | public HomeAdapter(@NonNull FragmentManager fm, int behavior) { 27 | super(fm, behavior); 28 | } 29 | 30 | @NonNull 31 | @Override 32 | public Fragment getItem(int position) { 33 | return mList.get(position); 34 | } 35 | 36 | @Override 37 | public int getCount() { 38 | return mList.size(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/MyView/MyEditText.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.MyView; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.util.AttributeSet; 6 | import android.view.Gravity; 7 | import android.widget.EditText; 8 | 9 | import com.yjx.androidword.R; 10 | 11 | @SuppressLint("AppCompatCustomView") 12 | public class MyEditText extends EditText { 13 | 14 | private void set() { 15 | //单行输出 16 | setSingleLine(true); 17 | //字体大小 18 | setTextSize(16); 19 | //设置内部元素对齐方式 20 | setGravity(Gravity.CENTER); 21 | //设置背景 22 | setBackgroundResource(R.drawable.edit_stroke); 23 | } 24 | 25 | 26 | public MyEditText(Context context) { 27 | super(context); 28 | set(); 29 | } 30 | 31 | public MyEditText(Context context, AttributeSet attrs) { 32 | super(context, attrs); 33 | set(); 34 | } 35 | 36 | public MyEditText(Context context, AttributeSet attrs, int defStyleAttr) { 37 | super(context, attrs, defStyleAttr); 38 | set(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/layout/dialog_aims.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 21 | 22 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/SQLiteHelper/OverWordsHelper.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.SQLiteHelper; 2 | 3 | import android.content.Context; 4 | import android.database.sqlite.SQLiteDatabase; 5 | import android.database.sqlite.SQLiteOpenHelper; 6 | 7 | /** 8 | * @Time : 2020/5/18 18:40 9 | * @Author : Android_小黑 10 | * @File : OverWordsHelper.java 11 | * @Software : Android Studio 12 | */ 13 | // 每日背诵单词数 数据库 14 | public class OverWordsHelper extends SQLiteOpenHelper { 15 | 16 | // 库名 17 | private static final String DB = "OverWordNum.db"; 18 | // 表名 19 | public static final String TBNAME = "tbname"; 20 | // 日期 21 | public static final String DATE = "date"; 22 | // 数量 23 | public static final String NUMBER = "number"; 24 | 25 | 26 | public OverWordsHelper(Context context) { 27 | super(context, DB, null, 1); 28 | } 29 | 30 | @Override 31 | public void onCreate(SQLiteDatabase db) { 32 | db.execSQL("create table " + TBNAME + "(" + DATE + " text," + NUMBER + " text)"); 33 | } 34 | 35 | @Override 36 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/res/layout/frag_translate.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/MD5Utils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import java.security.MessageDigest; 4 | 5 | /** 6 | * MD5编码相关的类 7 | * 8 | * @author wangjingtao 9 | */ 10 | public class MD5Utils { 11 | 12 | /** 13 | * 字符串MD5加密 14 | * 15 | * @param info 参数为需要加密的String 16 | * @return 返回加密后的String 17 | */ 18 | public static String MD5(String info) { 19 | try { 20 | MessageDigest md5 = MessageDigest.getInstance("MD5"); 21 | md5.update(info.getBytes("UTF-8"));//设置编码格式 22 | byte[] encryption = md5.digest(); 23 | StringBuilder builder = new StringBuilder(); 24 | for (int i = 0; i < encryption.length; i++) { 25 | if (Integer.toHexString(0xff & encryption[i]).length() == 1) { 26 | builder.append("0").append(Integer.toHexString(0xff & encryption[i])); 27 | } else { 28 | builder.append(Integer.toHexString(0xff & encryption[i])); 29 | } 30 | } 31 | return builder.toString(); 32 | } catch (Exception e) { 33 | return "MD5加密错误"; 34 | } 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/MyView/MyBookButton.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.MyView; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.Typeface; 6 | import android.util.AttributeSet; 7 | import android.widget.Button; 8 | 9 | import com.yjx.androidword.R; 10 | 11 | @SuppressLint("AppCompatCustomView") 12 | public class MyBookButton extends Button { 13 | 14 | private void set() { 15 | //背景 书的图标 16 | super.setBackgroundResource(R.mipmap.img_book); 17 | //字体阴影 18 | super.setShadowLayer(6, 3, 3, R.color.colorShadowBlack); 19 | //字体样式 20 | super.setTypeface(Typeface.DEFAULT, Typeface.BOLD); 21 | //字体大小 22 | super.setTextSize(14); 23 | //字体颜色 24 | super.setTextColor(getResources().getColor(R.color.colorWhite)); 25 | } 26 | 27 | public MyBookButton(Context context) { 28 | super(context); 29 | set(); 30 | } 31 | 32 | public MyBookButton(Context context, AttributeSet attrs) { 33 | super(context, attrs); 34 | set(); 35 | } 36 | 37 | public MyBookButton(Context context, AttributeSet attrs, int defStyleAttr) { 38 | super(context, attrs, defStyleAttr); 39 | set(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 小词典 2 | 3 | 2020年4月19日开始开发,旨在锻炼自身开发能力、以及版本管理工具的使用。 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 | ##### 关于: 40 | 41 | - 点击主页关于弹出对话框 42 | 43 | ### 2020/5/6更新: 44 | 45 | #### 新增功能: 46 | 47 | - 添加单词:添加四本单词书,可一键添加至词库(初中、高中词汇、大学四级、六级词汇) 48 | - 词库:新增查找功能,可根据单词查找其在词库的位置,并跳转至所查单词位置 49 | - 词库:新增一键清空词库功能 50 | - 通知&提示:大部分通知和提示改为对话框提示、Notification通知栏通知(兼容Android 8.0+) 51 | 52 | ##### 修复BUG: 53 | 54 | - 词库:修复因增删等操作导致的 position 错乱的BUG 55 | - 选择模式、填空模式:修复重复出现单词的BUG 56 | 57 | ### 2020/5/16更新 58 | 59 | ##### 新增 / 修改: 60 | 61 | - ToastUtils新增:自定义位置、自定义View 62 | - 多个默认Toast修改为:自定义位置Toast(居中) 63 | 64 | ##### 修复BUG: 65 | 66 | - 修复“确定对话框”出现宽度过长的BUG -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #82ACD6 4 | #99CCFF 5 | #C62272 6 | 7 | #424141 8 | 9 | #FFFFFF 10 | #80E3AF03 11 | #8C5023 12 | #000000 13 | #00FF09 14 | #FF1100 15 | #5F5251 16 | #E6E6DF 17 | 18 | #99CCFF 19 | 20 | 21 | #F6F6F7 22 | #FDFDFE 23 | 24 | 25 | #E9F2FF 26 | #C62272 27 | #DDAE49 28 | #4A97C6 29 | 30 | 31 | 32 | #737375 33 | #67AFFF 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/MyView/MyFirstButton.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.MyView; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.Typeface; 6 | import android.util.AttributeSet; 7 | import android.widget.Button; 8 | 9 | import com.yjx.androidword.R; 10 | 11 | @SuppressLint("AppCompatCustomView") 12 | public class MyFirstButton extends Button { 13 | 14 | private void set() { 15 | //字体阴影 16 | super.setShadowLayer(6, 3, 3, R.color.colorShadowBlack); 17 | //字体样式 18 | super.setTypeface(Typeface.DEFAULT, Typeface.BOLD); 19 | //背景 20 | super.setBackgroundResource(R.drawable.btn_first_bg); 21 | //字体颜色 22 | super.setTextColor(getResources().getColor(R.color.colorWhite)); 23 | //取消字母全部大写 24 | super.setAllCaps(false); 25 | //字体大小 26 | super.setTextSize(12); 27 | } 28 | 29 | public MyFirstButton(Context context) { 30 | super(context); 31 | set(); 32 | } 33 | 34 | public MyFirstButton(Context context, AttributeSet attrs) { 35 | super(context, attrs); 36 | set(); 37 | } 38 | 39 | public MyFirstButton(Context context, AttributeSet attrs, int defStyleAttr) { 40 | super(context, attrs, defStyleAttr); 41 | set(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Activity/TxBugActivity.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Activity; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.webkit.WebView; 5 | import android.webkit.WebViewClient; 6 | 7 | import com.yjx.androidword.Base.BaseActivity; 8 | import com.yjx.androidword.R; 9 | 10 | /** 11 | * @Time : 2020/5/18 16:20 12 | * @Author : Android_小黑 13 | * @File : TxBugActivity.java 14 | * @Software : Android Studio 15 | */ 16 | public class TxBugActivity extends BaseActivity { 17 | 18 | private android.webkit.WebView mWebview; 19 | 20 | @SuppressLint("SetJavaScriptEnabled") 21 | @Override 22 | protected void initData() { 23 | String url = "https://support.qq.com/product/154802"; 24 | mWebview.getSettings().setJavaScriptEnabled(true);//js支持 25 | mWebview.getSettings().setDomStorageEnabled(true); 26 | mWebview.loadUrl(url); 27 | mWebview.setWebViewClient(new WebViewClient() { 28 | @Override 29 | public boolean shouldOverrideUrlLoading(WebView view, String url) { 30 | mWebview.loadUrl(url); 31 | return true; 32 | } 33 | }); 34 | 35 | } 36 | 37 | @Override 38 | protected int initLayout() { 39 | return R.layout.layout_tx_bug; 40 | } 41 | 42 | @Override 43 | protected void initView() { 44 | 45 | mWebview = findViewById(R.id.webview); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /app/src/main/res/layout/item_person_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 21 | 22 | 29 | 30 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/WordsUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | 8 | import com.yjx.androidword.Bean.WordsBean; 9 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper; 10 | 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | import java.util.List; 14 | 15 | public class WordsUtils { 16 | 17 | /** 18 | * 用List获取到词库所有单词 19 | * 然后用 shuffle()方法打乱顺序(达到随机效果) 20 | * @return 打乱顺序的词库 21 | */ 22 | public static List get(Context context) { 23 | List list = new ArrayList<>(); 24 | DictionaryHelper helper = new DictionaryHelper(context); 25 | SQLiteDatabase database = helper.getWritableDatabase(); 26 | WordsBean bean; 27 | @SuppressLint("Recycle") 28 | Cursor cursor = database.query(DictionaryHelper.TABLE_NAME, null, null, null, null, null, null); 29 | 30 | //获取总词库 31 | while (cursor.moveToNext()) { 32 | bean = new WordsBean(); 33 | String english = cursor.getString(0); 34 | String chinese = cursor.getString(1); 35 | bean.setWord(english); 36 | bean.setChinese(chinese); 37 | list.add(bean); 38 | } 39 | 40 | //打乱List顺序 41 | Collections.shuffle(list); 42 | 43 | return list; 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/ToastUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | import android.widget.Toast; 6 | 7 | public class ToastUtils { 8 | 9 | private static Toast sToast; 10 | 11 | //即时消息 12 | public static void show(Context context, String msg) { 13 | //判断是否第一次弹窗 14 | if (sToast == null) 15 | sToast = Toast.makeText(context, msg, Toast.LENGTH_SHORT); 16 | else 17 | sToast.setText(msg); 18 | sToast.show(); 19 | } 20 | 21 | //重要的即时消息 自定义位置 22 | public static void show(Context context, String msg, int gravity) { 23 | //判断是否第一次弹窗 24 | if (sToast == null) 25 | sToast = Toast.makeText(context, msg, Toast.LENGTH_LONG); 26 | else 27 | sToast.setText(msg); 28 | sToast.setGravity(gravity, 0, 0); 29 | sToast.show(); 30 | } 31 | 32 | //长时间消息 33 | public static void showLong(Context context, String msg) { 34 | //判断是否第一次弹窗 35 | sToast.setDuration(Toast.LENGTH_LONG); 36 | if (sToast == null) 37 | sToast = Toast.makeText(context, msg, Toast.LENGTH_LONG); 38 | else 39 | sToast.setText(msg); 40 | sToast.show(); 41 | } 42 | 43 | public static void show(Context context, View view) { 44 | if (sToast == null) 45 | sToast = Toast.makeText(context, "", Toast.LENGTH_SHORT); 46 | sToast.setView(view); 47 | sToast.show(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 29 5 | buildToolsVersion "29.0.3" 6 | defaultConfig { 7 | applicationId "com.yjx.androidword" 8 | minSdkVersion 21 9 | targetSdkVersion 29 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | implementation fileTree(dir: 'libs', include: ['*.jar']) 24 | implementation 'androidx.appcompat:appcompat:1.1.0' 25 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 26 | testImplementation 'junit:junit:4.12' 27 | androidTestImplementation 'androidx.test:runner:1.2.0' 28 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' 29 | 30 | //noinspection GradleCompatible 31 | implementation 'com.android.support:design:28.0.0' 32 | 33 | //OkHttp(网络请求框架) 34 | implementation 'com.squareup.okhttp3:okhttp:3.12.1' 35 | 36 | //Retrofit(基于OKHTTP封装的网络请求库) 37 | //noinspection GradleDependency 38 | implementation 'com.squareup.retrofit2:retrofit:2.0.2' 39 | 40 | //fastjson 41 | implementation 'com.alibaba:fastjson:1.1.71.android' 42 | 43 | //圆形图片控件 CircleImageView 44 | implementation 'de.hdodenhof:circleimageview:3.0.0' 45 | 46 | //GIF 47 | implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' 48 | } -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/MyView/MyTranslateButton.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.MyView; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.graphics.Typeface; 6 | import android.util.AttributeSet; 7 | import android.view.Gravity; 8 | import android.widget.Button; 9 | 10 | import com.yjx.androidword.R; 11 | 12 | /** 13 | * @Time : 2020/5/18 13:24 14 | * @Author : Android_小黑 15 | * @File : MyTranslateButton.java 16 | * @Software : Android Studio 17 | */ 18 | @SuppressLint("AppCompatCustomView") 19 | public class MyTranslateButton extends Button { 20 | 21 | private void set() { 22 | //背景 23 | super.setBackgroundResource(R.drawable.btn_first_bg); 24 | //设置内边距 25 | super.setPadding(20, 0, 20, 0); 26 | //字体大小 27 | super.setTextSize(30); 28 | //字体格式 29 | super.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD)); 30 | //字体阴影 31 | super.setShadowLayer(6, 3, 3, R.color.colorShadowBlack); 32 | //内容对齐方式 33 | super.setGravity(Gravity.CENTER); 34 | } 35 | 36 | 37 | public MyTranslateButton(Context context) { 38 | super(context); 39 | set(); 40 | } 41 | 42 | public MyTranslateButton(Context context, AttributeSet attrs) { 43 | super(context, attrs); 44 | set(); 45 | } 46 | 47 | public MyTranslateButton(Context context, AttributeSet attrs, int defStyleAttr) { 48 | super(context, attrs, defStyleAttr); 49 | set(); 50 | } 51 | 52 | public MyTranslateButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { 53 | super(context, attrs, defStyleAttr, defStyleRes); 54 | set(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/Assets2SQLiteUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.content.Context; 4 | 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | 10 | /** 11 | * 读取Assets目录下数据库的工具类 12 | * */ 13 | public class Assets2SQLiteUtils { 14 | 15 | public static String getPath(Context context,String bookName) { 16 | //packagename包名 17 | final String packageBame = "com.yjx.androidword"; 18 | // assets 中的 xxx.db 文件的名字 19 | final String db_name = bookName; 20 | final String filePath = "data/data/" + packageBame + "/databases/" + db_name; 21 | final String pathStr = "data/data/" + packageBame + "/databases"; 22 | 23 | System.out.println("filePath:" + filePath); 24 | File dbFile = new File(filePath); 25 | if (dbFile.exists()) { 26 | return filePath; 27 | } else { 28 | File path = new File(pathStr); 29 | path.mkdir(); 30 | try { 31 | InputStream is = context.getClass().getClassLoader().getResourceAsStream("assets/" + db_name); 32 | 33 | FileOutputStream fos = new FileOutputStream(dbFile); 34 | byte[] buffer = new byte[10240]; 35 | int count = 0; 36 | while ((count = is.read(buffer)) > 0) { 37 | fos.write(buffer, 0, count); 38 | } 39 | fos.flush(); 40 | fos.close(); 41 | is.close(); 42 | } catch (IOException e) { 43 | e.printStackTrace(); 44 | return null; 45 | } 46 | return filePath; 47 | } 48 | } 49 | } 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/SystemUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.telephony.TelephonyManager; 7 | 8 | import java.util.Locale; 9 | 10 | /** 11 | * @Time : 2020/5/17 23:02 12 | * @Author : Android_小黑 13 | * @File : SystemUtils.java 14 | * @Software : Android Studio 15 | */ 16 | //获取系统信息工具类 17 | public class SystemUtils { 18 | /** 19 | * 获取当前手机系统语言。 20 | * 21 | * @return 返回当前系统语言。例如:当前设置的是“中文-中国”,则返回“zh-CN” 22 | */ 23 | public static String getSystemLanguage() { 24 | return Locale.getDefault().getLanguage(); 25 | } 26 | 27 | /** 28 | * 获取当前系统上的语言列表(Locale列表) 29 | * 30 | * @return 语言列表 31 | */ 32 | public static Locale[] getSystemLanguageList() { 33 | return Locale.getAvailableLocales(); 34 | } 35 | 36 | /** 37 | * 获取当前手机系统版本号 38 | * 39 | * @return 系统版本号 40 | */ 41 | public static String getSystemVersion() { 42 | return android.os.Build.VERSION.RELEASE; 43 | } 44 | 45 | /** 46 | * 获取手机型号 47 | * 48 | * @return 手机型号 49 | */ 50 | public static String getSystemModel() { 51 | return android.os.Build.MODEL; 52 | } 53 | 54 | /** 55 | * 获取手机厂商 56 | * 57 | * @return 手机厂商 58 | */ 59 | public static String getDeviceBrand() { 60 | return android.os.Build.BRAND; 61 | } 62 | 63 | /** 64 | * 获取手机IMEI(需要“android.permission.READ_PHONE_STATE”权限) 65 | * 66 | * @return 手机IMEI 67 | */ 68 | @SuppressLint({"MissingPermission", "HardwareIds"}) 69 | public static String getIMEI(Context ctx) { 70 | TelephonyManager tm = (TelephonyManager) ctx.getSystemService(Activity.TELEPHONY_SERVICE); 71 | if (tm != null) { 72 | return tm.getDeviceId(); 73 | } 74 | return null; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_translate_enzh.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 24 | 25 | 36 | 37 | 43 | 44 | 50 | 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/DialogUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.app.AlertDialog; 4 | import android.content.Context; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.provider.Settings; 8 | import android.view.View; 9 | 10 | import com.yjx.androidword.Activity.AddWordsActivity; 11 | import com.yjx.androidword.R; 12 | 13 | public class DialogUtils { 14 | 15 | //自定义View对话框 16 | public static AlertDialog show(Context context, View view) { 17 | AlertDialog dialog = new AlertDialog.Builder(context).create(); 18 | dialog.setView(view); 19 | dialog.setCancelable(true); 20 | //设置外部背景,dialog外面的那部分黑色 21 | dialog.getWindow().getDecorView().setBackground(null); 22 | dialog.show(); 23 | return dialog; 24 | } 25 | 26 | //简单提示对话框(去添加单词) 27 | public static void show(final Context context, String msg, final String btn_str) { 28 | new AlertDialog.Builder(context) 29 | .setMessage(msg) 30 | .setTitle("温馨提示") 31 | .setIcon(R.mipmap.img_icon) 32 | .setCancelable(false) 33 | .setPositiveButton("关闭", new DialogInterface.OnClickListener() { 34 | @Override 35 | public void onClick(DialogInterface dialog, int which) { 36 | } 37 | }) 38 | .setNegativeButton(btn_str, new DialogInterface.OnClickListener() { 39 | @Override 40 | public void onClick(DialogInterface dialog, int which) { 41 | if (btn_str.equals("去添加单词")) 42 | JumpUtils.To(context, AddWordsActivity.class); 43 | else if (btn_str.equals("去连接网络")) 44 | context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); 45 | } 46 | }) 47 | .show(); 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /app/src/main/java/com/yjx/androidword/Utils/AddBookUtils.java: -------------------------------------------------------------------------------- 1 | package com.yjx.androidword.Utils; 2 | 3 | import android.annotation.SuppressLint; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | 8 | import com.yjx.androidword.Bean.WordsBean; 9 | import com.yjx.androidword.SQLiteHelper.DictionaryHelper; 10 | 11 | import java.util.ArrayList; 12 | import java.util.List; 13 | 14 | /** 15 | * 将某书的单词全部加入到数据库中的工具类 16 | */ 17 | public class AddBookUtils { 18 | 19 | private static List 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 |