├── LICENSE ├── README.md ├── app.apk ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── cn │ │ └── javayuan │ │ └── diary │ │ ├── activity │ │ ├── AddDiaryActivity.java │ │ ├── ClassifyActivity.java │ │ ├── ImagesActivity.java │ │ ├── LoginActivity.java │ │ ├── MainActivity.java │ │ └── SettingActivity.java │ │ ├── adapter │ │ └── DiaryListAdapter.java │ │ ├── bean │ │ ├── DiaryBean.java │ │ └── UserBean.java │ │ └── utils │ │ ├── AppUtil.java │ │ ├── NetWorkUtil.java │ │ └── ScrollingCalendarBehavior.java │ └── res │ ├── drawable │ ├── bg_edit_text_no.xml │ ├── ic_arrow_drop_down.xml │ ├── ic_create.xml │ ├── ic_default_image.png │ ├── ic_info_black_24dp.xml │ ├── ic_menu_classify.xml │ ├── ic_menu_feedback.xml │ ├── ic_menu_gallery.xml │ ├── ic_menu_index.xml │ ├── ic_menu_manage.xml │ ├── ic_notifications_black_24dp.xml │ ├── ic_search.xml │ ├── ic_sync_black_24dp.xml │ ├── ic_toolbar_classify.xml │ ├── ic_toolbar_syn.xml │ ├── img.png │ ├── list_content_back.xml │ └── side_nav_bar.xml │ ├── layout │ ├── activity_add_diary.xml │ ├── activity_classify.xml │ ├── activity_images.xml │ ├── activity_login.xml │ ├── activity_main.xml │ ├── activity_setting.xml │ ├── app_bar_add_diary.xml │ ├── app_bar_images.xml │ ├── app_bar_login.xml │ ├── app_bar_main.xml │ ├── content_add_diary.xml │ ├── content_classify.xml │ ├── content_images.xml │ ├── content_login.xml │ ├── content_main.xml │ ├── content_setting.xml │ ├── list_classify.xml │ ├── list_images.xml │ ├── list_main.xml │ ├── list_setting.xml │ └── nav_header_main.xml │ ├── menu │ ├── activity_add_diary_menu.xml │ ├── activity_main_drawer.xml │ └── activity_main_menu.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## 一本日记安卓端 2 | 课程设计项目,采用Google Material Design 设计风格,Android Studio 作为开发工具,后端使用PHP通过json 进行数据交互。 3 | 4 | APP下载地址:[一本日记APP](https://raw.githubusercontent.com/yuan1/diary/master/app.apk) 5 | 6 | PHP后端链接:[https://github.com/pengshang1995/Daily](https://github.com/pengshang1995/Daily) 7 | 8 | 开源组件:[BGAPhotoPicker-Android](https://github.com/bingoogolapple/BGAPhotoPicker-Android)、[CompactCalendarViewToolbar](https://github.com/kleisauke/CompactCalendarViewToolbar) 9 | 、[easy-okhttp](http://git.oschina.net/mzllon/easy-okhttp)、[easypermissions](https://github.com/googlesamples/easypermissions)、[Glide](https://github.com/bumptech/glide) 10 | 感谢。 11 | 12 | 如有问题请联系limingyuan1996@gmail.com 13 | 14 | -------------------------------------------------------------------------------- /app.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuan1/diary/3c058f21ef0845e0e3db7030fc441c0d25040a3d/app.apk -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 25 5 | buildToolsVersion '25.0.2' 6 | defaultConfig { 7 | applicationId "cn.javayuan.diary" 8 | minSdkVersion 15 9 | targetSdkVersion 25 10 | versionCode 1 11 | versionName "1.0.1" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | vectorDrawables.useSupportLibrary = true 14 | } 15 | buildTypes { 16 | release { 17 | minifyEnabled false 18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 19 | } 20 | } 21 | } 22 | 23 | dependencies { 24 | compile fileTree(include: ['*.jar'], dir: 'libs') 25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 26 | exclude group: 'com.android.support', module: 'support-annotations' 27 | }) 28 | compile 'com.android.support:appcompat-v7:25.3.1' 29 | compile 'com.android.support:design:25.3.1' 30 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 31 | compile 'com.android.support:support-v4:25.3.1' 32 | compile 'com.android.support:recyclerview-v7:25.3.1' 33 | compile 'com.github.sundeepk:compact-calendar-view:1.9.2-beta' 34 | compile 'cn.bingoogolapple:bga-adapter:1.1.5@aar' 35 | compile 'cn.bingoogolapple:bga-photopicker:1.2.1@aar' 36 | compile 'com.github.bumptech.glide:glide:3.7.0' 37 | compile 'pub.devrel:easypermissions:0.4.2' 38 | compile 'com.mzlion:easy-okhttp:1.0.7-beta' 39 | compile 'com.android.support:support-vector-drawable:25.3.1' 40 | testCompile 'junit:junit:4.12' 41 | } 42 | -------------------------------------------------------------------------------- /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/lmy/Library/Android/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 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 18 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 32 | 36 | 40 | 44 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/activity/AddDiaryActivity.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.activity; 2 | 3 | import android.Manifest; 4 | import android.app.ProgressDialog; 5 | import android.content.DialogInterface; 6 | import android.content.Intent; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.os.Environment; 10 | import android.support.annotation.NonNull; 11 | import android.support.v7.app.AlertDialog; 12 | import android.support.v7.app.AppCompatActivity; 13 | import android.support.v7.widget.Toolbar; 14 | import android.text.TextUtils; 15 | import android.util.Log; 16 | import android.view.Menu; 17 | import android.view.MenuItem; 18 | import android.view.View; 19 | import android.widget.EditText; 20 | import android.widget.TextView; 21 | import android.widget.Toast; 22 | 23 | import com.mzlion.core.lang.StringUtils; 24 | import com.mzlion.easyokhttp.HttpClient; 25 | 26 | import org.json.JSONException; 27 | import org.json.JSONObject; 28 | 29 | import java.io.File; 30 | import java.io.IOException; 31 | import java.text.SimpleDateFormat; 32 | import java.util.ArrayList; 33 | import java.util.Date; 34 | import java.util.List; 35 | import java.util.Locale; 36 | 37 | import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity; 38 | import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity; 39 | import cn.bingoogolapple.photopicker.widget.BGASortableNinePhotoLayout; 40 | import cn.javayuan.diary.R; 41 | import cn.javayuan.diary.bean.DiaryBean; 42 | import cn.javayuan.diary.utils.AppUtil; 43 | import okhttp3.MediaType; 44 | import okhttp3.MultipartBody; 45 | import okhttp3.OkHttpClient; 46 | import okhttp3.Request; 47 | import okhttp3.RequestBody; 48 | import okhttp3.Response; 49 | import pub.devrel.easypermissions.AfterPermissionGranted; 50 | import pub.devrel.easypermissions.EasyPermissions; 51 | 52 | public class AddDiaryActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, BGASortableNinePhotoLayout.Delegate{ 53 | private static final int REQUEST_CODE_PERMISSION_PHOTO_PICKER = 1; 54 | private static final int REQUEST_CODE_PHOTO_PREVIEW = 2; 55 | private static final int REQUEST_CODE_CHOOSE_PHOTO = 1; 56 | 57 | private final String[] mWtItems = {"晴","阴","多云","雨","雪","霾","雾","未知"}; 58 | private static int WEATHER_SEL =0; 59 | //设置日历控件格式 60 | private SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd EE", Locale.CHINESE); 61 | private SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm", Locale.CHINESE); 62 | 63 | private TextView mTvWt, mTvDateTitle,mTvTimeTitle; 64 | //加载弹窗 65 | private ProgressDialog mProgressDialog; 66 | private final String IMAGE_UPLOAD_URL=AppUtil.URL+"/Daily/upload"; 67 | private final String GET_DIARY_URL=AppUtil.URL+"/Daily/selectDaily"; 68 | private final String DEAL_DIARY_URL=AppUtil.URL+"/Daily/dealDaily"; 69 | private EditText mEdtDiaryContent; 70 | private static int EDIT_ID=0; 71 | public static final MediaType MEDIA_TYPE_IMAGE 72 | = MediaType.parse("image/png; charset=utf-8"); 73 | 74 | private ArrayList LIST_NOW_IMAGE_URL =new ArrayList<>(); 75 | 76 | /** 77 | * 拖拽排序九宫格控件 78 | */ 79 | private BGASortableNinePhotoLayout mPhotosSnpl; 80 | @Override 81 | protected void onCreate(Bundle savedInstanceState) { 82 | super.onCreate(savedInstanceState); 83 | setContentView(R.layout.activity_add_diary); 84 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_add_diary); 85 | setSupportActionBar(toolbar); 86 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 87 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 88 | @Override 89 | public void onClick(View v) { 90 | alertDialog(); 91 | } 92 | }); 93 | mProgressDialog = ProgressDialog.show(this, null, "正在加载,请稍候...", true, false); 94 | mProgressDialog.dismiss(); 95 | mTvWt= (TextView) findViewById(R.id.add_diary_wt); 96 | mTvWt.setOnClickListener(new View.OnClickListener() { 97 | @Override 98 | public void onClick(View v) { 99 | new AlertDialog.Builder(AddDiaryActivity.this).setTitle("选择天气").setSingleChoiceItems( 100 | mWtItems, WEATHER_SEL, 101 | new DialogInterface.OnClickListener() { 102 | public void onClick(DialogInterface dialog, int which) { 103 | WEATHER_SEL =which; 104 | mTvWt.setText(mWtItems[which]); 105 | dialog.dismiss(); 106 | } 107 | }).setNegativeButton("取消", null).show(); 108 | 109 | } 110 | }); 111 | mEdtDiaryContent= (EditText) findViewById(R.id.add_diary_text); 112 | mTvDateTitle= (TextView) findViewById(R.id.add_diary_date_title); 113 | mTvDateTitle.setText(dateFormat.format(new Date())); 114 | mTvTimeTitle= (TextView) findViewById(R.id.add_diary_date_sub_title); 115 | mTvTimeTitle.setText(timeFormat.format(new Date())); 116 | mPhotosSnpl = (BGASortableNinePhotoLayout) findViewById(R.id.snpl_moment_add_photos); 117 | mPhotosSnpl.setDelegate(this); 118 | Intent intent=getIntent(); 119 | Bundle bundle=intent.getExtras(); 120 | if(bundle!=null){ 121 | EDIT_ID=bundle.getInt("diaryId"); 122 | }else { 123 | EDIT_ID=0; 124 | } 125 | //编辑状态 126 | if(EDIT_ID!=0){ 127 | mProgressDialog.show(); 128 | new GetDiaryAsyncTask().execute(EDIT_ID); 129 | } 130 | 131 | } 132 | 133 | 134 | 135 | /** 136 | * 显示提示框 137 | */ 138 | private void alertDialog(){ 139 | AlertDialog.Builder builder = new AlertDialog.Builder(AddDiaryActivity.this); 140 | builder.setTitle("提示"); 141 | builder.setMessage("确认放弃编辑?"); 142 | builder.setPositiveButton("保存", new DialogInterface.OnClickListener() { 143 | public void onClick(DialogInterface dialog, int whichButton) { 144 | saveDiary(); 145 | } 146 | }); 147 | 148 | builder.setNeutralButton("取消", new DialogInterface.OnClickListener() { 149 | public void onClick(DialogInterface dialog, int whichButton) { 150 | dialog.dismiss(); 151 | } 152 | }); 153 | 154 | builder.setNegativeButton("放弃", new DialogInterface.OnClickListener() { 155 | public void onClick(DialogInterface dialog, int whichButton) { 156 | setResult(RESULT_OK); 157 | finish(); 158 | } 159 | }); 160 | builder.create().show(); 161 | } 162 | 163 | /** 164 | * 保存操作 165 | */ 166 | private void saveDiary() { 167 | if(TextUtils.isEmpty(mEdtDiaryContent.getText())){ 168 | Toast.makeText(AddDiaryActivity.this,"请输入内容",Toast.LENGTH_LONG).show(); 169 | }else { 170 | mProgressDialog.show(); 171 | new SaveDiaryAsyncTask().execute(); 172 | } 173 | 174 | } 175 | 176 | @Override 177 | public void onBackPressed() { 178 | alertDialog(); 179 | } 180 | 181 | @Override 182 | public boolean onCreateOptionsMenu(Menu menu) { 183 | // Inflate the menu; this adds items to the action bar if it is present. 184 | getMenuInflater().inflate(R.menu.activity_add_diary_menu, menu); 185 | return true; 186 | } 187 | 188 | @Override 189 | public boolean onOptionsItemSelected(MenuItem item) { 190 | int id = item.getItemId(); 191 | if (id == R.id.add_diary_action_dis) { 192 | finish(); 193 | }else if(id==R.id.add_diary_action_save){ 194 | saveDiary(); 195 | }else if(id==R.id.add_diary_action_classify){ 196 | alertClassifyDialog(); 197 | } 198 | return super.onOptionsItemSelected(item); 199 | } 200 | 201 | /** 202 | * 分类提示框 203 | */ 204 | private void alertClassifyDialog() { 205 | new AlertDialog.Builder(AddDiaryActivity.this).setTitle("选择分类").setSingleChoiceItems( 206 | MainActivity.mClassifyItems, MainActivity.CLASSIFY_SEL, 207 | new DialogInterface.OnClickListener() { 208 | public void onClick(DialogInterface dialog, int which) { 209 | MainActivity.CLASSIFY_SEL =which; 210 | dialog.dismiss(); 211 | } 212 | }).setNegativeButton("取消", null).show(); 213 | } 214 | 215 | 216 | @Override 217 | public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList models) { 218 | choicePhotoWrapper(); 219 | } 220 | 221 | @Override 222 | public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList models) { 223 | LIST_NOW_IMAGE_URL.remove(position); 224 | mPhotosSnpl.removeItem(position); 225 | } 226 | 227 | @Override 228 | public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList models) { 229 | startActivityForResult(BGAPhotoPickerPreviewActivity.newIntent(this, mPhotosSnpl.getMaxItemCount(), models, models, position, false), REQUEST_CODE_PHOTO_PREVIEW); 230 | } 231 | @AfterPermissionGranted(REQUEST_CODE_PERMISSION_PHOTO_PICKER) 232 | private void choicePhotoWrapper() { 233 | String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA}; 234 | if (EasyPermissions.hasPermissions(this, perms)) { 235 | // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话就没有拍照功能 236 | File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "Diary"); 237 | startActivityForResult(BGAPhotoPickerActivity.newIntent(this, takePhotoDir, mPhotosSnpl.getMaxItemCount() - mPhotosSnpl.getItemCount(), null, false), REQUEST_CODE_CHOOSE_PHOTO); 238 | } else { 239 | EasyPermissions.requestPermissions(this, "图片选择需要以下权限:\n\n1.访问设备上的照片\n\n2.拍照", REQUEST_CODE_PERMISSION_PHOTO_PICKER, perms); 240 | } 241 | } 242 | 243 | @Override 244 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 245 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 246 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 247 | } 248 | 249 | @Override 250 | public void onPermissionsGranted(int requestCode, List perms) { 251 | } 252 | 253 | @Override 254 | public void onPermissionsDenied(int requestCode, List perms) { 255 | if (requestCode == REQUEST_CODE_PERMISSION_PHOTO_PICKER) { 256 | Toast.makeText(this, "您拒绝了「图片选择」所需要的相关权限!", Toast.LENGTH_SHORT).show(); 257 | } 258 | } 259 | 260 | @Override 261 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 262 | super.onActivityResult(requestCode, resultCode, data); 263 | if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_CHOOSE_PHOTO) { 264 | uploadImages(BGAPhotoPickerActivity.getSelectedImages(data)); 265 | mPhotosSnpl.addMoreData(BGAPhotoPickerActivity.getSelectedImages(data)); 266 | } else if (requestCode == REQUEST_CODE_PHOTO_PREVIEW) { 267 | mPhotosSnpl.setData(BGAPhotoPickerPreviewActivity.getSelectedImages(data)); 268 | } 269 | } 270 | 271 | private void uploadImages(ArrayList photos){ 272 | mProgressDialog.show(); 273 | for(String str:photos){ 274 | new UploadImageAsyncTask().execute(str); 275 | } 276 | } 277 | 278 | private DiaryBean getDiaryJsonDataById(int id){ 279 | String jsonString = HttpClient 280 | .post(GET_DIARY_URL) 281 | .param("id",String.valueOf(id)) 282 | .execute() 283 | .asString(); 284 | if(!StringUtils.isEmpty(jsonString)){ 285 | try { 286 | JSONObject jsonObject=new JSONObject(jsonString); 287 | if(jsonObject.getInt("state")==0){ 288 | jsonObject=jsonObject.getJSONObject("data"); 289 | DiaryBean diaryBean=new DiaryBean(); 290 | diaryBean=AppUtil.convertJsonToDiaryBean(jsonObject); 291 | return diaryBean; 292 | } 293 | } catch (JSONException e) { 294 | e.printStackTrace(); 295 | } 296 | } 297 | return null; 298 | } 299 | private class GetDiaryAsyncTask extends AsyncTask{ 300 | @Override 301 | protected DiaryBean doInBackground(Integer... params) { 302 | return getDiaryJsonDataById(params[0]); 303 | } 304 | 305 | @Override 306 | protected void onPostExecute(DiaryBean diaryBean) { 307 | super.onPostExecute(diaryBean); 308 | if(diaryBean!=null){ 309 | mEdtDiaryContent.setText(diaryBean.getContent()); 310 | mEdtDiaryContent.setSelection(diaryBean.getContent().length()); 311 | mTvDateTitle.setText(diaryBean.getCreateDate()); 312 | mTvTimeTitle.setText(diaryBean.getCreateTime()); 313 | if(diaryBean.getImages()!=null&&diaryBean.getImages().length>0){ 314 | for (int i = 0; i < diaryBean.getImages().length; i++) { 315 | LIST_NOW_IMAGE_URL.add(diaryBean.getImages()[i]); 316 | mPhotosSnpl.addLastItem(AppUtil.IMAGE_URL+diaryBean.getImages()[i]); 317 | } 318 | } 319 | WEATHER_SEL =diaryBean.getWeather(); 320 | mTvWt.setText(mWtItems[diaryBean.getWeather()]); 321 | } 322 | mProgressDialog.dismiss(); 323 | 324 | } 325 | } 326 | 327 | private class UploadImageAsyncTask extends AsyncTask{ 328 | @Override 329 | protected String doInBackground(String... params) { 330 | File file= new File(params[0]); 331 | RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM) 332 | .addFormDataPart("image", file.getName(), RequestBody.create(MEDIA_TYPE_IMAGE, file)) 333 | .build(); 334 | //创建Request 335 | final Request request = new Request.Builder().url(IMAGE_UPLOAD_URL).post(requestBody).build(); 336 | OkHttpClient client = new OkHttpClient(); 337 | Response response = null; 338 | try { 339 | response = client.newCall(request).execute(); 340 | if (!response.isSuccessful()) throw new IOException("Unexpected code " + response); 341 | String jsonString =response.body().string(); 342 | if(!StringUtils.isEmpty(jsonString)){ 343 | try { 344 | JSONObject jsonObj=new JSONObject(jsonString); 345 | if(jsonObj.getInt("state")==0){ 346 | return jsonObj.getString("data"); 347 | } 348 | } catch (JSONException e) { 349 | e.printStackTrace(); 350 | } 351 | } 352 | } catch (IOException e) { 353 | e.printStackTrace(); 354 | } 355 | return null; 356 | } 357 | 358 | @Override 359 | protected void onPostExecute(String s) { 360 | super.onPostExecute(s); 361 | if(s!=null){ 362 | LIST_NOW_IMAGE_URL.add(s); 363 | } 364 | mProgressDialog.dismiss(); 365 | } 366 | } 367 | 368 | private class SaveDiaryAsyncTask extends AsyncTask{ 369 | @Override 370 | protected Boolean doInBackground(Void... params) { 371 | String images=""; 372 | for (int i = 0; i < LIST_NOW_IMAGE_URL.size(); i++) { 373 | images+=LIST_NOW_IMAGE_URL.get(i)+","; 374 | } 375 | String jsonString=HttpClient.post(DEAL_DIARY_URL) 376 | .param("id",String.valueOf(EDIT_ID)) 377 | .param("content",mEdtDiaryContent.getText().toString()) 378 | .param("images",images.length()>0?images.substring(0,images.length()-1):images) 379 | .param("createDate",mTvDateTitle.getText().toString()) 380 | .param("createTime",mTvTimeTitle.getText().toString()) 381 | .param("weather",String.valueOf(WEATHER_SEL)) 382 | .param("tag", MainActivity.mClassifyItems[MainActivity.CLASSIFY_SEL]) 383 | .execute().asString(); 384 | if(!StringUtils.isEmpty(jsonString)){ 385 | try { 386 | JSONObject jsonObject = new JSONObject(jsonString); 387 | if(jsonObject.getInt("state")==0){ 388 | return true; 389 | } 390 | } catch (JSONException e) { 391 | e.printStackTrace(); 392 | } 393 | } 394 | return false; 395 | } 396 | 397 | @Override 398 | protected void onPostExecute(Boolean aBoolean) { 399 | super.onPostExecute(aBoolean); 400 | mProgressDialog.dismiss(); 401 | if(aBoolean){ 402 | Toast.makeText(AddDiaryActivity.this,EDIT_ID==0?"添加成功!":"修改成功",Toast.LENGTH_LONG).show(); 403 | finish(); 404 | }else { 405 | Toast.makeText(AddDiaryActivity.this,EDIT_ID==0?"添加失败!":"修改失败",Toast.LENGTH_LONG).show(); 406 | } 407 | } 408 | } 409 | 410 | 411 | } 412 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/activity/ClassifyActivity.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.activity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.DialogInterface; 5 | import android.os.AsyncTask; 6 | import android.os.Bundle; 7 | import android.support.design.widget.FloatingActionButton; 8 | import android.support.design.widget.Snackbar; 9 | import android.support.v7.app.AlertDialog; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.support.v7.widget.Toolbar; 12 | import android.util.Log; 13 | import android.view.View; 14 | import android.widget.AdapterView; 15 | import android.widget.EditText; 16 | import android.widget.ListView; 17 | import android.widget.SimpleAdapter; 18 | import android.widget.TextView; 19 | import android.widget.Toast; 20 | 21 | import com.mzlion.core.lang.StringUtils; 22 | import com.mzlion.easyokhttp.HttpClient; 23 | 24 | import org.json.JSONArray; 25 | import org.json.JSONException; 26 | import org.json.JSONObject; 27 | 28 | import java.util.ArrayList; 29 | import java.util.HashMap; 30 | import java.util.List; 31 | import java.util.Map; 32 | 33 | import cn.javayuan.diary.R; 34 | import cn.javayuan.diary.utils.AppUtil; 35 | 36 | public class ClassifyActivity extends AppCompatActivity { 37 | private static final String CLASSIFY_LIST_URL = AppUtil.URL+"/Tag/tagList"; 38 | private static final String CLASSIFY_ADD_URL = AppUtil.URL+"/Tag/addTag"; 39 | private static final String CLASSIFY_DELETE_URL = AppUtil.URL+"/Tag/deleteTag"; 40 | private ListView mClassifyListView; 41 | private List> classifyList; 42 | //加载弹窗 43 | private ProgressDialog mProgressDialog; 44 | private TextView mTvAddClassify; 45 | @Override 46 | protected void onCreate(Bundle savedInstanceState) { 47 | super.onCreate(savedInstanceState); 48 | setContentView(R.layout.activity_classify); 49 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_classify); 50 | setSupportActionBar(toolbar); 51 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 52 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 53 | @Override 54 | public void onClick(View v) { 55 | finish(); 56 | } 57 | }); 58 | mProgressDialog = ProgressDialog.show(this, null, "正在加载,请稍候...", true, false); 59 | mProgressDialog.show(); 60 | mClassifyListView= (ListView) findViewById(R.id.classify_list); 61 | mClassifyListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 62 | @Override 63 | public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { 64 | final String name=classifyList.get(position).get("name").toString(); 65 | new AlertDialog.Builder(ClassifyActivity.this) 66 | .setTitle("提示") 67 | .setMessage("确认删除?") 68 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 69 | @Override 70 | public void onClick(DialogInterface dialog, int which) { 71 | mProgressDialog.show(); 72 | new DeleteClassifyAsyncTask().execute(name); 73 | } 74 | }) 75 | .setNegativeButton("取消", null) 76 | .show(); 77 | return true; 78 | } 79 | }); 80 | mTvAddClassify= (TextView) findViewById(R.id.classify_add); 81 | mTvAddClassify.setOnClickListener(new View.OnClickListener() { 82 | @Override 83 | public void onClick(View v) { 84 | final EditText mClassifyText = new EditText(ClassifyActivity.this); 85 | new AlertDialog.Builder(ClassifyActivity.this) 86 | .setTitle("添加分类") 87 | .setView(mClassifyText,80,80,80,0) 88 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 89 | @Override 90 | public void onClick(DialogInterface dialog, int which) { 91 | String input = mClassifyText.getText().toString(); 92 | if(!StringUtils.isEmpty(input)){ 93 | mProgressDialog.show(); 94 | new AddClassifyAsyncTask().execute(input); 95 | } 96 | } 97 | }) 98 | .setNegativeButton("取消", null) 99 | .show(); 100 | } 101 | }); 102 | new ClassifyAsyncTask().execute(); 103 | } 104 | 105 | private class ClassifyAsyncTask extends AsyncTask { 106 | @Override 107 | protected Boolean doInBackground(Void... params) { 108 | classifyList =new ArrayList<>(); 109 | String jsonString=HttpClient.post(CLASSIFY_LIST_URL) 110 | .execute().asString(); 111 | if(!StringUtils.isEmpty(jsonString)){ 112 | try { 113 | JSONObject jsonObj=new JSONObject(jsonString); 114 | if(jsonObj.getInt("state")==0){ 115 | JSONArray jsonArray=jsonObj.getJSONArray("data"); 116 | for (int i = 0; i map = new HashMap<>(); 118 | jsonObj=jsonArray.getJSONObject(i); 119 | map.put("name", jsonObj.getString("tag")); 120 | map.put("count", jsonObj.getString("count")+"篇"); 121 | classifyList.add(map); 122 | } 123 | return true; 124 | } 125 | } catch (JSONException e) { 126 | e.printStackTrace(); 127 | } 128 | } 129 | return false; 130 | } 131 | 132 | @Override 133 | protected void onPostExecute(Boolean aBoolean) { 134 | mProgressDialog.dismiss(); 135 | super.onPostExecute(aBoolean); 136 | if(aBoolean){ 137 | String[] strings = {"name","count"};//Map的key集合数组 138 | int[] ids = {R.id.classify_list_name,R.id.classify_list_count};//对应布局文件的id 139 | SimpleAdapter simpleAdapter = new SimpleAdapter(ClassifyActivity.this, 140 | classifyList, R.layout.list_classify, strings, ids); 141 | mClassifyListView.setAdapter(simpleAdapter);//绑定适配器 142 | } 143 | } 144 | } 145 | private class AddClassifyAsyncTask extends AsyncTask { 146 | @Override 147 | protected Boolean doInBackground(String... params) { 148 | String jsonString =HttpClient.post(CLASSIFY_ADD_URL) 149 | .param("tag",params[0]) 150 | .execute().asString(); 151 | if(!StringUtils.isEmpty(jsonString)){ 152 | try { 153 | JSONObject jsonObj=new JSONObject(jsonString); 154 | if(jsonObj.getInt("state")==0){ 155 | return true; 156 | } 157 | } catch (JSONException e) { 158 | e.printStackTrace(); 159 | } 160 | } 161 | return false; 162 | } 163 | 164 | @Override 165 | protected void onPostExecute(Boolean aBoolean) { 166 | mProgressDialog.dismiss(); 167 | super.onPostExecute(aBoolean); 168 | Toast.makeText(ClassifyActivity.this,aBoolean?"添加分类成功!":"添加失败,分类名称已存在?",Toast.LENGTH_LONG).show(); 169 | if(aBoolean){ 170 | mProgressDialog.show(); 171 | new ClassifyAsyncTask().execute(); 172 | } 173 | 174 | } 175 | } 176 | 177 | private class DeleteClassifyAsyncTask extends AsyncTask{ 178 | 179 | @Override 180 | protected Boolean doInBackground(String... params) { 181 | String jsonString =HttpClient.post(CLASSIFY_DELETE_URL) 182 | .param("tag",params[0]) 183 | .execute().asString(); 184 | if(!StringUtils.isEmpty(jsonString)){ 185 | try { 186 | JSONObject jsonObj=new JSONObject(jsonString); 187 | if(jsonObj.getInt("state")==0){ 188 | return true; 189 | } 190 | } catch (JSONException e) { 191 | e.printStackTrace(); 192 | } 193 | } 194 | return false; 195 | } 196 | 197 | @Override 198 | protected void onPostExecute(Boolean aBoolean) { 199 | super.onPostExecute(aBoolean); 200 | mProgressDialog.dismiss(); 201 | Toast.makeText(ClassifyActivity.this,aBoolean?"删除成功":"删除失败",Toast.LENGTH_LONG).show(); 202 | if(aBoolean){ 203 | mProgressDialog.show(); 204 | new ClassifyAsyncTask().execute(); 205 | } 206 | } 207 | } 208 | } 209 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/activity/ImagesActivity.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.activity; 2 | 3 | import android.Manifest; 4 | import android.app.ProgressDialog; 5 | import android.content.Intent; 6 | import android.os.AsyncTask; 7 | import android.os.Bundle; 8 | import android.os.Environment; 9 | import android.support.annotation.NonNull; 10 | import android.support.v7.app.AppCompatActivity; 11 | import android.support.v7.widget.LinearLayoutManager; 12 | import android.support.v7.widget.RecyclerView; 13 | import android.support.v7.widget.Toolbar; 14 | import android.view.View; 15 | import android.widget.TextView; 16 | import android.widget.Toast; 17 | 18 | import com.mzlion.core.lang.StringUtils; 19 | import com.mzlion.easyokhttp.HttpClient; 20 | 21 | import org.json.JSONArray; 22 | import org.json.JSONException; 23 | import org.json.JSONObject; 24 | 25 | import java.io.File; 26 | import java.util.ArrayList; 27 | import java.util.Arrays; 28 | import java.util.List; 29 | 30 | import cn.bingoogolapple.androidcommon.adapter.BGARecyclerViewAdapter; 31 | import cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper; 32 | import cn.bingoogolapple.photopicker.activity.BGAPhotoPreviewActivity; 33 | import cn.bingoogolapple.photopicker.imageloader.BGARVOnScrollListener; 34 | import cn.bingoogolapple.photopicker.widget.BGANinePhotoLayout; 35 | import cn.javayuan.diary.R; 36 | import cn.javayuan.diary.bean.DiaryBean; 37 | import cn.javayuan.diary.utils.AppUtil; 38 | import pub.devrel.easypermissions.AfterPermissionGranted; 39 | import pub.devrel.easypermissions.EasyPermissions; 40 | 41 | public class ImagesActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks, BGANinePhotoLayout.Delegate{ 42 | private static final int REQUEST_CODE_PERMISSION_PHOTO_PREVIEW = 1; 43 | private static final String IMAGE_URL = AppUtil.URL+"/Daily/imagesList"; 44 | private static final int REQUEST_CODE_ADD_MOMENT = 1; 45 | private RecyclerView mImagesRv; 46 | private ImagesAdapter mImagesAdapter; 47 | //加载弹窗 48 | private ProgressDialog mProgressDialog; 49 | private BGANinePhotoLayout mCurrentClickNpl; 50 | @Override 51 | protected void onCreate(Bundle savedInstanceState) { 52 | super.onCreate(savedInstanceState); 53 | setContentView(R.layout.activity_images); 54 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_images); 55 | setSupportActionBar(toolbar); 56 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 57 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 58 | @Override 59 | public void onClick(View v) { 60 | finish(); 61 | } 62 | }); 63 | setTitle("图库"); 64 | mProgressDialog = ProgressDialog.show(this, null, "正在加载,请稍候...", true, false); 65 | mProgressDialog.show(); 66 | mImagesRv = (RecyclerView) findViewById(R.id.list_images); 67 | mImagesAdapter = new ImagesAdapter(mImagesRv); 68 | mImagesRv.addOnScrollListener(new BGARVOnScrollListener(this)); 69 | mImagesRv.setLayoutManager(new LinearLayoutManager(this)); 70 | mImagesRv.setAdapter(mImagesAdapter); 71 | new ImagesAsyncTask().execute(); 72 | } 73 | @Override 74 | public void setTitle(CharSequence title) { 75 | TextView textView= (TextView) findViewById(R.id.toolbar_images_title); 76 | if(title!=null&&!title.equals("")){ 77 | textView.setText(title); 78 | } 79 | } 80 | @Override 81 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 82 | super.onActivityResult(requestCode, resultCode, data); 83 | if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_ADD_MOMENT) { 84 | mImagesRv.smoothScrollToPosition(0); 85 | } 86 | } 87 | /** 88 | * 图片预览,兼容6.0动态权限 89 | */ 90 | @AfterPermissionGranted(REQUEST_CODE_PERMISSION_PHOTO_PREVIEW) 91 | private void photoPreviewWrapper() { 92 | if (mCurrentClickNpl == null) { 93 | return; 94 | } 95 | 96 | // 保存图片的目录,改成你自己要保存图片的目录。如果不传递该参数的话就不会显示右上角的保存按钮 97 | File downloadDir = new File(Environment.getExternalStorageDirectory(), "Diary"); 98 | 99 | String[] perms = {Manifest.permission.WRITE_EXTERNAL_STORAGE}; 100 | if (EasyPermissions.hasPermissions(this, perms)) { 101 | if (mCurrentClickNpl.getItemCount() == 1) { 102 | // 预览单张图片 103 | 104 | startActivity(BGAPhotoPreviewActivity.newIntent(this, downloadDir, mCurrentClickNpl.getCurrentClickItem())); 105 | } else if (mCurrentClickNpl.getItemCount() > 1) { 106 | // 预览多张图片 107 | 108 | startActivity(BGAPhotoPreviewActivity.newIntent(this,downloadDir, mCurrentClickNpl.getData(), mCurrentClickNpl.getCurrentClickItemPosition())); 109 | } 110 | } else { 111 | EasyPermissions.requestPermissions(this, "图片预览需要以下权限:\n\n1.访问设备上的照片", REQUEST_CODE_PERMISSION_PHOTO_PREVIEW, perms); 112 | } 113 | } 114 | @Override 115 | public void onClickNinePhotoItem(BGANinePhotoLayout ninePhotoLayout, View view, int position, String model, List models) { 116 | mCurrentClickNpl = ninePhotoLayout; 117 | photoPreviewWrapper(); 118 | } 119 | 120 | 121 | @Override 122 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 123 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 124 | EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this); 125 | } 126 | 127 | @Override 128 | public void onPermissionsGranted(int requestCode, List perms) { 129 | } 130 | 131 | @Override 132 | public void onPermissionsDenied(int requestCode, List perms) { 133 | if (requestCode == REQUEST_CODE_PERMISSION_PHOTO_PREVIEW) { 134 | Toast.makeText(this, "您拒绝了「图片预览」所需要的相关权限!", Toast.LENGTH_SHORT).show(); 135 | } 136 | } 137 | 138 | private class ImagesAdapter extends BGARecyclerViewAdapter { 139 | 140 | public ImagesAdapter(RecyclerView recyclerView) { 141 | super(recyclerView, R.layout.list_images); 142 | } 143 | 144 | @Override 145 | protected void fillData(BGAViewHolderHelper helper, int position, DiaryBean model) { 146 | if(model.getImages()!=null){ 147 | helper.setText(R.id.list_images_date,model.getCreateDate()); 148 | BGANinePhotoLayout ninePhotoLayout = helper.getView(R.id.list_images_photos); 149 | ninePhotoLayout.setDelegate(ImagesActivity.this); 150 | ninePhotoLayout.setData(new ArrayList(Arrays.asList(model.getImages()))); 151 | } 152 | } 153 | } 154 | 155 | private class ImagesAsyncTask extends AsyncTask>{ 156 | @Override 157 | protected List doInBackground(Void... params) { 158 | String jsonString = HttpClient.post(IMAGE_URL).execute().asString(); 159 | if(!StringUtils.isEmpty(jsonString)){ 160 | try { 161 | JSONObject jsonObject=new JSONObject(jsonString); 162 | if(jsonObject.getInt("state")==0){ 163 | List diaryBeanList = new ArrayList<>(); 164 | JSONArray jsonArray=jsonObject.getJSONArray("data"); 165 | for (int i = 0; i diaryBeen) { 187 | super.onPostExecute(diaryBeen); 188 | mProgressDialog.dismiss(); 189 | if(diaryBeen!=null){ 190 | for (DiaryBean bean : diaryBeen) { 191 | if(bean.getImages()!=null){ 192 | String [] images=new String[bean.getImages().length]; 193 | for (int i = 0; i 登录 1->注册 39 | private int USER_LOGIN_TYPE=0; 40 | 41 | private final String REG_URL=AppUtil.URL+"/Login/region"; 42 | 43 | private final String LOGIN_URL=AppUtil.URL+"/Login/loginTest"; 44 | //登录任务 45 | private UserLoginTask mAuthTask = null; 46 | 47 | // UI 48 | private AutoCompleteTextView mEmailView; 49 | private EditText mPasswordView; 50 | private View mProgressView; 51 | private View mLoginFormView; 52 | private TextView mTvLoginSub; 53 | private Button mEmailSignInButton; 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_login); 58 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_login); 59 | setSupportActionBar(toolbar); 60 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 61 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View v) { 64 | finish(); 65 | } 66 | }); 67 | setTitle("日记登录"); 68 | // Set up the login form. 69 | mEmailView = (AutoCompleteTextView) findViewById(R.id.email); 70 | mPasswordView = (EditText) findViewById(R.id.password); 71 | mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() { 72 | @Override 73 | public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) { 74 | if (id == R.id.login || id == EditorInfo.IME_NULL) { 75 | attemptLogin(); 76 | return true; 77 | } 78 | return false; 79 | } 80 | }); 81 | mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button); 82 | mEmailSignInButton.setOnClickListener(new OnClickListener() { 83 | @Override 84 | public void onClick(View view) { 85 | attemptLogin(); 86 | } 87 | }); 88 | mTvLoginSub= (TextView) findViewById(R.id.toolbar_login_sub); 89 | mTvLoginSub.setOnClickListener(new OnClickListener() { 90 | @Override 91 | public void onClick(View v) { 92 | if(USER_LOGIN_TYPE==0){ 93 | setTitle("邮箱注册"); 94 | mEmailSignInButton.setText("注册"); 95 | mTvLoginSub.setText("已有账号"); 96 | USER_LOGIN_TYPE=1; 97 | }else { 98 | setTitle("日记登录"); 99 | mEmailSignInButton.setText("登录"); 100 | mTvLoginSub.setText("注册"); 101 | USER_LOGIN_TYPE=0; 102 | } 103 | } 104 | }); 105 | mLoginFormView = findViewById(R.id.login_form); 106 | mProgressView = findViewById(R.id.login_progress); 107 | } 108 | 109 | @Override 110 | public void setTitle(CharSequence title) { 111 | TextView textView= (TextView) findViewById(R.id.toolbar_login_title); 112 | if(title!=null&&!title.equals("")){ 113 | textView.setText(title); 114 | } 115 | } 116 | 117 | 118 | /** 119 | * 登录操作 120 | */ 121 | private void attemptLogin() { 122 | if (mAuthTask != null) { 123 | return; 124 | } 125 | 126 | // Reset errors. 127 | mEmailView.setError(null); 128 | mPasswordView.setError(null); 129 | 130 | // Store values at the time of the login attempt. 131 | String email = mEmailView.getText().toString(); 132 | String password = mPasswordView.getText().toString(); 133 | 134 | boolean cancel = false; 135 | View focusView = null; 136 | 137 | // Check for a valid password, if the user entered one. 138 | if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) { 139 | mPasswordView.setError(getString(R.string.error_invalid_password)); 140 | focusView = mPasswordView; 141 | cancel = true; 142 | } 143 | 144 | // Check for a valid email address. 145 | if (TextUtils.isEmpty(email)) { 146 | mEmailView.setError(getString(R.string.error_field_required)); 147 | focusView = mEmailView; 148 | cancel = true; 149 | } else if (!isEmailValid(email)) { 150 | mEmailView.setError(getString(R.string.error_invalid_email)); 151 | focusView = mEmailView; 152 | cancel = true; 153 | } 154 | 155 | if (cancel) { 156 | // There was an error; don't attempt login and focus the first 157 | // form field with an error. 158 | focusView.requestFocus(); 159 | } else { 160 | // Show a progress spinner, and kick off a background task to 161 | // perform the user login attempt. 162 | if(NetWorkUtil.isNetworkConnected(this)){ 163 | showProgress(true); 164 | mAuthTask = new UserLoginTask(email, password); 165 | mAuthTask.execute((Void) null); 166 | }else { 167 | Toast.makeText(this,"请检查您的网络连接",Toast.LENGTH_LONG).show(); 168 | } 169 | 170 | } 171 | } 172 | 173 | private boolean isEmailValid(String email) { 174 | return email.contains("@"); 175 | } 176 | 177 | private boolean isPasswordValid(String password) { 178 | return password.length() > 4; 179 | } 180 | 181 | /** 182 | * Shows the progress UI and hides the login form. 183 | */ 184 | @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2) 185 | private void showProgress(final boolean show) { 186 | int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime); 187 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); 188 | mLoginFormView.animate().setDuration(shortAnimTime).alpha( 189 | show ? 0 : 1).setListener(new AnimatorListenerAdapter() { 190 | @Override 191 | public void onAnimationEnd(Animator animation) { 192 | mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE); 193 | } 194 | }); 195 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); 196 | mProgressView.animate().setDuration(shortAnimTime).alpha( 197 | show ? 1 : 0).setListener(new AnimatorListenerAdapter() { 198 | @Override 199 | public void onAnimationEnd(Animator animation) { 200 | mProgressView.setVisibility(show ? View.VISIBLE : View.GONE); 201 | } 202 | }); 203 | } 204 | 205 | 206 | /** 207 | * Represents an asynchronous login/registration task used to authenticate 208 | * the user. 209 | */ 210 | private class UserLoginTask extends AsyncTask { 211 | 212 | private final String mEmail; 213 | private final String mPassword; 214 | 215 | private String token; 216 | UserLoginTask(String email, String password) { 217 | mEmail = email; 218 | mPassword = password; 219 | } 220 | 221 | @Override 222 | protected Boolean doInBackground(Void... params) { 223 | boolean val=false; 224 | try { 225 | String jsonString=HttpClient.post(USER_LOGIN_TYPE==0?LOGIN_URL:REG_URL) 226 | .param("username",mEmail) 227 | .param("password",mPassword) 228 | .execute().asString(); 229 | if(jsonString!=null){ 230 | JSONObject jsonObject=new JSONObject(jsonString); 231 | if(jsonObject.getInt("state")==0){ 232 | jsonObject=jsonObject.getJSONObject("data"); 233 | token=jsonObject.getString("token"); 234 | val=true; 235 | 236 | } 237 | } 238 | } catch (JSONException e) { 239 | e.printStackTrace(); 240 | } 241 | return val; 242 | } 243 | 244 | @Override 245 | protected void onPostExecute(final Boolean success) { 246 | mAuthTask = null; 247 | showProgress(false); 248 | if (success) { 249 | SharedPreferences sp=getSharedPreferences("Diary",MODE_PRIVATE); 250 | SharedPreferences.Editor editor=sp.edit(); 251 | editor.putString("token",token); 252 | editor.apply(); 253 | editor.commit(); 254 | Toast.makeText(LoginActivity.this,USER_LOGIN_TYPE==0?"登录成功":"注册成功!",Toast.LENGTH_LONG).show(); 255 | finish(); 256 | } else { 257 | if(USER_LOGIN_TYPE==0){ 258 | mPasswordView.setError(getString(R.string.error_incorrect_password)); 259 | mPasswordView.requestFocus(); 260 | }else { 261 | mEmailView.setError("用户名已存在"); 262 | mEmailView.requestFocus(); 263 | } 264 | } 265 | } 266 | 267 | @Override 268 | protected void onCancelled() { 269 | mAuthTask = null; 270 | showProgress(false); 271 | } 272 | } 273 | } 274 | 275 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/activity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.activity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.DialogInterface; 5 | import android.content.Intent; 6 | import android.content.SharedPreferences; 7 | import android.os.AsyncTask; 8 | import android.os.Bundle; 9 | import android.support.design.widget.AppBarLayout; 10 | import android.support.design.widget.FloatingActionButton; 11 | import android.support.design.widget.NavigationView; 12 | import android.support.v4.view.GravityCompat; 13 | import android.support.v4.view.ViewCompat; 14 | import android.support.v4.widget.DrawerLayout; 15 | import android.support.v7.app.ActionBarDrawerToggle; 16 | import android.support.v7.app.AlertDialog; 17 | import android.support.v7.app.AppCompatActivity; 18 | import android.support.v7.widget.Toolbar; 19 | import android.view.Menu; 20 | import android.view.MenuItem; 21 | import android.view.View; 22 | import android.widget.AdapterView; 23 | import android.widget.EditText; 24 | import android.widget.ImageView; 25 | import android.widget.ListView; 26 | import android.widget.RelativeLayout; 27 | import android.widget.TextView; 28 | import android.widget.Toast; 29 | 30 | import com.github.sundeepk.compactcalendarview.CompactCalendarView; 31 | import com.mzlion.core.lang.StringUtils; 32 | import com.mzlion.easyokhttp.HttpClient; 33 | 34 | import org.json.JSONArray; 35 | import org.json.JSONException; 36 | import org.json.JSONObject; 37 | 38 | import java.text.SimpleDateFormat; 39 | import java.util.ArrayList; 40 | import java.util.Date; 41 | import java.util.List; 42 | import java.util.Locale; 43 | import java.util.TimeZone; 44 | 45 | import cn.javayuan.diary.R; 46 | import cn.javayuan.diary.adapter.DiaryListAdapter; 47 | import cn.javayuan.diary.bean.DiaryBean; 48 | import cn.javayuan.diary.bean.UserBean; 49 | import cn.javayuan.diary.utils.AppUtil; 50 | import cn.javayuan.diary.utils.NetWorkUtil; 51 | 52 | public class MainActivity extends AppCompatActivity 53 | implements NavigationView.OnNavigationItemSelectedListener { 54 | //加载弹窗 55 | private ProgressDialog mProgressDialog; 56 | //app bar 57 | private AppBarLayout mAppBarLayout; 58 | 59 | public static String[] mClassifyItems = {"默认"}; 60 | 61 | public static int CLASSIFY_SEL =0; 62 | //设置日历控件格式 63 | private SimpleDateFormat dateFormat = new SimpleDateFormat("yy/MM/dd EE", Locale.CHINESE); 64 | 65 | private CompactCalendarView mCompactCalendarView; 66 | 67 | private ListView mListView; 68 | 69 | private static final String LIST_DIARY_URL = AppUtil.URL+"/Daily/dailyList"; 70 | private static final String DEL_DIARY_URL = AppUtil.URL+"/Daily/deleteDaily"; 71 | private static final String TOKEN_LOGIN_URL = AppUtil.URL+"/Login/tokenLogin"; 72 | private static final String USER_UPDATE_NAME_URL = AppUtil.URL+"/User/updateName"; 73 | private static final String USER_UPDATE_DESC_URL = AppUtil.URL+"/User/updateDesc"; 74 | private static final String CLASSIFY_LIST_URL = AppUtil.URL+"/Tag/tagList"; 75 | private boolean isExpanded = false; 76 | 77 | private static final int ADD = 0; 78 | private static final int EDIT = 1; 79 | private static final int LOGIN = 2; 80 | private static final int IMAGES=3; 81 | private static final int CLASSIFY=4; 82 | private static final int SETTING=5; 83 | private TextView mTvNavHeadName,mTvNavHeadDesc,mTvMainCount; 84 | 85 | //登录成功1 86 | public static int LOGIN_STATE=0; 87 | private DiaryListAdapter diaryListAdapter; 88 | 89 | //空为当天 90 | private static String NOW_DATE_TIME=""; 91 | 92 | public static int NOW_USER_ID=0; 93 | 94 | private static String COUNT_MAIN_STR; 95 | @Override 96 | protected void onCreate(Bundle savedInstanceState) { 97 | super.onCreate(savedInstanceState); 98 | setContentView(R.layout.activity_main); 99 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_main); 100 | setSupportActionBar(toolbar); 101 | //添加按钮 102 | FloatingActionButton diary_add = (FloatingActionButton) findViewById(R.id.diary_add); 103 | diary_add.setOnClickListener(new View.OnClickListener() { 104 | @Override 105 | public void onClick(View view) { 106 | Intent intent=new Intent(MainActivity.this,AddDiaryActivity.class); 107 | startActivityForResult(intent, ADD); 108 | } 109 | }); 110 | //设置一个progressdialog的加载弹窗 111 | mTvMainCount= (TextView) findViewById(R.id.main_count); 112 | mProgressDialog = ProgressDialog.show(this, null, "正在加载,请稍候...", true, false); 113 | mProgressDialog.show(); 114 | //ListView 设置 115 | mListView = (ListView) findViewById(R.id.content_list); 116 | mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 117 | @Override 118 | public void onItemClick(AdapterView parent, View view, int position, long id) { 119 | int diaryId=((DiaryBean)diaryListAdapter.getItem(position)).getId(); 120 | Intent intent=new Intent(MainActivity.this,AddDiaryActivity.class); 121 | Bundle bundle=new Bundle(); 122 | bundle.putInt("diaryId",diaryId); 123 | intent.putExtras(bundle); 124 | startActivityForResult(intent,EDIT); 125 | } 126 | }); 127 | mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { 128 | @Override 129 | public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { 130 | if(LOGIN_STATE==1){ 131 | final int diaryId=((DiaryBean)diaryListAdapter.getItem(position)).getId(); 132 | new AlertDialog.Builder(MainActivity.this) 133 | .setTitle("提示") 134 | .setMessage("确认删除?") 135 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 136 | @Override 137 | public void onClick(DialogInterface dialog, int which) { 138 | mProgressDialog.show(); 139 | new DeleteDiaryAsyncTask().execute(diaryId); 140 | } 141 | }) 142 | .setNegativeButton("取消", null) 143 | .show(); 144 | } 145 | return true; 146 | } 147 | }); 148 | 149 | //侧滑栏 150 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 151 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( 152 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); 153 | drawer.setDrawerListener(toggle); 154 | toggle.syncState(); 155 | 156 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view); 157 | navigationView.setNavigationItemSelectedListener(this); 158 | //获取nav head view 159 | View headView=navigationView.getHeaderView(0); 160 | mTvNavHeadName= (TextView) headView.findViewById(R.id.nav_header_name); 161 | mTvNavHeadName.setOnClickListener(new View.OnClickListener() { 162 | @Override 163 | public void onClick(View v) { 164 | if(LOGIN_STATE==1){ 165 | final EditText mNavHeadNameText = new EditText(MainActivity.this); 166 | new AlertDialog.Builder(MainActivity.this) 167 | .setTitle("修改昵称") 168 | .setView(mNavHeadNameText,80,80,80,0) 169 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 170 | @Override 171 | public void onClick(DialogInterface dialog, int which) { 172 | String inputName = mNavHeadNameText.getText().toString(); 173 | if(!StringUtils.isEmpty(inputName)){ 174 | new UpdateNameAsyncTask().execute(inputName); 175 | } 176 | } 177 | }) 178 | .setNegativeButton("取消", null) 179 | .show(); 180 | } 181 | } 182 | }); 183 | mTvNavHeadDesc= (TextView) headView.findViewById(R.id.nav_header_desc); 184 | mTvNavHeadDesc.setOnClickListener(new View.OnClickListener() { 185 | @Override 186 | public void onClick(View v) { 187 | if(LOGIN_STATE==1){ 188 | final EditText mNavHeadDescText = new EditText(MainActivity.this); 189 | new AlertDialog.Builder(MainActivity.this) 190 | .setTitle("修改简介") 191 | .setView(mNavHeadDescText,80,80,80,0) 192 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 193 | @Override 194 | public void onClick(DialogInterface dialog, int which) { 195 | String inputDesc = mNavHeadDescText.getText().toString(); 196 | if(!StringUtils.isEmpty(inputDesc)){ 197 | new UpdateDescAsyncTask().execute(inputDesc); 198 | } 199 | } 200 | }) 201 | .setNegativeButton("取消", null) 202 | .show(); 203 | } 204 | } 205 | }); 206 | //设置toolbar中的日历 207 | mAppBarLayout = (AppBarLayout) findViewById(R.id.app_bar_main); 208 | // 设置 CompactCalendarView 209 | mCompactCalendarView = (CompactCalendarView) findViewById(R.id.compactcalendar_view); 210 | final ImageView arrow = (ImageView) findViewById(R.id.date_picker_arrow); 211 | // 设置 English 212 | mCompactCalendarView.setLocale(TimeZone.getDefault(), Locale.ENGLISH); 213 | mCompactCalendarView.setShouldDrawDaysHeader(true); 214 | mCompactCalendarView.setListener(new CompactCalendarView.CompactCalendarViewListener() { 215 | @Override 216 | public void onDayClick(Date dateClicked) { 217 | NOW_DATE_TIME=dateFormat.format(dateClicked); 218 | setTitle(NOW_DATE_TIME); 219 | ViewCompat.animate(arrow).rotation(0).start(); 220 | mAppBarLayout.setExpanded(false, true); 221 | isExpanded = false; 222 | if(LOGIN_STATE==1){ 223 | mProgressDialog.show(); 224 | new DiaryAsyncTask().execute(); 225 | } 226 | 227 | } 228 | @Override 229 | public void onMonthScroll(Date firstDayOfNewMonth) { 230 | setTitle(dateFormat.format(firstDayOfNewMonth)); 231 | } 232 | }); 233 | //设置为当前日期 234 | setCurrentDate(new Date()); 235 | RelativeLayout datePickerButton = (RelativeLayout) findViewById(R.id.date_picker_button); 236 | datePickerButton.setOnClickListener(new View.OnClickListener() { 237 | @Override 238 | public void onClick(View v) { 239 | if (isExpanded) { 240 | ViewCompat.animate(arrow).rotation(0).start(); 241 | mAppBarLayout.setExpanded(false, true); 242 | isExpanded = false; 243 | } else { 244 | ViewCompat.animate(arrow).rotation(180).start(); 245 | mAppBarLayout.setExpanded(true, true); 246 | isExpanded = true; 247 | } 248 | } 249 | }); 250 | if(NetWorkUtil.isNetworkConnected(this)){ 251 | new AutoLoginSyncTask().execute(); 252 | }else { 253 | mProgressDialog.dismiss(); 254 | Toast.makeText(this,"请检查您的网络连接",Toast.LENGTH_LONG).show(); 255 | } 256 | } 257 | 258 | public void setCurrentDate(Date date) { 259 | setTitle(dateFormat.format(date)); 260 | if (mCompactCalendarView != null) { 261 | mCompactCalendarView.setCurrentDate(date); 262 | } 263 | 264 | } 265 | 266 | @Override 267 | public void setTitle(CharSequence title) { 268 | TextView datePickerTextView = (TextView) findViewById(R.id.date_picker_text_view); 269 | 270 | if (datePickerTextView != null) { 271 | datePickerTextView.setText(title); 272 | } 273 | } 274 | 275 | 276 | @Override 277 | public void onBackPressed() { 278 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); 279 | if (drawer.isDrawerOpen(GravityCompat.START)) { 280 | drawer.closeDrawer(GravityCompat.START); 281 | } else { 282 | super.onBackPressed(); 283 | } 284 | } 285 | 286 | @Override 287 | public boolean onCreateOptionsMenu(Menu menu) { 288 | // Inflate the menu; this adds items to the action bar if it is present. 289 | getMenuInflater().inflate(R.menu.activity_main_menu, menu); 290 | return true; 291 | } 292 | 293 | @Override 294 | public boolean onOptionsItemSelected(MenuItem item) { 295 | // Handle action bar item clicks here. The action bar will 296 | // automatically handle clicks on the Home/Up button, so long 297 | // as you specify a parent activity in AndroidManifest.xml. 298 | int id = item.getItemId(); 299 | 300 | //noinspection SimplifiableIfStatement 301 | if (id == R.id.main_toolbar_syn) { 302 | if(NetWorkUtil.isNetworkConnected(this)){ 303 | mProgressDialog.show(); 304 | new AutoLoginSyncTask().execute(); 305 | }else { 306 | Toast.makeText(this,"请检查您的网络连接",Toast.LENGTH_LONG).show(); 307 | } 308 | 309 | }else if(id==R.id.main_toolbar_classify){ 310 | alertClassifyDialog(); 311 | }else if(id==R.id.main_toolbar_about){ 312 | alertAbout(); 313 | } 314 | 315 | return super.onOptionsItemSelected(item); 316 | } 317 | /** 318 | * 分类提示框 319 | */ 320 | private void alertClassifyDialog() { 321 | new AlertDialog.Builder(MainActivity.this).setTitle("选择分类").setSingleChoiceItems( 322 | MainActivity.mClassifyItems, CLASSIFY_SEL, 323 | new DialogInterface.OnClickListener() { 324 | public void onClick(DialogInterface dialog, int which) { 325 | CLASSIFY_SEL =which; 326 | mProgressDialog.show(); 327 | dialog.dismiss(); 328 | new DiaryAsyncTask().execute(); 329 | } 330 | }) 331 | .setNeutralButton("编辑分类", new DialogInterface.OnClickListener() { 332 | @Override 333 | public void onClick(DialogInterface dialog, int which) { 334 | startActivityForResult(new Intent(MainActivity.this,ClassifyActivity.class),CLASSIFY); 335 | } 336 | }) 337 | .setNegativeButton("取消", null).show(); 338 | } 339 | 340 | @SuppressWarnings("StatementWithEmptyBody") 341 | @Override 342 | public boolean onNavigationItemSelected(MenuItem item) { 343 | // Handle navigation view item clicks here. 344 | int id = item.getItemId(); 345 | 346 | if (id == R.id.nav_index) { 347 | }else if(id==R.id.nav_gallery){ 348 | startActivityForResult(new Intent(MainActivity.this,ImagesActivity.class),IMAGES); 349 | }else if(id==R.id.nav_about){ 350 | alertAbout(); 351 | }else if(id==R.id.nav_classify){ 352 | startActivityForResult(new Intent(MainActivity.this,ClassifyActivity.class),CLASSIFY); 353 | }else if(id==R.id.nav_manager) { 354 | startActivityForResult(new Intent(MainActivity.this,SettingActivity.class),SETTING); 355 | } 356 | 357 | return true; 358 | } 359 | 360 | /** 361 | * 获取日记列表转换json数据 362 | * @return 363 | */ 364 | private List getDiaryListJSONData() { 365 | List list = new ArrayList<>(); 366 | try { 367 | String jsonString = HttpClient 368 | .post(LIST_DIARY_URL) 369 | .param("tag",mClassifyItems[CLASSIFY_SEL]) 370 | .param("date",NOW_DATE_TIME) 371 | .execute() 372 | .asString(); 373 | if(!StringUtils.isEmpty(jsonString)){ 374 | JSONObject jsonObject; 375 | jsonObject =new JSONObject(jsonString); 376 | if(jsonObject.getInt("state")==0){ 377 | JSONArray jsonArray=jsonObject.getJSONArray("data"); 378 | COUNT_MAIN_STR =jsonObject.getString("str"); 379 | for (int i=0;i{ 396 | @Override 397 | protected UserBean doInBackground(Void... params) { 398 | SharedPreferences sp =getSharedPreferences("Diary", MODE_PRIVATE); 399 | String token=sp.getString("token", "limingyuan"); 400 | if(!token.equals("limingyuan")){ 401 | try { 402 | String jsonString = HttpClient 403 | .post(TOKEN_LOGIN_URL) 404 | .param("token",token) 405 | .execute() 406 | .asString(); 407 | if(!StringUtils.isEmpty(jsonString)){ 408 | JSONObject jsonObject=new JSONObject(jsonString); 409 | if(jsonObject.getInt("state")==0){ 410 | jsonObject=jsonObject.getJSONObject("data"); 411 | UserBean userBean=new UserBean(); 412 | userBean.setId(jsonObject.getInt("id")); 413 | userBean.setName(jsonObject.getString("name")); 414 | userBean.setPassword(jsonObject.getString("password")); 415 | userBean.setDesc(jsonObject.getString("desc")); 416 | userBean.setToken(jsonObject.getString("token")); 417 | return userBean; 418 | } 419 | } 420 | } catch (JSONException e) { 421 | e.printStackTrace(); 422 | } 423 | } 424 | return null; 425 | } 426 | 427 | @Override 428 | protected void onPostExecute(UserBean userBean) { 429 | super.onPostExecute(userBean); 430 | String name="未设置昵称"; 431 | String desc="记录你的日子"; 432 | if(userBean!=null){ 433 | LOGIN_STATE=1; 434 | NOW_USER_ID=userBean.getId(); 435 | if(userBean.getName()!=null&&!userBean.getName().equals("")){ 436 | name=userBean.getName(); 437 | } 438 | if(userBean.getDesc()!=null&&!userBean.getDesc().equals("")){ 439 | desc=userBean.getDesc(); 440 | } 441 | Toast.makeText(MainActivity.this,"自动登录成功!",Toast.LENGTH_LONG).show(); 442 | //获取分类列表 443 | new ClassifyAsyncTask().execute(); 444 | // 获取日记列表 445 | new DiaryAsyncTask().execute(); 446 | }else { 447 | name="未登录"; 448 | mProgressDialog.dismiss(); 449 | } 450 | mTvNavHeadName.setText(name); 451 | mTvNavHeadDesc.setText(desc); 452 | } 453 | } 454 | /** 455 | * 实现网络异步加载 456 | */ 457 | private class DiaryAsyncTask extends AsyncTask>{ 458 | 459 | @Override 460 | protected List doInBackground(Void... params) { 461 | return getDiaryListJSONData(); 462 | } 463 | 464 | @Override 465 | protected void onPostExecute(List diaryBeen) { 466 | super.onPostExecute(diaryBeen); 467 | //设置listView 的adapter 468 | diaryListAdapter=new DiaryListAdapter(MainActivity.this,diaryBeen); 469 | mListView.setAdapter(diaryListAdapter); 470 | mTvMainCount.setText("——"+ COUNT_MAIN_STR +"——"); 471 | //隐藏加载框 472 | mProgressDialog.dismiss(); 473 | } 474 | } 475 | private class UpdateNameAsyncTask extends AsyncTask{ 476 | private String name; 477 | 478 | @Override 479 | protected Boolean doInBackground(String... params) { 480 | name=params[0]; 481 | String jsonString=HttpClient.post(USER_UPDATE_NAME_URL) 482 | .param("name",name) 483 | .execute().asString(); 484 | if(!StringUtils.isEmpty(jsonString)){ 485 | try { 486 | JSONObject jsonObj=new JSONObject(jsonString); 487 | if(jsonObj.getInt("state")==0){ 488 | return true; 489 | } 490 | } catch (JSONException e) { 491 | e.printStackTrace(); 492 | } 493 | } 494 | return false; 495 | } 496 | 497 | @Override 498 | protected void onPostExecute(Boolean aBoolean) { 499 | super.onPostExecute(aBoolean); 500 | if(aBoolean){ 501 | mTvNavHeadName.setText(name); 502 | Toast.makeText(MainActivity.this,"修改成功!",Toast.LENGTH_LONG).show(); 503 | } 504 | } 505 | } 506 | private class UpdateDescAsyncTask extends AsyncTask{ 507 | private String desc; 508 | @Override 509 | protected Boolean doInBackground(String... params) { 510 | desc=params[0]; 511 | String jsonString=HttpClient.post(USER_UPDATE_DESC_URL) 512 | .param("desc",desc) 513 | .execute().asString(); 514 | if(!StringUtils.isEmpty(jsonString)){ 515 | try { 516 | JSONObject jsonObj=new JSONObject(jsonString); 517 | if(jsonObj.getInt("state")==0){ 518 | return true; 519 | } 520 | } catch (JSONException e) { 521 | e.printStackTrace(); 522 | } 523 | } 524 | return false; 525 | } 526 | 527 | @Override 528 | protected void onPostExecute(Boolean aBoolean) { 529 | super.onPostExecute(aBoolean); 530 | if(aBoolean){ 531 | mTvNavHeadDesc.setText(desc); 532 | Toast.makeText(MainActivity.this,"修改成功!",Toast.LENGTH_LONG).show(); 533 | } 534 | } 535 | } 536 | private class ClassifyAsyncTask extends AsyncTask{ 537 | @Override 538 | protected Void doInBackground(Void... params) { 539 | String jsonString=HttpClient.post(CLASSIFY_LIST_URL) 540 | .execute().asString(); 541 | if(!StringUtils.isEmpty(jsonString)){ 542 | try { 543 | JSONObject jsonObj=new JSONObject(jsonString); 544 | if(jsonObj.getInt("state")==0){ 545 | JSONArray jsonArray=jsonObj.getJSONArray("data"); 546 | mClassifyItems=new String[jsonArray.length()]; 547 | for (int i = 0; i { 562 | 563 | @Override 564 | protected Boolean doInBackground(Integer... params) { 565 | String jsonString=HttpClient.post(DEL_DIARY_URL) 566 | .param("id",String.valueOf(params[0])) 567 | .execute().asString(); 568 | if(!StringUtils.isEmpty(jsonString)){ 569 | try { 570 | JSONObject jsonObject=new JSONObject(jsonString); 571 | if(jsonObject.getInt("state")==0){ 572 | return true; 573 | } 574 | } catch (JSONException e) { 575 | e.printStackTrace(); 576 | } 577 | 578 | } 579 | return false; 580 | } 581 | 582 | @Override 583 | protected void onPostExecute(Boolean aBoolean) { 584 | super.onPostExecute(aBoolean); 585 | Toast.makeText(MainActivity.this,aBoolean?"删除成功":"删除失败",Toast.LENGTH_LONG).show(); 586 | mProgressDialog.dismiss(); 587 | if(aBoolean){ 588 | mProgressDialog.show(); 589 | new DiaryAsyncTask().execute(); 590 | } 591 | } 592 | } 593 | /** 594 | * 重写判断是否登录 595 | * @param intent 596 | */ 597 | @Override 598 | public void startActivity(Intent intent) { 599 | if(LOGIN_STATE==0){ 600 | intent=new Intent(MainActivity.this,LoginActivity.class); 601 | } 602 | super.startActivity(intent); 603 | } 604 | 605 | /** 606 | * 重写判断是否登录 607 | * @param intent 608 | * @param requestCode 609 | */ 610 | @Override 611 | public void startActivityForResult(Intent intent, int requestCode) { 612 | if(LOGIN_STATE==0){ 613 | intent=new Intent(MainActivity.this,LoginActivity.class); 614 | requestCode=LOGIN; 615 | } 616 | super.startActivityForResult(intent, requestCode); 617 | } 618 | 619 | @Override 620 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 621 | super.onActivityResult(requestCode, resultCode, data); 622 | switch (requestCode) { 623 | case ADD: 624 | mProgressDialog.show(); 625 | new DiaryAsyncTask().execute(); 626 | break; 627 | case LOGIN: 628 | if(NetWorkUtil.isNetworkConnected(this)){ 629 | mProgressDialog.show(); 630 | new AutoLoginSyncTask().execute(); 631 | }else { 632 | Toast.makeText(this,"请检查您的网络连接",Toast.LENGTH_LONG).show(); 633 | } 634 | break; 635 | case SETTING: 636 | if(NetWorkUtil.isNetworkConnected(this)){ 637 | mProgressDialog.show(); 638 | new AutoLoginSyncTask().execute(); 639 | }else { 640 | Toast.makeText(this,"请检查您的网络连接",Toast.LENGTH_LONG).show(); 641 | } 642 | break; 643 | case EDIT: 644 | mProgressDialog.show(); 645 | new DiaryAsyncTask().execute(); 646 | break; 647 | case CLASSIFY: 648 | mProgressDialog.show(); 649 | new ClassifyAsyncTask().execute(); 650 | new DiaryAsyncTask().execute(); 651 | break; 652 | } 653 | } 654 | 655 | private void alertAbout(){ 656 | new AlertDialog.Builder(MainActivity.this) 657 | .setTitle("关于") 658 | .setMessage("课程设计作品") 659 | .setNegativeButton("确定", null) 660 | .show(); 661 | } 662 | 663 | } 664 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/activity/SettingActivity.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.activity; 2 | 3 | import android.content.DialogInterface; 4 | import android.content.SharedPreferences; 5 | import android.os.AsyncTask; 6 | import android.os.Bundle; 7 | import android.support.v7.app.AlertDialog; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.Toolbar; 10 | import android.view.View; 11 | import android.widget.AdapterView; 12 | import android.widget.EditText; 13 | import android.widget.ListView; 14 | import android.widget.SimpleAdapter; 15 | import android.widget.Toast; 16 | 17 | import com.mzlion.core.lang.StringUtils; 18 | import com.mzlion.easyokhttp.HttpClient; 19 | 20 | import org.json.JSONException; 21 | import org.json.JSONObject; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | import cn.javayuan.diary.R; 29 | import cn.javayuan.diary.utils.AppUtil; 30 | 31 | public class SettingActivity extends AppCompatActivity { 32 | 33 | private final String UPDATE_PASSWORD_URL= AppUtil.URL+"/User/updatePassword"; 34 | private ListView mSettingList; 35 | private List> settingList =new ArrayList<>(); 36 | @Override 37 | protected void onCreate(Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.activity_setting); 40 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_setting); 41 | setSupportActionBar(toolbar); 42 | 43 | getSupportActionBar().setDisplayHomeAsUpEnabled(true); 44 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 45 | @Override 46 | public void onClick(View v) { 47 | finish(); 48 | } 49 | }); 50 | mSettingList= (ListView) findViewById(R.id.list_setting); 51 | initList(); 52 | String[] strings = {"content"};//Map的key集合数组 53 | int[] ids = {R.id.setting_content};//对应布局文件的id 54 | SimpleAdapter simpleAdapter = new SimpleAdapter(SettingActivity.this, 55 | settingList, R.layout.list_setting, strings, ids); 56 | mSettingList.setAdapter(simpleAdapter);//绑定适配器 57 | mSettingList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 58 | @Override 59 | public void onItemClick(AdapterView parent, View view, int position, long id) { 60 | if(settingList.get(position).get("content").equals("修改密码")){ 61 | final EditText mInputNameText = new EditText(SettingActivity.this); 62 | new AlertDialog.Builder(SettingActivity.this) 63 | .setTitle("请输入新密码") 64 | .setView(mInputNameText,80,80,80,0) 65 | .setPositiveButton("确定", new DialogInterface.OnClickListener() { 66 | @Override 67 | public void onClick(DialogInterface dialog, int which) { 68 | String inputName = mInputNameText.getText().toString(); 69 | new UpdatePasswordAsyncTask().execute(inputName); 70 | } 71 | }) 72 | .setNegativeButton("取消", null) 73 | .show(); 74 | }else if(settingList.get(position).get("content").equals("注销登录")){ 75 | Toast.makeText(SettingActivity.this,"注销成功!",Toast.LENGTH_LONG).show(); 76 | setLogout(); 77 | } 78 | } 79 | }); 80 | } 81 | 82 | private void initList(){ 83 | HashMap map1=new HashMap<>(); 84 | map1.put("content","修改密码"); 85 | HashMap map2=new HashMap<>(); 86 | map2.put("content","注销登录"); 87 | settingList.add(map1); 88 | settingList.add(map2); 89 | } 90 | 91 | private class UpdatePasswordAsyncTask extends AsyncTask{ 92 | 93 | @Override 94 | protected Boolean doInBackground(String... params) { 95 | String jsonString=HttpClient.post(UPDATE_PASSWORD_URL) 96 | .param("password",params[0]) 97 | .execute().asString(); 98 | if(!StringUtils.isEmpty(jsonString)){ 99 | try { 100 | JSONObject jsonObject=new JSONObject(jsonString); 101 | if(jsonObject.getInt("state")==0){ 102 | return true; 103 | } 104 | } catch (JSONException e) { 105 | e.printStackTrace(); 106 | } 107 | 108 | } 109 | return false; 110 | } 111 | 112 | @Override 113 | protected void onPostExecute(Boolean aBoolean) { 114 | super.onPostExecute(aBoolean); 115 | if(aBoolean){ 116 | setLogout(); 117 | } 118 | Toast.makeText(SettingActivity.this,aBoolean?"修改成功,请重新登录":"修改失败",Toast.LENGTH_LONG).show(); 119 | } 120 | } 121 | 122 | private void setLogout(){ 123 | SharedPreferences sp=getSharedPreferences("Diary",MODE_PRIVATE); 124 | SharedPreferences.Editor editor=sp.edit(); 125 | editor.putString("token","limingyuan"); 126 | editor.apply(); 127 | editor.commit(); 128 | MainActivity.LOGIN_STATE=0; 129 | finish(); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/adapter/DiaryListAdapter.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.adapter; 2 | 3 | import android.content.Context; 4 | import android.util.Log; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | import android.widget.BaseAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.TextView; 11 | 12 | import com.bumptech.glide.Glide; 13 | import com.mzlion.core.lang.StringUtils; 14 | 15 | import java.util.Arrays; 16 | import java.util.List; 17 | 18 | import cn.javayuan.diary.bean.DiaryBean; 19 | import cn.javayuan.diary.R; 20 | import cn.javayuan.diary.utils.AppUtil; 21 | 22 | /** 23 | * Created by lmy on 2017/6/18. 24 | */ 25 | 26 | public class DiaryListAdapter extends BaseAdapter { 27 | 28 | private List list; 29 | private LayoutInflater inflater; 30 | 31 | public DiaryListAdapter(Context context,List data){ 32 | list=data; 33 | inflater=LayoutInflater.from(context); 34 | 35 | } 36 | @Override 37 | public int getCount() { 38 | return list.size(); 39 | } 40 | 41 | @Override 42 | public Object getItem(int position) { 43 | return list.get(position); 44 | } 45 | 46 | @Override 47 | public long getItemId(int position) { 48 | return position; 49 | } 50 | 51 | @Override 52 | public View getView(int position, View convertView, ViewGroup parent) { 53 | ViewHolder viewHolder=null; 54 | if(convertView==null){ 55 | viewHolder = new ViewHolder(); 56 | convertView=inflater.inflate(R.layout.list_main,null); 57 | viewHolder.image= (ImageView) convertView.findViewById(R.id.main_list_image); 58 | viewHolder.date= (TextView) convertView.findViewById(R.id.main_list_date); 59 | viewHolder.content= (TextView) convertView.findViewById(R.id.main_list_content); 60 | viewHolder.time= (TextView) convertView.findViewById(R.id.main_list_time); 61 | convertView.setTag(viewHolder); 62 | }else { 63 | viewHolder= (ViewHolder) convertView.getTag(); 64 | } 65 | viewHolder.image.setImageResource(R.mipmap.bga_pp_ic_holder_dark); 66 | viewHolder.image.setVisibility(View.GONE); 67 | if(list.get(position).getImages()!=null&&list.get(position).getImages().length>0&&!list.get(position).getImages().equals("null")){ 68 | String url=list.get(position).getImages()[0]; 69 | if(!StringUtils.isEmpty(url)) { 70 | viewHolder.image.setVisibility(View.VISIBLE); 71 | Glide.with(convertView.getContext()) 72 | .load(AppUtil.IMAGE_URL+url) 73 | .into(viewHolder.image); 74 | } 75 | } 76 | viewHolder.time.setText(list.get(position).getCreateTime()); 77 | viewHolder.content.setText(list.get(position).getContent()); 78 | viewHolder.date.setText(list.get(position).getCreateDate()); 79 | return convertView; 80 | } 81 | 82 | private class ViewHolder{ 83 | public ImageView image; 84 | public TextView date,content,time; 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/bean/DiaryBean.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.bean; 2 | 3 | /** 4 | * 日记 5 | * Created by lmy on 2017/6/18. 6 | */ 7 | 8 | public class DiaryBean { 9 | private int id; 10 | private String content; 11 | private String[] images; 12 | private String createTime; 13 | private String createDate; 14 | private String createYear; 15 | 16 | public DiaryBean() { 17 | } 18 | 19 | public DiaryBean(String createYear, String createDate, String createTime, String[] images) { 20 | this.images = images; 21 | this.createTime = createTime; 22 | this.createDate = createDate; 23 | this.createYear = createYear; 24 | } 25 | 26 | public String getCreateYear() { 27 | return createYear; 28 | } 29 | 30 | public void setCreateYear(String createYear) { 31 | this.createYear = createYear; 32 | } 33 | 34 | private int type; 35 | private int weather; 36 | 37 | public int getType() { 38 | return type; 39 | } 40 | 41 | public void setType(int type) { 42 | this.type = type; 43 | } 44 | 45 | public int getWeather() { 46 | return weather; 47 | } 48 | 49 | public void setWeather(int weather) { 50 | this.weather = weather; 51 | } 52 | 53 | public int getId() { 54 | return id; 55 | } 56 | 57 | public void setId(int id) { 58 | this.id = id; 59 | } 60 | 61 | public String getContent() { 62 | return content; 63 | } 64 | 65 | public void setContent(String content) { 66 | this.content = content; 67 | } 68 | 69 | 70 | public String[] getImages() { 71 | return images; 72 | } 73 | 74 | public void setImages(String[] images) { 75 | this.images = images; 76 | } 77 | 78 | public String getCreateTime() { 79 | return createTime; 80 | } 81 | 82 | public void setCreateTime(String createTime) { 83 | this.createTime = createTime; 84 | } 85 | 86 | public String getCreateDate() { 87 | return createDate; 88 | } 89 | 90 | public void setCreateDate(String createDate) { 91 | this.createDate = createDate; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/bean/UserBean.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.bean; 2 | 3 | /** 4 | * 用户 5 | * Created by lmy on 2017/6/19. 6 | */ 7 | 8 | public class UserBean { 9 | private int id; 10 | private String username; 11 | private String password; 12 | private String token; 13 | private String name; 14 | private String desc; 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getUsername() { 25 | return username; 26 | } 27 | 28 | public void setUsername(String username) { 29 | this.username = username; 30 | } 31 | 32 | public String getPassword() { 33 | return password; 34 | } 35 | 36 | public void setPassword(String password) { 37 | this.password = password; 38 | } 39 | 40 | public String getToken() { 41 | return token; 42 | } 43 | 44 | public void setToken(String token) { 45 | this.token = token; 46 | } 47 | 48 | public String getName() { 49 | return name; 50 | } 51 | 52 | public void setName(String name) { 53 | this.name = name; 54 | } 55 | 56 | public String getDesc() { 57 | return desc; 58 | } 59 | 60 | public void setDesc(String desc) { 61 | this.desc = desc; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/utils/AppUtil.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.utils; 2 | 3 | import com.mzlion.core.lang.StringUtils; 4 | 5 | import org.json.JSONException; 6 | import org.json.JSONObject; 7 | 8 | import cn.javayuan.diary.bean.DiaryBean; 9 | 10 | /** 11 | * 主要用配置服务器信息 12 | * Created by lmy on 2017/6/19. 13 | */ 14 | 15 | public class AppUtil { 16 | public static String URL="http://123.206.84.232/daily/index.php/Home"; 17 | public static String IMAGE_URL="http://123.206.84.232/daily/Uploads/"; 18 | 19 | public static DiaryBean convertJsonToDiaryBean(JSONObject jsonObject){ 20 | DiaryBean diaryBean=new DiaryBean(); 21 | try { 22 | diaryBean.setId(jsonObject.getInt("id")); 23 | diaryBean.setCreateTime(jsonObject.getString("createtime")); 24 | diaryBean.setCreateDate(jsonObject.getString("createdate")); 25 | diaryBean.setCreateYear(jsonObject.getString("createyear")); 26 | diaryBean.setContent(jsonObject.getString("content")); 27 | if(!StringUtils.isEmpty(jsonObject.getString("images"))){ 28 | diaryBean.setImages(jsonObject.getString("images").split(",")); 29 | } 30 | diaryBean.setType(jsonObject.getInt("type")); 31 | diaryBean.setWeather(jsonObject.getInt("weather")); 32 | return diaryBean; 33 | } catch (JSONException e) { 34 | e.printStackTrace(); 35 | } 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/utils/NetWorkUtil.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.utils; 2 | 3 | import android.content.Context; 4 | import android.location.LocationManager; 5 | import android.net.ConnectivityManager; 6 | import android.net.NetworkInfo;import android.telephony.TelephonyManager; 7 | /** 8 | * 网络工具类 9 | * Created by lmy. 10 | */ 11 | public class NetWorkUtil { 12 | /** 13 | * 判断是否有网络连接 14 | * 15 | * @param context 16 | * @return 17 | */ 18 | public static boolean isNetworkConnected(Context context) { 19 | if (context != null) { 20 | // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) 21 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 22 | // 获取NetworkInfo对象 23 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 24 | //判断NetworkInfo对象是否为空 25 | if (networkInfo != null) 26 | return networkInfo.isAvailable(); 27 | } 28 | return false; 29 | } 30 | /** 31 | * 判断WIFI网络是否可用 32 | * 33 | * @param context 34 | * @return 35 | / 36 | public static boolean isWifiConnected(Context context) { 37 | if (context != null) { 38 | // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) 39 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 40 | // 获取NetworkInfo对象 41 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 42 | //判断NetworkInfo对象是否为空 并且类型是否为WIFI 43 | if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI) 44 | return networkInfo.isAvailable(); 45 | } return false; 46 | } 47 | /** 48 | * 判断MOBILE网络是否可用 49 | * 50 | * @param context 51 | * @return 52 | */ 53 | public static boolean isMobileConnected(Context context) { 54 | if (context != null) { 55 | //获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) 56 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 57 | //获取NetworkInfo对象 58 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 59 | //判断NetworkInfo对象是否为空 并且类型是否为MOBILE 60 | if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) 61 | return networkInfo.isAvailable(); 62 | } 63 | return false; 64 | } 65 | /** 66 | * 获取当前网络连接的类型信息 67 | * 原生 68 | * 69 | * @param context 70 | * @return 71 | */ public static int getConnectedType(Context context) { 72 | if (context != null) { 73 | //获取手机所有连接管理对象 74 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 75 | //获取NetworkInfo对象 76 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 77 | if (networkInfo != null && networkInfo.isAvailable()) { 78 | //返回NetworkInfo的类型 79 | return networkInfo.getType(); 80 | } 81 | } 82 | return -1; 83 | } 84 | /** 85 | * 获取当前的网络状态 :没有网络-0:WIFI网络1:4G网络-4:3G网络-3:2G网络-2 86 | * 自定义 87 | * 88 | * @param context 89 | * @return 90 | */ 91 | public static int getAPNType(Context context) { 92 | //结果返回值 93 | int netType = 0; 94 | //获取手机所有连接管理对象 95 | ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 96 | //获取NetworkInfo对象 97 | NetworkInfo networkInfo = manager.getActiveNetworkInfo(); 98 | //NetworkInfo对象为空 则代表没有网络 99 | if (networkInfo == null) { 100 | return netType; 101 | } 102 | //否则 NetworkInfo对象不为空 则获取该networkInfo的类型 103 | int nType = networkInfo.getType(); 104 | if (nType == ConnectivityManager.TYPE_WIFI) { 105 | //WIFI 106 | netType = 1; 107 | } else if (nType == ConnectivityManager.TYPE_MOBILE) { 108 | int nSubType = networkInfo.getSubtype(); 109 | TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 110 | //3G 联通的3G为UMTS或HSDPA 电信的3G为EVDO 111 | if (nSubType == TelephonyManager.NETWORK_TYPE_LTE 112 | && !telephonyManager.isNetworkRoaming()) { 113 | netType = 4; 114 | } else if (nSubType == TelephonyManager.NETWORK_TYPE_UMTS 115 | || nSubType == TelephonyManager.NETWORK_TYPE_HSDPA 116 | || nSubType == TelephonyManager.NETWORK_TYPE_EVDO_0 117 | && !telephonyManager.isNetworkRoaming()) { 118 | netType = 3; 119 | //2G 移动和联通的2G为GPRS或EGDE,电信的2G为CDMA 120 | } else if (nSubType == TelephonyManager.NETWORK_TYPE_GPRS 121 | || nSubType == TelephonyManager.NETWORK_TYPE_EDGE 122 | || nSubType == TelephonyManager.NETWORK_TYPE_CDMA 123 | && !telephonyManager.isNetworkRoaming()) { 124 | netType = 2; 125 | } else { 126 | netType = 2; 127 | } 128 | } 129 | return netType; 130 | } 131 | /** 132 | * 判断GPS是否打开 133 | *ACCESS_FINE_LOCATION权限 134 | * @param context 135 | * @return 136 | */ 137 | public static boolean isGPSEnabled(Context context) { 138 | //获取手机所有连接LOCATION_SERVICE对象 139 | LocationManager locationManager = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE)); 140 | return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); 141 | } 142 | } -------------------------------------------------------------------------------- /app/src/main/java/cn/javayuan/diary/utils/ScrollingCalendarBehavior.java: -------------------------------------------------------------------------------- 1 | package cn.javayuan.diary.utils; 2 | 3 | import android.content.Context; 4 | import android.support.design.widget.AppBarLayout; 5 | import android.support.design.widget.CoordinatorLayout; 6 | import android.util.AttributeSet; 7 | import android.view.MotionEvent; 8 | 9 | public class ScrollingCalendarBehavior extends AppBarLayout.Behavior { 10 | 11 | public ScrollingCalendarBehavior(Context context, AttributeSet attrs) { 12 | super(context, attrs); 13 | } 14 | 15 | @Override 16 | public boolean onInterceptTouchEvent(CoordinatorLayout parent, AppBarLayout child, MotionEvent ev) { 17 | return false;/*super.onInterceptTouchEvent(parent, child, ev);*/ 18 | } 19 | } -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg_edit_text_no.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_drop_down.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_create.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_default_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuan1/diary/3c058f21ef0845e0e3db7030fc441c0d25040a3d/app/src/main/res/drawable/ic_default_image.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_info_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_classify.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_feedback.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_gallery.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_index.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_menu_manage.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_notifications_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_search.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_sync_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_toolbar_classify.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_toolbar_syn.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yuan1/diary/3c058f21ef0845e0e3db7030fc441c0d25040a3d/app/src/main/res/drawable/img.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/list_content_back.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/side_nav_bar.xml: -------------------------------------------------------------------------------- 1 | 3 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_add_diary.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_classify.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_images.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_setting.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_add_diary.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 24 | 31 | 37 | 42 | 52 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_images.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 22 | 23 | 29 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 22 | 23 | 29 | 38 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /app/src/main/res/layout/app_bar_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 15 | 23 | 24 | 33 | 34 | 41 | 42 | 53 | 54 | 55 | 62 | 63 | 70 | 79 | 80 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_add_diary.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 16 | 28 | 48 | 53 | 59 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_classify.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 16 | 25 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_images.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/layout/content_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 23 | 24 | 28 | 29 | 34 | 35 | 38 | 39 | 47 | 48 | 49 | 50 | 53 | 54 | 65 | 66 | 67 | 68 |