├── .gitignore ├── LICENSE ├── README.md ├── app ├── .gitignore ├── architecture.jks ├── build.gradle ├── proguard-rules.pro ├── signing.properties └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── ithooks │ │ └── android │ │ └── xreap │ │ └── ApplicationTest.java │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── ithooks │ │ └── android │ │ └── xreap │ │ ├── adapter │ │ ├── BaseAbstractAdapter.java │ │ ├── BaseAbstractCursorAdapter.java │ │ ├── BaseAbstractRecycleCursorAdapter.java │ │ ├── BaseRecyclerAdapter.java │ │ ├── BaseRecyclerMultipleItemAdapter.java │ │ └── CursorFilter.java │ │ ├── app │ │ ├── AppApiContact.java │ │ ├── AppApplication.java │ │ ├── AppContact.java │ │ ├── AppParamContact.java │ │ └── AppSpContact.java │ │ ├── base │ │ ├── BaseAbstractActionBarActivity.java │ │ ├── BaseActionBarActivity.java │ │ ├── BaseCursorFragment.java │ │ ├── BaseFragment.java │ │ ├── BaseRecycleCursorFragment.java │ │ ├── PullToRefreshBaseFragment.java │ │ └── RecycleRefreshBaseFragment.java │ │ ├── dao │ │ ├── DataProvider.java │ │ ├── database │ │ │ ├── Column.java │ │ │ └── SQLiteTable.java │ │ └── datahelper │ │ │ ├── BaseDataHelper.java │ │ │ └── DBInterface.java │ │ ├── log │ │ └── LogUtils.java │ │ ├── model │ │ └── BaseModel.java │ │ ├── network │ │ ├── AppNetworkInfo.java │ │ ├── callback │ │ │ ├── HttpBaseCallBack.java │ │ │ └── UiDisplayListener.java │ │ ├── controller │ │ │ └── BaseHttpController.java │ │ └── http │ │ │ └── AppApiService.java │ │ ├── ui │ │ └── HomeActivity.java │ │ ├── utils │ │ ├── Md5EncryptionHelper.java │ │ ├── SharedPreferencesHelper.java │ │ ├── StringHelper.java │ │ ├── ToastHelper.java │ │ └── ViewHelper.java │ │ └── view │ │ ├── FixedRecyclerView.java │ │ ├── FullyExpandedListView.java │ │ ├── PageListView.java │ │ └── StatusListView.java │ └── res │ ├── drawable-hdpi │ └── ic_launcher.png │ ├── drawable-mdpi │ └── ic_launcher.png │ ├── drawable-xhdpi │ └── ic_launcher.png │ ├── drawable-xxhdpi │ └── ic_launcher.png │ ├── layout │ ├── activity_fragment_base.xml │ ├── activity_home.xml │ ├── fragment_home.xml │ ├── fragment_pull_to_refresh_base_view.xml │ ├── fragment_recycle_refresh_base.xml │ ├── include_empty_view.xml │ ├── include_error_view.xml │ └── include_loading_view.xml │ ├── menu │ └── menu_home.xml │ ├── values-w820dp │ └── dimens.xml │ └── values │ ├── attrs.xml │ ├── colors.xml │ ├── dimens.xml │ ├── ids.xml │ ├── strings.xml │ └── styles.xml ├── art └── art.jpg ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | .idea/ 19 | 20 | # Local configuration file (sdk path, etc) 21 | local.properties 22 | 23 | # Proguard folder generated by Eclipse 24 | proguard/ 25 | 26 | # Log Files 27 | *.log 28 | AppCodeArchitecture.iml 29 | app/app.iml 30 | -------------------------------------------------------------------------------- /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 | 203 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AppCodeArchitecture 2 | =================== 3 | 4 | 安卓APP代码架构,包含比较常用的开源库使用 5 | 6 |
7 | 更多介绍可以看下我的这篇博客---->[Android App 代码架构](http://frank-zhu.github.io/2014-11-22-android-app-code-architecture.html) 8 | 9 | UPDATE 10 | ============ 11 | 打包签名相关的可以看下这篇博客----->[安卓集成发布详解(二)](http://frank-zhu.github.io/android/2015/06/15/android-release_app_build_gradle/) 12 | 13 | Thanks 14 | ============ 15 | * [Retrofit](https://github.com/square/retrofit) 16 | * [OKHTTP](https://github.com/square/okhttp) 17 | * [Picasso](https://github.com/square/picasso) 18 | * [UIL](https://github.com/nostra13/Android-Universal-Image-Loader) 19 | * [Butterknife](https://github.com/JakeWharton/butterknife) 20 | * [GSON](https://code.google.com/p/google-gson/) 21 | * [EventBus](https://github.com/greenrobot/EventBus) 22 | * [otto](https://github.com/square/otto) 23 | * [AppMsg](https://github.com/johnkil/Android-AppMsg) 24 | * [CircleImageView](https://github.com/hdodenhof/CircleImageView) 25 | 26 | About me 27 | ============ 28 | [Click Me](http://frank-zhu.github.io/about.html) 29 | 30 | License 31 | ============ 32 | 33 | Copyright 2014 Frank Zhu 34 | 35 | Licensed under the Apache License, Version 2.0 (the "License"); 36 | you may not use this file except in compliance with the License. 37 | You may obtain a copy of the License at 38 | 39 | http://www.apache.org/licenses/LICENSE-2.0 40 | 41 | Unless required by applicable law or agreed to in writing, software 42 | distributed under the License is distributed on an "AS IS" BASIS, 43 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 | See the License for the specific language governing permissions and 45 | limitations under the License. 46 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/architecture.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/architecture.jks -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | //定义打包时间函数 4 | def packageTime() { 5 | return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC")) 6 | } 7 | 8 | android { 9 | compileSdkVersion Integer.parseInt(ANDROID_BUILD_COMPILE_SDK_VERSION) 10 | buildToolsVersion ANDROID_BUILD_TOOLS_VERSION 11 | 12 | signingConfigs { 13 | debug { 14 | 15 | } 16 | release { 17 | //storeFile file("../yourapp.keystore") 18 | //storePassword "your password" 19 | //keyAlias "your alias" 20 | //keyPassword "your password" 21 | 22 | //setting your signing.properties 23 | //first, add signing.properties to ./app/ 24 | //second, add property STORE_FILE, STORE_PASSWORD, KEY_ALIAS, KEY_PASSWORD 25 | } 26 | } 27 | 28 | defaultConfig { 29 | applicationId "com.ecloud.android.xreap" 30 | minSdkVersion Integer.parseInt(MIN_SDK_VERSION) 31 | targetSdkVersion Integer.parseInt(ANDROID_BUILD_TARGET_SDK_VERSION) 32 | versionCode Integer.parseInt(VERSION_CODE) 33 | versionName VERSION_NAME 34 | 35 | // dex突破65535的限制 36 | multiDexEnabled true 37 | } 38 | buildTypes { 39 | debug { 40 | buildConfigField "boolean", "LOG_DEBUG", "true"//是否输出LOG信息 41 | buildConfigField "String", "API_HOST", "\"http://api.test.com\""//API Host 42 | minifyEnabled false 43 | zipAlignEnabled true 44 | shrinkResources true 45 | signingConfig signingConfigs.debug 46 | } 47 | 48 | release { 49 | buildConfigField "boolean", "LOG_DEBUG", "false"//是否输出LOG信息 50 | buildConfigField "String", "API_HOST", "\"http://api.release.com\""//API Host 51 | minifyEnabled false//混淆编译 52 | zipAlignEnabled true 53 | //移除无用的资源文件 54 | shrinkResources true 55 | signingConfig signingConfigs.release 56 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 57 | } 58 | } 59 | 60 | compileOptions { 61 | sourceCompatibility JavaVersion.VERSION_1_7 62 | targetCompatibility JavaVersion.VERSION_1_7 63 | } 64 | 65 | lintOptions { 66 | disable 'InvalidPackage' 67 | abortOnError false 68 | } 69 | 70 | //修改生成的最终文件名 71 | applicationVariants.all { variant -> 72 | variant.outputs.each { output -> 73 | def outputFile = output.outputFile 74 | if (outputFile != null && outputFile.name.endsWith('.apk')) { 75 | File outputDirectory = new File(outputFile.parent); 76 | def fileName 77 | if (variant.buildType.name == "release") { 78 | // 输出apk名称为app_v1.0.0_2015-06-15_playStore.apk 79 | fileName = "app_v${defaultConfig.versionName}_${packageTime()}_${variant.productFlavors[0].name}.apk" 80 | } else { 81 | fileName = "app_v${defaultConfig.versionName}_${packageTime()}_beta.apk" 82 | } 83 | output.outputFile = new File(outputDirectory, fileName) 84 | } 85 | } 86 | } 87 | 88 | productFlavors { 89 | playStore { 90 | manifestPlaceholders = [UMENG_CHANNEL_VALUE: "playStore"] 91 | } 92 | miui { 93 | manifestPlaceholders = [UMENG_CHANNEL_VALUE: "miui"] 94 | } 95 | wandoujia { 96 | manifestPlaceholders = [UMENG_CHANNEL_VALUE: "wandoujia"] 97 | } 98 | } 99 | 100 | //批量替换 101 | // productFlavors { 102 | // palyStore {} 103 | // miui {} 104 | // wandoujia {} 105 | // } 106 | // 107 | // productFlavors.all { 108 | // flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] 109 | // } 110 | } 111 | 112 | def propFile = project.rootProject.file('signing.properties'); 113 | if (propFile.exists()) { 114 | def Properties props = new Properties() 115 | props.load(new FileInputStream(propFile)) 116 | if (props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') && 117 | props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) { 118 | android.signingConfigs.release.storeFile = file(props['STORE_FILE']) 119 | android.signingConfigs.release.storePassword = props['STORE_PASSWORD'] 120 | android.signingConfigs.release.keyAlias = props['KEY_ALIAS'] 121 | android.signingConfigs.release.keyPassword = props['KEY_PASSWORD'] 122 | } else { 123 | android.buildTypes.release.signingConfig = null 124 | } 125 | } else { 126 | android.buildTypes.release.signingConfig = null 127 | } 128 | 129 | dependencies { 130 | compile fileTree(dir: 'libs', include: ['*.jar']) 131 | compile 'com.android.support:appcompat-v7:22.2.0' 132 | compile 'com.android.support:cardview-v7:21.0.3' 133 | compile 'com.android.support:recyclerview-v7:21.0.3' 134 | // compile 'com.android.support:support-v4:22.0.0' 135 | compile 'com.android.support:multidex:1.0.0' 136 | 137 | //View注解 代码地址-----> https://github.com/JakeWharton/butterknife 138 | compile 'com.jakewharton:butterknife:6.1.0' 139 | //图片加载 代码地址-----> https://github.com/square/picasso 140 | compile 'com.squareup.picasso:picasso:2.5.2' 141 | //API网络请求注解库 代码地址-----> https://github.com/square/retrofit 142 | compile 'com.squareup.retrofit:retrofit:1.9.0' 143 | //网络请求库 代码地址-----> https://github.com/square/okhttp 144 | compile 'com.squareup.okhttp:okhttp:2.2.0' 145 | compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0' 146 | //消息通知数据更新(类似Broadcast) 代码地址-----> https://github.com/greenrobot/EventBus 147 | compile 'de.greenrobot:eventbus:2.4.0' 148 | //圆形头像 代码地址-----> https://github.com/hdodenhof/CircleImageView 149 | compile 'de.hdodenhof:circleimageview:1.2.1' 150 | //解析JSON数据 代码地址-----> https://code.google.com/p/google-gson/ 151 | compile 'com.google.code.gson:gson:2.3.1' 152 | //弹出提示信息 代码地址-----> https://github.com/johnkil/Android-AppMsg 153 | compile 'com.github.johnkil.android-appmsg:appmsg:1.2.0' 154 | //SuperRecyclerView 代码地址-----> https://github.com/Malinskiy/SuperRecyclerView 155 | compile 'com.malinskiy:superrecyclerview:1.1.0' 156 | //超强滚动效果View 代码地址-----> https://github.com/ksoichiro/Android-ObservableScrollView 157 | compile 'com.github.ksoichiro:android-observablescrollview:1.5.1' 158 | } 159 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/lilin/Andorid/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/signing.properties: -------------------------------------------------------------------------------- 1 | STORE_FILE=architecture.jks 2 | STORE_PASSWORD=123456 3 | KEY_ALIAS=architecture 4 | KEY_PASSWORD=123456 -------------------------------------------------------------------------------- /app/src/androidTest/java/com/ithooks/android/xreap/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/BaseAbstractAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.BaseAdapter; 8 | 9 | import java.util.List; 10 | 11 | /** 12 | * Author: ZhuWenWu 13 | * Version V1.0 14 | * Date: 14-11-22 14:49 15 | * Description: ListView/GridView Adapter 基类 16 | * Modification History: 17 | * Date Author Version Description 18 | * ----------------------------------------------------------------------------------- 19 | * 14-11-22 ZhuWenWu 1.0 1.0 20 | * Why & What is modified: 21 | */ 22 | public abstract class BaseAbstractAdapter extends BaseAdapter { 23 | protected final Context mContext; 24 | protected final LayoutInflater mLayoutInflater; 25 | protected List mListData; 26 | 27 | public BaseAbstractAdapter(Context context) { 28 | mContext = context; 29 | mLayoutInflater = LayoutInflater.from(mContext); 30 | } 31 | 32 | public void setListData(List mListData) { 33 | this.mListData = mListData; 34 | notifyDataSetChanged(); 35 | } 36 | 37 | @Override 38 | public int getCount() { 39 | return mListData == null ? 0 : mListData.size(); 40 | } 41 | 42 | @Override 43 | public Object getItem(int position) { 44 | return mListData == null ? null : mListData.get(position); 45 | } 46 | 47 | @Override 48 | public long getItemId(int position) { 49 | return position; 50 | } 51 | 52 | public abstract View getView(int position, View convertView, ViewGroup viewGroup); 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/BaseAbstractCursorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | 3 | import android.content.Context; 4 | import android.database.Cursor; 5 | import android.support.v4.widget.CursorAdapter; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | /** 11 | * Author: ZhuWenWu 12 | * Version V1.0 13 | * Date: 14-11-22 14:52 14 | * Description: ListView/GridView Cursor Adapter 基类 15 | * Modification History: 16 | * Date Author Version Description 17 | * ----------------------------------------------------------------------------------- 18 | * 14-11-22 ZhuWenWu 1.0 1.0 19 | * Why & What is modified: 20 | */ 21 | public abstract class BaseAbstractCursorAdapter extends CursorAdapter { 22 | protected final Context mContext; 23 | protected final LayoutInflater mLayoutInflater; 24 | 25 | public BaseAbstractCursorAdapter(Context context, Cursor c) { 26 | this(context, c, false); 27 | } 28 | 29 | public BaseAbstractCursorAdapter(Context context, Cursor c, boolean autoRequery) { 30 | super(context, c, autoRequery); 31 | mContext = context; 32 | mLayoutInflater = LayoutInflater.from(context); 33 | } 34 | 35 | public int getTotalCount() { 36 | return mCursor == null ? 0 : mCursor.getCount(); 37 | } 38 | 39 | public abstract View newView(Context context, Cursor cursor, ViewGroup parent); 40 | 41 | public abstract void bindView(View view, Context context, Cursor cursor); 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/BaseAbstractRecycleCursorAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | /* 3 | * Copyright (C) 2013 The Android Open Source Project 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /* 19 | * Copyright (C) 2014 flzyup@ligux.com 20 | * 21 | * Licensed under the Apache License, Version 2.0 (the "License"); 22 | * you may not use this file except in compliance with the License. 23 | * You may obtain a copy of the License at 24 | * 25 | * http://www.apache.org/licenses/LICENSE-2.0 26 | * 27 | * Unless required by applicable law or agreed to in writing, software 28 | * distributed under the License is distributed on an "AS IS" BASIS, 29 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 30 | * See the License for the specific language governing permissions and 31 | * limitations under the License. 32 | * 33 | */ 34 | 35 | import android.content.Context; 36 | import android.database.ContentObserver; 37 | import android.database.Cursor; 38 | import android.database.DataSetObserver; 39 | import android.os.Handler; 40 | import android.support.v7.widget.RecyclerView; 41 | import android.widget.Filter; 42 | import android.widget.FilterQueryProvider; 43 | import android.widget.Filterable; 44 | 45 | /** 46 | * url --> https://gist.github.com/skyfishjy/443b7448f59be978bc59 47 | * Version 1.0 48 | * Date: 2014-07-07 19:53 49 | * Author: flzyup@ligux.com 50 | * Copyright © 2009-2014 LiGux.com. 51 | */ 52 | public abstract class BaseAbstractRecycleCursorAdapter extends RecyclerView.Adapter implements Filterable, 53 | CursorFilter.CursorFilterClient { 54 | /** 55 | * Call when bind view with the cursor 56 | * 57 | * @param holder 58 | * @param cursor 59 | */ 60 | public abstract void onBindViewHolder(VH holder, Cursor cursor); 61 | 62 | /** 63 | * This field should be made private, so it is hidden from the SDK. 64 | * {@hide} 65 | */ 66 | protected boolean mDataValid; 67 | 68 | /** 69 | * The current cursor 70 | */ 71 | protected Cursor mCursor; 72 | 73 | /** 74 | * This field should be made private, so it is hidden from the SDK. 75 | * {@hide} 76 | */ 77 | protected Context mContext; 78 | 79 | /** 80 | * The row id column 81 | */ 82 | protected int mRowIDColumn; 83 | 84 | /** 85 | * This field should be made private, so it is hidden from the SDK. 86 | * {@hide} 87 | */ 88 | protected ChangeObserver mChangeObserver; 89 | /** 90 | * This field should be made private, so it is hidden from the SDK. 91 | * {@hide} 92 | */ 93 | protected DataSetObserver mDataSetObserver; 94 | 95 | /** 96 | * This field should be made private, so it is hidden from the SDK. 97 | * {@hide} 98 | */ 99 | protected CursorFilter mCursorFilter; 100 | 101 | /** 102 | * This field should be made private, so it is hidden from the SDK. 103 | * {@hide} 104 | */ 105 | protected FilterQueryProvider mFilterQueryProvider; 106 | 107 | /** 108 | * If set the adapter will register a content observer on the cursor and will call 109 | * {@link #onContentChanged()} when a notification comes in. Be careful when 110 | * using this flag: you will need to unset the current Cursor from the adapter 111 | * to avoid leaks due to its registered observers. This flag is not needed 112 | * when using a CursorAdapter with a 113 | * {@link android.content.CursorLoader}. 114 | */ 115 | public static final int FLAG_REGISTER_CONTENT_OBSERVER = 0x02; 116 | 117 | /** 118 | * Recommended constructor. 119 | * 120 | * @param c The cursor from which to get the data. 121 | * @param context The context 122 | * @param flags Flags used to determine the behavior of the adapter; 123 | * Currently it accept {@link #FLAG_REGISTER_CONTENT_OBSERVER}. 124 | */ 125 | public BaseAbstractRecycleCursorAdapter(Context context, Cursor c, int flags) { 126 | init(context, c, flags); 127 | } 128 | 129 | void init(Context context, Cursor c, int flags) { 130 | boolean cursorPresent = c != null; 131 | mCursor = c; 132 | mDataValid = cursorPresent; 133 | mContext = context; 134 | mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1; 135 | if ((flags & FLAG_REGISTER_CONTENT_OBSERVER) == FLAG_REGISTER_CONTENT_OBSERVER) { 136 | mChangeObserver = new ChangeObserver(); 137 | mDataSetObserver = new MyDataSetObserver(); 138 | } else { 139 | mChangeObserver = null; 140 | mDataSetObserver = null; 141 | } 142 | 143 | if (cursorPresent) { 144 | if (mChangeObserver != null) c.registerContentObserver(mChangeObserver); 145 | if (mDataSetObserver != null) c.registerDataSetObserver(mDataSetObserver); 146 | } 147 | setHasStableIds(true); 148 | } 149 | 150 | /** 151 | * Returns the cursor. 152 | * 153 | * @return the cursor. 154 | */ 155 | @Override 156 | public Cursor getCursor() { 157 | return mCursor; 158 | } 159 | 160 | /** 161 | * @see android.support.v7.widget.RecyclerView.Adapter#getItemCount() 162 | */ 163 | @Override 164 | public int getItemCount() { 165 | if (mDataValid && mCursor != null) { 166 | return mCursor.getCount(); 167 | } else { 168 | return 0; 169 | } 170 | } 171 | 172 | /** 173 | * @param position Adapter position to query 174 | * @return 175 | * @see android.support.v7.widget.RecyclerView.Adapter#getItemId(int) 176 | */ 177 | @Override 178 | public long getItemId(int position) { 179 | if (mDataValid && mCursor != null) { 180 | if (mCursor.moveToPosition(position)) { 181 | return mCursor.getLong(mRowIDColumn); 182 | } else { 183 | return 0; 184 | } 185 | } else { 186 | return 0; 187 | } 188 | } 189 | 190 | @Override 191 | public void onBindViewHolder(VH holder, int position) { 192 | if (!mDataValid) { 193 | throw new IllegalStateException("this should only be called when the cursor is valid"); 194 | } 195 | if (!mCursor.moveToPosition(position)) { 196 | throw new IllegalStateException("couldn't move cursor to position " + position); 197 | } 198 | onBindViewHolder(holder, mCursor); 199 | } 200 | 201 | /** 202 | * Change the underlying cursor to a new cursor. If there is an existing cursor it will be 203 | * closed. 204 | * 205 | * @param cursor The new cursor to be used 206 | */ 207 | public void changeCursor(Cursor cursor) { 208 | Cursor old = swapCursor(cursor); 209 | if (old != null) { 210 | old.close(); 211 | } 212 | } 213 | 214 | /** 215 | * Swap in a new Cursor, returning the old Cursor. Unlike 216 | * {@link #changeCursor(android.database.Cursor)}, the returned old Cursor is not 217 | * closed. 218 | * 219 | * @param newCursor The new cursor to be used. 220 | * @return Returns the previously set Cursor, or null if there wasa not one. 221 | * If the given new Cursor is the same instance is the previously set 222 | * Cursor, null is also returned. 223 | */ 224 | public Cursor swapCursor(Cursor newCursor) { 225 | if (newCursor == mCursor) { 226 | return null; 227 | } 228 | Cursor oldCursor = mCursor; 229 | if (oldCursor != null) { 230 | if (mChangeObserver != null) oldCursor.unregisterContentObserver(mChangeObserver); 231 | if (mDataSetObserver != null) oldCursor.unregisterDataSetObserver(mDataSetObserver); 232 | } 233 | mCursor = newCursor; 234 | if (newCursor != null) { 235 | if (mChangeObserver != null) newCursor.registerContentObserver(mChangeObserver); 236 | if (mDataSetObserver != null) newCursor.registerDataSetObserver(mDataSetObserver); 237 | mRowIDColumn = newCursor.getColumnIndexOrThrow("_id"); 238 | mDataValid = true; 239 | // notify the observers about the new cursor 240 | notifyDataSetChanged(); 241 | } else { 242 | mRowIDColumn = -1; 243 | mDataValid = false; 244 | // notify the observers about the lack of a data set 245 | notifyDataSetChanged(); 246 | } 247 | return oldCursor; 248 | } 249 | 250 | /** 251 | *

Converts the cursor into a CharSequence. Subclasses should override this 252 | * method to convert their results. The default implementation returns an 253 | * empty String for null values or the default String representation of 254 | * the value.

255 | * 256 | * @param cursor the cursor to convert to a CharSequence 257 | * @return a CharSequence representing the value 258 | */ 259 | public CharSequence convertToString(Cursor cursor) { 260 | return cursor == null ? "" : cursor.toString(); 261 | } 262 | 263 | /** 264 | * Runs a query with the specified constraint. This query is requested 265 | * by the filter attached to this adapter. 266 | *

267 | * The query is provided by a 268 | * {@link android.widget.FilterQueryProvider}. 269 | * If no provider is specified, the current cursor is not filtered and returned. 270 | *

271 | * After this method returns the resulting cursor is passed to {@link #changeCursor(android.database.Cursor)} 272 | * and the previous cursor is closed. 273 | *

274 | * This method is always executed on a background thread, not on the 275 | * application's main thread (or UI thread.) 276 | *

277 | * Contract: when constraint is null or empty, the original results, 278 | * prior to any filtering, must be returned. 279 | * 280 | * @param constraint the constraint with which the query must be filtered 281 | * @return a Cursor representing the results of the new query 282 | * @see #getFilter() 283 | * @see #getFilterQueryProvider() 284 | * @see #setFilterQueryProvider(android.widget.FilterQueryProvider) 285 | */ 286 | public Cursor runQueryOnBackgroundThread(CharSequence constraint) { 287 | if (mFilterQueryProvider != null) { 288 | return mFilterQueryProvider.runQuery(constraint); 289 | } 290 | 291 | return mCursor; 292 | } 293 | 294 | public Filter getFilter() { 295 | if (mCursorFilter == null) { 296 | mCursorFilter = new CursorFilter(this); 297 | } 298 | return mCursorFilter; 299 | } 300 | 301 | /** 302 | * Returns the query filter provider used for filtering. When the 303 | * provider is null, no filtering occurs. 304 | * 305 | * @return the current filter query provider or null if it does not exist 306 | * @see #setFilterQueryProvider(android.widget.FilterQueryProvider) 307 | * @see #runQueryOnBackgroundThread(CharSequence) 308 | */ 309 | public FilterQueryProvider getFilterQueryProvider() { 310 | return mFilterQueryProvider; 311 | } 312 | 313 | /** 314 | * Sets the query filter provider used to filter the current Cursor. 315 | * The provider's 316 | * {@link android.widget.FilterQueryProvider#runQuery(CharSequence)} 317 | * method is invoked when filtering is requested by a client of 318 | * this adapter. 319 | * 320 | * @param filterQueryProvider the filter query provider or null to remove it 321 | * @see #getFilterQueryProvider() 322 | * @see #runQueryOnBackgroundThread(CharSequence) 323 | */ 324 | public void setFilterQueryProvider(FilterQueryProvider filterQueryProvider) { 325 | mFilterQueryProvider = filterQueryProvider; 326 | } 327 | 328 | /** 329 | * Called when the {@link android.database.ContentObserver} on the cursor receives a change notification. 330 | * The default implementation provides the auto-requery logic, but may be overridden by 331 | * sub classes. 332 | * 333 | * @see android.database.ContentObserver#onChange(boolean) 334 | */ 335 | protected abstract void onContentChanged(); 336 | 337 | private class ChangeObserver extends ContentObserver { 338 | public ChangeObserver() { 339 | super(new Handler()); 340 | } 341 | 342 | @Override 343 | public boolean deliverSelfNotifications() { 344 | return true; 345 | } 346 | 347 | @Override 348 | public void onChange(boolean selfChange) { 349 | onContentChanged(); 350 | } 351 | } 352 | 353 | private class MyDataSetObserver extends DataSetObserver { 354 | @Override 355 | public void onChanged() { 356 | mDataValid = true; 357 | notifyDataSetChanged(); 358 | } 359 | 360 | @Override 361 | public void onInvalidated() { 362 | mDataValid = false; 363 | notifyDataSetChanged(); 364 | } 365 | } 366 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/BaseRecyclerAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | 7 | import com.ithooks.android.xreap.log.LogUtils; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | 12 | /** 13 | * Author: ZhuWenWu 14 | * Version V1.0 15 | * Date: 15/4/11 15:18 16 | * Description: RecyclerView 适配器基类 17 | * Modification History: 18 | * Date Author Version Description 19 | * ----------------------------------------------------------------------------------- 20 | * 15/4/11 ZhuWenWu 1.0 1.0 21 | * Why & What is modified: 22 | */ 23 | public abstract class BaseRecyclerAdapter extends RecyclerView.Adapter { 24 | protected final String TAG = getClass().getSimpleName(); 25 | protected final Context mContext; 26 | protected final LayoutInflater mLayoutInflater; 27 | 28 | protected List mDataList = new ArrayList<>(); 29 | 30 | public BaseRecyclerAdapter(Context context) { 31 | mContext = context; 32 | mLayoutInflater = LayoutInflater.from(context); 33 | } 34 | 35 | public List getDataList() { 36 | return mDataList; 37 | } 38 | 39 | public T getItemData(int position) { 40 | return position < mDataList.size() ? mDataList.get(position) : null; 41 | } 42 | 43 | @Override 44 | public int getItemCount() { 45 | return mDataList == null ? 0 : mDataList.size(); 46 | } 47 | 48 | /** 49 | * 移除某一条记录 50 | * 51 | * @param position 移除数据的position 52 | */ 53 | public void removeItem(int position) { 54 | if (position < mDataList.size()) { 55 | mDataList.remove(position); 56 | notifyItemRemoved(position); 57 | } 58 | } 59 | 60 | /** 61 | * 添加一条记录 62 | * 63 | * @param data 需要加入的数据结构 64 | * @param position 插入位置 65 | */ 66 | public void addItem(T data, int position) { 67 | if (position <= mDataList.size()) { 68 | mDataList.add(position, data); 69 | notifyItemInserted(position); 70 | } 71 | } 72 | 73 | /** 74 | * 添加一条记录 75 | * 76 | * @param data 需要加入的数据结构 77 | */ 78 | public void addItem(T data) { 79 | addItem(data, mDataList.size()); 80 | } 81 | 82 | /** 83 | * 移除所有记录 84 | */ 85 | public void clearItems() { 86 | int size = mDataList.size(); 87 | if (size > 0) { 88 | mDataList.clear(); 89 | LogUtils.d(TAG, "clearItems --> "); 90 | notifyItemRangeRemoved(0, size); 91 | } 92 | } 93 | 94 | /** 95 | * 批量添加记录 96 | * 97 | * @param data 需要加入的数据结构 98 | * @param position 插入位置 99 | */ 100 | public void addItems(List data, int position) { 101 | if (position <= mDataList.size() && data != null && data.size() > 0) { 102 | LogUtils.d(TAG, "addItems --> position" + position); 103 | mDataList.addAll(position, data); 104 | notifyItemRangeChanged(position, data.size()); 105 | } 106 | } 107 | 108 | /** 109 | * 批量添加记录 110 | * 111 | * @param data 需要加入的数据结构 112 | */ 113 | public void addItems(List data) { 114 | addItems(data, mDataList.size()); 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/BaseRecyclerMultipleItemAdapter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.ViewGroup; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * Author: ZhuWenWu 11 | * Version V1.0 12 | * Date: 15/4/11 15:23 13 | * Description:有头和尾的 RecyclerView 适配器基类 14 | * Modification History: 15 | * Date Author Version Description 16 | * ----------------------------------------------------------------------------------- 17 | * 15/4/11 ZhuWenWu 1.0 1.0 18 | * Why & What is modified: 19 | */ 20 | public abstract class BaseRecyclerMultipleItemAdapter extends BaseRecyclerAdapter { 21 | public static enum ITEM_TYPE { 22 | ITEM_TYPE_HEADER, 23 | ITEM_TYPE_CONTENT, 24 | ITEM_TYPE_BOTTOM 25 | } 26 | 27 | protected int mHeaderCount;//头部View个数 28 | protected int mBottomCount;//底部View个数 29 | 30 | public BaseRecyclerMultipleItemAdapter(Context context) { 31 | super(context); 32 | } 33 | 34 | public void setHeaderCount(int headerCount) { 35 | this.mHeaderCount = headerCount; 36 | } 37 | 38 | public void setBottomCount(int bottomCount) { 39 | this.mBottomCount = bottomCount; 40 | } 41 | 42 | public boolean isHeaderView(int position) { 43 | return mHeaderCount != 0 && position < mHeaderCount; 44 | } 45 | 46 | public boolean isBottomView(int position) { 47 | return mBottomCount != 0 && position >= (mHeaderCount + getContentItemCount()); 48 | } 49 | 50 | @Override 51 | public T getItemData(int position) { 52 | int index = position - mHeaderCount; 53 | if (index >= super.getItemCount()) { 54 | return null; 55 | } 56 | return super.getItemData(index); 57 | } 58 | 59 | /** 60 | * 移除某一条记录 61 | * 62 | * @param position 移除数据的position 如果有Header需要减去Header数量 63 | */ 64 | public void removeItem(int position) { 65 | if (position < mDataList.size()) { 66 | mDataList.remove(position); 67 | notifyItemRemoved(mHeaderCount + position); 68 | } 69 | } 70 | 71 | /** 72 | * 添加一条记录 73 | * 74 | * @param data 需要加入的数据结构 75 | * @param position 插入数据的位置 如果有Header需要减去Header数量 76 | */ 77 | public void addItem(T data, int position) { 78 | if (position <= mDataList.size()) { 79 | mDataList.add(position, data); 80 | notifyItemInserted(mHeaderCount + position); 81 | } 82 | } 83 | 84 | /** 85 | * 移除所有记录 86 | */ 87 | public void clearItems() { 88 | int size = mDataList.size(); 89 | if (size > 0) { 90 | mDataList.clear(); 91 | notifyItemRangeRemoved(mHeaderCount, size); 92 | } 93 | } 94 | 95 | /** 96 | * 批量添加记录 97 | * 98 | * @param data 需要加入的数据结构 99 | * @param position 插入数据的位置 如果有Header需要减去Header数量 100 | */ 101 | public void addItems(List data, int position) { 102 | if (position <= mDataList.size() && data != null && data.size() > 0) { 103 | mDataList.addAll(position, data); 104 | notifyItemRangeChanged(mHeaderCount + position, data.size()); 105 | } 106 | } 107 | 108 | @Override 109 | public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 110 | if (viewType == ITEM_TYPE.ITEM_TYPE_HEADER.ordinal()) { 111 | return onCreateHeaderView(parent); 112 | } else if (viewType == ITEM_TYPE.ITEM_TYPE_CONTENT.ordinal()) { 113 | return onCreateContentView(parent); 114 | } else if (viewType == ITEM_TYPE.ITEM_TYPE_BOTTOM.ordinal()) { 115 | return onCreateBottomView(parent); 116 | } 117 | return null; 118 | } 119 | 120 | @Override 121 | public int getItemViewType(int position) { 122 | int dataItemCount = getContentItemCount(); 123 | if (mHeaderCount != 0 && position < mHeaderCount) {//头部View 124 | return ITEM_TYPE.ITEM_TYPE_HEADER.ordinal(); 125 | } else if (mBottomCount != 0 && position >= (mHeaderCount + dataItemCount)) {//底部View 126 | return ITEM_TYPE.ITEM_TYPE_BOTTOM.ordinal(); 127 | } else { 128 | return ITEM_TYPE.ITEM_TYPE_CONTENT.ordinal(); 129 | } 130 | } 131 | 132 | @Override 133 | public int getItemCount() { 134 | return mHeaderCount + getContentItemCount() + mBottomCount; 135 | } 136 | 137 | public abstract RecyclerView.ViewHolder onCreateHeaderView(ViewGroup parent);//创建头部View 138 | 139 | public abstract RecyclerView.ViewHolder onCreateContentView(ViewGroup parent);//创建中间内容View 140 | 141 | public abstract RecyclerView.ViewHolder onCreateBottomView(ViewGroup parent);//创建底部View 142 | 143 | public abstract int getContentItemCount();//获取中间内容个数 144 | } 145 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/adapter/CursorFilter.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.adapter; 2 | 3 | import android.database.Cursor; 4 | import android.widget.Filter; 5 | 6 | /** 7 | * Author: ZhuWenWu 8 | * Version V1.0 9 | * Date: 2014/12/30 17:15. 10 | * Description: 数据库Cursor筛选 11 | * Modification History: 12 | * Date Author Version Description 13 | * ----------------------------------------------------------------------------------- 14 | * 2014/12/30 ZhuWenWu 1.0 1.0 15 | * Why & What is modified: 16 | */ 17 | public class CursorFilter extends Filter { 18 | CursorFilterClient mClient; 19 | 20 | interface CursorFilterClient { 21 | CharSequence convertToString(Cursor cursor); 22 | Cursor runQueryOnBackgroundThread(CharSequence constraint); 23 | Cursor getCursor(); 24 | void changeCursor(Cursor cursor); 25 | } 26 | 27 | CursorFilter(CursorFilterClient client) { 28 | mClient = client; 29 | } 30 | 31 | @Override 32 | public CharSequence convertResultToString(Object resultValue) { 33 | return mClient.convertToString((Cursor) resultValue); 34 | } 35 | 36 | @Override 37 | protected FilterResults performFiltering(CharSequence constraint) { 38 | Cursor cursor = mClient.runQueryOnBackgroundThread(constraint); 39 | 40 | FilterResults results = new FilterResults(); 41 | if (cursor != null) { 42 | results.count = cursor.getCount(); 43 | results.values = cursor; 44 | } else { 45 | results.count = 0; 46 | results.values = null; 47 | } 48 | return results; 49 | } 50 | 51 | @Override 52 | protected void publishResults(CharSequence constraint, Filter.FilterResults results) { 53 | Cursor oldCursor = mClient.getCursor(); 54 | 55 | if (results.values != null && results.values != oldCursor) { 56 | mClient.changeCursor((Cursor) results.values); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/app/AppApiContact.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.app; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:10 7 | * Description: APP API常量工具类 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public class AppApiContact { 15 | // public static final String API_HOST = "http://";//API Host 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/app/AppApplication.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.app; 2 | 3 | import android.content.Context; 4 | import android.support.multidex.MultiDexApplication; 5 | 6 | import com.google.gson.Gson; 7 | import com.google.gson.GsonBuilder; 8 | import com.google.gson.internal.bind.DateTypeAdapter; 9 | import com.ithooks.android.xreap.BuildConfig; 10 | import com.ithooks.android.xreap.network.http.AppApiService; 11 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper; 12 | import com.squareup.okhttp.OkHttpClient; 13 | 14 | import java.util.Date; 15 | import java.util.concurrent.TimeUnit; 16 | 17 | import retrofit.RestAdapter; 18 | import retrofit.client.OkClient; 19 | import retrofit.converter.GsonConverter; 20 | 21 | /** 22 | * Author: ZhuWenWu 23 | * Version V1.0 24 | * Date: 14-11-22 13:30 25 | * Description: 26 | * Modification History: 27 | * Date Author Version Description 28 | * ----------------------------------------------------------------------------------- 29 | * 14-11-22 ZhuWenWu 1.0 1.0 30 | * Why & What is modified: 31 | */ 32 | public class AppApplication extends MultiDexApplication { 33 | private static Context sContext; 34 | private static AppApiService sAppApiService;//API 请求Service对象 35 | 36 | @Override 37 | public void onCreate() { 38 | super.onCreate(); 39 | 40 | sContext = getApplicationContext(); 41 | 42 | setUpSharedPreferencesHelper(getApplicationContext());//初始化SharedPreferences 43 | setUpApiService();//初始化APP API 44 | } 45 | 46 | private void setUpApiService() { 47 | Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new DateTypeAdapter()).create(); 48 | OkHttpClient okHttpClient = new OkHttpClient(); 49 | okHttpClient.setConnectTimeout(15, TimeUnit.SECONDS); 50 | RestAdapter restAdapter = new RestAdapter.Builder() 51 | .setEndpoint(BuildConfig.API_HOST) 52 | .setConverter(new GsonConverter(gson)) 53 | .setClient(new OkClient(okHttpClient)) 54 | .build(); 55 | sAppApiService = restAdapter.create(AppApiService.class); 56 | } 57 | 58 | /** 59 | * 初始化SharedPreferences 60 | * 61 | * @param context 上下文 62 | */ 63 | private void setUpSharedPreferencesHelper(Context context) { 64 | SharedPreferencesHelper.getInstance().Builder(context); 65 | } 66 | 67 | public static Context getContext() { 68 | return sContext; 69 | } 70 | 71 | public static AppApplication getInstance() { 72 | return (AppApplication) sContext; 73 | } 74 | 75 | public static AppApiService getAppApiService() { 76 | return sAppApiService; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/app/AppContact.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.app; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:10 7 | * Description: APP常量工具类 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public class AppContact { 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/app/AppParamContact.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.app; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:12 7 | * Description: APP Intent 常量工具类 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public class AppParamContact { 15 | public static final String PARAM_KEY_ID = "id";//ID 16 | public static final String PARAM_KEY_TITLE = "title";//Title 17 | public static final String PARAM_KEY_DATA = "data";//Object 序列化以后的数据 18 | } 19 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/app/AppSpContact.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.app; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:11 7 | * Description: APP SharedPreferences KEY 常量工具类 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public class AppSpContact { 15 | public static final String SP_KEY_NAME = "name"; 16 | } 17 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/BaseAbstractActionBarActivity.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | 6 | import com.ithooks.android.xreap.R; 7 | 8 | /** 9 | * Author: ZhuWenWu 10 | * Version V1.0 11 | * Date: 14-11-22 15:13 12 | * Description: Fragment Activity 基类 13 | * Modification History: 14 | * Date Author Version Description 15 | * ----------------------------------------------------------------------------------- 16 | * 14-11-22 ZhuWenWu 1.0 1.0 17 | * Why & What is modified: 18 | */ 19 | public abstract class BaseAbstractActionBarActivity extends BaseActionBarActivity { 20 | @Override 21 | protected void onCreate(Bundle savedInstanceState) { 22 | super.onCreate(savedInstanceState); 23 | setContentView(R.layout.activity_fragment_base); 24 | if (savedInstanceState == null) { 25 | getSupportFragmentManager().beginTransaction() 26 | .add(R.id.container, getFragment()) 27 | .commit(); 28 | } 29 | } 30 | 31 | public abstract Fragment getFragment(); 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/BaseActionBarActivity.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.app.ActionBar; 4 | import android.os.Bundle; 5 | import android.support.v4.app.FragmentActivity; 6 | import android.view.MenuItem; 7 | 8 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper; 9 | 10 | /** 11 | * Author: ZhuWenWu 12 | * Version V1.0 13 | * Date: 14-11-22 13:31 14 | * Description: Activity 基类 15 | * Modification History: 16 | * Date Author Version Description 17 | * ----------------------------------------------------------------------------------- 18 | * 14-11-22 ZhuWenWu 1.0 1.0 19 | * Why & What is modified: 20 | */ 21 | public class BaseActionBarActivity extends FragmentActivity { 22 | protected final String TAG = getClass().getSimpleName(); 23 | protected ActionBar mActionBar; 24 | protected SharedPreferencesHelper mSharedPreferencesHelper; 25 | 26 | @Override 27 | protected void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | mActionBar = getActionBar(); 30 | mSharedPreferencesHelper = SharedPreferencesHelper.getInstance(); 31 | } 32 | 33 | protected void showActionBar() { 34 | if (mActionBar != null) { 35 | mActionBar.setDisplayShowCustomEnabled(false); 36 | mActionBar.setDisplayHomeAsUpEnabled(true); 37 | } 38 | } 39 | 40 | @Override 41 | public boolean onOptionsItemSelected(MenuItem item) { 42 | int id = item.getItemId(); 43 | if (id == android.R.id.home) { 44 | finish(); 45 | return true; 46 | } 47 | return super.onOptionsItemSelected(item); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/BaseCursorFragment.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.database.Cursor; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.LoaderManager; 7 | import android.support.v4.content.Loader; 8 | import android.view.View; 9 | 10 | import com.ithooks.android.xreap.adapter.BaseAbstractCursorAdapter; 11 | 12 | /** 13 | * Author: ZhuWenWu 14 | * Version V1.0 15 | * Date: 14-11-22 18:48 16 | * Description: DB配合LoaderManager加载数据 17 | * Modification History: 18 | * Date Author Version Description 19 | * ----------------------------------------------------------------------------------- 20 | * 14-11-22 ZhuWenWu 1.0 1.0 21 | * Why & What is modified: 22 | */ 23 | public abstract class BaseCursorFragment extends PullToRefreshBaseFragment implements LoaderManager.LoaderCallbacks { 24 | protected BaseAbstractCursorAdapter mCursorAdapter; 25 | 26 | @Override 27 | public void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | } 30 | 31 | @Override 32 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 33 | super.onViewCreated(view, savedInstanceState); 34 | setUpCursorAdapter(); 35 | } 36 | 37 | @Override 38 | public Loader onCreateLoader(int i, Bundle bundle) { 39 | return createCursorLoader(); 40 | } 41 | 42 | @Override 43 | public void onLoadFinished(Loader loader, Cursor cursor) { 44 | if (mCursorAdapter != null) { 45 | mCursorAdapter.changeCursor(cursor); 46 | } 47 | } 48 | 49 | @Override 50 | public void onLoaderReset(Loader loader) { 51 | if (mCursorAdapter != null) { 52 | mCursorAdapter.changeCursor(null); 53 | } 54 | } 55 | 56 | protected abstract void setUpCursorAdapter(); 57 | 58 | protected abstract Loader createCursorLoader(); 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/BaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.v4.app.Fragment; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.ithooks.android.xreap.utils.SharedPreferencesHelper; 10 | 11 | import butterknife.ButterKnife; 12 | 13 | /** 14 | * Author: ZhuWenWu 15 | * Version V1.0 16 | * Date: 14-11-22 15:19 17 | * Description: Fragment 基类 18 | * Modification History: 19 | * Date Author Version Description 20 | * ----------------------------------------------------------------------------------- 21 | * 14-11-22 ZhuWenWu 1.0 1.0 22 | * Why & What is modified: 23 | */ 24 | public abstract class BaseFragment extends Fragment { 25 | protected final String TAG = getClass().getSimpleName(); 26 | protected SharedPreferencesHelper mSharedPreferencesHelper; 27 | 28 | @Override 29 | public void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | mSharedPreferencesHelper = SharedPreferencesHelper.getInstance(); 32 | } 33 | 34 | @Override 35 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 36 | View rootView = inflater.inflate(getLayoutResId(), container, false); 37 | ButterKnife.inject(this, rootView); 38 | return rootView; 39 | } 40 | 41 | protected abstract int getLayoutResId(); 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/BaseRecycleCursorFragment.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.database.Cursor; 4 | import android.os.Bundle; 5 | import android.support.annotation.Nullable; 6 | import android.support.v4.app.LoaderManager; 7 | import android.support.v4.content.Loader; 8 | import android.view.View; 9 | 10 | import com.ithooks.android.xreap.adapter.BaseAbstractRecycleCursorAdapter; 11 | 12 | /** 13 | * Author: ZhuWenWu 14 | * Version V1.0 15 | * Date: 14-11-22 18:48 16 | * Description: DB配合LoaderManager加载数据 17 | * Modification History: 18 | * Date Author Version Description 19 | * ----------------------------------------------------------------------------------- 20 | * 14-11-22 ZhuWenWu 1.0 1.0 21 | * Why & What is modified: 22 | */ 23 | public abstract class BaseRecycleCursorFragment extends RecycleRefreshBaseFragment implements LoaderManager.LoaderCallbacks { 24 | protected BaseAbstractRecycleCursorAdapter mCursorAdapter; 25 | 26 | @Override 27 | public void onCreate(Bundle savedInstanceState) { 28 | super.onCreate(savedInstanceState); 29 | } 30 | 31 | @Override 32 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 33 | super.onViewCreated(view, savedInstanceState); 34 | setUpCursorAdapter(); 35 | } 36 | 37 | @Override 38 | public Loader onCreateLoader(int id, Bundle bundle) { 39 | return createCursorLoader(); 40 | } 41 | 42 | @Override 43 | public void onLoadFinished(Loader loader, Cursor cursor) { 44 | if (mCursorAdapter != null) { 45 | mCursorAdapter.changeCursor(cursor); 46 | } 47 | } 48 | 49 | @Override 50 | public void onLoaderReset(Loader loader) { 51 | if (mCursorAdapter != null) { 52 | mCursorAdapter.changeCursor(null); 53 | } 54 | } 55 | 56 | protected abstract void setUpCursorAdapter(); 57 | 58 | protected abstract Loader createCursorLoader(); 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/PullToRefreshBaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.ithooks.android.xreap.R; 11 | import com.ithooks.android.xreap.view.PageListView; 12 | 13 | import butterknife.ButterKnife; 14 | import butterknife.InjectView; 15 | 16 | /** 17 | * Author: ZhuWenWu 18 | * Version V1.0 19 | * Date: 14-11-22 16:33 20 | * Description: PullToRefreshList Fragment 基类 21 | * Modification History: 22 | * Date Author Version Description 23 | * ----------------------------------------------------------------------------------- 24 | * 14-11-22 ZhuWenWu 1.0 1.0 25 | * Why & What is modified: 26 | */ 27 | public abstract class PullToRefreshBaseFragment extends BaseFragment implements SwipeRefreshLayout.OnRefreshListener { 28 | @InjectView(R.id.swipe_container) 29 | SwipeRefreshLayout mSwipeContainer; 30 | @InjectView(R.id.page_list_view) 31 | PageListView mPageListView; 32 | 33 | @Override 34 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 35 | View rootView = inflater.inflate(R.layout.fragment_pull_to_refresh_base_view, container, false); 36 | ButterKnife.inject(this, rootView); 37 | return rootView; 38 | } 39 | 40 | @Override 41 | protected int getLayoutResId() { 42 | return 0;//不调用父类布局,所以返回0 43 | } 44 | 45 | @Override 46 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 47 | super.onViewCreated(view, savedInstanceState); 48 | mSwipeContainer.setOnRefreshListener(this); 49 | mSwipeContainer.setColorSchemeResources(android.R.color.holo_blue_bright, 50 | android.R.color.holo_green_light, android.R.color.holo_orange_light, 51 | android.R.color.holo_red_light); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/base/RecycleRefreshBaseFragment.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.base; 2 | 3 | import android.os.Bundle; 4 | import android.support.annotation.Nullable; 5 | import android.support.v4.widget.SwipeRefreshLayout; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | 10 | import com.ithooks.android.xreap.R; 11 | import com.malinskiy.superrecyclerview.OnMoreListener; 12 | import com.malinskiy.superrecyclerview.SuperRecyclerView; 13 | 14 | import butterknife.InjectView; 15 | 16 | /** 17 | * Author: ZhuWenWu 18 | * Version V1.0 19 | * Date: 2014/12/30 15:28. 20 | * Description: RecycleRefresh 基类 21 | * Modification History: 22 | * Date Author Version Description 23 | * ----------------------------------------------------------------------------------- 24 | * 2014/12/30 ZhuWenWu 1.0 1.0 25 | * Why & What is modified: 26 | */ 27 | public abstract class RecycleRefreshBaseFragment extends BaseFragment { 28 | @InjectView(R.id.recycle_view) 29 | protected SuperRecyclerView mRecycleView; 30 | 31 | @Override 32 | protected int getLayoutResId() { 33 | return R.layout.fragment_recycle_refresh_base; 34 | } 35 | 36 | @Override 37 | public void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | } 40 | 41 | @Override 42 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 43 | return super.onCreateView(inflater, container, savedInstanceState); 44 | } 45 | 46 | @Override 47 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { 48 | super.onViewCreated(view, savedInstanceState); 49 | setUpRecycleView(); 50 | } 51 | 52 | private void setUpRecycleView() { 53 | mRecycleView.setRefreshingColorResources(android.R.color.holo_blue_bright, 54 | android.R.color.holo_green_light, android.R.color.holo_orange_light, 55 | android.R.color.holo_red_light); 56 | 57 | mRecycleView.setRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 58 | @Override 59 | public void onRefresh() { 60 | onDataRefresh(); 61 | } 62 | }); 63 | mRecycleView.setupMoreListener(new OnMoreListener() { 64 | @Override 65 | public void onMoreAsked(int numberOfItems, int numberBeforeMore, int currentItemPos) { 66 | onDataMore(); 67 | } 68 | }, 1); 69 | } 70 | 71 | public abstract void onDataRefresh(); 72 | 73 | public abstract void onDataMore(); 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/dao/DataProvider.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.dao; 2 | 3 | import android.content.ContentProvider; 4 | import android.content.ContentUris; 5 | import android.content.ContentValues; 6 | import android.content.Context; 7 | import android.content.UriMatcher; 8 | import android.database.Cursor; 9 | import android.database.SQLException; 10 | import android.database.sqlite.SQLiteDatabase; 11 | import android.database.sqlite.SQLiteOpenHelper; 12 | import android.database.sqlite.SQLiteQueryBuilder; 13 | import android.net.Uri; 14 | import android.provider.BaseColumns; 15 | import android.support.annotation.NonNull; 16 | 17 | import com.ithooks.android.xreap.app.AppApplication; 18 | 19 | /** 20 | * Author: ZhuWenWu 21 | * Version V1.0 22 | * Date: 14-11-22 14:25 23 | * Description: 24 | * Modification History: 25 | * Date Author Version Description 26 | * ----------------------------------------------------------------------------------- 27 | * 14-11-22 ZhuWenWu 1.0 1.0 28 | * Why & What is modified: 29 | */ 30 | public class DataProvider extends ContentProvider { 31 | public static final Object obj = new Object(); 32 | public static final String AUTHORITY = "com.ithooks.android.xreap"; 33 | public static final String SCHEME = "content://"; 34 | 35 | private static DBHelper mDBHelper; 36 | 37 | public static DBHelper getDBHelper() { 38 | if (mDBHelper == null) { 39 | mDBHelper = new DBHelper(AppApplication.getContext()); 40 | } 41 | return mDBHelper; 42 | } 43 | 44 | @Override 45 | public boolean onCreate() { 46 | return true; 47 | } 48 | 49 | @Override 50 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 51 | synchronized (obj) { 52 | SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder(); 53 | queryBuilder.setTables(matchTable(uri)); 54 | 55 | SQLiteDatabase db = getDBHelper().getReadableDatabase(); 56 | Cursor cursor = queryBuilder.query(db, 57 | projection, 58 | selection, 59 | selectionArgs, 60 | null, 61 | null, 62 | sortOrder); 63 | cursor.setNotificationUri(getContext().getContentResolver(), uri); 64 | return cursor; 65 | } 66 | } 67 | 68 | private static final UriMatcher sUriMATCHER = new UriMatcher(UriMatcher.NO_MATCH) {{ 69 | 70 | }}; 71 | 72 | private String matchTable(Uri uri) { 73 | String table = null; 74 | switch (sUriMATCHER.match(uri)) { 75 | default: 76 | throw new IllegalArgumentException("Unknown Uri" + uri); 77 | } 78 | // return table; 79 | } 80 | 81 | @Override 82 | public String getType(Uri uri) { 83 | switch (sUriMATCHER.match(uri)) { 84 | default: 85 | throw new IllegalArgumentException("Unknown Uri" + uri); 86 | } 87 | } 88 | 89 | @Override 90 | public Uri insert(Uri uri, ContentValues values) { 91 | synchronized (obj) { 92 | SQLiteDatabase db = getDBHelper().getWritableDatabase(); 93 | long rowId = 0; 94 | db.beginTransaction(); 95 | try { 96 | rowId = db.insert(matchTable(uri), null, values); 97 | db.setTransactionSuccessful(); 98 | } catch (Exception e) { 99 | e.printStackTrace(); 100 | } finally { 101 | db.endTransaction(); 102 | } 103 | if (rowId > 0) { 104 | Uri returnUri = ContentUris.withAppendedId(uri, rowId); 105 | getContext().getContentResolver().notifyChange(uri, null); 106 | return returnUri; 107 | } 108 | throw new SQLException("Failed to insert row into " + uri); 109 | } 110 | } 111 | 112 | @Override 113 | public int bulkInsert(Uri uri, @NonNull ContentValues[] values) { 114 | synchronized (obj) { 115 | SQLiteDatabase db = getDBHelper().getWritableDatabase(); 116 | db.beginTransaction(); 117 | try { 118 | for (ContentValues contentValues : values) { 119 | db.insertWithOnConflict(matchTable(uri), BaseColumns._ID, contentValues, SQLiteDatabase.CONFLICT_IGNORE); 120 | } 121 | db.setTransactionSuccessful(); 122 | getContext().getContentResolver().notifyChange(uri, null); 123 | return values.length; 124 | } catch (Exception e) { 125 | e.printStackTrace(); 126 | } finally { 127 | db.endTransaction(); 128 | } 129 | throw new SQLException("Failed to insert row into " + uri); 130 | } 131 | } 132 | 133 | @Override 134 | public int delete(Uri uri, String selection, String[] selectionArgs) { 135 | synchronized (obj) { 136 | SQLiteDatabase db = getDBHelper().getWritableDatabase(); 137 | int count = 0; 138 | db.beginTransaction(); 139 | try { 140 | count = db.delete(matchTable(uri), selection, selectionArgs); 141 | db.setTransactionSuccessful(); 142 | } finally { 143 | db.endTransaction(); 144 | } 145 | getContext().getContentResolver().notifyChange(uri, null); 146 | return count; 147 | } 148 | } 149 | 150 | public static void clearDBCache() { 151 | synchronized (DataProvider.obj) { 152 | DataProvider.DBHelper mDBHelper = DataProvider.getDBHelper(); 153 | SQLiteDatabase db = mDBHelper.getWritableDatabase(); 154 | } 155 | } 156 | 157 | @Override 158 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { 159 | synchronized (obj) { 160 | SQLiteDatabase db = getDBHelper().getWritableDatabase(); 161 | int count; 162 | db.beginTransaction(); 163 | try { 164 | count = db.update(matchTable(uri), values, selection, selectionArgs); 165 | db.setTransactionSuccessful(); 166 | } finally { 167 | db.endTransaction(); 168 | } 169 | getContext().getContentResolver().notifyChange(uri, null); 170 | return count; 171 | } 172 | } 173 | 174 | public static class DBHelper extends SQLiteOpenHelper { 175 | 176 | private static final String DB_NAME = "xx.db"; 177 | 178 | private static final int DB_VERSION = 1; 179 | 180 | private DBHelper(Context context) { 181 | super(context, DB_NAME, null, DB_VERSION); 182 | } 183 | 184 | @Override 185 | public void onCreate(SQLiteDatabase db) { 186 | } 187 | 188 | @Override 189 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/dao/database/Column.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.dao.database; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:31 7 | * Description: 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public class Column { 15 | public static enum Constraint { 16 | UNIQUE("UNIQUE"), NOT("NOT"), NULL("NULL"), CHECK("CHECK"), FOREIGN_KEY("FOREIGN KEY"), PRIMARY_KEY( 17 | "PRIMARY KEY"); 18 | 19 | private String value; 20 | 21 | private Constraint(String value) { 22 | this.value = value; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return value; 28 | } 29 | } 30 | 31 | public static enum DataType { 32 | NULL, INTEGER, REAL, TEXT, BLOB 33 | } 34 | 35 | private String mColumnName; 36 | 37 | private Constraint mConstraint; 38 | 39 | private DataType mDataType; 40 | 41 | public Column(String columnName, Constraint constraint, DataType dataType) { 42 | mColumnName = columnName; 43 | mConstraint = constraint; 44 | mDataType = dataType; 45 | } 46 | 47 | public String getColumnName() { 48 | return mColumnName; 49 | } 50 | 51 | public Constraint getConstraint() { 52 | return mConstraint; 53 | } 54 | 55 | public DataType getDataType() { 56 | return mDataType; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/dao/database/SQLiteTable.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.dao.database; 2 | 3 | import android.database.sqlite.SQLiteDatabase; 4 | import android.provider.BaseColumns; 5 | 6 | import java.util.ArrayList; 7 | 8 | /** 9 | * Author: ZhuWenWu 10 | * Version V1.0 11 | * Date: 14-11-22 14:31 12 | * Description: 13 | * Modification History: 14 | * Date Author Version Description 15 | * ----------------------------------------------------------------------------------- 16 | * 14-11-22 ZhuWenWu 1.0 1.0 17 | * Why & What is modified: 18 | */ 19 | public class SQLiteTable { 20 | String mTableName; 21 | 22 | ArrayList mColumnsDefinitions = new ArrayList(); 23 | 24 | public String getTableName() { 25 | return mTableName; 26 | } 27 | 28 | /** 29 | * 会自动添加主键 BaseColumns._ID 30 | * 31 | * @param tableName 表名 32 | */ 33 | public SQLiteTable(String tableName) { 34 | mTableName = tableName; 35 | mColumnsDefinitions.add(new Column(BaseColumns._ID, Column.Constraint.PRIMARY_KEY, 36 | Column.DataType.INTEGER)); 37 | } 38 | 39 | public SQLiteTable addColumn(Column columnsDefinition) { 40 | mColumnsDefinitions.add(columnsDefinition); 41 | return this; 42 | } 43 | 44 | public SQLiteTable addColumn(String columnName, Column.DataType dataType) { 45 | mColumnsDefinitions.add(new Column(columnName, null, dataType)); 46 | return this; 47 | } 48 | 49 | public SQLiteTable addColumn(String columnName, Column.Constraint constraint, 50 | Column.DataType dataType) { 51 | mColumnsDefinitions.add(new Column(columnName, constraint, dataType)); 52 | return this; 53 | } 54 | 55 | public void create(SQLiteDatabase db) { 56 | String formatter = " %s"; 57 | StringBuilder stringBuilder = new StringBuilder(); 58 | stringBuilder.append("CREATE TABLE IF NOT EXISTS "); 59 | stringBuilder.append(mTableName); 60 | stringBuilder.append("("); 61 | int columnCount = mColumnsDefinitions.size(); 62 | int index = 0; 63 | for (Column columnsDefinition : mColumnsDefinitions) { 64 | stringBuilder.append(columnsDefinition.getColumnName()).append( 65 | String.format(formatter, columnsDefinition.getDataType().name())); 66 | Column.Constraint constraint = columnsDefinition.getConstraint(); 67 | 68 | if (constraint != null) { 69 | stringBuilder.append(String.format(formatter, constraint.toString())); 70 | } 71 | if (index < columnCount - 1) { 72 | stringBuilder.append(","); 73 | } 74 | index++; 75 | } 76 | stringBuilder.append(");"); 77 | db.execSQL(stringBuilder.toString()); 78 | } 79 | 80 | public void delete(final SQLiteDatabase db) { 81 | db.execSQL("DROP TABLE IF EXISTS " + mTableName); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/dao/datahelper/BaseDataHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.dao.datahelper; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.net.Uri; 7 | import android.support.v4.content.CursorLoader; 8 | 9 | /** 10 | * Author: ZhuWenWu 11 | * Version V1.0 12 | * Date: 14-11-22 14:29 13 | * Description: 数据库帮助类基类 14 | * Modification History: 15 | * Date Author Version Description 16 | * ----------------------------------------------------------------------------------- 17 | * 14-11-22 ZhuWenWu 1.0 1.0 18 | * Why & What is modified: 19 | */ 20 | public abstract class BaseDataHelper { 21 | private Context mContext; 22 | 23 | protected abstract Uri getContentUri(); 24 | protected abstract String getTableName(); 25 | 26 | public BaseDataHelper(Context context) { 27 | mContext = context; 28 | } 29 | 30 | public Context getContext() { 31 | return mContext; 32 | } 33 | 34 | public void notifyChange() { 35 | mContext.getContentResolver().notifyChange(getContentUri(), null); 36 | } 37 | 38 | protected final Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 39 | return mContext.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder); 40 | } 41 | 42 | protected final Cursor query(String[] projection, String selection, String[] selectionArgs, String sortOrder) { 43 | return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder); 44 | } 45 | 46 | protected final Uri insert(ContentValues values) { 47 | return mContext.getContentResolver().insert(getContentUri(), values); 48 | } 49 | 50 | protected final int bulkInsert(ContentValues[] values) { 51 | return mContext.getContentResolver().bulkInsert(getContentUri(), values); 52 | } 53 | 54 | protected final int update(ContentValues values, String where, String[] whereArgs) { 55 | return mContext.getContentResolver().update(getContentUri(), values, where, whereArgs); 56 | } 57 | 58 | protected final int delete(String where, String[] selectionArgs) { 59 | return mContext.getContentResolver().delete(getContentUri(), where, selectionArgs); 60 | } 61 | 62 | public CursorLoader getCursorLoader(Context context) { 63 | return getCursorLoader(context, null, null, null, null); 64 | } 65 | 66 | public CursorLoader getCursorLoader(Context context, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 67 | return new CursorLoader(context, getContentUri(), projection, selection, selectionArgs, sortOrder); 68 | } 69 | 70 | protected final Cursor getList(String[] projection, String selection, String[] selectionArgs, String sortOrder) { 71 | return mContext.getContentResolver().query(getContentUri(), projection, selection, selectionArgs, sortOrder); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/dao/datahelper/DBInterface.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.dao.datahelper; 2 | 3 | import android.content.ContentValues; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Author: ZhuWenWu 9 | * Version V1.0 10 | * Date: 14-11-22 19:25 11 | * Description: DB操作接口类 12 | * Modification History: 13 | * Date Author Version Description 14 | * ----------------------------------------------------------------------------------- 15 | * 14-11-22 ZhuWenWu 1.0 1.0 16 | * Why & What is modified: 17 | */ 18 | public interface DBInterface { 19 | /** 20 | * 查询某一条记录 21 | * 22 | * @param id ID 23 | * @return T 返回查询到得第一条记录 24 | */ 25 | public T query(String id); 26 | 27 | /** 28 | * 删除所有数据 29 | * 30 | * @return count 本次操作的条数 31 | */ 32 | public int clearAll(); 33 | 34 | /** 35 | * 批量插入数据 36 | * 37 | * @param listData 需要插入的数据列表 38 | */ 39 | public void bulkInsert(List listData); 40 | 41 | public ContentValues getContentValues(T data); 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/log/LogUtils.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.log; 2 | 3 | import com.ithooks.android.xreap.BuildConfig; 4 | 5 | /** 6 | * Author: ZhuWenWu 7 | * Version V1.0 8 | * Date: 14-11-22 14:09 9 | * Description:Log 控制工具类 10 | * Modification History: 11 | * Date Author Version Description 12 | * ----------------------------------------------------------------------------------- 13 | * 14-11-22 ZhuWenWu 1.0 1.0 14 | * Why & What is modified: 15 | */ 16 | public class LogUtils { 17 | public static void v(String tag, String msg, Throwable tr) { 18 | if (BuildConfig.LOG_DEBUG) { 19 | android.util.Log.v(tag, msg, tr); 20 | } 21 | } 22 | 23 | public static void d(String tag, String msg) { 24 | if (BuildConfig.LOG_DEBUG) { 25 | android.util.Log.d(tag, msg); 26 | } 27 | } 28 | 29 | public static void d(String tag, String msg, Throwable tr) { 30 | if (BuildConfig.LOG_DEBUG) { 31 | android.util.Log.d(tag, msg, tr); 32 | } 33 | } 34 | 35 | public static void i(String tag, String msg) { 36 | if (BuildConfig.LOG_DEBUG) { 37 | android.util.Log.i(tag, msg); 38 | } 39 | } 40 | 41 | public static void i(String tag, String msg, Throwable tr) { 42 | if (BuildConfig.LOG_DEBUG) { 43 | android.util.Log.i(tag, msg, tr); 44 | } 45 | } 46 | 47 | public static void w(String tag, String msg, Throwable tr) { 48 | if (BuildConfig.LOG_DEBUG) { 49 | android.util.Log.w(tag, msg, tr); 50 | } 51 | } 52 | 53 | public static void w(String tag, Throwable tr) { 54 | if (BuildConfig.LOG_DEBUG) { 55 | android.util.Log.w(tag, tr); 56 | } 57 | } 58 | 59 | public static void e(String tag, String msg, Throwable tr) { 60 | if (BuildConfig.LOG_DEBUG) { 61 | android.util.Log.e(tag, msg, tr); 62 | } 63 | } 64 | 65 | public static void e(String tag, String msg) { 66 | if (BuildConfig.LOG_DEBUG) { 67 | android.util.Log.e(tag, msg); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/model/BaseModel.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.model; 2 | 3 | import android.os.Parcel; 4 | import android.os.Parcelable; 5 | 6 | import com.google.gson.Gson; 7 | 8 | /** 9 | * Author: ZhuWenWu 10 | * Version V1.0 11 | * Date: 14-11-22 14:45 12 | * Description: Model 基类 13 | * Modification History: 14 | * Date Author Version Description 15 | * ----------------------------------------------------------------------------------- 16 | * 14-11-22 ZhuWenWu 1.0 1.0 17 | * Why & What is modified: 18 | */ 19 | public class BaseModel implements Parcelable { 20 | public String toJson() { 21 | return new Gson().toJson(this); 22 | } 23 | 24 | @Override 25 | public int describeContents() { 26 | return 0; 27 | } 28 | 29 | @Override 30 | public void writeToParcel(Parcel dest, int flags) { 31 | } 32 | 33 | public BaseModel() { 34 | } 35 | 36 | private BaseModel(Parcel in) { 37 | } 38 | 39 | public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { 40 | public BaseModel createFromParcel(Parcel source) { 41 | return new BaseModel(source); 42 | } 43 | 44 | public BaseModel[] newArray(int size) { 45 | return new BaseModel[size]; 46 | } 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/network/AppNetworkInfo.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.network; 2 | 3 | import android.content.Context; 4 | import android.net.ConnectivityManager; 5 | import android.net.NetworkInfo; 6 | 7 | /** 8 | * Author: ZhuWenWu 9 | * Version V1.0 10 | * Date: 14-11-22 13:27 11 | * Description:手机网络资源工具类 12 | * Modification History: 13 | * Date Author Version Description 14 | * ----------------------------------------------------------------------------------- 15 | * 14-11-22 ZhuWenWu 1.0 1.0 16 | * Why & What is modified: 17 | */ 18 | public class AppNetworkInfo { 19 | /** 20 | * 网络是否可用 21 | * 22 | * @param context 上下文 23 | * @return true 可用 false 不可用 24 | */ 25 | public static boolean isNetworkAvailable(Context context) { 26 | if (context != null) { 27 | ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 28 | NetworkInfo[] info = mgr.getAllNetworkInfo(); 29 | if (info != null) { 30 | for (NetworkInfo anInfo : info) { 31 | if (anInfo.getState() == NetworkInfo.State.CONNECTED) { 32 | return true; 33 | } 34 | } 35 | } 36 | } 37 | return false; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/network/callback/HttpBaseCallBack.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.network.callback; 2 | 3 | import com.ithooks.android.xreap.log.LogUtils; 4 | 5 | import retrofit.Callback; 6 | import retrofit.RetrofitError; 7 | import retrofit.client.Response; 8 | 9 | /** 10 | * Author: ZhuWenWu 11 | * Version V1.0 12 | * Date: 14-11-22 14:55 13 | * Description: Http 数据请求 CallBack 14 | * Modification History: 15 | * Date Author Version Description 16 | * ----------------------------------------------------------------------------------- 17 | * 14-11-22 ZhuWenWu 1.0 1.0 18 | * Why & What is modified: 19 | */ 20 | public class HttpBaseCallBack implements Callback { 21 | protected String TAG = HttpBaseCallBack.class.getSimpleName(); 22 | 23 | @Override 24 | public void success(T data, Response response) { 25 | LogUtils.d(TAG, "success--> url = " + response.getUrl()); 26 | } 27 | 28 | @Override 29 | public void failure(RetrofitError retrofitError) { 30 | LogUtils.e(TAG, "failure--> url = " + retrofitError.getUrl()); 31 | retrofitError.printStackTrace(); 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/network/callback/UiDisplayListener.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.network.callback; 2 | 3 | import retrofit.RetrofitError; 4 | 5 | /** 6 | * Author: ZhuWenWu 7 | * Version V1.0 8 | * Date: 14-11-22 15:06 9 | * Description: HTTP 请求刷新UI回调接口 10 | * Modification History: 11 | * Date Author Version Description 12 | * ----------------------------------------------------------------------------------- 13 | * 14-11-22 ZhuWenWu 1.0 1.0 14 | * Why & What is modified: 15 | */ 16 | public interface UiDisplayListener { 17 | /** 18 | * HTTP请求成功回调 19 | * 20 | * @param data GSON解析之后的数据model 21 | */ 22 | public void onSuccessDisplay(T data); 23 | 24 | /** 25 | * HTTP请求失败回调 26 | */ 27 | public void onFailDisplay(RetrofitError retrofitError); 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/network/controller/BaseHttpController.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.network.controller; 2 | 3 | import com.ithooks.android.xreap.app.AppApplication; 4 | import com.ithooks.android.xreap.network.AppNetworkInfo; 5 | import com.ithooks.android.xreap.network.callback.UiDisplayListener; 6 | 7 | /** 8 | * Author: ZhuWenWu 9 | * Version V1.0 10 | * Date: 14-11-22 13:28 11 | * Description:网络请求控制类父类 12 | * Modification History: 13 | * Date Author Version Description 14 | * ----------------------------------------------------------------------------------- 15 | * 14-11-22 ZhuWenWu 1.0 1.0 16 | * Why & What is modified: 17 | */ 18 | public abstract class BaseHttpController { 19 | protected UiDisplayListener uiDisplayListener; 20 | 21 | public BaseHttpController() { 22 | } 23 | 24 | public BaseHttpController(UiDisplayListener uiDisplayListener) { 25 | this.uiDisplayListener = uiDisplayListener; 26 | } 27 | 28 | public void setUiDisplayListener(UiDisplayListener uiDisplayListener) { 29 | this.uiDisplayListener = uiDisplayListener; 30 | } 31 | 32 | public void loadData() { 33 | if (AppNetworkInfo.isNetworkAvailable(AppApplication.getContext())) {//没有网络时直接调用失败接口 34 | getNetData(); 35 | } else { 36 | if (uiDisplayListener != null) { 37 | uiDisplayListener.onFailDisplay(null); 38 | } 39 | } 40 | } 41 | 42 | /** 43 | * 获取网络数据 44 | */ 45 | protected abstract void getNetData(); 46 | } 47 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/network/http/AppApiService.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.network.http; 2 | 3 | /** 4 | * Author: ZhuWenWu 5 | * Version V1.0 6 | * Date: 14-11-22 14:39 7 | * Description: Retrofit 注解API接口 8 | * Modification History: 9 | * Date Author Version Description 10 | * ----------------------------------------------------------------------------------- 11 | * 14-11-22 ZhuWenWu 1.0 1.0 12 | * Why & What is modified: 13 | */ 14 | public interface AppApiService { 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/ui/HomeActivity.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.ui; 2 | 3 | import android.app.Fragment; 4 | import android.os.Bundle; 5 | import android.view.LayoutInflater; 6 | import android.view.Menu; 7 | import android.view.MenuItem; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.ithooks.android.xreap.R; 12 | import com.ithooks.android.xreap.base.BaseActionBarActivity; 13 | 14 | 15 | public class HomeActivity extends BaseActionBarActivity { 16 | 17 | @Override 18 | protected void onCreate(Bundle savedInstanceState) { 19 | super.onCreate(savedInstanceState); 20 | setContentView(R.layout.activity_home); 21 | if (savedInstanceState == null) { 22 | getFragmentManager().beginTransaction() 23 | .add(R.id.container, new PlaceholderFragment()) 24 | .commit(); 25 | } 26 | } 27 | 28 | 29 | @Override 30 | public boolean onCreateOptionsMenu(Menu menu) { 31 | // Inflate the menu; this adds items to the action bar if it is present. 32 | getMenuInflater().inflate(R.menu.menu_home, menu); 33 | return true; 34 | } 35 | 36 | @Override 37 | public boolean onOptionsItemSelected(MenuItem item) { 38 | // Handle action bar item clicks here. The action bar will 39 | // automatically handle clicks on the Home/Up button, so long 40 | // as you specify a parent activity in AndroidManifest.xml. 41 | int id = item.getItemId(); 42 | 43 | //noinspection SimplifiableIfStatement 44 | if (id == R.id.action_settings) { 45 | return true; 46 | } 47 | 48 | return super.onOptionsItemSelected(item); 49 | } 50 | 51 | /** 52 | * A placeholder fragment containing a simple view. 53 | */ 54 | public static class PlaceholderFragment extends Fragment { 55 | 56 | public PlaceholderFragment() { 57 | } 58 | 59 | @Override 60 | public View onCreateView(LayoutInflater inflater, ViewGroup container, 61 | Bundle savedInstanceState) { 62 | View rootView = inflater.inflate(R.layout.fragment_home, container, false); 63 | return rootView; 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/utils/Md5EncryptionHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | 6 | /** 7 | * Author: ZhuWenWu 8 | * Version V1.0 9 | * Date: 14-11-22 22:48 10 | * Description: MD5加密工具类 11 | * Modification History: 12 | * Date Author Version Description 13 | * ----------------------------------------------------------------------------------- 14 | * 14-11-22 ZhuWenWu 1.0 1.0 15 | * Why & What is modified: 16 | */ 17 | public class Md5EncryptionHelper { 18 | /** 19 | * 获取MD5字符串 20 | * @param content 需要转换的字符串 21 | * @return String 22 | */ 23 | public static String getMD5(String content) { 24 | try { 25 | MessageDigest digest = MessageDigest.getInstance("MD5"); 26 | digest.update(content.getBytes()); 27 | return getHashString(digest); 28 | 29 | } catch (NoSuchAlgorithmException e) { 30 | e.printStackTrace(); 31 | } 32 | return null; 33 | } 34 | 35 | private static String getHashString(MessageDigest digest) { 36 | StringBuilder builder = new StringBuilder(); 37 | for (byte b : digest.digest()) { 38 | builder.append(Integer.toHexString((b >> 4) & 0xf)); 39 | builder.append(Integer.toHexString(b & 0xf)); 40 | } 41 | return builder.toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/utils/SharedPreferencesHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.utils; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | import android.graphics.Bitmap; 6 | import android.graphics.BitmapFactory; 7 | import android.os.Environment; 8 | import android.preference.PreferenceManager; 9 | import android.text.TextUtils; 10 | import android.util.Log; 11 | 12 | import java.io.File; 13 | import java.io.FileOutputStream; 14 | import java.io.IOException; 15 | import java.io.OutputStream; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.Map; 19 | 20 | /** 21 | * Author: ZhuWenWu 22 | * Version V1.0 23 | * Date: 14-11-22 14:14 24 | * Description: SharedPreferences 帮助类 25 | * Modification History: 26 | * Date Author Version Description 27 | * ----------------------------------------------------------------------------------- 28 | * 14-11-22 ZhuWenWu 1.0 1.0 29 | * Why & What is modified: 30 | */ 31 | public class SharedPreferencesHelper { 32 | private static SharedPreferences sPreferences = null; 33 | private String DEFAULT_APP_IMAGE_DATA_DIRECTORY; 34 | public static String lastImagePath = ""; 35 | 36 | private SharedPreferencesHelper() { 37 | } 38 | 39 | private static class SharedPreferencesHelperHolder { 40 | private static SharedPreferencesHelper appSharedPreferencesHelper = new SharedPreferencesHelper(); 41 | } 42 | 43 | public static SharedPreferencesHelper getInstance() { 44 | return SharedPreferencesHelperHolder.appSharedPreferencesHelper; 45 | } 46 | 47 | public void Builder(Context context) { 48 | if (sPreferences == null) { 49 | sPreferences = PreferenceManager.getDefaultSharedPreferences(context); 50 | } 51 | } 52 | 53 | public Bitmap getImage(String path) { 54 | Bitmap theGottenBitmap = null; 55 | try { 56 | theGottenBitmap = BitmapFactory.decodeFile(path); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | return theGottenBitmap; 61 | } 62 | 63 | /** 64 | * Returns the String path of the last image that was saved with this Object 65 | *

66 | */ 67 | public String getSavedImagePath() { 68 | return lastImagePath; 69 | } 70 | 71 | /** 72 | * Returns the String path of the last image that was saved with this FullPath 73 | * 74 | * @param theFolder String 75 | * the theFolder - the folder path dir you want to save it to e.g 76 | * "DropBox/WorkImages" 77 | * @param theImageName String 78 | * the theImageName - the name you want to assign to the image file e.g 79 | * "MeAtlunch.png" 80 | */ 81 | public String putImagePNG(String theFolder, String theImageName, 82 | Bitmap theBitmap) { 83 | this.DEFAULT_APP_IMAGE_DATA_DIRECTORY = theFolder; 84 | String mFullPath = setupFolderPath(theImageName); 85 | saveBitmapPNG(mFullPath, theBitmap); 86 | lastImagePath = mFullPath; 87 | return mFullPath; 88 | } 89 | 90 | private String setupFolderPath(String imageName) { 91 | File filePath = Environment.getExternalStorageDirectory(); 92 | File mFolder = new File(filePath, DEFAULT_APP_IMAGE_DATA_DIRECTORY); 93 | if (!mFolder.exists()) { 94 | if (!mFolder.mkdirs()) { 95 | Log.e("While creating save path", 96 | "Default Save Path Creation Error"); 97 | } 98 | } 99 | return mFolder.getPath() + '/' + imageName; 100 | } 101 | 102 | private boolean saveBitmapPNG(String strFileName, Bitmap bitmap) { 103 | if (strFileName == null || bitmap == null) 104 | return false; 105 | boolean bSuccess1 = false; 106 | boolean bSuccess2; 107 | boolean bSuccess3; 108 | File saveFile = new File(strFileName); 109 | 110 | if (saveFile.exists()) { 111 | if (!saveFile.delete()) 112 | return false; 113 | } 114 | 115 | try { 116 | bSuccess1 = saveFile.createNewFile(); 117 | } catch (IOException e1) { 118 | e1.printStackTrace(); 119 | } 120 | 121 | OutputStream out = null; 122 | try { 123 | out = new FileOutputStream(saveFile); 124 | bSuccess2 = bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); 125 | } catch (Exception e) { 126 | e.printStackTrace(); 127 | bSuccess2 = false; 128 | } 129 | try { 130 | if (out != null) { 131 | out.flush(); 132 | out.close(); 133 | bSuccess3 = true; 134 | } else 135 | bSuccess3 = false; 136 | 137 | } catch (IOException e) { 138 | e.printStackTrace(); 139 | bSuccess3 = false; 140 | } finally { 141 | if (out != null) { 142 | try { 143 | out.close(); 144 | } catch (IOException e) { 145 | e.printStackTrace(); 146 | } 147 | } 148 | } 149 | 150 | return (bSuccess1 && bSuccess2 && bSuccess3); 151 | } 152 | 153 | public int getInt(String key) { 154 | return sPreferences.getInt(key, 0); 155 | } 156 | 157 | public long getLong(String key) { 158 | return sPreferences.getLong(key, 0l); 159 | } 160 | 161 | public String getString(String key) { 162 | return sPreferences.getString(key, ""); 163 | } 164 | 165 | public String getString(String key, String defaultValue) { 166 | return sPreferences.getString(key, defaultValue); 167 | } 168 | 169 | public double getDouble(String key) { 170 | String number = getString(key); 171 | try { 172 | return Double.parseDouble(number); 173 | } catch (NumberFormatException e) { 174 | return 0; 175 | } 176 | } 177 | 178 | public void putInt(String key, int value) { 179 | SharedPreferences.Editor editor = sPreferences.edit(); 180 | editor.putInt(key, value); 181 | editor.apply(); 182 | } 183 | 184 | public void putLong(String key, long value) { 185 | SharedPreferences.Editor editor = sPreferences.edit(); 186 | editor.putLong(key, value); 187 | editor.apply(); 188 | } 189 | 190 | public void putDouble(String key, double value) { 191 | putString(key, String.valueOf(value)); 192 | } 193 | 194 | public void putString(String key, String value) { 195 | 196 | SharedPreferences.Editor editor = sPreferences.edit(); 197 | editor.putString(key, value); 198 | editor.apply(); 199 | } 200 | 201 | public void putList(String key, ArrayList array) { 202 | 203 | SharedPreferences.Editor editor = sPreferences.edit(); 204 | String[] lists = array.toArray(new String[array.size()]); 205 | // the comma like character used below is not a comma it is the SINGLE 206 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for 207 | // seprating the items in the list 208 | editor.putString(key, TextUtils.join("‚‗‚", lists)); 209 | editor.apply(); 210 | } 211 | 212 | public ArrayList getList(String key) { 213 | // the comma like character used below is not a comma it is the SINGLE 214 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for 215 | // seprating the items in the list 216 | String[] lists = TextUtils.split(sPreferences.getString(key, ""), "‚‗‚"); 217 | return new ArrayList(Arrays.asList(lists)); 218 | } 219 | 220 | public void putListInt(String key, ArrayList array, 221 | Context context) { 222 | SharedPreferences.Editor editor = sPreferences.edit(); 223 | Integer[] lists = array.toArray(new Integer[array.size()]); 224 | // the comma like character used below is not a comma it is the SINGLE 225 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for 226 | // seprating the items in the list 227 | editor.putString(key, TextUtils.join("‚‗‚", lists)); 228 | editor.apply(); 229 | } 230 | 231 | public ArrayList getListInt(String key, 232 | Context context) { 233 | // the comma like character used below is not a comma it is the SINGLE 234 | // LOW-9 QUOTATION MARK unicode 201A and unicode 2017 they are used for 235 | // seprating the items in the list 236 | String[] mylist = TextUtils.split(sPreferences.getString(key, ""), "‚‗‚"); 237 | ArrayList gottenlist = new ArrayList(Arrays.asList(mylist)); 238 | ArrayList gottenlist2 = new ArrayList(); 239 | for (String data : gottenlist) { 240 | gottenlist2.add(Integer.parseInt(data)); 241 | } 242 | 243 | return gottenlist2; 244 | } 245 | 246 | public void putListBoolean(String key, ArrayList marray) { 247 | ArrayList origList = new ArrayList(); 248 | for (Boolean b : marray) { 249 | if (b) { 250 | origList.add("true"); 251 | } else { 252 | origList.add("false"); 253 | } 254 | } 255 | putList(key, origList); 256 | } 257 | 258 | public ArrayList getListBoolean(String key) { 259 | ArrayList origList = getList(key); 260 | ArrayList mBools = new ArrayList(); 261 | for (String b : origList) { 262 | if (b.equals("true")) { 263 | mBools.add(true); 264 | } else { 265 | mBools.add(false); 266 | } 267 | } 268 | return mBools; 269 | } 270 | 271 | public void putBoolean(String key, boolean value) { 272 | SharedPreferences.Editor editor = sPreferences.edit(); 273 | editor.putBoolean(key, value); 274 | editor.apply(); 275 | } 276 | 277 | public boolean getBoolean(String key) { 278 | return sPreferences.getBoolean(key, false); 279 | } 280 | 281 | public boolean getBoolean(String key, boolean defaultValue) { 282 | return sPreferences.getBoolean(key, defaultValue); 283 | } 284 | 285 | public void putFloat(String key, float value) { 286 | SharedPreferences.Editor editor = sPreferences.edit(); 287 | editor.putFloat(key, value); 288 | editor.apply(); 289 | } 290 | 291 | public float getFloat(String key) { 292 | return sPreferences.getFloat(key, 0f); 293 | } 294 | 295 | public void remove(String key) { 296 | SharedPreferences.Editor editor = sPreferences.edit(); 297 | editor.remove(key); 298 | editor.apply(); 299 | } 300 | 301 | public void clear() { 302 | SharedPreferences.Editor editor = sPreferences.edit(); 303 | editor.clear(); 304 | editor.apply(); 305 | } 306 | 307 | public Map getAll() { 308 | return sPreferences.getAll(); 309 | } 310 | 311 | public void registerOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) { 312 | sPreferences.registerOnSharedPreferenceChangeListener(listener); 313 | } 314 | 315 | public void unregisterOnSharedPreferenceChangeListener(SharedPreferences.OnSharedPreferenceChangeListener listener) { 316 | sPreferences.unregisterOnSharedPreferenceChangeListener(listener); 317 | } 318 | } 319 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/utils/StringHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.utils; 2 | 3 | import android.widget.EditText; 4 | import android.widget.TextView; 5 | 6 | /** 7 | * Author: ZhuWenWu 8 | * Version V1.0 9 | * Date: 14-11-22 14:32 10 | * Description: 字符串帮助类 11 | * Modification History: 12 | * Date Author Version Description 13 | * ----------------------------------------------------------------------------------- 14 | * 14-11-22 ZhuWenWu 1.0 1.0 15 | * Why & What is modified: 16 | */ 17 | public class StringHelper { 18 | public static String getStr(String str) { 19 | return isEmpty(str) ? "" : str; 20 | } 21 | 22 | public static String getEditTextContent(EditText edt) { 23 | return edt.getText().toString().trim(); 24 | } 25 | 26 | public static boolean isEmpty(String str) { 27 | return str == null || str.equals("null") || str.equals(""); 28 | } 29 | 30 | public static boolean isEditTextEmpty(EditText edt) { 31 | return isEmpty(getEditTextContent(edt)); 32 | } 33 | 34 | public static boolean isPhoneEditTextEmpty(EditText edt) { 35 | return isEmpty(getEditTextContent(edt)) || getEditTextContent(edt).length() != 11; 36 | } 37 | 38 | public static boolean notEmpty(String str) { 39 | return !isEmpty(str); 40 | } 41 | 42 | public static String getTextViewContent(TextView tv) { 43 | return tv.getText().toString().trim(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/utils/ToastHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.utils; 2 | 3 | import android.app.Activity; 4 | import android.view.Gravity; 5 | 6 | import com.devspark.appmsg.AppMsg; 7 | 8 | /** 9 | * Author: ZhuWenWu 10 | * Version V1.0 11 | * Date: 14-11-22 14:34 12 | * Description: 弹出信息工具类 13 | * Modification History: 14 | * Date Author Version Description 15 | * ----------------------------------------------------------------------------------- 16 | * 14-11-22 ZhuWenWu 1.0 1.0 17 | * Why & What is modified: 18 | */ 19 | public class ToastHelper { 20 | public static void showInfo(Activity context, String msg) { 21 | AppMsg.makeText(context, msg, AppMsg.STYLE_INFO).show(); 22 | } 23 | 24 | public static void showInfo(Activity context, int resId) { 25 | AppMsg.makeText(context, resId, AppMsg.STYLE_INFO).show(); 26 | } 27 | 28 | public static void showBottomInfo(Activity context, String msg) { 29 | AppMsg.makeText(context, msg, AppMsg.STYLE_INFO).setLayoutGravity(Gravity.BOTTOM).show(); 30 | } 31 | 32 | public static void showBottomInfo(Activity context, int resId) { 33 | AppMsg.makeText(context, resId, AppMsg.STYLE_INFO).setLayoutGravity(Gravity.BOTTOM).show(); 34 | } 35 | 36 | public static void showAlert(Activity context, String msg) { 37 | AppMsg.makeText(context, msg, AppMsg.STYLE_ALERT).show(); 38 | } 39 | 40 | public static void showAlert(Activity context, int resId) { 41 | AppMsg.makeText(context, resId, AppMsg.STYLE_ALERT).show(); 42 | } 43 | 44 | public static void showBottomAlert(Activity context, String msg) { 45 | AppMsg.makeText(context, msg, AppMsg.STYLE_ALERT).setLayoutGravity(Gravity.BOTTOM).show(); 46 | } 47 | 48 | public static void showBottomAlert(Activity context, int resId) { 49 | AppMsg.makeText(context, resId, AppMsg.STYLE_ALERT).setLayoutGravity(Gravity.BOTTOM).show(); 50 | } 51 | 52 | public static void showConfirm(Activity context, String msg) { 53 | AppMsg.makeText(context, msg, AppMsg.STYLE_CONFIRM).show(); 54 | } 55 | 56 | public static void showConfirm(Activity context, int resId) { 57 | AppMsg.makeText(context, resId, AppMsg.STYLE_CONFIRM).show(); 58 | } 59 | 60 | public static void showBottomConfirm(Activity context, String msg) { 61 | AppMsg.makeText(context, msg, AppMsg.STYLE_CONFIRM).setLayoutGravity(Gravity.BOTTOM).show(); 62 | } 63 | 64 | public static void showBottomConfirm(Activity context, int resId) { 65 | AppMsg.makeText(context, resId, AppMsg.STYLE_CONFIRM).setLayoutGravity(Gravity.BOTTOM).show(); 66 | } 67 | 68 | 69 | public static void showMsg(Activity context, String msg, AppMsg.Style style) { 70 | AppMsg.makeText(context, msg, style).show(); 71 | } 72 | 73 | public static void showMsg(Activity context, int resId, AppMsg.Style style) { 74 | AppMsg.makeText(context, resId, style).show(); 75 | } 76 | 77 | public static void showMsg(Activity context, String msg, AppMsg.Style style, int gravity) { 78 | AppMsg.makeText(context, msg, style).setLayoutGravity(gravity).show(); 79 | } 80 | 81 | public static void showMsg(Activity context, int resId, AppMsg.Style style, int gravity) { 82 | AppMsg.makeText(context, resId, style).setLayoutGravity(gravity).show(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/utils/ViewHelper.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.utils; 2 | 3 | import android.view.View; 4 | 5 | /** 6 | * Author: ZhuWenWu 7 | * Version V1.0 8 | * Date: 14-11-22 14:35 9 | * Description: View 帮助类 10 | * Modification History: 11 | * Date Author Version Description 12 | * ----------------------------------------------------------------------------------- 13 | * 14-11-22 ZhuWenWu 1.0 1.0 14 | * Why & What is modified: 15 | */ 16 | public class ViewHelper { 17 | /** 18 | * 设置View 是否显示 19 | * 20 | * @param view 需要设置的View对象 21 | * @param isGone 是否隐藏 22 | * @param V 23 | * @return V 当前View 24 | */ 25 | public static V setGone(V view, boolean isGone) { 26 | if (view != null) { 27 | if (isGone) { 28 | if (View.GONE != view.getVisibility()) 29 | view.setVisibility(View.GONE); 30 | } else { 31 | if (View.VISIBLE != view.getVisibility()) 32 | view.setVisibility(View.VISIBLE); 33 | } 34 | } 35 | return view; 36 | } 37 | 38 | /** 39 | * 多个view隐藏或显示 40 | * 41 | * @param gone true 隐藏;false 显示 42 | * @param views 多个view对象 43 | */ 44 | public static void setViewsGone(boolean gone, View... views) { 45 | for (View view : views) { 46 | setGone(view, gone); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/view/FixedRecyclerView.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | 6 | import com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView; 7 | 8 | /** 9 | * Author: ZhuWenWu 10 | * Version V1.0 11 | * Date: 14-12-14 23:48 12 | * Description: fixed RecyclerView and SwipeRefreshLayout BUG 13 | * Modification History: 14 | * Date Author Version Description 15 | * ----------------------------------------------------------------------------------- 16 | * 14-12-14 ZhuWenWu 1.0 1.0 17 | * Why & What is modified: 18 | */ 19 | public class FixedRecyclerView extends ObservableRecyclerView { 20 | public FixedRecyclerView(Context context) { 21 | this(context, null); 22 | } 23 | 24 | public FixedRecyclerView(Context context, AttributeSet attrs) { 25 | this(context, attrs, 0); 26 | } 27 | 28 | public FixedRecyclerView(Context context, AttributeSet attrs, int defStyle) { 29 | super(context, attrs, defStyle); 30 | } 31 | 32 | @Override 33 | public boolean canScrollVertically(int direction) { 34 | if (direction < 1) { 35 | boolean original = super.canScrollVertically(direction); 36 | return !original && getChildAt(0) != null && getChildAt(0).getTop() < 0 || original; 37 | } 38 | return super.canScrollVertically(direction); 39 | } 40 | } -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/view/FullyExpandedListView.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.ListView; 6 | 7 | /** 8 | * Author: ZhuWenWu 9 | * Version V1.0 10 | * Date: 14-11-22 16:47 11 | * Description: 默认全部展开的ListView 12 | * Modification History: 13 | * Date Author Version Description 14 | * ----------------------------------------------------------------------------------- 15 | * 14-11-22 ZhuWenWu 1.0 1.0 16 | * Why & What is modified: 17 | */ 18 | public class FullyExpandedListView extends ListView { 19 | public FullyExpandedListView(Context context) { 20 | super(context); 21 | } 22 | 23 | public FullyExpandedListView(Context context, AttributeSet attrs) { 24 | super(context, attrs); 25 | } 26 | 27 | public FullyExpandedListView(Context context, AttributeSet attrs, int defStyle) { 28 | super(context, attrs, defStyle); 29 | } 30 | 31 | @Override 32 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 33 | int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 34 | super.onMeasure(widthMeasureSpec, expandSpec); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/view/PageListView.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.view; 2 | 3 | import android.content.Context; 4 | import android.util.AttributeSet; 5 | import android.widget.AbsListView; 6 | 7 | /** 8 | * Author: ZhuWenWu 9 | * Version V1.0 10 | * Date: 14-11-22 16:41 11 | * Description: 分页加载的自定义ListView 12 | * Modification History: 13 | * Date Author Version Description 14 | * ----------------------------------------------------------------------------------- 15 | * 14-11-22 ZhuWenWu 1.0 1.0 16 | * Why & What is modified: 17 | */ 18 | public class PageListView extends StatusListView implements AbsListView.OnScrollListener { 19 | private OnLoadNextListener mLoadNextListener; 20 | private boolean isLoadMoreEnable; 21 | private PageListViewState mStatus; 22 | 23 | public static enum PageListViewState { 24 | Idle, TheEnd, Loading 25 | } 26 | 27 | public PageListView(Context context) { 28 | this(context, null); 29 | } 30 | 31 | public PageListView(Context context, AttributeSet attrs) { 32 | this(context, attrs, 0); 33 | } 34 | 35 | public PageListView(Context context, AttributeSet attrs, int defStyle) { 36 | super(context, attrs, defStyle); 37 | setOnScrollListener(this); 38 | } 39 | 40 | public void setLoadMoreEnable(boolean isLoadMoreEnable) { 41 | this.isLoadMoreEnable = isLoadMoreEnable; 42 | } 43 | 44 | @Override 45 | public void onScrollStateChanged(AbsListView absListView, int scrollState) { 46 | 47 | } 48 | 49 | @Override 50 | public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) { 51 | if (mStatus == PageListViewState.Loading 52 | || mStatus == PageListViewState.TheEnd || !isLoadMoreEnable) { 53 | return; 54 | } 55 | 56 | if (firstVisibleItem + visibleItemCount >= totalItemCount 57 | && totalItemCount != 0 58 | && totalItemCount != getHeaderViewsCount() 59 | + getFooterViewsCount() && mLoadNextListener != null) { 60 | setState(PageListViewState.Loading); 61 | mLoadNextListener.onLoadNext(); 62 | } 63 | } 64 | 65 | public void setState(PageListViewState status) { 66 | mStatus = status; 67 | } 68 | 69 | public void setLoadNextListener(OnLoadNextListener listener) { 70 | mLoadNextListener = listener; 71 | } 72 | 73 | public interface OnLoadNextListener { 74 | public void onLoadNext(); 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/com/ithooks/android/xreap/view/StatusListView.java: -------------------------------------------------------------------------------- 1 | package com.ithooks.android.xreap.view; 2 | 3 | import android.content.Context; 4 | import android.content.res.TypedArray; 5 | import android.util.AttributeSet; 6 | import android.view.LayoutInflater; 7 | import android.view.View; 8 | import android.view.ViewGroup; 9 | import android.widget.AbsListView; 10 | import android.widget.Button; 11 | import android.widget.FrameLayout; 12 | import android.widget.ListView; 13 | import android.widget.TextView; 14 | 15 | import com.ithooks.android.xreap.R; 16 | 17 | /** 18 | * Author: ZhuWenWu 19 | * Version V1.0 20 | * Date: 14-11-22 16:41 21 | * Description: 不同状态的自定义ListView empty / loading / error 22 | * Modification History: 23 | * Date Author Version Description 24 | * ----------------------------------------------------------------------------------- 25 | * 14-11-22 ZhuWenWu 1.0 1.0 26 | * Why & What is modified: 27 | */ 28 | public class StatusListView extends ListView { 29 | private static final String VIEW_TAG = "tag"; 30 | private LayoutInflater mLayoutInflater; 31 | private View mLoadingView; 32 | private View mEmptyView; 33 | private View mErrorView; 34 | private TextView mEmptyMsgView; 35 | private Button mEmptyButton; 36 | private TextView mErrorMsgView; 37 | private Button mErrorButton; 38 | private boolean isInitViews = true; 39 | private boolean isInvalidateView; 40 | 41 | public StatusListView(Context context) { 42 | this(context, null); 43 | } 44 | 45 | public StatusListView(Context context, AttributeSet attrs) { 46 | this(context, attrs, 0); 47 | } 48 | 49 | public StatusListView(Context context, AttributeSet attrs, int defStyle) { 50 | super(context, attrs, defStyle); 51 | init(attrs); 52 | } 53 | 54 | private void init(AttributeSet attrs) { 55 | if (attrs != null) { 56 | //初始化状态View 57 | mLayoutInflater = LayoutInflater.from(getContext()); 58 | 59 | TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.StatusListView); 60 | 61 | int loadingViewResId = a.getResourceId(R.styleable.StatusListView_loadingView, 0); 62 | if (loadingViewResId > 0) { 63 | mLoadingView = mLayoutInflater.inflate(loadingViewResId, null); 64 | } 65 | 66 | int emptyViewResId = a.getResourceId(R.styleable.StatusListView_emptyView, 0); 67 | if (emptyViewResId > 0) { 68 | mEmptyView = mLayoutInflater.inflate(emptyViewResId, null); 69 | mEmptyMsgView = (TextView) mEmptyView.findViewById(R.id.tv_list_empty); 70 | mEmptyButton = (Button) mEmptyView.findViewById(R.id.btn_list_empty); 71 | } 72 | 73 | int errorViewResId = a.getResourceId(R.styleable.StatusListView_errorView, 0); 74 | if (errorViewResId > 0) { 75 | mErrorView = mLayoutInflater.inflate(errorViewResId, null); 76 | mErrorMsgView = (TextView) mErrorView.findViewById(R.id.tv_list_error); 77 | mErrorButton = (Button) mErrorView.findViewById(R.id.btn_list_error); 78 | } 79 | a.recycle(); 80 | } 81 | } 82 | 83 | public static class Builder { 84 | 85 | private Context mContext; 86 | private LayoutInflater mLayoutInflater; 87 | 88 | private View mLoadingView; 89 | private View mEmptyView; 90 | private View mErrorView; 91 | 92 | public Builder(Context context) { 93 | if (context == null) { 94 | throw new IllegalArgumentException("Context must not be null."); 95 | } 96 | mContext = context; 97 | mLayoutInflater = LayoutInflater.from(context); 98 | } 99 | 100 | public Builder loadingView(View view) { 101 | if (view == null) { 102 | throw new IllegalArgumentException("View must not be null."); 103 | } 104 | mLoadingView = view; 105 | return this; 106 | } 107 | 108 | public Builder loadingView(View view, OnClickListener clickListener) { 109 | if (view == null) { 110 | throw new IllegalArgumentException("View must not be null."); 111 | } 112 | mLoadingView = view; 113 | mLoadingView.setOnClickListener(clickListener); 114 | return this; 115 | } 116 | 117 | public Builder loadingView(int resId) { 118 | if (resId <= 0) { 119 | throw new IllegalArgumentException("View resource id must be greater than 0."); 120 | } 121 | mLoadingView = mLayoutInflater.inflate(resId, null); 122 | return this; 123 | } 124 | 125 | public Builder emptyView(View view) { 126 | if (view == null) { 127 | throw new IllegalArgumentException("View must not be null."); 128 | } 129 | mEmptyView = view; 130 | return this; 131 | } 132 | 133 | public Builder emptyView(View view, OnClickListener clickListener) { 134 | if (view == null) { 135 | throw new IllegalArgumentException("View must not be null."); 136 | } 137 | mEmptyView = view; 138 | mEmptyView.setOnClickListener(clickListener); 139 | return this; 140 | } 141 | 142 | public Builder emptyView(int resId) { 143 | if (resId <= 0) { 144 | throw new IllegalArgumentException("View resource id must be greater than 0."); 145 | } 146 | mEmptyView = mLayoutInflater.inflate(resId, null); 147 | return this; 148 | } 149 | 150 | public Builder errorView(View view) { 151 | if (view == null) { 152 | throw new IllegalArgumentException("View must not be null."); 153 | } 154 | mErrorView = view; 155 | return this; 156 | } 157 | 158 | public Builder errorView(View view, OnClickListener clickListener) { 159 | if (view == null) { 160 | throw new IllegalArgumentException("View must not be null."); 161 | } 162 | mErrorView = view; 163 | mErrorView.setOnClickListener(clickListener); 164 | return this; 165 | } 166 | 167 | public Builder errorView(int resId) { 168 | if (resId <= 0) { 169 | throw new IllegalArgumentException("View resource id must be greater than 0."); 170 | } 171 | mErrorView = mLayoutInflater.inflate(resId, null); 172 | return this; 173 | } 174 | 175 | public StatusListView build() { 176 | return new StatusListView(mContext); 177 | } 178 | } 179 | 180 | //================================================================================ 181 | // Getters 182 | //================================================================================ 183 | 184 | public View getLoadingView() { 185 | return mLoadingView; 186 | } 187 | 188 | @Override 189 | public View getEmptyView() { 190 | return mEmptyView; 191 | } 192 | 193 | public View getErrorView() { 194 | return mErrorView; 195 | } 196 | 197 | public TextView getEmptyTextView() { 198 | return mEmptyMsgView; 199 | } 200 | 201 | public TextView getErrorTextView() { 202 | return mErrorMsgView; 203 | } 204 | //================================================================================ 205 | // Setters 206 | //================================================================================ 207 | 208 | public void setLoadingView(View view) { 209 | setLoadingView(view, false); 210 | } 211 | 212 | public void setLoadingView(View view, boolean invalidateView) { 213 | if (view == null) { 214 | throw new IllegalArgumentException("View must not be null."); 215 | } 216 | mLoadingView = view; 217 | isInvalidateView = invalidateView; 218 | } 219 | 220 | public void setLoadingView(int resId) { 221 | setLoadingView(resId, false); 222 | } 223 | 224 | public void setLoadingView(int resId, boolean invalidateView) { 225 | if (resId <= 0) { 226 | throw new IllegalArgumentException("View resource id must be greater than 0."); 227 | } 228 | mLoadingView = mLayoutInflater.inflate(resId, null); 229 | isInvalidateView = invalidateView; 230 | } 231 | 232 | public void setLoadingView(View view, OnClickListener clickListener) { 233 | setLoadingView(view, clickListener, false); 234 | } 235 | 236 | public void setLoadingView(View view, OnClickListener clickListener, boolean invalidateView) { 237 | if (view == null) { 238 | throw new IllegalArgumentException("View must not be null."); 239 | } 240 | mLoadingView = view; 241 | mLoadingView.setOnClickListener(clickListener); 242 | isInvalidateView = invalidateView; 243 | } 244 | 245 | public void setLoadingView(int resId, OnClickListener clickListener) { 246 | setLoadingView(resId, clickListener, false); 247 | } 248 | 249 | public void setLoadingView(int resId, OnClickListener clickListener, boolean invalidateView) { 250 | if (resId <= 0) { 251 | throw new IllegalArgumentException("View resource id must be greater than 0."); 252 | } 253 | mLoadingView = mLayoutInflater.inflate(resId, null); 254 | mLoadingView.setOnClickListener(clickListener); 255 | isInvalidateView = invalidateView; 256 | } 257 | 258 | public void setLoadingViewClickListener(OnClickListener clickListener) { 259 | if (mLoadingView == null) { 260 | throw new IllegalStateException("Loading view is null. Cannot set click listener."); 261 | } 262 | mLoadingView.setOnClickListener(clickListener); 263 | } 264 | 265 | @Override 266 | public void setEmptyView(View view) { 267 | setEmptyView(view, false); 268 | } 269 | 270 | public void setEmptyView(View view, boolean invalidateView) { 271 | if (view == null) { 272 | throw new IllegalArgumentException("View must not be null."); 273 | } 274 | mEmptyView = view; 275 | isInvalidateView = invalidateView; 276 | } 277 | 278 | public void setEmptyView(int resId) { 279 | setEmptyView(resId, false); 280 | } 281 | 282 | public void setEmptyView(int resId, boolean invalidateView) { 283 | if (resId <= 0) { 284 | throw new IllegalArgumentException("View resource id must be greater than 0."); 285 | } 286 | mEmptyView = mLayoutInflater.inflate(resId, null); 287 | isInvalidateView = invalidateView; 288 | } 289 | 290 | public void setEmptyView(View view, OnClickListener clickListener) { 291 | setEmptyView(view, clickListener, false); 292 | } 293 | 294 | public void setEmptyView(View view, OnClickListener clickListener, boolean invalidateView) { 295 | if (view == null) { 296 | throw new IllegalArgumentException("View must not be null."); 297 | } 298 | mEmptyView = view; 299 | mEmptyView.setOnClickListener(clickListener); 300 | isInvalidateView = invalidateView; 301 | } 302 | 303 | public void setEmptyView(int resId, OnClickListener clickListener) { 304 | setEmptyView(resId, clickListener, false); 305 | } 306 | 307 | public void setEmptyView(int resId, OnClickListener clickListener, boolean invalidateView) { 308 | if (resId <= 0) { 309 | throw new IllegalArgumentException("View resource id must be greater than 0."); 310 | } 311 | mEmptyView = mLayoutInflater.inflate(resId, null); 312 | mEmptyView.setOnClickListener(clickListener); 313 | isInvalidateView = invalidateView; 314 | } 315 | 316 | public void setEmptyViewClickListener(OnClickListener clickListener) { 317 | if (mEmptyView == null) { 318 | throw new IllegalStateException("Empty view is null. Cannot set click listener."); 319 | } 320 | mEmptyView.setOnClickListener(clickListener); 321 | } 322 | 323 | public void setErrorView(View view) { 324 | setErrorView(view, false); 325 | } 326 | 327 | public void setErrorView(View view, boolean invalidateView) { 328 | if (view == null) { 329 | throw new IllegalArgumentException("View must not be null."); 330 | } 331 | mErrorView = view; 332 | isInvalidateView = invalidateView; 333 | } 334 | 335 | public void setErrorView(int resId) { 336 | setErrorView(resId, false); 337 | } 338 | 339 | public void setErrorView(int resId, boolean invalidateView) { 340 | if (resId <= 0) { 341 | throw new IllegalArgumentException("View resource id must be greater than 0."); 342 | } 343 | mErrorView = mLayoutInflater.inflate(resId, null); 344 | isInvalidateView = invalidateView; 345 | } 346 | 347 | public void setErrorView(View view, OnClickListener clickListener) { 348 | setErrorView(view, clickListener, false); 349 | } 350 | 351 | public void setErrorView(View view, OnClickListener clickListener, boolean invalidateView) { 352 | if (view == null) { 353 | throw new IllegalArgumentException("View must not be null."); 354 | } 355 | mErrorView = view; 356 | mErrorView.setOnClickListener(clickListener); 357 | isInvalidateView = invalidateView; 358 | } 359 | 360 | public void setErrorView(int resId, OnClickListener clickListener) { 361 | setErrorView(resId, clickListener, false); 362 | } 363 | 364 | public void setErrorView(int resId, OnClickListener clickListener, boolean invalidateView) { 365 | if (resId <= 0) { 366 | throw new IllegalArgumentException("View resource id must be greater than 0."); 367 | } 368 | mErrorView = mLayoutInflater.inflate(resId, null); 369 | mErrorView.setOnClickListener(clickListener); 370 | isInvalidateView = invalidateView; 371 | } 372 | 373 | public void setErrorViewClickListener(OnClickListener clickListener) { 374 | if (mErrorView == null) { 375 | throw new IllegalStateException("Error view is null. Cannot set click listener."); 376 | } 377 | mErrorView.setOnClickListener(clickListener); 378 | } 379 | 380 | //================================================================================ 381 | // State Handling 382 | //================================================================================ 383 | 384 | public static enum State { 385 | LOADING, 386 | EMPTY, 387 | ERROR 388 | } 389 | 390 | public void showLoadingView() { 391 | showView(State.LOADING); 392 | } 393 | 394 | public void showEmptyView() { 395 | showView(State.EMPTY); 396 | } 397 | 398 | public void showErrorView() { 399 | showView(State.ERROR); 400 | } 401 | 402 | public void showView(State state) { 403 | if (isInitViews || isInvalidateView) { 404 | initViews(); 405 | isInitViews = isInvalidateView = false; 406 | } 407 | 408 | boolean showLoadingView = false; 409 | boolean showEmptyView = false; 410 | boolean showErrorView = false; 411 | 412 | switch (state) { 413 | case LOADING: 414 | showLoadingView = true; 415 | break; 416 | case EMPTY: 417 | showEmptyView = true; 418 | break; 419 | case ERROR: 420 | showErrorView = true; 421 | break; 422 | } 423 | 424 | if (mLoadingView != null) { 425 | mLoadingView.setVisibility(showLoadingView ? View.VISIBLE : View.GONE); 426 | } 427 | 428 | if (mEmptyView != null) { 429 | mEmptyView.setVisibility(showEmptyView ? View.VISIBLE : View.GONE); 430 | } 431 | 432 | if (mErrorView != null) { 433 | mErrorView.setVisibility(showErrorView ? View.VISIBLE : View.GONE); 434 | } 435 | } 436 | 437 | private void initViews() { 438 | ViewGroup parent = (ViewGroup) getParent(); 439 | if (parent == null) { 440 | throw new IllegalStateException(getClass().getSimpleName() + " is not attached to parent view."); 441 | } 442 | 443 | ViewGroup container = getContainerView(parent); 444 | container.removeAllViews(); 445 | 446 | parent.removeView(container); 447 | parent.addView(container); 448 | 449 | if (mLoadingView != null) { 450 | container.addView(mLoadingView); 451 | } 452 | 453 | if (mEmptyView != null) { 454 | container.addView(mEmptyView); 455 | } 456 | 457 | if (mErrorView != null) { 458 | container.addView(mErrorView); 459 | } 460 | 461 | super.setEmptyView(container); 462 | } 463 | 464 | private ViewGroup getContainerView(ViewGroup parent) { 465 | ViewGroup container = findContainerView(parent); 466 | if (container == null) { 467 | container = createContainerView(); 468 | } 469 | return container; 470 | } 471 | 472 | private ViewGroup findContainerView(ViewGroup parent) { 473 | return (ViewGroup) parent.findViewWithTag(VIEW_TAG); 474 | } 475 | 476 | private ViewGroup createContainerView() { 477 | AbsListView.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 478 | FrameLayout container = new FrameLayout(getContext()); 479 | container.setTag(VIEW_TAG); 480 | container.setLayoutParams(lp); 481 | return container; 482 | } 483 | 484 | public void setEmptyViewMsg(String msg) { 485 | if (mEmptyMsgView != null) { 486 | mEmptyMsgView.setText(msg); 487 | } 488 | } 489 | 490 | public void setEmptyViewMsg(int resId) { 491 | if (mEmptyMsgView != null) { 492 | mEmptyMsgView.setText(resId); 493 | } 494 | } 495 | 496 | public void setErrorViewMsg(String msg) { 497 | if (mErrorMsgView != null) { 498 | mErrorMsgView.setText(msg); 499 | } 500 | } 501 | 502 | public void setErrorViewMsg(int resId) { 503 | if (mErrorMsgView != null) { 504 | mErrorMsgView.setText(resId); 505 | } 506 | } 507 | 508 | public void setEmptyButtonListener(OnClickListener listener) { 509 | if (mEmptyButton != null) { 510 | mEmptyButton.setOnClickListener(listener); 511 | } 512 | } 513 | 514 | public void setErrorButtonListener(OnClickListener listener) { 515 | if (mErrorButton != null) { 516 | mErrorButton.setOnClickListener(listener); 517 | } 518 | } 519 | 520 | } 521 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Frank-Zhu/AppCodeArchitecture/bf6a192f2bfc3354c83e55aa44b7af07e6e553bb/app/src/main/res/drawable-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_fragment_base.xml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_home.xml: -------------------------------------------------------------------------------- 1 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_home.xml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_pull_to_refresh_base_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/layout/fragment_recycle_refresh_base.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/include_empty_view.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 22 | 23 |