├── 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