├── .gitignore ├── .idea ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── libs │ ├── AssetsDataBase.jar │ ├── Msc.jar │ ├── slf4j-api-1.7.26.jar │ └── slf4j-simple-1.7.26.jar ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── mingrisoft │ │ └── sockword │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── wisdom.db │ │ └── word.db │ ├── java │ │ └── com │ │ │ └── mingrisoft │ │ │ ├── adapter │ │ │ ├── CardFragmentPagerAdapter.java │ │ │ ├── HistoryWordAdapter.java │ │ │ └── ReviewFragmentPagerAdapter.java │ │ │ ├── fragment │ │ │ ├── CardFragment.java │ │ │ ├── HistoryWordFragment.java │ │ │ ├── ReviewFragment.java │ │ │ ├── SetFragment.java │ │ │ ├── StudyFragment.java │ │ │ └── WordDetailFrament.java │ │ │ ├── greendao │ │ │ └── entity │ │ │ │ └── greendao │ │ │ │ ├── CET4Entity.java │ │ │ │ └── WisdomEntity.java │ │ │ ├── sockword │ │ │ ├── HomeActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── ReviewAcitivty.java │ │ │ ├── TranslateActivity.java │ │ │ └── WrongAcitivty.java │ │ │ ├── transform │ │ │ └── CardTransformer.java │ │ │ └── util │ │ │ ├── AndroidStateDetection.java │ │ │ ├── BaseApplication.java │ │ │ ├── ScreenListener.java │ │ │ ├── SwitchButton.java │ │ │ └── TranslationService.java │ ├── jniLibs │ │ ├── armeabi-v7a │ │ │ └── libmsc.so │ │ └── armeabi │ │ │ └── libmsc.so │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── btn_kuang.xml │ │ ├── btn_review.xml │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ ├── activity_main.xml │ │ ├── history_word_fragment.xml │ │ ├── home_layout.xml │ │ ├── list_item_layout.xml │ │ ├── review_fragment.xml │ │ ├── review_layout.xml │ │ ├── set_fragment_layout.xml │ │ ├── study_fragment.xml │ │ ├── switch_button.xml │ │ ├── translation_layout.xml │ │ ├── word_detail_fragment.xml │ │ ├── wrong_fragment.xml │ │ └── wrong_layout.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── background.png │ │ ├── down.png │ │ ├── ease_close_icon.png │ │ ├── ease_open_icon.png │ │ ├── fanhui.png │ │ ├── translate.png │ │ ├── up.png │ │ ├── vioce.png │ │ ├── wordpress.png │ │ └── x.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── mingrisoft │ └── sockword │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── greendao ├── .gitignore ├── build.gradle └── src │ └── main │ └── java │ └── com │ └── mingrisoft │ └── greendao │ └── MyClass.java └── settings.gradle /.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 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SorkWord 2 | 3 | ## **背景** 4 | 5 | 近日,统计机构Strategy Analytics旗下的AppOptix发布了有关安卓手机用户每天的解锁次数和亮屏时间数据,数据显示:安卓手机用户平均每天要解锁65.8次,累计看屏幕的时间达到了4小时。其中有一类应该是无聊就锁屏--解锁--锁屏--解锁反复操作的人群。如果每次解锁都能背两个单词,那么日积月累就能掌握许多单词,能在碎片时间里学到更多知识。 6 | 7 | 项目是一款基于Android手机平台的新颖、实用的背单词软件,利用手机解锁记忆单词。锁屏背单词力争帮大家合理地利用好碎片时间,把原本无用的时间变得有用,把没有意义的事情(解锁)变得有意义。 8 | 9 | ## **主要功能** 10 | 11 | (1)背单词解锁:锁屏界面滑动单词解锁。 12 | 13 | (2)语音朗读:单词真人发音。 14 | 15 | (3)复习单词:内置专业的复习功能,有效巩固单词。 16 | 17 | (4)学习记录:记录每日解锁次数和学习量,鼓励督促学习。 18 | 19 | (5)生词本:卡片堆叠式记录学习不熟练和答错的单词并复习。 20 | 21 | (6)词句翻译:查询陌生词句,了解释义与读音。 22 | 23 | (7)锁屏壁纸选择:可选默认壁纸,也可选取手机相册照片作为锁屏壁纸。 24 | 25 | (8)名人名句:每日一句名人名句。 26 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'org.greenrobot.greendao' 3 | 4 | 5 | android { 6 | sourceSets.main.jniLibs.srcDirs = ['libs'] 7 | compileSdkVersion 27 8 | 9 | sourceSets { 10 | main { 11 | jniLibs.srcDirs = ['src/main/jniLibs'] 12 | } 13 | } 14 | defaultConfig { 15 | 16 | applicationId "com.mingrisoft.sockword" 17 | minSdkVersion 15 18 | targetSdkVersion 27 19 | versionCode 1 20 | versionName "1.0" 21 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 22 | // ndk { 23 | // abiFilters "armeabi-v7a", "x86", "armeabi", "mips" 24 | // } 25 | } 26 | buildTypes { 27 | release { 28 | minifyEnabled false 29 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 30 | lintOptions { 31 | checkReleaseBuilds false 32 | abortOnError false 33 | } 34 | } 35 | } 36 | dexOptions { 37 | preDexLibraries false 38 | } 39 | packagingOptions { 40 | exclude 'META-INF/DEPENDENCIES' 41 | } 42 | splits { 43 | abi { 44 | enable true 45 | reset() 46 | include 'x86', 'armeabi-v7a','x86_64' 47 | universalApk true 48 | } 49 | } 50 | 51 | 52 | useLibrary 'org.apache.http.legacy' 53 | } 54 | 55 | dependencies { 56 | implementation fileTree(dir: 'libs', include: ['*.jar']) 57 | implementation 'com.android.support:appcompat-v7:27.1.1' 58 | implementation 'com.android.support.constraint:constraint-layout:1.1.3' 59 | testImplementation 'junit:junit:4.12' 60 | androidTestImplementation 'com.android.support.test:runner:1.0.2' 61 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' 62 | implementation 'org.greenrobot:greendao:3.2.0' 63 | implementation 'org.greenrobot:greendao-generator:3.2.0' 64 | implementation 'com.google.code.gson:gson:2.7' 65 | implementation group: 'org.apache.httpcomponents', name: 'httpclient-android',version: '4.3.5.1' 66 | implementation 'com.android.support:appcompat-v7:27.1.1' 67 | implementation 'com.android.support:cardview-v7:27.1.1' 68 | } 69 | -------------------------------------------------------------------------------- /app/libs/AssetsDataBase.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/libs/AssetsDataBase.jar -------------------------------------------------------------------------------- /app/libs/Msc.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/libs/Msc.jar -------------------------------------------------------------------------------- /app/libs/slf4j-api-1.7.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/libs/slf4j-api-1.7.26.jar -------------------------------------------------------------------------------- /app/libs/slf4j-simple-1.7.26.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/libs/slf4j-simple-1.7.26.jar -------------------------------------------------------------------------------- /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/androidTest/java/com/mingrisoft/sockword/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.sockword; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.mingrisoft.sockword", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 24 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /app/src/main/assets/wisdom.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/src/main/assets/wisdom.db -------------------------------------------------------------------------------- /app/src/main/assets/word.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/src/main/assets/word.db -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/adapter/CardFragmentPagerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.adapter; 2 | 3 | import android.support.v4.app.Fragment; 4 | import android.support.v4.app.FragmentManager; 5 | import android.support.v4.app.FragmentStatePagerAdapter; 6 | 7 | import com.mingrisoft.fragment.CardFragment; 8 | import com.mingrisoft.greendao.entity.greendao.CET4Entity; 9 | 10 | import java.util.List; 11 | 12 | public class CardFragmentPagerAdapter extends FragmentStatePagerAdapter { 13 | 14 | private List wrongData; 15 | 16 | public CardFragmentPagerAdapter(FragmentManager fm, List list) { 17 | super(fm); 18 | this.wrongData = list; 19 | } 20 | 21 | @Override 22 | public Fragment getItem(int position) { 23 | return CardFragment.newInstance(wrongData.get(position)); 24 | } 25 | 26 | @Override 27 | public int getCount() { 28 | return this.wrongData.size(); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/adapter/HistoryWordAdapter.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.annotation.NonNull; 5 | import android.support.annotation.Nullable; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ArrayAdapter; 10 | import android.widget.BaseAdapter; 11 | import android.widget.TextView; 12 | 13 | import com.mingrisoft.sockword.R; 14 | 15 | public class HistoryWordAdapter extends BaseAdapter { 16 | private String [] mData; 17 | private LayoutInflater mInflater; 18 | 19 | public HistoryWordAdapter(LayoutInflater inflater,String [] data) { 20 | mInflater=inflater; 21 | mData=data; 22 | } 23 | 24 | @Override 25 | public int getCount() { 26 | return mData.length; 27 | } 28 | 29 | @Override 30 | public Object getItem(int i) { 31 | return mData[i]; 32 | } 33 | 34 | @Override 35 | public long getItemId(int i) { 36 | return i; 37 | } 38 | //ListView提升效率 39 | //convertView缓存之前加载过的View 40 | //ViewHolder存取之前加载过的对象 41 | @NonNull 42 | @Override 43 | public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { 44 | //获得ListView中得View 45 | View view; 46 | String data=mData[position]; 47 | String [] middelData=new String[2]; //用于存取data splite后的数据 48 | ViewHolder viewHolder; 49 | if(convertView==null){ 50 | view=mInflater.inflate(R.layout.list_item_layout,null); 51 | viewHolder=new ViewHolder(); 52 | viewHolder.wordText=(TextView) view.findViewById(R.id.history_word); 53 | viewHolder.basicText=(TextView) view.findViewById(R.id.history_basic); 54 | view.setTag(viewHolder); 55 | }else{ 56 | view=convertView; 57 | viewHolder=(ViewHolder)view.getTag(); 58 | } 59 | 60 | middelData=data.split("#"); 61 | if(middelData.length==2 && position reviewData; 16 | 17 | public ReviewFragmentPagerAdapter(FragmentManager fm, List list) { 18 | super(fm); 19 | this.reviewData = list; 20 | } 21 | 22 | @Override 23 | public Fragment getItem(int position) { 24 | return ReviewFragment.newInstance(reviewData.get(position)); 25 | } 26 | 27 | @Override 28 | public int getCount() { 29 | return this.reviewData.size(); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/CardFragment.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.app.Activity; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.Fragment; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.widget.ImageView; 11 | import android.widget.TextView; 12 | 13 | import com.iflytek.cloud.speech.SpeechConstant; 14 | import com.iflytek.cloud.speech.SpeechError; 15 | import com.iflytek.cloud.speech.SpeechListener; 16 | import com.iflytek.cloud.speech.SpeechSynthesizer; 17 | import com.iflytek.cloud.speech.SpeechUser; 18 | import com.iflytek.cloud.speech.SynthesizerListener; 19 | import com.mingrisoft.greendao.entity.greendao.CET4Entity; 20 | import com.mingrisoft.sockword.R; 21 | 22 | import java.io.Serializable; 23 | 24 | public class CardFragment extends Fragment implements View.OnClickListener,SynthesizerListener { 25 | 26 | private View mRootView; 27 | private CET4Entity wrong; 28 | 29 | private TextView chinaText, wordText, englishText; //用来显示单词和音标的 30 | private ImageView playVioce; //播放声音 31 | private SpeechSynthesizer speechSynthesizer; //语音 合成对象 32 | 33 | 34 | public static CardFragment newInstance(CET4Entity info) { 35 | CardFragment fragment = new CardFragment(); 36 | Bundle bundle = new Bundle(); 37 | bundle.putSerializable("info", (Serializable) info); 38 | fragment.setArguments(bundle); 39 | return fragment; 40 | } 41 | 42 | @Nullable 43 | @Override 44 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 45 | mRootView = inflater.inflate(R.layout.wrong_fragment,container,false); 46 | return mRootView; 47 | } 48 | 49 | @Override 50 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 51 | super.onViewCreated(view, savedInstanceState); 52 | 53 | chinaText = mRootView.findViewById(R.id.china_text); //汉语绑定id 54 | englishText = mRootView.findViewById(R.id.english_text); //音标绑定id 55 | wordText = mRootView.findViewById(R.id.word_text); //单词绑定id 56 | playVioce = mRootView.findViewById(R.id.play_vioce); //播放声音按钮绑定id 57 | playVioce.setOnClickListener(this); // 播放声音设置监听事件 58 | wrong = (CET4Entity) getArguments().getSerializable("info"); 59 | setData(); 60 | setParam(); //初始化语音播报 61 | SpeechUser.getUser().login(this.getActivity(),null,null,"appid=5cb7368a",listener); 62 | 63 | } 64 | 65 | 66 | /** 67 | * 设置错题 68 | * */ 69 | private void setData() { 70 | if (wrong != null) { //判断如果数据库不为空 71 | /** 72 | * 分别将list里面的数据取出数据设置单词音标以及汉语 73 | * */ 74 | wordText.setText(wrong.getWord()); 75 | englishText.setText(wrong.getEnglish()); 76 | chinaText.setText(wrong.getChina()); 77 | 78 | } else { 79 | /** 80 | * 如果数据库为空 81 | * 隐藏“我会了”按钮 82 | * */ 83 | wordText.setText("好厉害"); 84 | englishText.setText("[没有]"); 85 | chinaText.setText("不会的单词了"); 86 | } 87 | 88 | } 89 | 90 | /** 91 | * 点击事件 92 | */ 93 | @Override 94 | public void onClick(View v) { 95 | // TODO Auto-generated method stub 96 | switch (v.getId()) { 97 | case R.id.play_vioce: //播放单词声音 98 | String text = wordText.getText().toString(); //获取文本 99 | speechSynthesizer.startSpeaking(text, this); //传给后台 100 | break; 101 | } 102 | } 103 | 104 | //缓冲进度回调通知 105 | @Override 106 | public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) { 107 | // TODO Auto-generated method stub 108 | } 109 | 110 | //结束回调 111 | @Override 112 | public void onCompleted(SpeechError arg0) { 113 | // TODO Auto-generated method stub 114 | 115 | } 116 | 117 | //开始播放 118 | @Override 119 | public void onSpeakBegin() { 120 | // TODO Auto-generated method stub 121 | 122 | } 123 | 124 | //暂停播放 125 | @Override 126 | public void onSpeakPaused() { 127 | // TODO Auto-generated method stub 128 | 129 | } 130 | 131 | //播放进度 132 | @Override 133 | public void onSpeakProgress(int arg0, int arg1, int arg2) { 134 | // TODO Auto-generated method stub 135 | 136 | } 137 | 138 | //继续播放 139 | @Override 140 | public void onSpeakResumed() { 141 | // TODO Auto-generated method stub 142 | 143 | } 144 | 145 | /** 146 | * 通用回调接口 147 | */ 148 | private SpeechListener listener = new SpeechListener() { 149 | 150 | //消息回调 151 | @Override 152 | public void onEvent(int arg0, Bundle arg1) { 153 | // TODO Auto-generated method stub 154 | 155 | } 156 | 157 | //数据回调 158 | @Override 159 | public void onData(byte[] arg0) { 160 | // TODO Auto-generated method stub 161 | 162 | } 163 | 164 | //结束回调(没有错误) 165 | @Override 166 | public void onCompleted(SpeechError arg0) { 167 | // TODO Auto-generated method stub 168 | 169 | } 170 | }; 171 | 172 | /** 173 | * 初始化语音播报 174 | * */ 175 | public void setParam() { 176 | speechSynthesizer = SpeechSynthesizer.createSynthesizer(this.getActivity()); 177 | //设置发音人名( 178 | speechSynthesizer.setParameter(SpeechConstant.VOICE_NAME,"Catherine"); 179 | //语速 180 | speechSynthesizer.setParameter(SpeechConstant.SPEED,"50"); 181 | //声音大小 182 | speechSynthesizer.setParameter(SpeechConstant.VOLUME,"80"); 183 | //音调 184 | speechSynthesizer.setParameter(SpeechConstant.PITCH,"50"); 185 | } 186 | 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/HistoryWordFragment.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.os.Bundle; 7 | import android.support.annotation.Nullable; 8 | import android.util.Log; 9 | import android.view.LayoutInflater; 10 | import android.view.View; 11 | import android.view.ViewGroup; 12 | import android.widget.AdapterView; 13 | import android.widget.ListView; 14 | import android.widget.TextView; 15 | 16 | import com.mingrisoft.adapter.HistoryWordAdapter; 17 | import com.mingrisoft.sockword.R; 18 | import com.mingrisoft.sockword.TranslateActivity; 19 | 20 | import java.util.Iterator; 21 | import java.util.LinkedHashSet; 22 | import java.util.List; 23 | import java.util.Set; 24 | 25 | public class HistoryWordFragment extends Fragment { 26 | //变量定义 27 | public static final String TAG="HistoryWordFragment"; 28 | private List historyWord; //用于保存历史查询过的单词 29 | private String [] data=new String[20]; 30 | private HistoryWordAdapter adapter; 31 | private ListView listView; 32 | private View view; 33 | private SharedPreferences sharedPreferences; //数据库 34 | private Set wordRecord; //历史记录表 35 | private LayoutInflater inflater; 36 | 37 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 38 | 39 | sharedPreferences = getActivity().getSharedPreferences("share", Context.MODE_PRIVATE); 40 | view=inflater.inflate(R.layout.history_word_fragment,null); 41 | inflater=getActivity().getLayoutInflater(); 42 | listView=(ListView) view.findViewById(R.id.history_word_list); 43 | for(int i=0;i adapterView, View view, int position, long l) { 54 | TextView wordText=(TextView) view.findViewById(R.id.history_word); 55 | if(!wordText.getText().toString().equals("")&&position(sharedPreferences.getStringSet("wordrecord",null)); 69 | Iterator iterator = wordRecord.iterator(); 70 | int i = 0; 71 | while (iterator.hasNext()) { 72 | data[i++] = iterator.next(); 73 | } 74 | } 75 | adapter.notifyDataSetChanged(); 76 | } 77 | 78 | @Override 79 | public void onDetach() { 80 | super.onDetach(); 81 | Log.e(TAG,"onDetach"); 82 | } 83 | 84 | @Override 85 | public void onDestroy() { 86 | super.onDestroy(); 87 | Log.e(TAG,"onDestroy"); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/ReviewFragment.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.app.Fragment; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.iflytek.cloud.speech.SpeechConstant; 13 | import com.iflytek.cloud.speech.SpeechError; 14 | import com.iflytek.cloud.speech.SpeechListener; 15 | import com.iflytek.cloud.speech.SpeechSynthesizer; 16 | import com.iflytek.cloud.speech.SpeechUser; 17 | import com.iflytek.cloud.speech.SynthesizerListener; 18 | import com.mingrisoft.greendao.entity.greendao.CET4Entity; 19 | import com.mingrisoft.sockword.R; 20 | 21 | import java.io.Serializable; 22 | 23 | public class ReviewFragment extends Fragment implements View.OnClickListener,SynthesizerListener { 24 | 25 | private View mRootView; 26 | private CET4Entity review; 27 | 28 | private TextView chinaText, wordText, englishText; //用来显示单词和音标的 29 | private ImageView playVioce; //播放声音 30 | private SpeechSynthesizer speechSynthesizer; //语音 合成对象 31 | 32 | 33 | public static ReviewFragment newInstance(CET4Entity info) { 34 | ReviewFragment fragment = new ReviewFragment(); 35 | Bundle bundle = new Bundle(); 36 | bundle.putSerializable("review", (Serializable) info); 37 | fragment.setArguments(bundle); 38 | return fragment; 39 | } 40 | 41 | @Nullable 42 | @Override 43 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 44 | mRootView = inflater.inflate(R.layout.review_fragment,container,false); 45 | return mRootView; 46 | } 47 | 48 | @Override 49 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 50 | super.onViewCreated(view, savedInstanceState); 51 | 52 | chinaText = mRootView.findViewById(R.id.china_text); //汉语绑定id 53 | englishText = mRootView.findViewById(R.id.english_text); //音标绑定id 54 | wordText = mRootView.findViewById(R.id.word_text); //单词绑定id 55 | playVioce = mRootView.findViewById(R.id.play_vioce); //播放声音按钮绑定id 56 | playVioce.setOnClickListener(this); // 播放声音设置监听事件 57 | review = (CET4Entity) getArguments().getSerializable("review"); 58 | setData(); 59 | setParam(); //初始化语音播报 60 | SpeechUser.getUser().login(this.getActivity(),null,null,"appid=5cb7368a",listener); 61 | 62 | } 63 | 64 | 65 | /** 66 | * 设置错题 67 | * */ 68 | private void setData() { 69 | if (review != null) { //判断如果数据库不为空 70 | /** 71 | * 分别将list里面的数据取出数据设置单词音标以及汉语 72 | * */ 73 | wordText.setText(review.getWord()); 74 | englishText.setText(review.getEnglish()); 75 | chinaText.setText(review.getChina()); 76 | 77 | } else { 78 | /** 79 | * 如果数据库为空 80 | * 隐藏“我会了”按钮 81 | * */ 82 | wordText.setText("好厉害"); 83 | englishText.setText("[今天的单词]"); 84 | chinaText.setText("都复习完啦"); 85 | } 86 | 87 | } 88 | 89 | /** 90 | * 点击事件 91 | */ 92 | @Override 93 | public void onClick(View v) { 94 | // TODO Auto-generated method stub 95 | switch (v.getId()) { 96 | case R.id.play_vioce: //播放单词声音 97 | String text = wordText.getText().toString(); //获取文本 98 | speechSynthesizer.startSpeaking(text, this); //传给后台 99 | break; 100 | } 101 | } 102 | 103 | //缓冲进度回调通知 104 | @Override 105 | public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) { 106 | // TODO Auto-generated method stub 107 | } 108 | 109 | //结束回调 110 | @Override 111 | public void onCompleted(SpeechError arg0) { 112 | // TODO Auto-generated method stub 113 | 114 | } 115 | 116 | //开始播放 117 | @Override 118 | public void onSpeakBegin() { 119 | // TODO Auto-generated method stub 120 | 121 | } 122 | 123 | //暂停播放 124 | @Override 125 | public void onSpeakPaused() { 126 | // TODO Auto-generated method stub 127 | 128 | } 129 | 130 | //播放进度 131 | @Override 132 | public void onSpeakProgress(int arg0, int arg1, int arg2) { 133 | // TODO Auto-generated method stub 134 | 135 | } 136 | 137 | //继续播放 138 | @Override 139 | public void onSpeakResumed() { 140 | // TODO Auto-generated method stub 141 | 142 | } 143 | 144 | /** 145 | * 通用回调接口 146 | */ 147 | private SpeechListener listener = new SpeechListener() { 148 | 149 | //消息回调 150 | @Override 151 | public void onEvent(int arg0, Bundle arg1) { 152 | // TODO Auto-generated method stub 153 | 154 | } 155 | 156 | //数据回调 157 | @Override 158 | public void onData(byte[] arg0) { 159 | // TODO Auto-generated method stub 160 | 161 | } 162 | 163 | //结束回调(没有错误) 164 | @Override 165 | public void onCompleted(SpeechError arg0) { 166 | // TODO Auto-generated method stub 167 | 168 | } 169 | }; 170 | 171 | /** 172 | * 初始化语音播报 173 | * */ 174 | public void setParam() { 175 | speechSynthesizer = SpeechSynthesizer.createSynthesizer(this.getActivity()); 176 | //设置发音人名( 177 | speechSynthesizer.setParameter(SpeechConstant.VOICE_NAME,"Catherine"); 178 | //语速 179 | speechSynthesizer.setParameter(SpeechConstant.SPEED,"50"); 180 | //声音大小 181 | speechSynthesizer.setParameter(SpeechConstant.VOLUME,"80"); 182 | //音调 183 | speechSynthesizer.setParameter(SpeechConstant.PITCH,"50"); 184 | } 185 | 186 | 187 | } 188 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/SetFragment.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.Manifest; 4 | import android.annotation.SuppressLint; 5 | import android.annotation.TargetApi; 6 | import android.app.Activity; 7 | import android.app.Fragment; 8 | import android.content.ContentUris; 9 | import android.content.Context; 10 | import android.content.Intent; 11 | import android.content.SharedPreferences; 12 | import android.content.pm.PackageManager; 13 | import android.database.Cursor; 14 | import android.graphics.Bitmap; 15 | import android.graphics.BitmapFactory; 16 | import android.graphics.drawable.Drawable; 17 | import android.net.Uri; 18 | import android.os.Build; 19 | import android.os.Bundle; 20 | import android.provider.DocumentsContract; 21 | import android.provider.MediaStore; 22 | import android.support.annotation.Nullable; 23 | import android.support.v4.app.ActivityCompat; 24 | import android.support.v4.content.ContextCompat; 25 | import android.util.Log; 26 | import android.view.LayoutInflater; 27 | import android.view.View; 28 | import android.view.ViewGroup; 29 | import android.widget.AdapterView; 30 | import android.widget.ArrayAdapter; 31 | import android.widget.ImageView; 32 | import android.widget.Spinner; 33 | import android.widget.SpinnerAdapter; 34 | import android.widget.Toast; 35 | 36 | import com.mingrisoft.sockword.HomeActivity; 37 | import com.mingrisoft.sockword.MainActivity; 38 | import com.mingrisoft.sockword.R; 39 | import com.mingrisoft.util.SwitchButton; 40 | 41 | import static android.app.Activity.RESULT_OK; 42 | 43 | /** 44 | * 设置界面的逻辑 45 | */ 46 | public class SetFragment extends Fragment implements View.OnClickListener { 47 | 48 | public static final String TAG = "SetFragment"; 49 | public static final int CHOOSE_PHOTO = 2; 50 | private ImageView picture; 51 | private Uri imageUri; 52 | 53 | private SharedPreferences sharedPreferences; //定义轻量级数据库 54 | private SwitchButton switchButton; //开关按钮 55 | private Spinner spinnerDifficulty; //定义选择难度的下拉框 56 | private Spinner spinnerALLNum; //定义选择解锁题目的下拉框 57 | private Spinner spinnerNewNum; //定义新题目的下拉框 58 | private Spinner spinnerReviewNum; //定义复习题的下拉框 59 | private Spinner spinnerLockBackground; //锁屏壁纸 60 | private ArrayAdapter adapterDifficulty,adapterAllNum,adapterNewNum,adapterReviewNum,adapterLockBackground; //定义下拉框的适配器 61 | 62 | //选择难度的下拉框内容 63 | String [] difficulty =new String[]{"小学","初中","高中","四级","六级"}; 64 | //选择解锁题目的下拉框 65 | String [] allNum=new String[]{"2","4","6","8"}; 66 | //新题目下拉框的选项内容 67 | String [] newNum=new String []{"10","30","50","100"}; 68 | //复习题的下拉框 69 | String [] revicwNum= new String[] {"5","10","15","20"}; 70 | //锁屏壁纸选择下拉框内容 71 | String [] LockBackground= new String[] {"默认壁纸","从手机相册选择"}; 72 | 73 | SharedPreferences.Editor editor=null; 74 | 75 | 76 | @Nullable 77 | @Override 78 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 79 | View view=inflater.inflate(R.layout.set_fragment_layout,null); 80 | init(view); 81 | return view; 82 | } 83 | 84 | private void init(View view){ 85 | sharedPreferences=getActivity().getSharedPreferences("share", Context.MODE_PRIVATE); //初始化数据库 86 | editor=sharedPreferences.edit(); //初始化编辑器 87 | 88 | switchButton=(SwitchButton) view.findViewById(R.id.switch_btn); 89 | switchButton.setOnClickListener(this); 90 | 91 | spinnerDifficulty=(Spinner) view.findViewById(R.id.spinner_difficulty); 92 | spinnerALLNum=(Spinner) view.findViewById(R.id.spinner_all_number); 93 | spinnerNewNum=(Spinner) view.findViewById(R.id.spinner_new_number); 94 | spinnerReviewNum=(Spinner) view.findViewById(R.id.spinner_revise_number); 95 | spinnerLockBackground=(Spinner) view.findViewById(R.id.spinnerLockBackground); 96 | 97 | picture = (ImageView) view.findViewById(R.id.picture); 98 | // picture.setBackgroundDrawable(Drawable.createFromPath(sharedPreferences.getString("lockback",String.valueOf(R.mipmap.background)))); 99 | picture.setBackgroundDrawable(Drawable.createFromPath(sharedPreferences.getString("lockback","/storage/emulated/0/Tencent/QQfile_recv/background.png"))); 100 | 101 | /** 102 | * 选择难度 103 | */ 104 | //初始化选择难度下拉框的适配器 105 | adapterDifficulty=new ArrayAdapter(getActivity(),android.R.layout.simple_selectable_list_item,difficulty); 106 | //给下拉框设置适配器 107 | spinnerDifficulty.setAdapter(adapterDifficulty); 108 | //定义选择难度下拉框的默认选项 109 | setSpinnerItemSelectedByValue(spinnerDifficulty,sharedPreferences.getString("difficulty","四级")); 110 | //设置选择难度下拉框的监听事件 111 | this.spinnerDifficulty.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 112 | @Override 113 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 114 | //获取选择的内容 115 | String msg=adapterView.getItemAtPosition(i).toString(); 116 | editor.putString("difficulty",msg); 117 | editor.commit(); 118 | } 119 | 120 | @Override 121 | public void onNothingSelected(AdapterView adapterView) { 122 | 123 | } 124 | }); 125 | 126 | /** 127 | * 解锁题个数的选项框,同上面的选择难度的选项框的原理一样 128 | */ 129 | 130 | //初始化解锁题目下拉框的适配器 131 | adapterAllNum=new ArrayAdapter(getActivity(),android.R.layout.simple_selectable_list_item,allNum); 132 | //给下拉框设置适配器 133 | spinnerALLNum.setAdapter(adapterAllNum); 134 | //定义选择难度下拉框的默认选项 135 | setSpinnerItemSelectedByValue(spinnerALLNum,sharedPreferences.getInt("allNum",2)+"道"); 136 | 137 | //设置选择难度下拉框的监听事件 138 | this.spinnerALLNum.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 139 | @Override 140 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 141 | //获取选择的内容 142 | String msg = adapterView.getItemAtPosition(i).toString(); 143 | int ii=Integer.parseInt(msg); 144 | editor.putInt("allNum",ii); 145 | editor.commit(); 146 | } 147 | 148 | @Override 149 | public void onNothingSelected(AdapterView adapterView) { 150 | 151 | } 152 | }); 153 | 154 | /** 155 | * 每日新题个数的选项框,同上面的选择难度的选项框的原理一样 156 | */ 157 | 158 | //初始化每日新题个数下拉框的适配器 159 | adapterNewNum=new ArrayAdapter(getActivity(),android.R.layout.simple_selectable_list_item,newNum); 160 | //给下拉框设置适配器 161 | spinnerNewNum.setAdapter(adapterNewNum); 162 | //定义选择难度下拉框的默认选项 163 | setSpinnerItemSelectedByValue(spinnerNewNum,sharedPreferences.getString("newNum","10")); 164 | //设置选择难度下拉框的监听事件 165 | this.spinnerNewNum.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 166 | @Override 167 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 168 | //获取选择的内容 169 | String msg=adapterView.getItemAtPosition(i).toString(); 170 | editor.putString("newNum",msg); 171 | editor.commit(); 172 | } 173 | 174 | @Override 175 | public void onNothingSelected(AdapterView adapterView) { 176 | 177 | } 178 | }); 179 | /** 180 | *每日复习题个数的选项框,同上面的选择难度的选项框原理一样 181 | */ 182 | 183 | //初始化选择难度下拉框的适配器 184 | adapterReviewNum=new ArrayAdapter(getActivity(),android.R.layout.simple_selectable_list_item,revicwNum); 185 | //给下拉框设置适配器 186 | spinnerReviewNum.setAdapter(adapterReviewNum); 187 | //定义选择难度下拉框的默认选项 188 | setSpinnerItemSelectedByValue(spinnerReviewNum,sharedPreferences.getString("reviewNum","20")); 189 | //设置选择难度下拉框的监听事件 190 | this.spinnerReviewNum.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 191 | @Override 192 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 193 | //获取选择的内容 194 | String msg=adapterView.getItemAtPosition(i).toString(); 195 | editor.putString("reviewNum",msg); 196 | editor.commit(); 197 | } 198 | 199 | @Override 200 | public void onNothingSelected(AdapterView adapterView) { 201 | 202 | } 203 | }); 204 | 205 | /** 206 | * 选择锁屏壁纸 207 | */ 208 | 209 | //初始化选择难度下拉框的适配器 210 | adapterLockBackground=new ArrayAdapter(getActivity(),android.R.layout.simple_selectable_list_item,LockBackground); 211 | //给下拉框设置适配器 212 | spinnerLockBackground.setAdapter(adapterLockBackground); 213 | //定义选择难度下拉框的默认选项 214 | setSpinnerItemSelectedByValue(spinnerLockBackground,sharedPreferences.getString("LockBackground","默认壁纸")); 215 | //设置选择难度下拉框的监听事件 216 | this.spinnerLockBackground.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { 217 | @Override 218 | public void onItemSelected(AdapterView adapterView, View view, int i, long l) { 219 | //获取选择的内容 220 | String msg=adapterView.getItemAtPosition(i).toString(); 221 | editor.putString("LockBackground",msg); 222 | editor.commit(); 223 | if(msg.equals("默认壁纸")){ 224 | 225 | editor.putString("lockback","/storage/emulated/0/Tencent/QQfile_recv/background.png"); 226 | editor.commit(); 227 | 228 | Bitmap bitmap = BitmapFactory.decodeFile("/storage/emulated/0/Tencent/QQfile_recv/background.png"); 229 | picture.setImageBitmap(bitmap); 230 | 231 | }else if(msg.equals("从手机相册选择")){ 232 | //动态申请权限 233 | if (ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { 234 | ActivityCompat.requestPermissions(getActivity(), new String[]{ Manifest.permission. WRITE_EXTERNAL_STORAGE }, 1); 235 | } else { 236 | openAlbum(); 237 | } 238 | } 239 | } 240 | 241 | @Override 242 | public void onNothingSelected(AdapterView adapterView) { 243 | 244 | } 245 | }); 246 | 247 | } 248 | 249 | /** 250 | * 每次进入设置页面时下拉框显示最新选择的数据 251 | * @param spinner 252 | * @param value 253 | */ 254 | public void setSpinnerItemSelectedByValue(Spinner spinner, String value) { 255 | SpinnerAdapter spinnerAdapter=spinner.getAdapter(); 256 | int k=spinnerAdapter.getCount(); 257 | for (int i=0;i 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { 313 | openAlbum(); 314 | } else { 315 | Toast.makeText(getActivity(), "You denied the permission", Toast.LENGTH_SHORT).show(); 316 | } 317 | break; 318 | default: 319 | } 320 | } 321 | 322 | @Override 323 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 324 | switch (requestCode) { 325 | case CHOOSE_PHOTO: 326 | if (resultCode == RESULT_OK) { 327 | // 判断手机系统版本号 328 | if (Build.VERSION.SDK_INT >= 19) { 329 | // 4.4及以上系统使用这个方法处理图片 330 | handleImageOnKitKat(data); 331 | } else { 332 | // 4.4以下系统使用这个方法处理图片 333 | handleImageBeforeKitKat(data); 334 | } 335 | } 336 | break; 337 | default: 338 | break; 339 | } 340 | } 341 | 342 | @TargetApi(19) 343 | private void handleImageOnKitKat(Intent data) { 344 | String imagePath = null; 345 | Uri uri = data.getData(); 346 | Log.d(TAG, "handleImageOnKitKat: uri is " + uri); 347 | if (DocumentsContract.isDocumentUri(getActivity(), uri)) { 348 | // 如果是document类型的Uri,则通过document id处理 349 | String docId = DocumentsContract.getDocumentId(uri); 350 | if("com.android.providers.media.documents".equals(uri.getAuthority())) { 351 | String id = docId.split(":")[1]; // 解析出数字格式的id 352 | String selection = MediaStore.Images.Media._ID + "=" + id; 353 | imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection); 354 | } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { 355 | Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId)); 356 | imagePath = getImagePath(contentUri, null); 357 | } 358 | } else if ("content".equalsIgnoreCase(uri.getScheme())) { 359 | // 如果是content类型的Uri,则使用普通方式处理 360 | imagePath = getImagePath(uri, null); 361 | } else if ("file".equalsIgnoreCase(uri.getScheme())) { 362 | // 如果是file类型的Uri,直接获取图片路径即可 363 | imagePath = uri.getPath(); 364 | } 365 | 366 | editor.putString("lockback",imagePath); 367 | editor.commit(); 368 | Log.d(TAG, "选择图片路径为: "+imagePath); 369 | displayImage(imagePath); // 根据图片路径显示图片 370 | } 371 | 372 | private void handleImageBeforeKitKat(Intent data) { 373 | Uri uri = data.getData(); 374 | String imagePath = getImagePath(uri, null); 375 | displayImage(imagePath); 376 | } 377 | 378 | 379 | 380 | private String getImagePath(Uri uri, String selection) { 381 | String path = null; 382 | // 通过Uri和selection来获取真实的图片路径 383 | Cursor cursor = getActivity().getContentResolver().query(uri, null, selection, null, null); 384 | if (cursor != null) { 385 | if (cursor.moveToFirst()) { 386 | path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA)); 387 | } 388 | cursor.close(); 389 | } 390 | return path; 391 | } 392 | 393 | private void displayImage(String imagePath) { 394 | if (imagePath != null) { 395 | Bitmap bitmap = BitmapFactory.decodeFile(imagePath); 396 | picture.setImageBitmap(bitmap); 397 | } else { 398 | Toast.makeText(getActivity(), "failed to get image", Toast.LENGTH_SHORT).show(); 399 | } 400 | } 401 | 402 | } 403 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/StudyFragment.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.app.Fragment; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.database.sqlite.SQLiteDatabase; 8 | import android.os.Bundle; 9 | import android.support.annotation.Nullable; 10 | import android.view.LayoutInflater; 11 | import android.view.View; 12 | import android.view.ViewGroup; 13 | import android.widget.Button; 14 | import android.widget.ImageView; 15 | import android.widget.TextView; 16 | 17 | import com.example.assetsbasedata.AssetsDatabaseManager; 18 | import com.iflytek.cloud.speech.SpeechConstant; 19 | import com.iflytek.cloud.speech.SpeechError; 20 | import com.iflytek.cloud.speech.SpeechListener; 21 | import com.iflytek.cloud.speech.SpeechSynthesizer; 22 | import com.iflytek.cloud.speech.SpeechUser; 23 | import com.iflytek.cloud.speech.SynthesizerListener; 24 | import com.mingrisoft.greendao.entity.greendao.DaoMaster; 25 | import com.mingrisoft.greendao.entity.greendao.DaoSession; 26 | import com.mingrisoft.greendao.entity.greendao.WisdomEntity; 27 | import com.mingrisoft.greendao.entity.greendao.WisdomEntityDao; 28 | import com.mingrisoft.sockword.HomeActivity; 29 | import com.mingrisoft.sockword.R; 30 | import com.mingrisoft.sockword.ReviewAcitivty; 31 | import com.mingrisoft.sockword.WrongAcitivty; 32 | 33 | import java.util.List; 34 | import java.util.Random; 35 | 36 | public class StudyFragment extends Fragment implements View.OnClickListener,SynthesizerListener { 37 | //名言(英语), 名言(汉语), 学习难度,总共学习, 掌握单词,答错题数 38 | private TextView wisdomEnglish, wisdomChina, 39 | difficultyTv, alreadyStudyText, alreadyMasteredText, wrongText; 40 | private ImageView playVioce; //播放声音 41 | private Button review_btn; //开始复习按钮 42 | private SpeechSynthesizer speechSynthesizer; //语音 合成对象 43 | private SharedPreferences sharedPreferences; //定义轻量级数据库 44 | private DaoMaster mDaoMaster; //数据库管理者 45 | private DaoSession mDaoSession; //与数据库进行会话 46 | private WisdomEntityDao questionDao; 47 | 48 | @Nullable 49 | @Override 50 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 51 | 52 | //绑定布局文件 53 | View view = inflater.inflate(R.layout.study_fragment, null); 54 | //初始化数据库 55 | sharedPreferences = getActivity().getSharedPreferences("share", Context.MODE_PRIVATE); 56 | 57 | wisdomEnglish = (TextView) view.findViewById(R.id.wisdom_english); 58 | wisdomChina = (TextView) view.findViewById(R.id.wisdom_china); 59 | difficultyTv = (TextView) view.findViewById(R.id.difficulty_text); 60 | alreadyStudyText = (TextView) view.findViewById(R.id.already_study); 61 | alreadyMasteredText = (TextView) view.findViewById(R.id.already_mastered); 62 | wrongText = (TextView) view.findViewById(R.id.wrong_text); 63 | playVioce = (ImageView)view.findViewById(R.id.play_vioce); //播放声音按钮绑定id 64 | playVioce.setOnClickListener(this); // 播放声音设置监听事件 65 | review_btn = (Button)view.findViewById(R.id.review_btn); 66 | review_btn.setOnClickListener(this); 67 | 68 | //初始化,只需要调用一次 69 | AssetsDatabaseManager.initManager(getActivity()); 70 | //获取管理对象,因为数据库需要通过管理对象才能获取 71 | AssetsDatabaseManager mg = AssetsDatabaseManager.getManager(); 72 | SQLiteDatabase db1 = mg.getDatabase("wisdom.db"); 73 | mDaoMaster = new DaoMaster(db1); 74 | mDaoSession = mDaoMaster.newSession(); 75 | //获取数据 76 | questionDao = mDaoSession.getWisdomEntityDao(); 77 | 78 | setParam(); //初始化语音播报 79 | SpeechUser.getUser().login(this.getActivity(),null,null,"appid=5cb7368a",listener); 80 | 81 | return view; 82 | 83 | 84 | } 85 | 86 | @Override 87 | public void onStart() { 88 | super.onStart(); 89 | difficultyTv.setText(sharedPreferences.getString("difficulty","四级")+"英语"); 90 | List datas=questionDao.queryBuilder().list(); 91 | Random random=new Random(); 92 | int i=random.nextInt(10); 93 | wisdomEnglish.setText(datas.get(i).getEnglish()); 94 | wisdomChina.setText(datas.get(i).getChina()); 95 | setText(); 96 | } 97 | 98 | /** 99 | * 设置十字内的各个单词书(从轻量级数据库中获取数据) 100 | */ 101 | private void setText(){ 102 | alreadyMasteredText.setText(sharedPreferences.getInt("alreadyMastered",0)+""); 103 | alreadyStudyText.setText(sharedPreferences.getInt("alreadyStudy",0)+""); 104 | wrongText.setText(sharedPreferences.getInt("wrong",0)+""); 105 | } 106 | 107 | /** 108 | * 点击事件 109 | */ 110 | @Override 111 | public void onClick(View v) { 112 | // TODO Auto-generated method stub 113 | switch (v.getId()) { 114 | case R.id.play_vioce: //播放单词声音 115 | String text = wisdomEnglish.getText().toString(); //获取文本 116 | speechSynthesizer.startSpeaking(text, this); //传给后台 117 | break; 118 | case R.id.review_btn: 119 | Intent intent=new Intent(getActivity(),ReviewAcitivty.class); 120 | startActivity(intent); 121 | break; 122 | } 123 | } 124 | 125 | //缓冲进度回调通知 126 | @Override 127 | public void onBufferProgress(int arg0, int arg1, int arg2, String arg3) { 128 | // TODO Auto-generated method stub 129 | } 130 | 131 | //结束回调 132 | @Override 133 | public void onCompleted(SpeechError arg0) { 134 | // TODO Auto-generated method stub 135 | 136 | } 137 | 138 | //开始播放 139 | @Override 140 | public void onSpeakBegin() { 141 | // TODO Auto-generated method stub 142 | 143 | } 144 | 145 | //暂停播放 146 | @Override 147 | public void onSpeakPaused() { 148 | // TODO Auto-generated method stub 149 | 150 | } 151 | 152 | //播放进度 153 | @Override 154 | public void onSpeakProgress(int arg0, int arg1, int arg2) { 155 | // TODO Auto-generated method stub 156 | 157 | } 158 | 159 | //继续播放 160 | @Override 161 | public void onSpeakResumed() { 162 | // TODO Auto-generated method stub 163 | 164 | } 165 | 166 | /** 167 | * 通用回调接口 168 | */ 169 | private SpeechListener listener = new SpeechListener() { 170 | 171 | //消息回调 172 | @Override 173 | public void onEvent(int arg0, Bundle arg1) { 174 | // TODO Auto-generated method stub 175 | 176 | } 177 | 178 | //数据回调 179 | @Override 180 | public void onData(byte[] arg0) { 181 | // TODO Auto-generated method stub 182 | 183 | } 184 | 185 | //结束回调(没有错误) 186 | @Override 187 | public void onCompleted(SpeechError arg0) { 188 | // TODO Auto-generated method stub 189 | 190 | } 191 | }; 192 | 193 | /** 194 | * 初始化语音播报 195 | * */ 196 | public void setParam() { 197 | speechSynthesizer = SpeechSynthesizer.createSynthesizer(this.getActivity()); 198 | //设置发音人名( 199 | speechSynthesizer.setParameter(SpeechConstant.VOICE_NAME,"Catherine"); 200 | //语速 201 | speechSynthesizer.setParameter(SpeechConstant.SPEED,"50"); 202 | //声音大小 203 | speechSynthesizer.setParameter(SpeechConstant.VOLUME,"80"); 204 | //音调 205 | speechSynthesizer.setParameter(SpeechConstant.PITCH,"50"); 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/fragment/WordDetailFrament.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.fragment; 2 | 3 | import android.annotation.TargetApi; 4 | import android.app.Fragment; 5 | import android.content.Context; 6 | import android.content.SharedPreferences; 7 | import android.os.Build; 8 | import android.os.Bundle; 9 | import android.os.Handler; 10 | import android.os.Message; 11 | import android.support.annotation.Nullable; 12 | import android.support.annotation.RequiresApi; 13 | import android.util.Log; 14 | import android.view.LayoutInflater; 15 | import android.view.View; 16 | import android.view.ViewGroup; 17 | import android.widget.Button; 18 | import android.widget.EditText; 19 | import android.widget.ImageView; 20 | import android.widget.TabHost; 21 | import android.widget.TextView; 22 | import android.widget.Toast; 23 | 24 | import com.google.gson.Gson; 25 | import com.google.gson.reflect.TypeToken; 26 | import com.iflytek.cloud.speech.SpeechConstant; 27 | import com.iflytek.cloud.speech.SpeechError; 28 | import com.iflytek.cloud.speech.SpeechListener; 29 | import com.iflytek.cloud.speech.SpeechSynthesizer; 30 | import com.iflytek.cloud.speech.SpeechUser; 31 | import com.iflytek.cloud.speech.SynthesizerListener; 32 | import com.mingrisoft.sockword.R; 33 | import com.mingrisoft.util.TranslationService; 34 | 35 | import org.json.JSONArray; 36 | import org.json.JSONException; 37 | import org.json.JSONObject; 38 | 39 | import java.io.IOException; 40 | import java.util.HashMap; 41 | import java.util.HashSet; 42 | import java.util.Iterator; 43 | import java.util.LinkedHashSet; 44 | import java.util.LinkedList; 45 | import java.util.List; 46 | import java.util.Map; 47 | import java.util.Queue; 48 | import java.util.Set; 49 | 50 | public class WordDetailFrament extends Fragment implements View.OnClickListener, SynthesizerListener { 51 | //变量定义 52 | public static final String TAG="WordDetailFrament"; 53 | private TextView wordText, englishText, //单词文本,音标文本,基本释义,网络释义 54 | basicChineseText, webChineseText; 55 | private TextView didText, doneText, doingText; //过去式文本,过去分词文本,现在分词文本 56 | private TextView wordClassText; //词性类别 57 | private ImageView playVoice; //播放单词发音 58 | private SpeechSynthesizer speechSynthesizer; //语音合成 59 | private Set wordsRecord; //查询过的单词记录 60 | private List workList; //处理字符 61 | private static Map resultMap; //保存查询的结果 62 | private ImageView tranWord; 63 | private SharedPreferences sharedPreferences; //数据库操作 64 | private SharedPreferences.Editor editor; //编辑者 65 | 66 | //转主线程处理获取的数据 67 | private Handler mHandler=new Handler(){ 68 | @Override 69 | public void handleMessage(Message msg) { 70 | switch (msg.what){ 71 | case TranslationService.SUCCEE_RESULT: 72 | //更新单词历史记录 73 | update(resultMap); 74 | //设置query 75 | wordText.setText(resultMap.get("query")); 76 | //设置音标 77 | englishText.setText("["+resultMap.get("phonetic")+"]"); 78 | //设置基本释义 79 | basicChineseText.setText(resultMap.get("explains")); 80 | //设置网络释义 81 | webChineseText.setText(resultMap.get("web")); 82 | //设置过去式过去分词和现在分词 83 | if(resultMap.containsKey("value0")){ 84 | didText.setText(resultMap.get("value0")); 85 | doneText.setText(resultMap.get("value1")); 86 | doingText.setText(resultMap.get("value2")); 87 | }else{ 88 | didText.setText("暂不支持"); 89 | doneText.setText("暂不支持"); 90 | doingText.setText("暂不支持"); 91 | } 92 | //设置词性类别 93 | if(resultMap.containsKey("exam_type")){ 94 | wordClassText.setText(resultMap.get("exam_type")); 95 | }else{ 96 | wordClassText.setText("暂不支持"); 97 | } 98 | break; 99 | case TranslationService.ERROR_INVALID_APPKEY: 100 | Toast.makeText(getActivity(),"appKey无效",Toast.LENGTH_SHORT).show(); 101 | break; 102 | case TranslationService.ERROR_PARAMAT_DISCARD: 103 | Toast.makeText(getActivity(),"参数不齐全或书写不正确",Toast.LENGTH_SHORT).show(); 104 | break; 105 | case TranslationService.ERROR_PROBLEM_CODE: 106 | Toast.makeText(getActivity(),"编码问题。请确保 q 为UTF-8编码.",Toast.LENGTH_SHORT).show(); 107 | break; 108 | case TranslationService.ERROR_UNBINDING_INSTANCE: 109 | Toast.makeText(getActivity(),"没有绑定服务实例",Toast.LENGTH_SHORT).show(); 110 | break; 111 | default: 112 | Toast.makeText(getActivity(),"出现未知错误",Toast.LENGTH_SHORT).show(); 113 | } 114 | super.handleMessage(msg); 115 | } 116 | }; 117 | 118 | @Nullable 119 | @Override 120 | public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { 121 | //绑定布局文件 122 | View view=inflater.inflate(R.layout.word_detail_fragment,null); 123 | //初始化控件 124 | init(view); 125 | sharedPreferences=getActivity().getSharedPreferences("share", Context.MODE_PRIVATE); 126 | editor=sharedPreferences.edit(); 127 | //开启线程执行 128 | return view; 129 | } 130 | 131 | /** 132 | * 初始化控件 133 | */ 134 | public void init(View view){ 135 | resultMap=new HashMap<>(); 136 | wordText = (TextView) view.findViewById(R.id.tran_word); 137 | englishText = (TextView) view.findViewById(R.id.tran_en); 138 | basicChineseText = (TextView) view.findViewById(R.id.tran_basic_chinese); 139 | webChineseText = (TextView) view.findViewById(R.id.tran_web_chinese); 140 | didText = (TextView) view.findViewById(R.id.tran_did); 141 | doneText = (TextView) view.findViewById(R.id.tran_done); 142 | doingText = (TextView) view.findViewById(R.id.tran_doing); 143 | wordClassText = (TextView) view.findViewById(R.id.tran_word_class); 144 | playVoice= (ImageView) view.findViewById(R.id.tran_play_voice); 145 | playVoice.setOnClickListener(this); 146 | } 147 | 148 | //确保与碎片相关联的活动一定已经创建完毕的时候调用 149 | @TargetApi(Build.VERSION_CODES.M) 150 | @Override 151 | public void onActivityCreated(@Nullable Bundle savedInstanceState) { 152 | super.onActivityCreated(savedInstanceState); 153 | 154 | setParam(); 155 | SpeechUser.getUser().login(this.getActivity(),null,null,"appid=5cb7368a",listener); 156 | } 157 | 158 | 159 | /** 160 | * 此方法耗时,必循在线程中执行,要不然会报错 161 | */ 162 | //获取翻译结果并解析存储到resultMap 163 | 164 | public void translationStrat(String word) throws IOException, JSONException { 165 | 166 | String queryResult = TranslationService.start(word); //翻译结果 167 | JSONArray jsonArray=new JSONArray(queryResult); 168 | for(int i=0;i() { 203 | }.getType()); 204 | Log.e(TAG,"explain"); 205 | for (String item : basic) { 206 | message += (item+"\n"); 207 | Log.e(TAG,item); 208 | } 209 | resultMap.put("explains", message); 210 | } 211 | 212 | if(basicJsonObject.has("exam_type")){ 213 | //单词所属类别 214 | String examMessage=""; 215 | Gson gson = new Gson(); 216 | String[] examType = gson.fromJson(basicJsonObject.getString("exam_type"), new TypeToken() { 217 | }.getType()); 218 | for (String item : examType) { 219 | examMessage +=(item+"/"); 220 | } 221 | //去掉最后的反斜杠 222 | examMessage=examMessage.substring(0,examMessage.length()-1); 223 | resultMap.put("exam_type", examMessage); 224 | } 225 | 226 | if(basicJsonObject.has("wfs")){ 227 | String wfs=""; 228 | JSONArray jsonArray1=new JSONArray(basicJsonObject.getString("wfs")); 229 | for(int j=0;j(){}.getType()); 251 | for (int j = 0; j < values.length; j++) { 252 | String value = values[j]; 253 | webmsg += value; 254 | if (j < values.length - 1) { 255 | webmsg += ";"; 256 | } 257 | } 258 | } 259 | } 260 | resultMap.put("web",webmsg); 261 | } 262 | //如果有过去式,过去分词,现在分词 263 | if(jsonObject.has("basic")){ 264 | } 265 | msg.obj=resultMap; 266 | mHandler.sendMessage(msg); 267 | } 268 | 269 | } 270 | } 271 | } 272 | 273 | @Override 274 | public void onClick(View view) { 275 | switch (view.getId()){ 276 | case R.id.tran_play_voice: 277 | String text=wordText.getText().toString(); 278 | speechSynthesizer.startSpeaking(text,this); 279 | break; 280 | } 281 | } 282 | 283 | //更新单词列表的记录 284 | private void update(Map map) { 285 | if(sharedPreferences.getStringSet("wordrecord",null)==null){ 286 | wordsRecord=new LinkedHashSet<>(); 287 | }else{ 288 | wordsRecord=new LinkedHashSet<>(sharedPreferences.getStringSet("wordrecord",null)); 289 | } 290 | //当历史浏览数据大于20个时,删除最后一个加入新的一个 291 | if(wordsRecord.size()>=20){ 292 | workList=new LinkedList<>(); 293 | Iterator iterator=wordsRecord.iterator(); 294 | //循环存入字符串 295 | while (iterator.hasNext()){ 296 | workList.add(iterator.next()); 297 | } 298 | //先移除末尾数据 299 | workList.remove(0); 300 | //再将新数据添加 301 | workList.add(workList.size()-1,resultMap.get("query")+"#"+resultMap.get("explains")); 302 | wordsRecord.clear(); 303 | for(int i=workList.size()-1;i>=0;i--){ 304 | wordsRecord.add(workList.get(i)); 305 | } 306 | editor.putStringSet("wordrecord",wordsRecord); 307 | editor.commit(); 308 | }else { 309 | wordsRecord.add(resultMap.get("query") + "#" + resultMap.get("explains")); 310 | editor.putStringSet("wordrecord", wordsRecord); 311 | editor.commit(); 312 | } 313 | } 314 | 315 | 316 | //接口回调 317 | @Override 318 | public void onSpeakBegin() { 319 | 320 | } 321 | 322 | @Override 323 | public void onBufferProgress(int i, int i1, int i2, String s) { 324 | 325 | } 326 | 327 | @Override 328 | public void onSpeakPaused() { 329 | 330 | } 331 | 332 | @Override 333 | public void onSpeakResumed() { 334 | 335 | } 336 | 337 | @Override 338 | public void onSpeakProgress(int i, int i1, int i2) { 339 | 340 | } 341 | 342 | @Override 343 | public void onCompleted(SpeechError speechError) { 344 | 345 | } 346 | 347 | @Override 348 | public void onDestroy() { 349 | super.onDestroy(); 350 | 351 | } 352 | 353 | /** 354 | * 通用回调接口 355 | */ 356 | private SpeechListener listener = new SpeechListener() { 357 | 358 | //消息回调 359 | @Override 360 | public void onEvent(int arg0, Bundle arg1) { 361 | // TODO Auto-generated method stub 362 | 363 | } 364 | 365 | //数据回调 366 | @Override 367 | public void onData(byte[] arg0) { 368 | // TODO Auto-generated method stub 369 | 370 | } 371 | 372 | //结束回调(没有错误) 373 | @Override 374 | public void onCompleted(SpeechError arg0) { 375 | // TODO Auto-generated method stub 376 | 377 | } 378 | }; 379 | 380 | //设置参数 381 | @TargetApi(Build.VERSION_CODES.M) 382 | private void setParam(){ 383 | speechSynthesizer = SpeechSynthesizer.createSynthesizer(this.getActivity()); 384 | //设置发音人名( 385 | speechSynthesizer.setParameter(SpeechConstant.VOICE_NAME,"xiaoyan"); 386 | //语速 387 | speechSynthesizer.setParameter(SpeechConstant.SPEED,"50"); 388 | //声音大小 389 | speechSynthesizer.setParameter(SpeechConstant.VOLUME,"80"); 390 | //音调 391 | speechSynthesizer.setParameter(SpeechConstant.PITCH,"50"); 392 | } 393 | 394 | } 395 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/greendao/entity/greendao/CET4Entity.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.greendao.entity.greendao; 2 | 3 | import org.greenrobot.greendao.annotation.Entity; 4 | import org.greenrobot.greendao.annotation.Generated; 5 | import org.greenrobot.greendao.annotation.Id; 6 | 7 | import java.io.Serializable; 8 | 9 | @Entity 10 | public class CET4Entity implements Serializable { 11 | private static final long serialVersionUID = 1L; 12 | @Id 13 | private Long id; 14 | private String word; 15 | private String english; 16 | private String china; 17 | private String sign; 18 | @Generated(hash = 1296110788) 19 | public CET4Entity(Long id, String word, String english, String china, 20 | String sign) { 21 | this.id = id; 22 | this.word = word; 23 | this.english = english; 24 | this.china = china; 25 | this.sign = sign; 26 | } 27 | @Generated(hash = 413105732) 28 | public CET4Entity() { 29 | } 30 | public Long getId() { 31 | return this.id; 32 | } 33 | public void setId(Long id) { 34 | this.id = id; 35 | } 36 | public String getWord() { 37 | return this.word; 38 | } 39 | public void setWord(String word) { 40 | this.word = word; 41 | } 42 | public String getEnglish() { 43 | return this.english; 44 | } 45 | public void setEnglish(String english) { 46 | this.english = english; 47 | } 48 | public String getChina() { 49 | return this.china; 50 | } 51 | public void setChina(String china) { 52 | this.china = china; 53 | } 54 | public String getSign() { 55 | return this.sign; 56 | } 57 | public void setSign(String sign) { 58 | this.sign = sign; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/greendao/entity/greendao/WisdomEntity.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.greendao.entity.greendao; 2 | 3 | import org.greenrobot.greendao.annotation.Entity; 4 | import org.greenrobot.greendao.annotation.Generated; 5 | import org.greenrobot.greendao.annotation.Id; 6 | 7 | import java.io.Serializable; 8 | 9 | @Entity 10 | public class WisdomEntity { 11 | @Id 12 | private Long id; 13 | private String english; 14 | private String china; 15 | @Generated(hash = 75080817) 16 | public WisdomEntity(Long id, String english, String china) { 17 | this.id = id; 18 | this.english = english; 19 | this.china = china; 20 | } 21 | @Generated(hash = 722270434) 22 | public WisdomEntity() { 23 | } 24 | public Long getId() { 25 | return this.id; 26 | } 27 | public void setId(Long id) { 28 | this.id = id; 29 | } 30 | public String getEnglish() { 31 | return this.english; 32 | } 33 | public void setEnglish(String english) { 34 | this.english = english; 35 | } 36 | public String getChina() { 37 | return this.china; 38 | } 39 | public void setChina(String china) { 40 | this.china = china; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/sockword/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.sockword; 2 | 3 | import android.app.Fragment; 4 | import android.app.FragmentTransaction; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.SharedPreferences; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.LinearLayout; 14 | 15 | import com.mingrisoft.fragment.SetFragment; 16 | import com.mingrisoft.fragment.StudyFragment; 17 | import com.mingrisoft.util.BaseApplication; 18 | import com.mingrisoft.util.ScreenListener; 19 | 20 | public class HomeActivity extends AppCompatActivity implements View.OnClickListener { 21 | private ScreenListener screenListener; //绑定此页面与手机屏幕状态的监听 22 | private SharedPreferences sharedPreferences; //定义轻量级数据库 23 | private FragmentTransaction transaction; //定义用于加载复习与设置的界面 24 | private StudyFragment studyFragment; //绑定复习界面 25 | private SetFragment setFragment; //绑定设置界面 26 | private Button wrongBtn; //定义错词本按钮 27 | private Button translateBtn; //定义翻译按钮 28 | 29 | 30 | @Override 31 | protected void onCreate(Bundle savedInstanceState) { 32 | super.onCreate(savedInstanceState); 33 | setContentView(R.layout.home_layout); 34 | init(); 35 | } 36 | 37 | private void init(){ 38 | sharedPreferences=getSharedPreferences("share",Context.MODE_PRIVATE); 39 | 40 | wrongBtn=(Button) findViewById(R.id.wrong_btn); 41 | wrongBtn.setOnClickListener(this); 42 | translateBtn=(Button) findViewById(R.id.translation); 43 | translateBtn.setOnClickListener(this); 44 | 45 | final SharedPreferences.Editor edit=sharedPreferences.edit(); 46 | 47 | //屏幕状态进行监听 48 | screenListener=new ScreenListener(this); 49 | 50 | screenListener.begin(new ScreenListener.ScreenStateListener() { 51 | @Override 52 | public void onScreenOn() { 53 | //判断是否在设置界面开启了锁屏按钮,如果开启则启动单词锁屏界面 54 | if (sharedPreferences.getBoolean("btnTf", false)) { 55 | //判断屏幕是否解锁 56 | Log.d("HomeActivity","解锁了"); 57 | if (sharedPreferences.getBoolean("tf", false)) { 58 | Log.d("HomeActivity","屏幕解锁了"); 59 | Intent intent = new Intent(HomeActivity.this, MainActivity.class); 60 | startActivity(intent); 61 | } 62 | } 63 | } 64 | 65 | @Override 66 | public void onScreenOff() { //手机已锁屏操作 67 | /** 68 | *如果手机已经锁了 69 | * 就把数据库中的tf字段改成true 70 | */ 71 | Log.d("HomeActivity","手机锁屏了"); 72 | edit.putBoolean("tf",true); 73 | edit.commit(); 74 | //销毁锁屏界面 75 | BaseApplication.destroyActivity("mainActivity"); 76 | } 77 | 78 | @Override 79 | public void onUserPresent() { 80 | /** 81 | * 如果手机已经解锁了 82 | * 就把数据库中的tf字段改成false 83 | */ 84 | Log.d("HomeActivity","手机解锁了"); 85 | edit.putBoolean("tf",false); 86 | edit.commit(); 87 | 88 | } 89 | }); 90 | 91 | //当此界面加载时,就显示复习界面的fragment 92 | studyFragment=new StudyFragment(); 93 | setFragment(studyFragment); 94 | 95 | } 96 | 97 | public void setFragment(Fragment fragment) { 98 | //开启碎片交易 99 | transaction=getFragmentManager().beginTransaction(); 100 | transaction.replace(R.id.frame_layout,fragment); 101 | transaction.commit(); 102 | } 103 | 104 | //单击进入复习界面 105 | public void study(View view){ 106 | if(studyFragment==null){ 107 | studyFragment=new StudyFragment(); 108 | } 109 | setFragment(studyFragment); 110 | } 111 | 112 | //单击进入设置界面 113 | public void set(View view){ 114 | if(setFragment==null){ 115 | setFragment=new SetFragment(); 116 | } 117 | setFragment(setFragment); 118 | } 119 | 120 | @Override 121 | public void onClick(View view) { 122 | switch (view.getId()){ 123 | case R.id.wrong_btn: 124 | Intent intent=new Intent(HomeActivity.this,WrongAcitivty.class); 125 | startActivity(intent); 126 | break; 127 | case R.id.translation: 128 | Intent intent1=new Intent(HomeActivity.this,TranslateActivity.class); 129 | startActivity(intent1); 130 | break; 131 | } 132 | } 133 | 134 | @Override 135 | protected void onDestroy() { 136 | screenListener.unregisterListener(); 137 | super.onDestroy(); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/sockword/ReviewAcitivty.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.sockword; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.database.sqlite.SQLiteDatabase; 6 | import android.os.Bundle; 7 | import android.support.v4.app.FragmentPagerAdapter; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | import android.widget.Toast; 16 | 17 | import com.example.assetsbasedata.AssetsDatabaseManager; 18 | import com.mingrisoft.adapter.CardFragmentPagerAdapter; 19 | import com.mingrisoft.adapter.ReviewFragmentPagerAdapter; 20 | import com.mingrisoft.greendao.entity.greendao.CET4Entity; 21 | import com.mingrisoft.greendao.entity.greendao.CET4EntityDao; 22 | import com.mingrisoft.greendao.entity.greendao.DaoMaster; 23 | import com.mingrisoft.greendao.entity.greendao.DaoSession; 24 | import com.mingrisoft.transform.CardTransformer; 25 | 26 | import java.util.ArrayList; 27 | import java.util.List; 28 | import java.util.Random; 29 | 30 | public class ReviewAcitivty extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener { 31 | 32 | public static final String TAG = "ReviewAcitivty"; 33 | private SharedPreferences sharedPreferences; //定义轻量级数据库 34 | private SharedPreferences.Editor editor; //数据库编辑器 35 | private ViewPager viewpager; 36 | private ReviewFragmentPagerAdapter mAapter; 37 | 38 | private ImageView back; 39 | private Button review_yes,review_no; //记住了,没记住按钮 40 | private TextView currentItem,allItem,dispatch; //当前页码和页码总数 41 | 42 | private SQLiteDatabase db,db2; //定义数据库 43 | private DaoMaster mDaoMaster,dbMaster,rMaster; // 数据库管理者 44 | private DaoSession mDaoSession,dbSession,rSession; // 与数据库进行会话 45 | private CET4EntityDao questionDao,dbDao,rDao; // 对应的表,由java代码生成的,对数据库内相应的表操作使用此对象 46 | 47 | List list; //判断题的数目 48 | List datas; //用于从数据库读取相应的词库 49 | List reviewData; //定义一个list泛型为CET4Entity 50 | int reviewNum = 0; //当前是第几个 51 | int rnum = 0; //错题数目 52 | List wrong = new ArrayList(); //把错题id(即k)存进来 53 | 54 | 55 | @Override 56 | protected void onCreate(Bundle savedInstanceState) { 57 | super.onCreate(savedInstanceState); 58 | setContentView(R.layout.review_layout); //绑定布局文件 59 | viewpager = (ViewPager) findViewById(R.id.viewpager); 60 | allItem = (TextView)findViewById(R.id.allItem); 61 | currentItem = (TextView)findViewById(R.id.currentItem); 62 | dispatch = (TextView)findViewById(R.id.dispatch); 63 | 64 | back = (ImageView)findViewById(R.id.review_back_btn); 65 | back.setOnClickListener(this); 66 | review_yes = (Button) findViewById(R.id.review_yes); 67 | review_no = (Button) findViewById(R.id.review_no); 68 | review_yes.setOnClickListener(this); //记住按钮设置监听事件 69 | review_no.setOnClickListener(this); 70 | 71 | viewpager.setOnPageChangeListener(this); 72 | 73 | sharedPreferences = getSharedPreferences("share", Context.MODE_PRIVATE); //初始化数据库 74 | editor = sharedPreferences.edit(); //初始化编辑器 75 | 76 | //初始化list 判断题的数目 77 | list=new ArrayList(); 78 | 79 | /** 80 | * 添加十个20以内的随机数 81 | */ 82 | Random r=new Random(); 83 | int i; 84 | while (list.size()<10){ 85 | i=r.nextInt(20); 86 | if(!list.contains(i)){ 87 | list.add(i); 88 | } 89 | } 90 | 91 | AssetsDatabaseManager.initManager(this); 92 | AssetsDatabaseManager mg = AssetsDatabaseManager.getManager(); 93 | SQLiteDatabase db1 = mg.getDatabase("word.db"); 94 | mDaoMaster=new DaoMaster(db1); 95 | mDaoSession=mDaoMaster.newSession(); 96 | questionDao=mDaoSession.getCET4EntityDao(); 97 | datas=questionDao.queryBuilder().list(); 98 | //第一个参数为Context 第二个参数为数据库名字 第三参数为CursorFactory 99 | DaoMaster.DevOpenHelper helper=new DaoMaster.DevOpenHelper(this,"wrong.db",null); 100 | /** 101 | * 初始化数据库 102 | */ 103 | //第一步获得一个Dao类: 104 | db=helper.getWritableDatabase(); 105 | dbMaster=new DaoMaster(db); 106 | dbSession=dbMaster.newSession(); 107 | dbDao=dbSession.getCET4EntityDao(); 108 | 109 | DaoMaster.DevOpenHelper helper1=new DaoMaster.DevOpenHelper(this,"review.db",null); 110 | /** 111 | * 初始化数据库 112 | */ 113 | //第一步获得一个Dao类: 114 | db2=helper1.getWritableDatabase(); 115 | rMaster=new DaoMaster(db2); 116 | rSession=rMaster.newSession(); 117 | rDao=rSession.getCET4EntityDao(); 118 | 119 | if(rDao.queryBuilder().list().size()==0){ 120 | copyData(); 121 | } 122 | 123 | if(wrong.size()!=dbDao.queryBuilder().list().size()){ 124 | copyWrongId(); 125 | } 126 | 127 | setData(reviewNum); //设置复习题 128 | Log.d(TAG, "初始复习题数:"+String.valueOf(rnum)); 129 | 130 | 131 | } 132 | 133 | /** 134 | * 将复习题复制到数据库 135 | */ 136 | private void copyData(){ 137 | int a = Integer.parseInt(sharedPreferences.getString("reviewNum","20")); 138 | for(int i=0;i(); //初始化list 175 | if (rDao.queryBuilder().list() != null 176 | && rDao.queryBuilder().list().size() > 0 177 | && j <= rDao.queryBuilder().list().size() 178 | && j >= 0 179 | ) { //判断如果数据库不为空 180 | for (int i = 0; i < rDao.queryBuilder().list().size(); i++) { 181 | reviewData.add(i, rDao.queryBuilder().list().get(i)); //把数据循环加到list里面 182 | } 183 | } else { 184 | reviewData.add(null); 185 | review_yes.setVisibility(View.GONE); 186 | review_no.setVisibility(View.GONE); 187 | currentItem.setVisibility(View.GONE); 188 | allItem.setVisibility(View.GONE); 189 | dispatch.setVisibility(View.GONE); 190 | } 191 | rnum = rDao.queryBuilder().list().size(); //错题数量 192 | Log.d(TAG, "复习题数量为:"+rnum); 193 | 194 | allItem.setText(rnum+""); 195 | 196 | mAapter = new ReviewFragmentPagerAdapter(getSupportFragmentManager(),reviewData); 197 | viewpager.setAdapter(mAapter); 198 | viewpager.setOffscreenPageLimit(3); 199 | viewpager.setCurrentItem(reviewData.size()-1); 200 | viewpager.setPageTransformer(true,new CardTransformer()); 201 | 202 | } 203 | 204 | /** 205 | * 点击事件 206 | */ 207 | @Override 208 | public void onClick(View v) { 209 | // TODO Auto-generated method stub 210 | switch (v.getId()) { 211 | case R.id.review_yes: //记住了 按钮的点击操作 212 | rDao.deleteByKey(rDao.queryBuilder().list().get(reviewNum).getId()); //从数据库删除该条数据 213 | Log.d(TAG, "删除的是第几个:"+String.valueOf(reviewNum)); 214 | setData(reviewNum); //刷新数据 215 | break; 216 | case R.id.review_no: //没记住 按钮的点击操作 217 | //加入生词本 218 | if(!wrong.contains(rDao.queryBuilder().list().get(reviewNum).getId().intValue())){ 219 | wrong.add(rDao.queryBuilder().list().get(reviewNum).getId().intValue()); 220 | saveWrongData(rDao.queryBuilder().list().get(reviewNum).getId().intValue()); 221 | } 222 | rDao.deleteByKey(rDao.queryBuilder().list().get(reviewNum).getId()); //从数据库删除该条数据 223 | Log.d(TAG, "删除的是第几个:"+String.valueOf(reviewNum)); 224 | setData(reviewNum); //刷新数据 225 | break; 226 | case R.id.review_back_btn: //返回按钮 227 | finish(); //返回上一个页面 228 | break; 229 | } 230 | } 231 | @Override 232 | protected void onStop() { 233 | super.onStop(); 234 | } 235 | 236 | @Override 237 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 238 | reviewNum = position; 239 | currentItem.setText(reviewNum+1+""); 240 | } 241 | 242 | @Override 243 | public void onPageSelected(int position) { 244 | 245 | } 246 | 247 | @Override 248 | public void onPageScrollStateChanged(int state) { 249 | 250 | } 251 | } 252 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/sockword/TranslateActivity.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.sockword; 2 | 3 | import android.app.Fragment; 4 | import android.app.FragmentTransaction; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.EditText; 9 | import android.widget.ImageView; 10 | import android.widget.Toast; 11 | 12 | import com.mingrisoft.fragment.HistoryWordFragment; 13 | import com.mingrisoft.fragment.WordDetailFrament; 14 | import com.mingrisoft.util.AndroidStateDetection; 15 | 16 | import org.json.JSONException; 17 | 18 | import java.io.IOException; 19 | 20 | public class TranslateActivity extends AppCompatActivity implements View.OnClickListener { 21 | 22 | public static final String TAG = "TranslateActivity"; 23 | private ImageView backBtn,clearBtn,translationBtn; //返回按钮,清除按钮,翻译按钮 24 | private EditText editText; //单词句子编辑框 25 | private FragmentTransaction transaction; //定义用于加载单词详情与历史记录的界面 26 | private WordDetailFrament wordDetailFragment; //绑定单词详情界面 27 | private HistoryWordFragment historyWordFragment; //绑定历史记录界面 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.translation_layout); 33 | init(); 34 | 35 | historyWordFragment = new HistoryWordFragment(); 36 | wordDetailFragment = new WordDetailFrament(); 37 | setFragment(historyWordFragment); 38 | } 39 | 40 | /** 41 | * 初始化控件 42 | */ 43 | private void init() { 44 | backBtn = (ImageView) findViewById(R.id.translate_back_btn); 45 | backBtn.setOnClickListener(this); 46 | clearBtn = (ImageView) findViewById(R.id.tran_clear); 47 | clearBtn.setOnClickListener(this); 48 | editText = (EditText) findViewById(R.id.tran_edit); 49 | translationBtn = (ImageView) findViewById(R.id.tran_btn); 50 | translationBtn.setOnClickListener(this); 51 | } 52 | 53 | @Override 54 | public void onClick(View view) { 55 | switch (view.getId()) { 56 | case R.id.translate_back_btn: 57 | finish(); 58 | break; 59 | case R.id.tran_btn: 60 | translationWordFromEditText(); 61 | break; 62 | case R.id.tran_clear: 63 | if (!editText.getText().toString().equals("")) { 64 | editText.setText(""); 65 | } 66 | historyWord(historyWordFragment); 67 | break; 68 | } 69 | } 70 | 71 | /** 72 | * @param fragment 73 | */ 74 | private void setFragment(Fragment fragment) { 75 | //开启碎片交换 76 | transaction = getFragmentManager().beginTransaction(); 77 | transaction.replace(R.id.tran_frame_layout, fragment); 78 | transaction.commit(); 79 | } 80 | 81 | //进入历史单词界面 82 | private void historyWord(HistoryWordFragment historyWordFragment) { 83 | if (historyWordFragment == null) { 84 | historyWordFragment = new HistoryWordFragment(); 85 | } 86 | setFragment(historyWordFragment); 87 | } 88 | 89 | //进入单词详情页面 90 | private void wordDetail(WordDetailFrament wordDetailFragment) { 91 | if (wordDetailFragment == null) { 92 | wordDetailFragment = new WordDetailFrament(); 93 | } 94 | setFragment(wordDetailFragment); 95 | } 96 | 97 | //核心方法,在线程中执行翻译方法 98 | private void translationWordFromEditText() { 99 | //首先判断是否有wifi或者移动数据 100 | if(AndroidStateDetection.isMobile(this)||AndroidStateDetection.isNetworkAvailable(this)) 101 | { 102 | wordDetail(wordDetailFragment); //进入单词详情页面 103 | if (wordDetailFragment != null && (AndroidStateDetection.isMobile(this) 104 | || AndroidStateDetection.isNetworkAvailable(this))) { 105 | //开启翻译线程 106 | new Thread(new Runnable() { 107 | @Override 108 | public void run() { 109 | try { 110 | wordDetailFragment.translationStrat(editText.getText().toString()); 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } catch (JSONException e) { 114 | e.printStackTrace(); 115 | } 116 | } 117 | }).start(); 118 | } 119 | }else{ 120 | Toast.makeText(this,"请打开wifi或移动数据",Toast.LENGTH_SHORT).show(); 121 | } 122 | } 123 | 124 | //核心方法,从另一个碎片传来得数据来执行方法 125 | public void translationWordFromAnotherFragment(final String word) { 126 | //首先判断是否有wifi或者移动数据 127 | if (AndroidStateDetection.isMobile(this) || AndroidStateDetection.isNetworkAvailable(this)) { 128 | wordDetail(wordDetailFragment); 129 | editText.setText(word); 130 | editText.setSelection(word.length()); 131 | if (wordDetailFragment != null) { 132 | //开启翻译线程 133 | new Thread(new Runnable() { 134 | @Override 135 | public void run() { 136 | try { 137 | wordDetailFragment.translationStrat(word); 138 | } catch (IOException e) { 139 | e.printStackTrace(); 140 | } catch (JSONException e) { 141 | e.printStackTrace(); 142 | } 143 | } 144 | }).start(); 145 | } 146 | }else{ 147 | Toast.makeText(this,"请打开wifi或移动数据",Toast.LENGTH_SHORT).show(); 148 | } 149 | } 150 | 151 | } 152 | 153 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/sockword/WrongAcitivty.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.sockword; 2 | 3 | 4 | import android.content.Context; 5 | import android.content.SharedPreferences; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.os.Bundle; 8 | import android.support.v4.view.ViewPager; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.util.Log; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.ImageView; 14 | import android.widget.TextView; 15 | 16 | import com.mingrisoft.adapter.CardFragmentPagerAdapter; 17 | import com.mingrisoft.fragment.CardFragment; 18 | import com.mingrisoft.greendao.entity.greendao.CET4Entity; 19 | import com.mingrisoft.greendao.entity.greendao.CET4EntityDao; 20 | import com.mingrisoft.greendao.entity.greendao.DaoMaster; 21 | import com.mingrisoft.greendao.entity.greendao.DaoSession; 22 | import com.mingrisoft.transform.CardTransformer; 23 | 24 | 25 | import org.w3c.dom.Text; 26 | 27 | import java.util.ArrayList; 28 | import java.util.Collections; 29 | import java.util.List; 30 | 31 | 32 | public class WrongAcitivty extends AppCompatActivity implements View.OnClickListener, ViewPager.OnPageChangeListener { 33 | 34 | public static final String TAG = "WrongAcitivty"; 35 | private SharedPreferences sharedPreferences; //定义轻量级数据库 36 | private SharedPreferences.Editor editor; //数据库编辑器 37 | private ViewPager viewpager; 38 | private CardFragmentPagerAdapter mAapter; 39 | private ImageView backBtn; //“返回”按钮 40 | private Button iKnowBtn; //“我会了”按钮 41 | private TextView currentItem,allItem,dispatch; //当前页码和页码总数 42 | 43 | private SQLiteDatabase db; //定义数据库 44 | private DaoMaster mDaoMaster; // 数据库管理者 45 | private DaoSession mDaoSession; // 与数据库进行会话 46 | private CET4EntityDao questionDao; // 对应的表,由java代码生成的,对数据库内相应的表操作使用此对象 47 | 48 | List wrongData; //定义一个list泛型为CET4Entity 49 | int wrongNum = 0; //当前是第几个 50 | int wnum = 0; //错题数目 51 | 52 | @Override 53 | protected void onCreate(Bundle savedInstanceState) { 54 | super.onCreate(savedInstanceState); 55 | setContentView(R.layout.wrong_layout); //绑定布局文件 56 | viewpager = (ViewPager) findViewById(R.id.viewpager); 57 | allItem = (TextView)findViewById(R.id.allItem); 58 | currentItem = (TextView)findViewById(R.id.currentItem); 59 | dispatch = (TextView)findViewById(R.id.dispatch); 60 | iKnowBtn = (Button) findViewById(R.id.i_know_btn); //“我会了”按钮绑定id 61 | iKnowBtn.setOnClickListener(this); //“我会了”按钮设置监听事件 62 | backBtn = (ImageView) findViewById(R.id.back_btn); //返回按钮绑定id 63 | backBtn.setOnClickListener(this); //返回按钮设置监听事件 64 | viewpager.setOnPageChangeListener(this); 65 | 66 | sharedPreferences = getSharedPreferences("share", Context.MODE_PRIVATE); //初始化数据库 67 | editor = sharedPreferences.edit(); //初始化编辑器 68 | // 通过管理对象获取数据库 69 | // 对数据库进行操作 70 | // 此DevOpenHelper类继承自SQLiteOpenHelper,第一个参数Context,第二个参数数据库名字,第三个参数CursorFactory 71 | DaoMaster.DevOpenHelper helper = new DaoMaster.DevOpenHelper(this, "wrong.db", null); 72 | db = helper.getWritableDatabase(); 73 | mDaoMaster = new DaoMaster(db); 74 | mDaoSession = mDaoMaster.newSession(); 75 | questionDao = mDaoSession.getCET4EntityDao(); 76 | 77 | setData(wrongNum); //设置错题 78 | Log.d(TAG, "初始错题数:"+String.valueOf(wnum)); 79 | 80 | 81 | } 82 | 83 | /** 84 | * 设置错题 85 | */ 86 | private void setData(int j) { 87 | iKnowBtn.setVisibility(View.VISIBLE); //“我会了”按钮显示出来 88 | wrongData = new ArrayList<>(); //初始化list 89 | if (questionDao.queryBuilder().list() != null 90 | && questionDao.queryBuilder().list().size() > 0 91 | && j <= questionDao.queryBuilder().list().size() 92 | && j >= 0 93 | ) { //判断如果数据库不为空 94 | for (int i = 0; i < questionDao.queryBuilder().list().size(); i++) { 95 | wrongData.add(i, questionDao.queryBuilder().list().get(i)); //把数据循环加到list里面 96 | } 97 | } else { 98 | wrongData.add(null); 99 | iKnowBtn.setVisibility(View.GONE); 100 | currentItem.setVisibility(View.GONE); 101 | allItem.setVisibility(View.GONE); 102 | dispatch.setVisibility(View.GONE); 103 | } 104 | wnum = questionDao.queryBuilder().list().size(); //错题数量 105 | Log.d(TAG, "错题数量为:"+wnum); 106 | 107 | allItem.setText(wnum+""); 108 | 109 | mAapter = new CardFragmentPagerAdapter(getSupportFragmentManager(),wrongData); 110 | viewpager.setAdapter(mAapter); 111 | viewpager.setOffscreenPageLimit(3); 112 | viewpager.setCurrentItem(wrongNum); 113 | viewpager.setPageTransformer(true,new CardTransformer()); 114 | 115 | 116 | } 117 | 118 | /** 119 | * 点击事件 120 | */ 121 | @Override 122 | public void onClick(View v) { 123 | // TODO Auto-generated method stub 124 | switch (v.getId()) { 125 | case R.id.i_know_btn: //我会了 按钮的点击操作 126 | questionDao.deleteByKey(questionDao.queryBuilder().list().get(wrongNum).getId()); //从数据库删除该条数据 127 | Log.d(TAG, "删除的是第几个:"+String.valueOf(wrongNum)); 128 | setData(wrongNum); //刷新数据 129 | break; 130 | case R.id.back_btn: //返回按钮 131 | finish(); //返回上一个页面 132 | break; 133 | } 134 | } 135 | @Override 136 | protected void onStop() { 137 | super.onStop(); 138 | } 139 | 140 | @Override 141 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { 142 | wrongNum = position; 143 | currentItem.setText(wrongNum+1+""); 144 | } 145 | 146 | @Override 147 | public void onPageSelected(int position) { 148 | 149 | } 150 | 151 | @Override 152 | public void onPageScrollStateChanged(int state) { 153 | 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/transform/CardTransformer.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.transform; 2 | 3 | 4 | import android.os.Build; 5 | import android.support.annotation.RequiresApi; 6 | import android.support.v4.view.ViewPager; 7 | import android.view.View; 8 | 9 | public class CardTransformer implements ViewPager.PageTransformer { 10 | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) 11 | @Override 12 | public void transformPage(View page, float position) { 13 | if(position < 0) { 14 | page.setTranslationX(-position*page.getWidth()); 15 | page.setTranslationZ(position); 16 | //缩放比例 17 | float scale = (page.getWidth()+40*position)/page.getWidth(); 18 | page.setScaleY(scale); 19 | page.setScaleX(scale); 20 | page.setTranslationY(-position*40); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/util/AndroidStateDetection.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.util; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | public class AndroidStateDetection { 8 | 9 | //判断网络连接是否可用 10 | public static boolean isNetworkAvailable(Context context){ 11 | ConnectivityManager connectivityManager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 12 | if(connectivityManager!=null){ 13 | NetworkInfo [] networkInfos=connectivityManager.getAllNetworkInfo(); 14 | 15 | if(networkInfos!=null&&networkInfos.length>0){ 16 | for(int i=0;i destroyMap=new HashMap<>(); 17 | private static BaseApplication instance; //全局实例 18 | 19 | @Override 20 | public void onCreate() { 21 | super.onCreate(); 22 | instance=this; 23 | } 24 | 25 | public BaseApplication() { 26 | super(); 27 | } 28 | 29 | /** 30 | * 添加到要销毁的列队 31 | *

32 | * 要销毁的activity 33 | */ 34 | 35 | 36 | public static void addDestoryActivity(Activity activity,String activityName){ 37 | destroyMap.put(activityName,activity); 38 | } 39 | 40 | /** 41 | * 销毁指定的activtiy 42 | */ 43 | 44 | public static void destroyActivity(String activityName){ 45 | //将Map转化成集合 46 | Set keyset=destroyMap.keySet(); 47 | for (String key:keyset) { 48 | destroyMap.get(key).finish(); 49 | } 50 | } 51 | 52 | //获取实例 53 | public static BaseApplication getInstance(){ 54 | return instance; 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/util/ScreenListener.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.util; 2 | 3 | import android.content.BroadcastReceiver; 4 | import android.content.Context; 5 | import android.content.Intent; 6 | import android.content.IntentFilter; 7 | import android.os.Build; 8 | import android.os.PowerManager; 9 | import android.support.annotation.RequiresApi; 10 | 11 | /** 12 | * 设置屏幕的监听状态 13 | */ 14 | public class ScreenListener { 15 | private Context context; //联系上下文 16 | private ScreenBroadcastReceiver mScreenReceiver; //定义一个广播 17 | private ScreenStateListener mScreenStateListener; //定义内部接口 18 | 19 | 20 | /** 21 | *初始化 22 | */ 23 | 24 | public ScreenListener(Context context){ 25 | this.context=context; 26 | mScreenReceiver=new ScreenBroadcastReceiver(); //初始化广播 27 | } 28 | 29 | /** 30 | * 自定义接口 31 | */ 32 | 33 | public interface ScreenStateListener{ 34 | void onScreenOn(); //手机屏幕亮起时 35 | void onScreenOff(); //手机屏幕关闭 36 | void onUserPresent(); //手机屏幕解锁 37 | } 38 | 39 | /** 40 | * 获取screen的状态 41 | */ 42 | 43 | @RequiresApi(api = Build.VERSION_CODES.ECLAIR_MR1) 44 | private void getScreenState(){ 45 | //初始化powerManager 46 | PowerManager manager= (PowerManager) context.getSystemService(Context.POWER_SERVICE); 47 | 48 | //如果屏幕亮起,屏幕监听器调用onScreenOn() 49 | if(manager.isScreenOn()){ 50 | mScreenStateListener.onScreenOn(); 51 | }else { 52 | mScreenStateListener.onScreenOff(); 53 | } 54 | } 55 | 56 | 57 | /** 58 | * 59 | * 一个内部广播,用于监听屏幕亮起时,屏幕关闭时,解锁时的状态 60 | * 61 | */ 62 | 63 | private class ScreenBroadcastReceiver extends BroadcastReceiver { 64 | 65 | private String action = null; 66 | 67 | @Override 68 | public void onReceive(Context context, Intent intent) { 69 | action = intent.getAction(); 70 | if (Intent.ACTION_SCREEN_ON.equals(action)) { //屏幕亮时操作 71 | mScreenStateListener.onScreenOn(); 72 | } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { //屏幕关闭时的操作 73 | mScreenStateListener.onScreenOff(); 74 | } else if (Intent.ACTION_USER_PRESENT.equals(action)) { //屏幕解锁 75 | mScreenStateListener.onUserPresent(); 76 | } 77 | 78 | } 79 | } 80 | 81 | /** 82 | * 开始监听广播状态 83 | * @param listener 84 | */ 85 | 86 | public void begin(ScreenStateListener listener){ 87 | mScreenStateListener=listener; 88 | registerListener(); 89 | getScreenState(); 90 | 91 | } 92 | 93 | /** 94 | * 注册广播接收器 95 | */ 96 | public void registerListener(){ 97 | IntentFilter filter=new IntentFilter(); 98 | filter.addAction(Intent.ACTION_SCREEN_ON); //屏幕亮起时开启的广博 99 | filter.addAction(Intent.ACTION_SCREEN_OFF); //屏幕关闭时开启的广播 100 | filter.addAction(Intent.ACTION_USER_PRESENT); //屏幕解锁时开启的广播 101 | context.registerReceiver(mScreenReceiver,filter); //发送广播 102 | } 103 | 104 | 105 | /** 106 | * 解除注册广播接收器 107 | */ 108 | public void unregisterListener(){ 109 | context.unregisterReceiver(mScreenReceiver); //注销广播 110 | } 111 | 112 | 113 | 114 | 115 | } 116 | 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/util/SwitchButton.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.util; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.graphics.drawable.Drawable; 6 | import android.util.AttributeSet; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.widget.FrameLayout; 10 | import android.widget.ImageView; 11 | 12 | import com.mingrisoft.sockword.R; 13 | 14 | public class SwitchButton extends FrameLayout { 15 | private ImageView openImage; //打开按钮图片 16 | private ImageView closeImage; //关闭按钮图片 17 | public SwitchButton(Context context){ 18 | this(context,null); 19 | } 20 | 21 | /** 22 | * 构造方法 23 | * @param context 24 | * @param attrs 25 | * @param defStyleAttr 26 | */ 27 | public SwitchButton(Context context, AttributeSet attrs,int defStyleAttr){ 28 | this(context,attrs); 29 | } 30 | 31 | public SwitchButton(Context context,AttributeSet attrs){ 32 | super(context,attrs); 33 | /** 34 | * context 通过调用obtainStyledAttributes方法获取一个TypeArray,然后由TypeArray 35 | * 对属性进行设置 36 | */ 37 | TypedArray typedArray=context.obtainStyledAttributes(attrs, R.styleable.SwitchButton); 38 | //画出开关打开状态 39 | Drawable openDrawable=typedArray.getDrawable(R.styleable.SwitchButton_switchOpenImag); 40 | //画出开关为关闭状态 41 | Drawable closeDrawable=typedArray.getDrawable(R.styleable.SwitchButton_switchCloseImage); 42 | //获取开关状态,默认为打开0 43 | int switchStatus=typedArray.getInt(R.styleable.SwitchButton_switchStatus,0); 44 | //必须释放资源 45 | typedArray.recycle(); 46 | //绑定布局文件 47 | LayoutInflater.from(context).inflate(R.layout.switch_button,this); 48 | 49 | openImage=(ImageView)findViewById(R.id.switch_open); 50 | closeImage=(ImageView)findViewById(R.id.switch_close); 51 | 52 | if(openDrawable!=null){ 53 | openImage.setImageDrawable(openDrawable); 54 | } 55 | 56 | if(closeDrawable!=null){ 57 | closeImage.setImageDrawable(closeDrawable); 58 | } 59 | 60 | if(switchStatus==1){ 61 | closeSwitch(); 62 | } 63 | 64 | } 65 | 66 | 67 | //判断开关状态 68 | public boolean isSwitchOpen(){ 69 | return openImage.getVisibility()== View.VISIBLE; 70 | } 71 | 72 | public void openSwitch(){ 73 | openImage.setVisibility(View.VISIBLE); 74 | closeImage.setVisibility(View.INVISIBLE); 75 | } 76 | 77 | public void closeSwitch(){ 78 | openImage.setVisibility(View.INVISIBLE); 79 | closeImage.setVisibility(View.VISIBLE); 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/mingrisoft/util/TranslationService.java: -------------------------------------------------------------------------------- 1 | package com.mingrisoft.util; 2 | 3 | 4 | 5 | import android.util.Log; 6 | 7 | import org.apache.http.Header; 8 | import org.apache.http.HttpEntity; 9 | import org.apache.http.NameValuePair; 10 | import org.apache.http.client.entity.UrlEncodedFormEntity; 11 | import org.apache.http.client.methods.CloseableHttpResponse; 12 | import org.apache.http.client.methods.HttpPost; 13 | import org.apache.http.impl.client.CloseableHttpClient; 14 | import org.apache.http.impl.client.HttpClients; 15 | import org.apache.http.message.BasicNameValuePair; 16 | 17 | import org.apache.http.util.EntityUtils; 18 | import org.slf4j.Logger; 19 | import org.slf4j.LoggerFactory; 20 | 21 | 22 | import java.io.*; 23 | import java.security.MessageDigest; 24 | import java.security.NoSuchAlgorithmException; 25 | import java.util.*; 26 | 27 | public class TranslationService { 28 | private static Logger logger = LoggerFactory.getLogger(TranslationService.class); 29 | 30 | private static final String YOUDAO_URL = "http://openapi.youdao.com/api"; 31 | 32 | private static final String APP_KEY = "489888f611fe71fd"; 33 | 34 | private static final String APP_SECRET = "hEOuS3S0d2hv1lYpFFQGAbNcYY4nTWhw"; 35 | 36 | //errorCode 37 | public static final int SUCCEE_RESULT = 0; //翻译成功 38 | public static final int ERROR_UNBINDING_INSTANCE = 110; //应用没有绑定服务实例 39 | public static final int ERROR_INVALID_APPKEY = 108; //appkey无效 40 | public static final int ERROR_PARAMAT_DISCARD = 101; //参数不齐全,或书写不正确 41 | public static final int ERROR_PROBLEM_CODE= 202; //如果确认 appKey 和 appSecret 的正确性,仍返回202,一般是编码问题。请确保 q 为UTF-8编码. 42 | 43 | 44 | public static String start(String word) throws IOException { 45 | String result; //查询结果 46 | Map params = new HashMap(); 47 | String q = word; 48 | String salt = String.valueOf(System.currentTimeMillis()); 49 | params.put("from", "EN"); 50 | params.put("to", "zh-CHS"); 51 | params.put("signType", "v3"); 52 | String curtime = String.valueOf(System.currentTimeMillis() / 1000); 53 | params.put("curtime", curtime); 54 | String signStr = APP_KEY + truncate(q) + salt + curtime + APP_SECRET; 55 | String sign = getDigest(signStr); 56 | params.put("appKey", APP_KEY); 57 | params.put("q", q); 58 | params.put("salt", salt); 59 | params.put("sign", sign); 60 | /** 处理结果 */ 61 | result=requestForHttp(YOUDAO_URL,params); 62 | return result; 63 | } 64 | 65 | public static String requestForHttp(String url,Map params) throws IOException { 66 | String json; 67 | 68 | /** 创建HttpClient */ 69 | CloseableHttpClient httpClient = HttpClients.createDefault(); 70 | 71 | /** httpPost */ 72 | HttpPost httpPost = new HttpPost(url); 73 | List paramsList = new ArrayList(); 74 | Iterator> it = params.entrySet().iterator(); 75 | while(it.hasNext()){ 76 | Map.Entry en = it.next(); 77 | String key = en.getKey(); 78 | String value = en.getValue(); 79 | paramsList.add(new BasicNameValuePair(key,value)); 80 | } 81 | httpPost.setEntity(new UrlEncodedFormEntity(paramsList,"UTF-8")); 82 | CloseableHttpResponse httpResponse = httpClient.execute(httpPost); 83 | try{ 84 | Header[] contentType = httpResponse.getHeaders("Content-Type"); 85 | logger.info("Content-Type:" + contentType[0].getValue()); 86 | HttpEntity httpEntity = httpResponse.getEntity(); 87 | json = EntityUtils.toString(httpEntity,"UTF-8"); 88 | consume(httpEntity); 89 | logger.info(json); 90 | System.out.println("翻译结果为:"+json); 91 | }finally { 92 | try{ 93 | if(httpResponse!=null){ 94 | httpResponse.close(); 95 | } 96 | }catch(IOException e){ 97 | logger.info("## release resouce error ##" + e); 98 | } 99 | } 100 | return "["+json+"]"; 101 | } 102 | 103 | /** 104 | * 生成加密字段 105 | */ 106 | public static String getDigest(String string) { 107 | if (string == null) { 108 | return null; 109 | } 110 | char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 111 | byte[] btInput = string.getBytes(); 112 | try { 113 | MessageDigest mdInst = MessageDigest.getInstance("SHA-256"); 114 | mdInst.update(btInput); 115 | byte[] md = mdInst.digest(); 116 | int j = md.length; 117 | char str[] = new char[j * 2]; 118 | int k = 0; 119 | for (byte byte0 : md) { 120 | str[k++] = hexDigits[byte0 >>> 4 & 0xf]; 121 | str[k++] = hexDigits[byte0 & 0xf]; 122 | } 123 | return new String(str); 124 | } catch (NoSuchAlgorithmException e) { 125 | return null; 126 | } 127 | } 128 | 129 | /** 130 | * 131 | * @param result 音频字节流 132 | * @param file 存储路径 133 | */ 134 | private static void byte2File(byte[] result, String file) { 135 | File audioFile = new File(file); 136 | FileOutputStream fos = null; 137 | try{ 138 | fos = new FileOutputStream(audioFile); 139 | fos.write(result); 140 | 141 | }catch (Exception e){ 142 | logger.info(e.toString()); 143 | }finally { 144 | if(fos != null){ 145 | try { 146 | fos.close(); 147 | } catch (IOException e) { 148 | e.printStackTrace(); 149 | } 150 | } 151 | } 152 | 153 | } 154 | 155 | public static String truncate(String q) { 156 | if (q == null) { 157 | return null; 158 | } 159 | int len = q.length(); 160 | String result; 161 | return len <= 20 ? q : (q.substring(0, 10) + len + q.substring(len - 10, len)); 162 | } 163 | 164 | public static void consume(HttpEntity entity) throws IOException { 165 | if (entity != null) { 166 | if (entity.isStreaming()) { 167 | InputStream inStream = entity.getContent(); 168 | if (inStream != null) { 169 | inStream.close(); 170 | } 171 | } 172 | 173 | } 174 | } 175 | 176 | } 177 | -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/src/main/jniLibs/armeabi-v7a/libmsc.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libmsc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/csmSimona/SorkWord/f17409f673725d5ef36da189bd6486fcf8b4611c/app/src/main/jniLibs/armeabi/libmsc.so -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_kuang.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 13 | 14 | 15 | 16 | 22 | 23 | 24 | 25 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/btn_review.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 13 | 14 | 15 | 16 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 19 | 20 | 27 | 31 | 32 | 33 | 42 | 43 | 52 | 53 | 57 | 65 | 66 | 74 | 75 | 76 | 77 | 86 | 87 | 94 | 95 | 103 | 104 | 113 | 114 | 123 | 124 | 125 | 133 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /app/src/main/res/layout/history_word_fragment.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/home_layout.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 |