├── .gitignore
├── .idea
├── .gitignore
├── compiler.xml
├── deploymentTargetDropDown.xml
├── encodings.xml
├── gradle.xml
├── inspectionProfiles
│ └── Project_Default.xml
├── jarRepositories.xml
├── misc.xml
└── vcs.xml
├── README.md
├── Resources
├── 1.png
├── 2.png
└── 3.png
├── app
├── .gitignore
├── build.gradle
├── libs
│ ├── BaiduLBS_Android.jar
│ ├── arm64-v8a
│ │ └── liblocSDK7b.so
│ ├── armeabi-v7a
│ │ └── liblocSDK7b.so
│ ├── armeabi
│ │ └── liblocSDK7b.so
│ ├── gson-2.3.1.jar
│ ├── x86
│ │ └── liblocSDK7b.so
│ └── x86_64
│ │ └── liblocSDK7b.so
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── example
│ │ └── easynote
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ └── litepal.xml
│ ├── ic_launcher-web.png
│ ├── java
│ │ └── com
│ │ │ └── example
│ │ │ └── easynote
│ │ │ ├── Access_token.java
│ │ │ ├── AddDataActivity.java
│ │ │ ├── BaseActivity.java
│ │ │ ├── BmpToBase64.java
│ │ │ ├── ChangePwd.java
│ │ │ ├── ChartFragment.java
│ │ │ ├── DataFragment.java
│ │ │ ├── DetailActivity.java
│ │ │ ├── DetectService.java
│ │ │ ├── DetectTask.java
│ │ │ ├── Diary.java
│ │ │ ├── DiaryAdapter.java
│ │ │ ├── FaceDect.java
│ │ │ ├── GsonUtils.java
│ │ │ ├── HttpUtil.java
│ │ │ ├── InputPwd.java
│ │ │ ├── MainActivity.java
│ │ │ ├── MyLineChart.java
│ │ │ ├── MyXAxisRenderer.java
│ │ │ ├── OnPasswordInputFinish.java
│ │ │ ├── PasswordView.java
│ │ │ ├── SetPwd.java
│ │ │ ├── StartActivity.java
│ │ │ └── TextDect.java
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable-xxhdpi
│ │ └── ic_menu.png
│ │ ├── drawable
│ │ ├── about.png
│ │ ├── camera.png
│ │ ├── cry.png
│ │ ├── diary_ico.png
│ │ ├── feedback.png
│ │ ├── happy.png
│ │ ├── ic_add.png
│ │ ├── ic_chart.png
│ │ ├── ic_chart_select.png
│ │ ├── ic_clear_black_24dp.xml
│ │ ├── ic_dashboard_black_24dp.xml
│ │ ├── ic_data.png
│ │ ├── ic_data_select.png
│ │ ├── ic_home_black_24dp.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── ic_notifications_black_24dp.xml
│ │ ├── mood_ico.png
│ │ ├── pwd.png
│ │ ├── right.png
│ │ ├── sad.png
│ │ ├── selector_gride.xml
│ │ ├── selector_key_del.xml
│ │ ├── shape_input_area.xml
│ │ ├── smile.png
│ │ ├── startlogo.png
│ │ ├── sun.gif
│ │ ├── toolbar_back.png
│ │ ├── toolbar_delete.png
│ │ ├── toolbar_save.png
│ │ ├── toolbar_update.png
│ │ └── weather.gif
│ │ ├── layout
│ │ ├── activity_add_data.xml
│ │ ├── activity_change_pwd.xml
│ │ ├── activity_detail.xml
│ │ ├── activity_input_pwd.xml
│ │ ├── activity_main.xml
│ │ ├── activity_set_pwd.xml
│ │ ├── activity_start.xml
│ │ ├── data_item.xml
│ │ ├── frag_base.xml
│ │ ├── frag_chart.xml
│ │ ├── frag_data.xml
│ │ ├── item_gride.xml
│ │ ├── layout_popup_bottom.xml
│ │ └── nav_header.xml
│ │ ├── menu
│ │ ├── add_toolbar.xml
│ │ ├── bottom_nav_menu.xml
│ │ ├── detail_toolbar.xml
│ │ └── nav_menu.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ ├── ic_launcher_foreground.png
│ │ └── ic_launcher_round.png
│ │ ├── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── ic_launcher_background.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ │ └── xml
│ │ └── file_paths.xml
│ └── test
│ └── java
│ └── com
│ └── example
│ └── easynote
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ### 项目介绍
2 |
3 | 一个更加高级的日记本App
4 |
5 | - 可以拍照:能测颜值
6 | - 可测心情:根据文本分析情感
7 | - 图表显示:清晰统计颜值与心情的变化
8 |
9 | 
10 | 
11 | 
--------------------------------------------------------------------------------
/Resources/1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/Resources/1.png
--------------------------------------------------------------------------------
/Resources/2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/Resources/2.png
--------------------------------------------------------------------------------
/Resources/3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/Resources/3.png
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "com.example.easynote"
7 | minSdkVersion 15
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | }
13 | buildTypes {
14 | release {
15 | minifyEnabled false
16 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | }
20 | dependencies {
21 | implementation fileTree(include: ['*.jar'], dir: 'libs')
22 | implementation 'com.android.support:appcompat-v7:28.0.0'
23 | implementation 'com.android.support:design:28.0.0'
24 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
25 | implementation 'com.android.support:support-vector-drawable:28.0.0'
26 | testImplementation 'junit:junit:4.12'
27 | androidTestImplementation 'com.android.support.test:runner:1.0.2'
28 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
29 | implementation 'com.github.ittianyu:BottomNavigationViewEx:2.0.4'
30 | implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
31 | implementation 'com.android.support:recyclerview-v7:28.0.0'
32 | implementation 'org.litepal.android:java:3.0.0'
33 | implementation files('libs/gson-2.3.1.jar')
34 | implementation 'com.amap.api:map2d:5.2.0'
35 | implementation files('libs/BaiduLBS_Android.jar')
36 | implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
37 | }
38 |
--------------------------------------------------------------------------------
/app/libs/BaiduLBS_Android.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/BaiduLBS_Android.jar
--------------------------------------------------------------------------------
/app/libs/arm64-v8a/liblocSDK7b.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/arm64-v8a/liblocSDK7b.so
--------------------------------------------------------------------------------
/app/libs/armeabi-v7a/liblocSDK7b.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/armeabi-v7a/liblocSDK7b.so
--------------------------------------------------------------------------------
/app/libs/armeabi/liblocSDK7b.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/armeabi/liblocSDK7b.so
--------------------------------------------------------------------------------
/app/libs/gson-2.3.1.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/gson-2.3.1.jar
--------------------------------------------------------------------------------
/app/libs/x86/liblocSDK7b.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/x86/liblocSDK7b.so
--------------------------------------------------------------------------------
/app/libs/x86_64/liblocSDK7b.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/libs/x86_64/liblocSDK7b.so
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/easynote/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumented test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.example.easynote", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
16 |
19 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
30 |
31 |
35 |
37 |
38 |
39 |
43 |
44 |
46 |
47 |
49 |
50 |
55 |
58 |
59 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/assets/litepal.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jayying007/EasyNote/ce7e599182cb64574c8b4406978ff80ab244e297/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/Access_token.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.util.Log;
4 |
5 | import org.json.JSONObject;
6 |
7 | import java.io.BufferedReader;
8 | import java.io.InputStreamReader;
9 | import java.net.HttpURLConnection;
10 | import java.net.URL;
11 | import java.util.List;
12 | import java.util.Map;
13 |
14 | public class Access_token {
15 | // 获取权限token
16 | public static String getAuth() {
17 | // 官网获取的 API Key 更新为你注册的
18 | String clientId = "4uzwcrPVFFh9hXRr1HriBlWq";
19 | // 官网获取的 Secret Key 更新为你注册的
20 | String clientSecret = "UCgm3G0wsC6MxQs7RdP7wBOdIyZrM4om";
21 | return getAuth(clientId, clientSecret);
22 | }
23 |
24 | // 获取权限token
25 | public static String getAuth(String ak, String sk) {
26 | // 获取token地址
27 | String authHost = "https://aip.baidubce.com/oauth/2.0/token?";
28 | String getAccessTokenUrl = authHost
29 | // 1. grant_type为固定参数
30 | + "grant_type=client_credentials"
31 | // 2. 官网获取的 API Key
32 | + "&client_id=" + ak
33 | // 3. 官网获取的 Secret Key
34 | + "&client_secret=" + sk;
35 | HttpURLConnection connection = null;
36 | try {
37 | URL realUrl = new URL(getAccessTokenUrl);
38 | // 打开和URL之间的连接
39 | connection = (HttpURLConnection) realUrl.openConnection();
40 | connection.setRequestMethod("GET");
41 | connection.connect();
42 | // 获取所有响应头字段
43 | Map> map = connection.getHeaderFields();
44 | // 遍历所有的响应头字段
45 | for (String key : map.keySet()) {
46 | System.err.println(key + "--->" + map.get(key));
47 | }
48 | // 定义 BufferedReader输入流来读取URL的响应
49 | BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
50 | String result = "";
51 | String line;
52 | while ((line = in.readLine()) != null) {
53 | result += line;
54 | }
55 | /**
56 | * 返回结果示例
57 | */
58 | System.err.println("result:" + result);
59 | JSONObject jsonObject = new JSONObject(result);
60 | String access_token = jsonObject.getString("access_token");
61 | return access_token;
62 | } catch (Exception e) {
63 | System.err.printf("获取token失败!");
64 | e.printStackTrace(System.err);
65 | }finally {
66 | if (connection!=null){
67 | connection.disconnect();
68 | }
69 | }
70 | return null;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/AddDataActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.Manifest;
4 | import android.annotation.TargetApi;
5 | import android.app.ProgressDialog;
6 | import android.content.ComponentName;
7 | import android.content.ContentUris;
8 | import android.content.Context;
9 | import android.content.DialogInterface;
10 | import android.content.Intent;
11 | import android.content.ServiceConnection;
12 | import android.content.pm.PackageManager;
13 | import android.database.Cursor;
14 | import android.graphics.Bitmap;
15 | import android.graphics.BitmapFactory;
16 | import android.net.Uri;
17 | import android.os.Build;
18 | import android.os.Environment;
19 | import android.os.IBinder;
20 | import android.provider.DocumentsContract;
21 | import android.provider.MediaStore;
22 | import android.support.annotation.NonNull;
23 | import android.support.v4.app.ActivityCompat;
24 | import android.support.v4.content.ContextCompat;
25 | import android.support.v4.content.FileProvider;
26 | import android.support.v7.app.AlertDialog;
27 | import android.support.v7.app.AppCompatActivity;
28 | import android.os.Bundle;
29 | import android.support.v7.widget.Toolbar;
30 | import android.util.Log;
31 | import android.view.Menu;
32 | import android.view.MenuItem;
33 | import android.view.View;
34 | import android.widget.EditText;
35 | import android.widget.ImageView;
36 | import android.widget.TextView;
37 | import android.widget.Toast;
38 |
39 | import org.litepal.LitePal;
40 |
41 | import java.io.BufferedOutputStream;
42 | import java.io.File;
43 | import java.io.FileNotFoundException;
44 | import java.io.FileOutputStream;
45 | import java.io.IOException;
46 | import java.util.Calendar;
47 | import java.util.TimeZone;
48 |
49 | public class AddDataActivity extends AppCompatActivity {
50 | // 服务
51 | private DetectService.DetectBinder detectBinder;
52 | private ServiceConnection connection = new ServiceConnection() {
53 | @Override
54 | public void onServiceConnected(ComponentName name, IBinder service) {
55 | detectBinder = (DetectService.DetectBinder)service;
56 | }
57 |
58 | @Override
59 | public void onServiceDisconnected(ComponentName name) {
60 |
61 | }
62 | };
63 | // 接口
64 | private String access_token;//改
65 | /** 首先默认个文件保存路径 */
66 | private static final String SAVE_PIC_PATH= Environment.getExternalStorageState().equalsIgnoreCase(Environment.MEDIA_MOUNTED) ? Environment.getExternalStorageDirectory().getAbsolutePath() : "/mnt/sdcard";//保存到SD卡
67 | private static final String SAVE_REAL_PATH = SAVE_PIC_PATH+ "/easynote/image";//保存的确切位置
68 | // 视图
69 | private ImageView imageView;
70 | private TextView ageText,beautyText,faceShapeText;
71 | private EditText titleEdit,passageEdit;
72 | private String imgPath;
73 | private ProgressDialog progressDialog;//改
74 | private TextView time;
75 | // 数据
76 | private int id;
77 | private String age,beauty,faceShape;
78 | private String title,passage;
79 | private String year,month,day;
80 | // 相机数据
81 | public static final int TAKE_PHOTO = 1;
82 | public static final int CHOOSE_PHOTO = 2;
83 | private Uri imageUri;
84 | private Bitmap bitmap;
85 | // 接受数据并显示,用于解决(直接创建、浏览原有信息后修改两种方式的跳转)
86 | public static void actionStart(Context context,String title,
87 | String passage,String imgPath,
88 | String age,String beauty,
89 | String faceShape,int id){
90 | Intent intent = new Intent(context, AddDataActivity.class);
91 | intent.putExtra("title",title);
92 | intent.putExtra("passage",passage);
93 | intent.putExtra("imgPath",imgPath);
94 | intent.putExtra("age",age);
95 | intent.putExtra("beauty",beauty);
96 | intent.putExtra("faceShape",faceShape);
97 | intent.putExtra("id",id);
98 | context.startActivity(intent);
99 | }
100 | @Override
101 | protected void onCreate(Bundle savedInstanceState) {
102 | super.onCreate(savedInstanceState);
103 | setContentView(R.layout.activity_add_data);
104 | // 启动服务
105 | Intent intent = new Intent(this,DetectService.class);
106 | startService(intent);
107 | // 绑定服务
108 | bindService(intent,connection,BIND_AUTO_CREATE);
109 |
110 | // 获取access_token
111 | new Thread(new Runnable() {
112 | @Override
113 | public void run() {
114 | access_token = Access_token.getAuth();
115 | }
116 | }).start();
117 | initView();
118 | initData();
119 | initEvent();
120 | }
121 | public boolean onCreateOptionsMenu(Menu menu){
122 | getMenuInflater().inflate(R.menu.add_toolbar,menu);
123 | return true;
124 | }
125 | @Override
126 | public boolean onOptionsItemSelected(MenuItem item){
127 | if (item.getItemId() == R.id.toolbar_save) {
128 | // 检查表单
129 | if(bitmap==null){
130 | Toast.makeText(AddDataActivity.this,"帅帅的照片呢?",Toast.LENGTH_SHORT).show();
131 | return false;
132 | }
133 | title = titleEdit.getText().toString();
134 | passage = passageEdit.getText().toString();
135 | if(title.equals("")){
136 | Toast.makeText(AddDataActivity.this,"记得写标题哦",Toast.LENGTH_SHORT).show();
137 | return false;
138 | }
139 | if(passage.equals("")){
140 | Toast.makeText(AddDataActivity.this,"记录一下今天的内容吧",Toast.LENGTH_SHORT).show();
141 | return false;
142 | }
143 | // 判断是新创建还是修改已有
144 | Diary diary;
145 | if (id == -1) diary = new Diary();
146 | else diary = LitePal.find(Diary.class, id);
147 | // 先更新数据
148 | try {
149 | String fileName = System.currentTimeMillis() + ".jpg";
150 | saveFile(bitmap, fileName);
151 | imgPath = SAVE_REAL_PATH + '/' + fileName;
152 | } catch (IOException e) {
153 | e.printStackTrace();
154 | }
155 |
156 | age = ageText.getText().toString();
157 | beauty = beautyText.getText().toString();
158 | faceShape = faceShapeText.getText().toString();
159 | // 文本预测-》保存数据
160 | detectBinder.startDetect(progressDialog,diary,this,passage,access_token);
161 | // 还需获取文本情感分析的结果
162 | diary.setYear(year);
163 | diary.setMonth(month);
164 | diary.setDay(day);
165 | diary.setTitle(title);
166 | diary.setPassage(passage);
167 | diary.setAge(age);
168 | diary.setBeauty(beauty);
169 | diary.setFaceShape(faceShape);
170 | diary.setImgPath(imgPath);
171 | Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show();
172 | }
173 | return true;
174 | }
175 | private void initView(){
176 | imageView = findViewById(R.id.add_img);
177 | ageText = findViewById(R.id.add_age);
178 | beautyText = findViewById(R.id.add_beauty);
179 | faceShapeText = findViewById(R.id.add_faceShape);
180 | titleEdit = findViewById(R.id.add_title);
181 | passageEdit = findViewById(R.id.add_passage);
182 | time = findViewById(R.id.add_time);
183 | progressDialog = new ProgressDialog(AddDataActivity.this);
184 | progressDialog.setMessage("Waiting...");
185 | progressDialog.setCancelable(false);
186 | Toolbar toolbar = findViewById(R.id.add_toolbar);
187 | setSupportActionBar(toolbar);
188 | }
189 |
190 | private void initData(){
191 | // 先接受数据
192 | Intent intent = getIntent();
193 | title = intent.getStringExtra("title");
194 | passage = intent.getStringExtra("passage");
195 | faceShape = intent.getStringExtra("faceShape");
196 | age = intent.getStringExtra("age");
197 | beauty = intent.getStringExtra("beauty");
198 | imgPath = intent.getStringExtra("imgPath");
199 | id = intent.getIntExtra("id",-1);
200 | // 再设置数据
201 | titleEdit.setText(title);
202 | passageEdit.setText(passage);
203 | ageText.setText(String.format("%s%s", ageText.getText(), age));
204 | beautyText.setText(String.format("%s%s", beautyText.getText(), beauty));
205 | faceShapeText.setText(String.format("%s%s", faceShapeText.getText(), faceShape));
206 | bitmap = BitmapFactory.decodeFile(imgPath);
207 | if(bitmap!=null){
208 | imageView.setImageBitmap(bitmap);
209 | }
210 | // 获取当前时间
211 | Calendar calendar = Calendar.getInstance();
212 | calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
213 | year = String.valueOf(calendar.get(Calendar.YEAR));
214 | month = String.valueOf(calendar.get(Calendar.MONTH)+1);
215 | day = String.valueOf(calendar.get(Calendar.DATE));
216 |
217 | time.setText(year+"/"+month+"/"+day);
218 | }
219 |
220 | private void initEvent(){
221 | imageView.setOnClickListener(new View.OnClickListener() {
222 | @Override
223 | public void onClick(View v) {
224 | final String[] choices = {"使用相机","从相册中选取"};
225 | AlertDialog.Builder listDialog = new AlertDialog.Builder(AddDataActivity.this);
226 | listDialog.setItems(choices, new DialogInterface.OnClickListener() {
227 | @Override
228 | public void onClick(DialogInterface dialog, int which) {
229 | switch (which){
230 | // 使用相机
231 | case 0:
232 | takePhoto();
233 | break;
234 | // 从相册中选取
235 | case 1:
236 | chooseFromAlbum();
237 | break;
238 | default:
239 | break;
240 | }
241 |
242 | }
243 | });
244 | listDialog.show();
245 | }
246 | });
247 | }
248 |
249 |
250 | /*
251 | * 图片处理部分
252 | */
253 | private void takePhoto(){
254 | if (ContextCompat.checkSelfPermission(AddDataActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
255 | ActivityCompat.requestPermissions(AddDataActivity.this, new String[]{ Manifest.permission. WRITE_EXTERNAL_STORAGE }, 1);
256 | }
257 | else {
258 | File outputImage = new File(getExternalCacheDir(), "output_image.jpg");
259 | try {
260 | if (outputImage.exists()) {
261 | outputImage.delete();
262 | }
263 | outputImage.createNewFile();
264 | } catch (IOException e) {
265 | e.printStackTrace();
266 | }
267 | //判断sdk版本
268 | if (Build.VERSION.SDK_INT >= 24) {
269 | imageUri = FileProvider.getUriForFile(AddDataActivity.this, "com.example.easynote.fileprovider", outputImage);
270 | } else {
271 | imageUri = Uri.fromFile(outputImage);
272 | }
273 | Log.d("url", imageUri.toString());
274 | //启动相机程序
275 | Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
276 | intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
277 | startActivityForResult(intent, TAKE_PHOTO);
278 | }
279 | }
280 | private void chooseFromAlbum(){
281 | if (ContextCompat.checkSelfPermission(AddDataActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
282 | ActivityCompat.requestPermissions(AddDataActivity.this, new String[]{ Manifest.permission. WRITE_EXTERNAL_STORAGE }, 1);
283 | } else {
284 | openAlbum();
285 | }
286 | }
287 | //拍完将图片显示出来
288 | protected void onActivityResult(int requestCode, int resultCode, Intent data){
289 | switch (requestCode){
290 | case TAKE_PHOTO:
291 | if(resultCode == RESULT_OK){
292 | try{
293 | if(!imgPath.equals("")){
294 | File file = new File(imgPath);
295 | file.delete();
296 | }
297 | bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(imageUri));
298 | imageView.setImageBitmap(bitmap);
299 | //改
300 | String imgBase64 = BmpToBase64.bitmapToBase64(bitmap);
301 | //对话框
302 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddDataActivity.this);
303 | alertDialog.setTitle("检测不到人脸,请重新选择哦");
304 | alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
305 | @Override
306 | public void onClick(DialogInterface dialogInterface, int i) {
307 |
308 | }
309 | });
310 | detectBinder.startDetect(progressDialog,alertDialog,imageView
311 | ,ageText,beautyText,faceShapeText,imgBase64,access_token);
312 | }catch (FileNotFoundException e){
313 | e.printStackTrace();
314 | }
315 | }
316 | break;
317 | case CHOOSE_PHOTO:
318 | if (resultCode == RESULT_OK) {
319 | // 判断手机系统版本号
320 | if (Build.VERSION.SDK_INT >= 19) {
321 | // 4.4及以上系统使用这个方法处理图片
322 | handleImageOnKitKat(data);
323 | } else {
324 | // 4.4以下系统使用这个方法处理图片
325 | handleImageBeforeKitKat(data);
326 | }
327 | }
328 | break;
329 | default:
330 | break;
331 | }
332 | }
333 | // 打开相册
334 | private void openAlbum() {
335 | Intent intent = new Intent("android.intent.action.GET_CONTENT");
336 | intent.setType("image/*");
337 | startActivityForResult(intent, CHOOSE_PHOTO); // 打开相册
338 | }
339 | // 读取相册授权
340 | @Override
341 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
342 | if (requestCode == 1) {
343 | if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
344 | openAlbum();
345 | } else {
346 | Toast.makeText(this, "You denied the permission", Toast.LENGTH_SHORT).show();
347 | }
348 | }
349 | }
350 | // 显示相册图片
351 | @TargetApi(19)
352 | private void handleImageOnKitKat(Intent data) {
353 | String imagePath = null;
354 | Uri uri = data.getData();
355 | Log.d("TAG", "handleImageOnKitKat: uri is " + uri);
356 | if(uri != null) {
357 | if (DocumentsContract.isDocumentUri(this, uri)) {
358 | // 如果是document类型的Uri,则通过document id处理
359 | String docId = DocumentsContract.getDocumentId(uri);
360 | if ("com.android.providers.media.documents".equals(uri.getAuthority())) {
361 | String id = docId.split(":")[1]; // 解析出数字格式的id
362 | String selection = MediaStore.Images.Media._ID + "=" + id;
363 | imagePath = getImagePath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, selection);
364 | } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) {
365 | Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(docId));
366 | imagePath = getImagePath(contentUri, null);
367 | }
368 | } else if ("content".equalsIgnoreCase(uri.getScheme())) {
369 | // 如果是content类型的Uri,则使用普通方式处理
370 | imagePath = getImagePath(uri, null);
371 | } else if ("file".equalsIgnoreCase(uri.getScheme())) {
372 | // 如果是file类型的Uri,直接获取图片路径即可
373 | imagePath = uri.getPath();
374 | }
375 | displayImage(imagePath); // 根据图片路径显示图片
376 | }
377 | }
378 | private void handleImageBeforeKitKat(Intent data) {
379 | Uri uri = data.getData();
380 | String imagePath = getImagePath(uri, null);
381 | displayImage(imagePath);
382 | }
383 | private String getImagePath(Uri uri, String selection) {
384 | String path = null;
385 | // 通过Uri和selection来获取真实的图片路径
386 | Cursor cursor = getContentResolver().query(uri, null, selection, null, null);
387 | if (cursor != null) {
388 | if (cursor.moveToFirst()) {
389 | path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATA));
390 | }
391 | cursor.close();
392 | }
393 | return path;
394 | }
395 | private void displayImage(String imagePath) {
396 | if (imagePath != null) {
397 | if(!imgPath.equals("")){
398 | File file = new File(imgPath);
399 | file.delete();
400 | }
401 | bitmap = BitmapFactory.decodeFile(imagePath);
402 | imageView.setImageBitmap(bitmap);
403 | String imgBase64 = BmpToBase64.bitmapToBase64(bitmap);
404 | //
405 | AlertDialog.Builder alertDialog = new AlertDialog.Builder(AddDataActivity.this);
406 | alertDialog.setTitle("检测不到人脸,请重新选择哦");
407 | alertDialog.setPositiveButton("ok", new DialogInterface.OnClickListener() {
408 | @Override
409 | public void onClick(DialogInterface dialogInterface, int i) {
410 |
411 | }
412 | });
413 | detectBinder.startDetect(progressDialog,alertDialog,imageView,ageText,beautyText,faceShapeText,imgBase64,access_token);
414 | } else {
415 | Toast.makeText(this, "failed to get image", Toast.LENGTH_SHORT).show();
416 | }
417 | }
418 | /*
419 | // 将图片转为字节
420 | private byte[]img(Bitmap bitmap){
421 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
422 | try{
423 | bitmap.compress(Bitmap.CompressFormat.PNG, 20, baos);
424 | }catch (Exception e){
425 | e.printStackTrace();
426 | }
427 | return baos.toByteArray();
428 | }*/
429 | // 存储图片
430 | public void saveFile(Bitmap bm, String fileName) throws IOException {
431 | String subFolder = SAVE_REAL_PATH;
432 | File folder = new File(subFolder);
433 | if (!folder.exists()) {
434 | folder.mkdirs();
435 | }
436 | File myCaptureFile = new File(subFolder, fileName);
437 | if (!myCaptureFile.exists()) {
438 | myCaptureFile.createNewFile();
439 | }
440 | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
441 | bm.compress(Bitmap.CompressFormat.JPEG, 100, bos);
442 | bos.flush();
443 | bos.close();
444 | // Toast.makeText(AddDataActivity.this,subFolder,Toast.LENGTH_SHORT).show();
445 | }
446 | }
447 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 |
6 | public class BaseActivity extends AppCompatActivity {
7 | @Override
8 | protected void onCreate(Bundle saveInstanceState){
9 | super.onCreate(saveInstanceState);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/BmpToBase64.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.graphics.Bitmap;
4 | import android.util.Base64;
5 |
6 | import java.io.ByteArrayOutputStream;
7 | import java.io.IOException;
8 |
9 | public class BmpToBase64 {
10 | //图片转为base64编码
11 | public static String bitmapToBase64(Bitmap bitmap) {
12 |
13 | String result = null;
14 |
15 | ByteArrayOutputStream baos = null;
16 | try {
17 | if (bitmap != null) {
18 | baos = new ByteArrayOutputStream();
19 | bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
20 |
21 | baos.flush();
22 | baos.close();
23 |
24 | byte[] bitmapBytes = baos.toByteArray();
25 | result = Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
26 | }
27 | } catch (IOException e) {
28 | e.printStackTrace();
29 | } finally {
30 | try {
31 | if (baos != null) {
32 | baos.flush();
33 | baos.close();
34 | }
35 | } catch (IOException e) {
36 | e.printStackTrace();
37 | }
38 | }
39 | return result;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/ChangePwd.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 |
8 | public class ChangePwd extends AppCompatActivity {
9 | private PasswordView pwdView;
10 | private SharedPreferences preferences;
11 | private SharedPreferences.Editor editor;
12 |
13 | @Override
14 | protected void onCreate(Bundle savedInstanceState) {
15 | super.onCreate(savedInstanceState);
16 | setContentView(R.layout.activity_change_pwd);
17 |
18 | initView();
19 | initEvent();
20 | }
21 |
22 | private void initView(){
23 | pwdView = findViewById(R.id.pwd_view);
24 | pwdView.setTitle("设置密码");
25 | preferences = getSharedPreferences("password",MODE_PRIVATE);
26 | editor = preferences.edit();
27 | }
28 |
29 | private void initEvent(){
30 | // 添加回调接口
31 | pwdView.setOnFinishInput(new OnPasswordInputFinish() {
32 | @Override
33 | public void inputFinish() {
34 | // 输入完成后我们简单显示一下输入的密码
35 | // 也就是说——>实现你的交易逻辑什么的在这里写
36 | // pwdView.getStrPassword()
37 | editor.clear();
38 | editor.putBoolean("isCheck",true);
39 | editor.putString("password",pwdView.getStrPassword());
40 | editor.apply();
41 | finish();
42 | }
43 | //取消
44 | @Override
45 | public void outfo() {
46 | //关闭页面
47 | finish();
48 | }
49 | //忘记密码回调事件
50 | @Override
51 | public void forgetPwd() {
52 |
53 | }
54 | });
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/ChartFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.graphics.Color;
7 | import android.graphics.drawable.Drawable;
8 | import android.os.Bundle;
9 | import android.support.annotation.NonNull;
10 | import android.support.annotation.Nullable;
11 | import android.support.v4.app.Fragment;
12 | import android.util.Log;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.ImageView;
17 | import android.widget.LinearLayout;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import com.github.mikephil.charting.charts.LineChart;
22 | import com.github.mikephil.charting.components.AxisBase;
23 | import com.github.mikephil.charting.components.Description;
24 | import com.github.mikephil.charting.components.XAxis;
25 | import com.github.mikephil.charting.components.YAxis;
26 | import com.github.mikephil.charting.data.Entry;
27 | import com.github.mikephil.charting.data.LineData;
28 | import com.github.mikephil.charting.data.LineDataSet;
29 | import com.github.mikephil.charting.formatter.IAxisValueFormatter;
30 | import com.github.mikephil.charting.highlight.Highlight;
31 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
32 | import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
33 |
34 | import org.litepal.LitePal;
35 |
36 | import java.util.ArrayList;
37 | import java.util.List;
38 |
39 |
40 | public class ChartFragment extends Fragment implements OnChartValueSelectedListener {
41 | private List diaryList = new ArrayList<>();
42 | private LineChart chart;
43 | private View view;
44 | private Context context;
45 | private TextView timeText,titleText,passageText;
46 | private ImageView imageView;
47 | private LinearLayout linearLayout;
48 | private String time,imgPath,title,passage;//页面显示内容
49 | private Diary diary;//用于传送到详情页面
50 | private IAxisValueFormatter formatter;
51 | private List quarters;
52 | @Override
53 | public void onCreate(@Nullable Bundle savedInstanceState) {
54 | super.onCreate(savedInstanceState);
55 | context = getContext();
56 | quarters = new ArrayList<>();
57 | formatter = new IAxisValueFormatter() {
58 | @Override
59 | public String getFormattedValue(float value, AxisBase axis) {
60 | int index = (int) value;
61 | if(index>=0&&index beautyEntries = new ArrayList<>();
89 | for(int i=0;i moodEntries = new ArrayList<>();
104 | for(int i=0;i lineDataSetList = new ArrayList<>();
121 | lineDataSetList.add(beautyDataSet);
122 | lineDataSetList.add(moodDataSet);
123 | LineData lineData = new LineData(lineDataSetList);
124 |
125 | YAxis yAxisR = chart.getAxisRight();//取消右侧Y轴
126 | yAxisR.setEnabled(false);
127 | YAxis yAxisL = chart.getAxisLeft();
128 | yAxisL.setPosition(YAxis.YAxisLabelPosition.OUTSIDE_CHART);
129 | yAxisL.setAxisMinimum(0f);
130 | yAxisL.setAxisMaximum(100f);
131 | yAxisL.setTextSize(10f);
132 |
133 | XAxis xAxis = chart.getXAxis();
134 | xAxis.setAvoidFirstLastClipping(true);
135 | xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);
136 | xAxis.setValueFormatter(formatter);
137 | xAxis.setDrawGridLines(false);//竖线
138 | xAxis.setGranularity(1f);//间隔
139 | xAxis.setTextSize(10f);
140 |
141 |
142 | chart.setData(lineData);
143 | //动画效果
144 | // chart.animateXY(1000,1000);
145 | // 描述
146 | chart.setDescription(null);
147 | // 背景颜色
148 | chart.setBackgroundColor(getResources().getColor(R.color.background));
149 | chart.setDragEnabled(true);//可以拖动
150 | chart.setScaleEnabled(false);//无法缩小
151 | chart.setPinchZoom(false);//无法放大
152 | chart.setVisibleXRangeMaximum(3);//最大容纳
153 |
154 | chart.setOnChartValueSelectedListener(this);
155 | chart.invalidate();
156 | }
157 |
158 | @Nullable
159 | @Override
160 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
161 | view = inflater.inflate(R.layout.frag_chart, container, false);
162 | chart = view.findViewById(R.id.chart);
163 | timeText = view.findViewById(R.id.chart_time);
164 | titleText = view.findViewById(R.id.chart_title);
165 | passageText = view.findViewById(R.id.chart_passage);
166 | imageView = view.findViewById(R.id.chart_image);
167 | linearLayout = view.findViewById(R.id.chart_item);
168 | linearLayout.setOnClickListener(new View.OnClickListener() {
169 | @Override
170 | public void onClick(View v) {
171 | if(diary!=null){
172 | DetailActivity.actionStart(context,diary.getTitle(),
173 | diary.getPassage(),diary.getYear(),diary.getMonth(),
174 | diary.getDay(),diary.getImgPath(),diary.getAge(),
175 | diary.getBeauty(),diary.getFaceShape(),
176 | diary.getMood(),diary.getId());
177 | try {
178 | Thread.sleep(500);
179 | timeText.setText(null);
180 | titleText.setText(null);
181 | passageText.setText(null);
182 | imageView.setImageBitmap(null);
183 | diary=null;
184 | } catch (InterruptedException e) {
185 | e.printStackTrace();
186 | }
187 |
188 | }
189 | }
190 | });
191 | return view;
192 | }
193 | @Override
194 | public void onValueSelected(Entry e, Highlight h) {
195 | diary = (Diary)e.getData();
196 | title = diary.getTitle();
197 | passage = diary.getPassage();
198 | time = diary.getMonth()+'/'+diary.getDay()+'\n'+diary.getYear();
199 | imgPath = diary.getImgPath();
200 |
201 | titleText.setText(title);
202 | passageText.setText(passage);
203 | timeText.setText(time);
204 | Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
205 | imageView.setImageBitmap(bitmap);
206 | }
207 | @Override
208 | public void onNothingSelected() {
209 |
210 | }
211 | }
212 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/DataFragment.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.NonNull;
5 | import android.support.annotation.Nullable;
6 | import android.support.v4.app.Fragment;
7 | import android.support.v7.widget.LinearLayoutManager;
8 | import android.support.v7.widget.RecyclerView;
9 | import android.view.LayoutInflater;
10 | import android.view.View;
11 | import android.view.ViewGroup;
12 | import android.widget.TextView;
13 |
14 | import com.amap.api.maps2d.AMap;
15 | import com.amap.api.maps2d.MapView;
16 |
17 | import org.litepal.LitePal;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Calendar;
21 | import java.util.List;
22 | import java.util.TimeZone;
23 |
24 | public class DataFragment extends Fragment {
25 | private List diaryList = new ArrayList<>();
26 | private TextView tips;
27 | private RecyclerView recyclerView;
28 | private DiaryAdapter diaryAdapter;
29 | private String[] months = new String[]{"一","二","三","四","五","六","七","八","九","十","十一","十二"};
30 | @Override
31 | public void onCreate(@Nullable Bundle savedInstanceState) {
32 | super.onCreate(savedInstanceState);
33 | diaryList = LitePal.findAll(Diary.class);
34 |
35 |
36 | }
37 | @Override
38 | public void onStart() {
39 | super.onStart();
40 | diaryList = LitePal.findAll(Diary.class);
41 | diaryAdapter.setDiaryList(diaryList);
42 | recyclerView.setAdapter(diaryAdapter);
43 | }
44 |
45 | @Nullable
46 | @Override
47 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
48 | View view = inflater.inflate(R.layout.frag_data, container, false);
49 | // 开头时间
50 | TextView time = view.findViewById(R.id.Time);
51 | Calendar calendar = Calendar.getInstance();
52 | calendar.setTimeZone(TimeZone.getTimeZone("GMT+8:00"));
53 | String year = String.valueOf(calendar.get(Calendar.YEAR));
54 | int month = calendar.get(Calendar.MONTH);
55 | time.setText(months[month]+"月 "+year);
56 |
57 | // 无内容提示
58 | tips = view.findViewById(R.id.tips);
59 | tips.setText("空空如也,"+"\n快来记录有意义的事情吧~");
60 |
61 | recyclerView = view.findViewById(R.id.recycler_view);
62 | LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
63 | recyclerView.setLayoutManager(linearLayoutManager);
64 | diaryAdapter = new DiaryAdapter(diaryList);
65 | recyclerView.setAdapter(diaryAdapter);
66 |
67 | return view;
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/DetailActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.Manifest;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.graphics.Bitmap;
8 | import android.graphics.BitmapFactory;
9 | import android.location.Location;
10 | import android.location.LocationListener;
11 | import android.support.v4.app.ActivityCompat;
12 | import android.support.v4.content.ContextCompat;
13 | import android.support.v7.app.AlertDialog;
14 | import android.support.v7.app.AppCompatActivity;
15 | import android.os.Bundle;
16 | import android.support.v7.widget.Toolbar;
17 | import android.util.Log;
18 | import android.view.Menu;
19 | import android.view.MenuItem;
20 | import android.widget.ImageView;
21 | import android.widget.TextView;
22 | import android.widget.Toast;
23 | import com.baidu.location.BDAbstractLocationListener;
24 | import com.baidu.location.BDLocation;
25 | import com.baidu.location.LocationClient;
26 | import com.baidu.location.LocationClientOption;
27 |
28 | import org.litepal.LitePal;
29 |
30 | import java.io.File;
31 | import java.text.SimpleDateFormat;
32 | import java.util.ArrayList;
33 | import java.util.Date;
34 | import java.util.List;
35 |
36 | public class DetailActivity extends AppCompatActivity {
37 | private ImageView imageView,mood_ico;
38 | private TextView ageText,beautyText,faceShapeText;
39 | private TextView timeText,moodText;
40 | private TextView titleText,passageText;
41 | // 数据
42 | private int id;
43 | private String title,passage;
44 | private String imgPath;
45 | private String age,beauty,faceShape;
46 |
47 | public static void actionStart(Context context, String title,
48 | String passage, String year,
49 | String month, String day,
50 | String imgPath, String age,
51 | String beauty, String faceShape,
52 | String mood,int id){
53 | Intent intent = new Intent(context, DetailActivity.class);
54 | intent.putExtra("title",title);
55 | intent.putExtra("passage",passage);
56 | intent.putExtra("year",year);
57 | intent.putExtra("month",month);
58 | intent.putExtra("day",day);
59 | intent.putExtra("imgPath",imgPath);
60 | intent.putExtra("age",age);
61 | intent.putExtra("beauty",beauty);
62 | intent.putExtra("faceShape",faceShape);
63 | intent.putExtra("mood",mood);
64 | intent.putExtra("id",id);
65 | context.startActivity(intent);
66 | }
67 | @Override
68 | protected void onCreate(Bundle savedInstanceState) {
69 | super.onCreate(savedInstanceState);
70 | setContentView(R.layout.activity_detail);
71 | initView();
72 | initData();
73 | // List permission = new ArrayList<>();
74 | // permission.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
75 | // permission.add(Manifest.permission.INTERNET);
76 | // permission.add(Manifest.permission.ACCESS_NETWORK_STATE);
77 | // permission.add(Manifest.permission.ACCESS_COARSE_LOCATION);
78 | // permission.add(Manifest.permission.ACCESS_FINE_LOCATION);
79 | // permission.add(Manifest.permission.ACCESS_WIFI_STATE);
80 | // permission.add(Manifest.permission.CHANGE_WIFI_STATE);
81 | // permission.add(Manifest.permission.READ_PHONE_STATE);
82 | // permission.add(Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS);
83 | // permission.add(Manifest.permission.BLUETOOTH);
84 | // permission.add(Manifest.permission.BLUETOOTH_ADMIN);
85 | //
86 | // String[] permissions = permission.toArray(new String[permission.size()]);
87 | // ActivityCompat.requestPermissions(DetailActivity.this,permissions,1);
88 |
89 |
90 | }
91 | public boolean onCreateOptionsMenu(Menu menu){
92 | getMenuInflater().inflate(R.menu.detail_toolbar,menu);
93 | return true;
94 | }
95 | @Override
96 | public boolean onOptionsItemSelected(MenuItem item){
97 | switch (item.getItemId()){
98 | case R.id.toolbar_delete:
99 | AlertDialog.Builder deleteDialog = new AlertDialog.Builder(DetailActivity.this);
100 | deleteDialog.setTitle("确认删除该记录吗?");
101 | deleteDialog.setPositiveButton("确定", new DialogInterface.OnClickListener() {
102 | @Override
103 | public void onClick(DialogInterface dialog, int which) {
104 | LitePal.delete(Diary.class,id);
105 | if(!imgPath.equals("")){
106 | File file = new File(imgPath);
107 | file.delete();
108 | }
109 | Toast.makeText(DetailActivity.this,"删除成功"+id,Toast.LENGTH_SHORT).show();
110 | finish();
111 | }
112 | });
113 | deleteDialog.setNegativeButton("取消", new DialogInterface.OnClickListener() {
114 | @Override
115 | public void onClick(DialogInterface dialog, int which) {
116 | }
117 | });
118 | deleteDialog.show();
119 | break;
120 | case R.id.toolbar_update:
121 | AlertDialog.Builder updateDialog = new AlertDialog.Builder(DetailActivity.this);
122 | updateDialog.setTitle("是否修改该记录?");
123 | updateDialog.setPositiveButton("是", new DialogInterface.OnClickListener() {
124 | @Override
125 | public void onClick(DialogInterface dialog, int which) {
126 | AddDataActivity.actionStart(DetailActivity.this,title,
127 | passage,imgPath,age,beauty,faceShape,id);
128 | finish();
129 | }
130 | });
131 | updateDialog.setNegativeButton("否", new DialogInterface.OnClickListener() {
132 | @Override
133 | public void onClick(DialogInterface dialog, int which) {
134 | }
135 | });
136 | updateDialog.show();
137 | break;
138 | default:
139 | break;
140 | }
141 | return true;
142 | }
143 | private void initView(){
144 | // 组件
145 | imageView = findViewById(R.id.detail_img);
146 | mood_ico = findViewById(R.id.mood_ico);
147 | ageText = findViewById(R.id.detail_age);
148 | beautyText = findViewById(R.id.detail_beauty);
149 | faceShapeText = findViewById(R.id.detail_faceShape);
150 | timeText = findViewById(R.id.detail_time);
151 | moodText = findViewById(R.id.detail_mood);
152 | titleText = findViewById(R.id.detail_title);
153 | passageText = findViewById(R.id.detail_passage);
154 | Toolbar toolbar = findViewById(R.id.detail_toolbar);
155 | setSupportActionBar(toolbar);
156 | }
157 | private void initData(){
158 | // 接收数据
159 | Intent intent = getIntent();
160 | title = intent.getStringExtra("title");
161 | passage = intent.getStringExtra("passage");
162 | // 无需传递,设为局部变量
163 | String year = intent.getStringExtra("year");
164 | String month = intent.getStringExtra("month");
165 | String day = intent.getStringExtra("day");
166 | imgPath = intent.getStringExtra("imgPath");
167 | age = intent.getStringExtra("age");
168 | beauty = intent.getStringExtra("beauty");
169 | faceShape = intent.getStringExtra("faceShape");
170 | long mood_value = Math.round(Double.valueOf(intent.getStringExtra("mood").split(",")[1])*100);
171 | String mood = String.valueOf(mood_value);
172 | id = intent.getIntExtra("id",-1);
173 | // 设置数据
174 | Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
175 | //Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes,0,imgBytes.length);
176 | imageView.setImageBitmap(bitmap);
177 | ageText.setText(String.format("%s%s", ageText.getText(), age));
178 | beautyText.setText(String.format("%s%s", beautyText.getText(), beauty));
179 | faceShapeText.setText(String.format("%s%s", faceShapeText.getText(), faceShape));
180 | titleText.setText(String.format("%s%s", titleText.getText(), title));
181 | passageText.setText(String.format("%s%s", passageText.getText(), passage));
182 | timeText.setText(String.format("%s%s/%s/%s", timeText.getText(), year, month, day));
183 | moodText.setText(String.format("%s%s", moodText.getText(), mood));
184 |
185 | if (mood_value<=25)
186 | mood_ico.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.cry));
187 | else if(mood_value<=50)
188 | mood_ico.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.sad));
189 | else if (mood_value<=75)
190 | mood_ico.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.smile));
191 | else
192 | mood_ico.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(),R.drawable.happy));
193 | }
194 | }
195 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/DetectService.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.app.ProgressDialog;
4 | import android.app.Service;
5 | import android.content.Intent;
6 | import android.os.Binder;
7 | import android.os.IBinder;
8 | import android.support.v7.app.AlertDialog;
9 | import android.util.Log;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | public class DetectService extends Service {
14 | private DetectBinder mBinder = new DetectBinder();
15 |
16 | public DetectService() {
17 | }
18 |
19 | @Override
20 | public IBinder onBind(Intent intent) {
21 | // TODO: Return the communication channel to the service.
22 | return mBinder;
23 | }
24 |
25 | class DetectBinder extends Binder{
26 | public void startDetect(ProgressDialog pD, AlertDialog.Builder aD, ImageView imageView, TextView age, TextView beauty, TextView faceShape, String imgBase64, String access_token){
27 | new DetectTask(pD,aD,imageView,age,beauty,faceShape).execute("face",imgBase64,access_token);
28 | Log.d("AddDataActivity", "service");
29 | }
30 | public void startDetect(ProgressDialog pD, Diary d , AddDataActivity add, String passage, String access_token){
31 | new DetectTask(pD,d,add).execute("text",passage,access_token);
32 | Log.d("AddDataActivity", "service");
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/DetectTask.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.app.ProgressDialog;
4 | import android.content.DialogInterface;
5 | import android.graphics.Bitmap;
6 | import android.graphics.BitmapFactory;
7 | import android.os.AsyncTask;
8 | import android.support.v7.app.AlertDialog;
9 | import android.util.Log;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import java.util.HashMap;
15 |
16 | public class DetectTask extends AsyncTask {
17 | private ProgressDialog progressDialog;
18 | private AlertDialog.Builder alertDialog;
19 | // 人脸预测
20 | private TextView ageText, beautyText, faceShapeText;
21 | private ImageView imageView;
22 | // 人脸脸型对应关系
23 | private HashMap map = new HashMap<>();
24 |
25 | private String detect_type;
26 | private Diary diary;
27 | private AddDataActivity addDataActivity;
28 |
29 | public DetectTask(ProgressDialog pD, AlertDialog.Builder aD, ImageView img, TextView age, TextView beauty, TextView faceShape){
30 | progressDialog = pD;
31 | imageView = img;
32 | alertDialog = aD;
33 | ageText = age;
34 | beautyText = beauty;
35 | faceShapeText = faceShape;
36 | map.put("square","正方形");
37 | map.put("triangle","三角形");
38 | map.put("oval","椭圆");
39 | map.put("heart","心形");
40 | map.put("round","圆形");
41 | }
42 | public DetectTask(ProgressDialog pD,Diary d ,AddDataActivity add){
43 | progressDialog = pD;
44 | diary = d;
45 | addDataActivity = add;
46 | map.put("square","正方形");
47 | map.put("triangle","三角形");
48 | map.put("oval","椭圆");
49 | map.put("heart","心形");
50 | map.put("round","圆形");
51 | }
52 |
53 | protected void onPreExecute(){
54 | progressDialog.show();
55 | }
56 |
57 | protected String[] doInBackground(String... params){
58 | if (params[0].equals("face")){
59 | detect_type = params[0];
60 | return FaceDect.detect(params[1], params[2]);
61 | }
62 | else{
63 | detect_type = params[0];
64 | return TextDect.detect(params[1],params[2]);
65 | }
66 | }
67 |
68 | protected void onProgressUpdate(String... values){
69 |
70 | }
71 |
72 | protected void onPostExecute(String[] result){
73 | progressDialog.dismiss();
74 | if(detect_type.equals("face"))
75 | {
76 | if(result!=null){
77 | ageText.setText(result[0]);
78 | beautyText.setText(result[1]);
79 | faceShapeText.setText(map.get(result[2]));
80 |
81 |
82 | }
83 | else{
84 | ageText.setText("");
85 | beautyText.setText("");
86 | faceShapeText.setText("");
87 | Log.d("face error", "no result" );
88 | alertDialog.show();
89 |
90 | //imageView.setImageBitmap(BitmapFactory.decodeResource(addDataActivity.getResources(),R.drawable.camera));
91 | }
92 | }
93 | else{
94 | if(result!=null){
95 | String data = result[0]+","+result[1];
96 | diary.setMood(data);
97 | }
98 | diary.save();
99 | addDataActivity.finish();
100 | }
101 |
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/Diary.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import org.litepal.crud.LitePalSupport;
4 |
5 | public class Diary extends LitePalSupport {
6 | private int id;
7 | private String year,month,day;
8 | private String title,passage;
9 | private String mood;
10 | private String imgPath;
11 | private String age,beauty,faceShape;
12 |
13 | public int getId() {
14 | return id;
15 | }
16 | public void setId(int id) {
17 | this.id = id;
18 | }
19 |
20 | String getImgPath() {
21 | return imgPath;
22 | }
23 | void setImgPath(String imgPath) {
24 | this.imgPath = imgPath;
25 | }
26 |
27 | String getYear() {
28 | return year;
29 | }
30 | void setYear(String year) {
31 | this.year = year;
32 | }
33 |
34 | String getMonth() {
35 | return month;
36 | }
37 | void setMonth(String month) {
38 | this.month = month;
39 | }
40 |
41 | String getDay() {
42 | return day;
43 | }
44 | void setDay(String day) {
45 | this.day = day;
46 | }
47 |
48 | String getTitle() {
49 | return title;
50 | }
51 | void setTitle(String title) {
52 | this.title = title;
53 | }
54 |
55 | String getPassage() {
56 | return passage;
57 | }
58 | void setPassage(String passage) {
59 | this.passage = passage;
60 | }
61 |
62 | String getMood() {
63 | return mood;
64 | }
65 | void setMood(String mood) {
66 | this.mood = mood;
67 | }
68 |
69 | String getAge() {
70 | return age;
71 | }
72 | void setAge(String age) {
73 | this.age = age;
74 | }
75 |
76 | String getBeauty() {
77 | return beauty;
78 | }
79 | void setBeauty(String beauty) {
80 | this.beauty = beauty;
81 | }
82 |
83 | String getFaceShape() {
84 | return faceShape;
85 | }
86 | void setFaceShape(String faceShape) {
87 | this.faceShape = faceShape;
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/DiaryAdapter.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.support.annotation.NonNull;
7 | import android.support.v7.widget.RecyclerView;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import java.util.List;
15 |
16 | public class DiaryAdapter extends RecyclerView.Adapter{
17 | private Context mContext;
18 | private List diaryList;
19 |
20 | static class ViewHolder extends RecyclerView.ViewHolder{
21 | ImageView dataImage;
22 | TextView dataTime,dataTitle,dataPassage;
23 | ViewHolder(View view){
24 | super(view);
25 | dataTime = view.findViewById(R.id.data_time);
26 | dataImage = view.findViewById(R.id.data_image);
27 | dataTitle = view.findViewById(R.id.data_title);
28 | dataPassage = view.findViewById(R.id.data_passage);
29 | }
30 | }
31 |
32 | DiaryAdapter(List DiaryList){
33 | diaryList = DiaryList;
34 | }
35 | void setDiaryList(List DiaryList){
36 | diaryList = DiaryList;
37 | }
38 |
39 | @NonNull
40 | @Override
41 | public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
42 | if (mContext == null) {
43 | mContext = parent.getContext();
44 | }
45 | View view = LayoutInflater.from(mContext).inflate(R.layout.data_item, parent, false);
46 | final ViewHolder holder = new ViewHolder(view);
47 | holder.itemView.setOnClickListener(new View.OnClickListener() {
48 | @Override
49 | public void onClick(View v) {
50 | int position = holder.getAdapterPosition();
51 | Diary diary = diaryList.get(position);
52 | DetailActivity.actionStart(mContext,diary.getTitle(),diary.getPassage(),
53 | diary.getYear(),diary.getMonth(),diary.getDay(),diary.getImgPath(),
54 | diary.getAge(),diary.getBeauty(),diary.getFaceShape(),diary.getMood(),
55 | diary.getId());
56 | // Toast.makeText(mContext,"You click "+position,Toast.LENGTH_SHORT).show();
57 | }
58 | });
59 | return holder;
60 | }
61 | @Override
62 | public void onBindViewHolder(@NonNull ViewHolder holder, int position){
63 | Diary diary = diaryList.get(position);
64 | holder.dataTime.setText(String.format("%s/%s\n%s", diary.getMonth(), diary.getDay(),diary.getYear()));
65 | holder.dataTitle.setText(diary.getTitle());
66 | // 设置内容
67 | String passage = diary.getPassage();
68 | if(passage.length()>50)
69 | passage = passage.substring(0,50)+"......";
70 | holder.dataPassage.setText(passage);
71 | //Glide一行代码及实现复杂图片的加载,需在build.gradle中引用
72 | String imgPath = diary.getImgPath();
73 | Bitmap bitmap = BitmapFactory.decodeFile(imgPath);
74 | //byte[] imgBytes = diary.getImgBytes();
75 | //Bitmap bitmap = BitmapFactory.decodeByteArray(imgBytes,0,imgBytes.length);
76 | //Glide.with(mContext).load(bitmap).into(holder.dataImage);
77 | holder.dataImage.setImageBitmap(bitmap);
78 | }
79 | @Override
80 | public int getItemCount(){
81 | return diaryList.size();
82 | }
83 | }
84 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/FaceDect.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.util.Log;
4 |
5 | import org.json.JSONArray;
6 | import org.json.JSONObject;
7 |
8 | import java.util.HashMap;
9 | import java.util.Map;
10 |
11 |
12 | public class FaceDect {
13 | public static String[] detect(String image ,String access_token) {
14 | // 请求url
15 | String url = "https://aip.baidubce.com/rest/2.0/face/v3/detect";
16 | try {
17 | Map map = new HashMap<>();
18 | map.put("image", image);
19 | map.put("face_field", "age,faceshape,beauty");
20 | map.put("image_type", "BASE64");
21 |
22 | String param = GsonUtils.toJson(map);
23 |
24 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
25 | String accessToken = access_token;
26 |
27 | final String result = HttpUtil.post(url, accessToken, "application/json", param);
28 |
29 | // 解析json(默认只提取第一条数据,若多张人脸则循环)
30 | JSONArray jsonArray = new JSONObject(result).getJSONObject("result").getJSONArray("face_list");
31 | JSONObject jsonObject = jsonArray.getJSONObject(0);
32 | String age = String.valueOf(jsonObject.getDouble("age"));
33 | String beauty = String.valueOf(jsonObject.getInt("beauty"));
34 | String face_shape = jsonObject.getJSONObject("face_shape").getString("type");
35 | Log.d("MainActivity", age);
36 | Log.d("MainActivity", beauty);
37 | Log.d("MainActivity", face_shape);
38 |
39 | // 返回年龄、颜值、脸型
40 | String [] data = new String[3];
41 | data[0]=age;
42 | data[1]=beauty;
43 | data[2]=face_shape;
44 |
45 | return data;
46 | } catch (Exception e) {
47 | e.printStackTrace();
48 | }
49 | return null;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/GsonUtils.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2017 Baidu, Inc. All Rights Reserved.
3 | */
4 | package com.example.easynote;
5 |
6 | import com.google.gson.Gson;
7 | import com.google.gson.GsonBuilder;
8 | import com.google.gson.JsonParseException;
9 |
10 | import java.lang.reflect.Type;
11 |
12 | /**
13 | * Json工具类.
14 | */
15 | public class GsonUtils {
16 | private static Gson gson = new GsonBuilder().create();
17 |
18 | public static String toJson(Object value) {
19 | return gson.toJson(value);
20 | }
21 |
22 | public static T fromJson(String json, Class classOfT) throws JsonParseException {
23 | return gson.fromJson(json, classOfT);
24 | }
25 |
26 | public static T fromJson(String json, Type typeOfT) throws JsonParseException {
27 | return (T) gson.fromJson(json, typeOfT);
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/HttpUtil.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import java.io.BufferedReader;
4 | import java.io.DataOutputStream;
5 | import java.io.InputStreamReader;
6 | import java.net.HttpURLConnection;
7 | import java.net.URL;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * http 工具类
13 | */
14 | public class HttpUtil {
15 |
16 | public static String post(String requestUrl, String accessToken, String params)
17 | throws Exception {
18 | String contentType = "application/x-www-form-urlencoded";
19 | return HttpUtil.post(requestUrl, accessToken, contentType, params);
20 | }
21 |
22 | public static String post(String requestUrl, String accessToken, String contentType, String params)
23 | throws Exception {
24 | String encoding = "UTF-8";
25 | if (requestUrl.contains("nlp")) {
26 | encoding = "GBK";
27 | }
28 | return HttpUtil.post(requestUrl, accessToken, contentType, params, encoding);
29 | }
30 |
31 | public static String post(String requestUrl, String accessToken, String contentType, String params, String encoding)
32 | throws Exception {
33 | String url = requestUrl + "?access_token=" + accessToken;
34 | return HttpUtil.postGeneralUrl(url, contentType, params, encoding);
35 | }
36 |
37 | public static String postGeneralUrl(String generalUrl, String contentType, String params, String encoding)
38 | throws Exception {
39 | URL url = new URL(generalUrl);
40 | // 打开和URL之间的连接
41 | HttpURLConnection connection = (HttpURLConnection) url.openConnection();
42 | connection.setRequestMethod("POST");
43 | // 设置通用的请求属性
44 | connection.setRequestProperty("Content-Type", contentType);
45 | connection.setRequestProperty("Connection", "Keep-Alive");
46 | connection.setUseCaches(false);
47 | connection.setDoOutput(true);
48 | connection.setDoInput(true);
49 |
50 | // 得到请求的输出流对象
51 | DataOutputStream out = new DataOutputStream(connection.getOutputStream());
52 | out.write(params.getBytes(encoding));
53 | out.flush();
54 | out.close();
55 |
56 | // 建立实际的连接
57 | connection.connect();
58 | // 获取所有响应头字段
59 | Map> headers = connection.getHeaderFields();
60 | // 遍历所有的响应头字段
61 | for (String key : headers.keySet()) {
62 | System.err.println(key + "--->" + headers.get(key));
63 | }
64 | // 定义 BufferedReader输入流来读取URL的响应
65 | BufferedReader in = null;
66 | in = new BufferedReader(
67 | new InputStreamReader(connection.getInputStream(), encoding));
68 | String result = "";
69 | String getLine;
70 | while ((getLine = in.readLine()) != null) {
71 | result += getLine;
72 | }
73 | in.close();
74 | System.err.println("result:" + result);
75 | return result;
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/InputPwd.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.content.Intent;
4 | import android.content.SharedPreferences;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.os.Bundle;
7 | import android.widget.Toast;
8 |
9 | public class InputPwd extends AppCompatActivity {
10 | private PasswordView pwdView;
11 | private SharedPreferences preferences;
12 | private SharedPreferences.Editor editor;
13 | private String target;
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_input_pwd);
19 |
20 | initView();
21 | initEvent();
22 | }
23 |
24 | private void initView(){
25 | pwdView = findViewById(R.id.pwd_view);
26 | pwdView.setTitle("输入密码");
27 | preferences = getSharedPreferences("password",MODE_PRIVATE);
28 | editor = preferences.edit();
29 | Intent intent = getIntent();
30 | target = intent.getStringExtra("target");
31 | }
32 |
33 | private void initEvent(){
34 | // 添加回调接口
35 | pwdView.setOnFinishInput(new OnPasswordInputFinish() {
36 | @Override
37 | public void inputFinish() {
38 | // 输入完成后我们简单显示一下输入的密码
39 | // 也就是说——>实现你的交易逻辑什么的在这里写
40 | // pwdView.getStrPassword()
41 | String password = preferences.getString("password","");
42 | if(pwdView.getStrPassword().equals(password))
43 | {
44 | if(target.equals("SetPwd")){
45 | Intent intent = new Intent(InputPwd.this,SetPwd.class);
46 | startActivity(intent);
47 | }
48 | finish();
49 | }
50 | else{
51 | Toast.makeText(InputPwd.this,"密码错误",Toast.LENGTH_SHORT).show();
52 | }
53 | }
54 | //取消
55 | @Override
56 | public void outfo() {
57 | //关闭页面
58 | if (target.equals("MainActivity")){
59 | MainActivity.mainActivity.finish();
60 | }
61 | finish();
62 | }
63 | //忘记密码回调事件
64 | @Override
65 | public void forgetPwd() {
66 |
67 | }
68 | });
69 | }
70 | public void onBackPressed(){
71 | super.onBackPressed();
72 | MainActivity.mainActivity.finish();
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import android.Manifest;
4 | import android.content.BroadcastReceiver;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.IntentFilter;
8 | import android.content.SharedPreferences;
9 | import android.content.pm.PackageManager;
10 | import android.net.ConnectivityManager;
11 | import android.net.NetworkInfo;
12 | import android.os.Bundle;
13 | import android.support.annotation.NonNull;
14 | import android.support.design.widget.BottomNavigationView;
15 | import android.support.design.widget.FloatingActionButton;
16 | import android.support.design.widget.NavigationView;
17 | import android.support.v4.app.ActivityCompat;
18 | import android.support.v4.app.Fragment;
19 | import android.support.v4.app.FragmentManager;
20 | import android.support.v4.app.FragmentPagerAdapter;
21 | import android.support.v4.content.ContextCompat;
22 | import android.support.v4.view.GravityCompat;
23 | import android.support.v4.view.ViewPager;
24 | import android.support.v4.widget.DrawerLayout;
25 | import android.support.v7.app.ActionBar;
26 | import android.support.v7.app.AppCompatActivity;
27 | import android.support.v7.widget.Toolbar;
28 | import android.util.Log;
29 | import android.view.MenuItem;
30 | import android.view.View;
31 | import android.widget.TextView;
32 | import android.widget.Toast;
33 |
34 | import com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx;
35 |
36 | import org.litepal.LitePal;
37 |
38 | import java.util.ArrayList;
39 | import java.util.List;
40 |
41 | public class MainActivity extends AppCompatActivity {
42 | // 主活动单例
43 | public static MainActivity mainActivity;
44 | private BottomNavigationViewEx bnve;
45 | private VpAdapter adapter;
46 | private List fragments;
47 | private ViewPager viewPager;
48 | private FloatingActionButton floatingActionButton;
49 | private DrawerLayout mDrawerLayout;
50 | private NavigationView navView;
51 | private Toolbar toolbar;
52 | private ActionBar actionBar;
53 | private TextView diary_num;
54 | private TextView mood_avg;
55 | // 密码存储
56 | private SharedPreferences preferences;
57 | // 网络广播
58 | private IntentFilter intentFilter;
59 | private NetworkChangeReceiver networkChangeReceiver;
60 |
61 | @Override
62 | protected void onCreate(Bundle savedInstanceState) {
63 | super.onCreate(savedInstanceState);
64 | mainActivity = this;
65 |
66 |
67 | preferences = getSharedPreferences("password",MODE_PRIVATE);
68 | // 是否需要密码
69 | boolean check = preferences.getBoolean("isCheck",false);
70 | if(check){
71 | Intent intent = new Intent(MainActivity.this,InputPwd.class);
72 | intent.putExtra("target","MainActivity");
73 | startActivity(intent);
74 | }
75 | setContentView(R.layout.activity_main);
76 | //创建数据库
77 | LitePal.getDatabase();
78 | initView();
79 | initData();
80 | initBNVE();
81 | initEvent();
82 |
83 | //网络广播
84 | intentFilter = new IntentFilter();
85 | intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
86 | networkChangeReceiver = new NetworkChangeReceiver();
87 | registerReceiver(networkChangeReceiver,intentFilter);
88 |
89 | }
90 | // 该程序销毁时取消注册
91 | protected void onDestroy(){
92 | super.onDestroy();
93 | unregisterReceiver(networkChangeReceiver);
94 | }
95 | /**
96 | * init BottomNavigationViewEx envent
97 | */
98 | private void initEvent() {
99 | bnve.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
100 | private int previousPosition = -1;
101 |
102 | @Override
103 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
104 | int position = 0;
105 | switch (item.getItemId()) {
106 | case R.id.menu_main:
107 | position = 0;
108 | break;
109 | case R.id.menu_chart:
110 | position = 2;
111 | break;
112 | case R.id.menu_add: {
113 | //position = 1;
114 | //此处return false且在FloatingActionButton没有自定义点击事件时 会屏蔽点击事件
115 | return false;
116 | }
117 | default:
118 | break;
119 | }
120 | if (previousPosition != position) {
121 | viewPager.setCurrentItem(position, false);
122 | previousPosition = position;
123 | }
124 |
125 | return true;
126 | }
127 | });
128 |
129 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
130 | @Override
131 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
132 |
133 | }
134 |
135 | @Override
136 | public void onPageSelected(int position) {
137 |
138 | /*if (1 == position) {
139 | floatingActionButton.setImageResource(R.drawable.ic_add);
140 |
141 | } else {
142 | floatingActionButton.setImageResource(R.drawable.ic_add);
143 |
144 | }*/
145 | /* // 1 is center 此段结合屏蔽FloatingActionButton点击事件的情况使用
146 | //在viewPage滑动的时候 跳过最中间的page也
147 | if (position >= 1) {
148 | position++;
149 | }*/
150 | bnve.setCurrentItem(position);
151 | }
152 |
153 | @Override
154 | public void onPageScrollStateChanged(int state) {
155 |
156 | }
157 | });
158 | /*
159 | * fab 点击事件结合OnNavigationItemSelectedListener中return false使用
160 | */
161 | floatingActionButton.setOnClickListener(new View.OnClickListener() {
162 | @Override
163 | public void onClick(View view) {
164 | AddDataActivity.actionStart(MainActivity.this,"",
165 | "","","","","",-1);
166 | }
167 | });
168 |
169 |
170 | // 抽屉导航栏
171 | navView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
172 | @Override
173 | public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
174 | switch (menuItem.getItemId()){
175 | case R.id.nav_pwd:
176 | boolean ischeck = preferences.getBoolean("isCheck",false);
177 | Intent intent;
178 | if(ischeck)
179 | {
180 | intent= new Intent(MainActivity.this,InputPwd.class);
181 | intent.putExtra("target","SetPwd");
182 | }
183 | else
184 | intent = new Intent(MainActivity.this,SetPwd.class);
185 | startActivity(intent);
186 | break;
187 | }
188 | return true;
189 | }
190 | });
191 | }
192 |
193 |
194 |
195 | private void initView() {
196 | floatingActionButton = findViewById(R.id.fab);
197 | viewPager = findViewById(R.id.vp);
198 | bnve = findViewById(R.id.bnve);
199 | toolbar = findViewById(R.id.index_toolbar);
200 | setSupportActionBar(toolbar);
201 |
202 | mDrawerLayout = findViewById(R.id.drawer_layout);
203 | navView = findViewById(R.id.nav_view);
204 | actionBar = getSupportActionBar();
205 | if(actionBar!=null){
206 | actionBar.setDisplayHomeAsUpEnabled(true);
207 | actionBar.setHomeAsUpIndicator(R.drawable.ic_menu);
208 | }
209 | mood_avg = navView.getHeaderView(0).findViewById(R.id.mood_avg);
210 | diary_num = navView.getHeaderView(0).findViewById(R.id.diary_num);
211 | }
212 |
213 | /**
214 | * create fragments
215 | */
216 | private void initData() {
217 | //第一个页面
218 | fragments = new ArrayList<>(2);
219 | DataFragment dataFragment = new DataFragment();
220 | Bundle bundle = new Bundle();
221 | bundle.putString("title", "记录");
222 | dataFragment.setArguments(bundle);
223 | //第二个页面
224 | ChartFragment chartFragment = new ChartFragment();
225 | bundle = new Bundle();
226 | bundle.putString("title", "统计");
227 | chartFragment.setArguments(bundle);
228 |
229 | fragments.add(dataFragment);
230 | fragments.add(chartFragment);
231 | }
232 |
233 | /**
234 | * init BottomNavigationViewEx
235 | */
236 | private void initBNVE() {
237 | //取消动画效果
238 | // bnve.enableAnimation(false);
239 | // bnve.enableShiftingMode(false);
240 | // bnve.enableItemShiftingMode(false);
241 |
242 | adapter = new VpAdapter(getSupportFragmentManager(), fragments);
243 | viewPager.setAdapter(adapter);
244 |
245 | }
246 |
247 |
248 | public boolean onOptionsItemSelected(MenuItem item){
249 | switch (item.getItemId()){
250 | case android.R.id.home:
251 | //DrawerLayout
252 | List diaryList = new ArrayList<>();
253 | diaryList = LitePal.findAll(Diary.class);
254 | if (diaryList==null)
255 | diary_num.setText(0);
256 | else
257 | diary_num.setText(" "+String.valueOf(diaryList.size())+" ");
258 | long sum=0;
259 | for(Diary diary:diaryList){
260 | sum+=Math.round(Double.valueOf(diary.getMood().split(",")[1])*100);
261 | }
262 | long avg = Math.round((double)sum/(double)diaryList.size());
263 | mood_avg.setText(" "+String.valueOf(avg)+" ");
264 |
265 | mDrawerLayout.openDrawer(GravityCompat.START);
266 | break;
267 | default:
268 | }
269 | return true;
270 | }
271 | /**
272 | * view pager adapter
273 | */
274 | private static class VpAdapter extends FragmentPagerAdapter {
275 | private List data;
276 |
277 | VpAdapter(FragmentManager fm, List data) {
278 | super(fm);
279 | this.data = data;
280 | }
281 |
282 | @Override
283 | public int getCount() {
284 | return data.size();
285 | }
286 |
287 | @Override
288 | public Fragment getItem(int position) {
289 | return data.get(position);
290 | }
291 | }
292 |
293 |
294 | // 监听网络(广播)
295 | class NetworkChangeReceiver extends BroadcastReceiver {
296 | public void onReceive(Context context , Intent intent){
297 |
298 | ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
299 | NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
300 | if (networkInfo!=null&&networkInfo.isAvailable()){
301 | Toast.makeText(context, "network is available", Toast.LENGTH_SHORT).show();
302 | }else{
303 | Toast.makeText(context,"network is unavailable",Toast.LENGTH_SHORT).show();
304 | }
305 | }
306 | }
307 | }
308 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/MyLineChart.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 |
4 | import android.content.Context;
5 | import android.util.AttributeSet;
6 |
7 | import com.github.mikephil.charting.charts.LineChart;
8 |
9 | public class MyLineChart extends LineChart {
10 |
11 |
12 | public MyLineChart(Context context) {
13 | super(context);
14 | }
15 |
16 | public MyLineChart(Context context, AttributeSet attrs) {
17 | super(context, attrs);
18 | }
19 |
20 | @Override
21 | protected void init() {
22 | super.init();
23 | mXAxisRenderer = new MyXAxisRenderer(mViewPortHandler, mXAxis, mLeftAxisTransformer);
24 | }
25 |
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/MyXAxisRenderer.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 |
4 | import android.graphics.Canvas;
5 |
6 | import com.github.mikephil.charting.components.XAxis;
7 | import com.github.mikephil.charting.renderer.XAxisRenderer;
8 | import com.github.mikephil.charting.utils.MPPointF;
9 | import com.github.mikephil.charting.utils.Transformer;
10 | import com.github.mikephil.charting.utils.Utils;
11 | import com.github.mikephil.charting.utils.ViewPortHandler;
12 |
13 | import java.util.ArrayList;
14 | import java.util.List;
15 |
16 | public class MyXAxisRenderer extends XAxisRenderer {
17 | //这里为了方便把X轴标签放到这里了,其实可以通过其他方式能拿到要设置的X轴标签就可以
18 | private static List xLable;
19 |
20 | public MyXAxisRenderer(ViewPortHandler viewPortHandler, XAxis xAxis, Transformer trans) {
21 | super(viewPortHandler, xAxis, trans);
22 | xLable = new ArrayList<>();
23 | }
24 |
25 |
26 | //重写drawLabels
27 | @Override
28 | protected void drawLabels(Canvas c, float pos, MPPointF anchor) {
29 | //把源码代码复制过来
30 | final float labelRotationAngleDegrees = mXAxis.getLabelRotationAngle();
31 | boolean centeringEnabled = mXAxis.isCenterAxisLabelsEnabled();
32 |
33 | float[] positions = new float[mXAxis.mEntryCount * 2];
34 |
35 | for (int i = 0; i < positions.length; i += 2) {
36 |
37 | // only fill x values
38 | if (centeringEnabled) {
39 | positions[i] = mXAxis.mCenteredEntries[i / 2];
40 | } else {
41 | positions[i] = mXAxis.mEntries[i / 2];
42 | }
43 | }
44 |
45 | mTrans.pointValuesToPixel(positions);
46 |
47 | for (int i = 0; i < positions.length; i += 2) {
48 |
49 | float x = positions[i];
50 |
51 | if (mViewPortHandler.isInBoundsX(x)) {
52 |
53 | //修改源码 这里添加要设置的X轴的label
54 | String label = xLable.get(i/2);
55 | // String label = mXAxis.getValueFormatter().getFormattedValue(mXAxis.mEntries[i / 2], mXAxis);
56 |
57 | if (mXAxis.isAvoidFirstLastClippingEnabled()) {
58 | // avoid clipping of the last mXAxis.mEntryCount - 1为x轴坐标的标签数
59 | if (i == mXAxis.mEntryCount - 1 && mXAxis.mEntryCount > 1) {
60 | float width = Utils.calcTextWidth(mAxisLabelPaint, label);
61 |
62 | if (width > mViewPortHandler.offsetRight() * 2
63 | && x + width > mViewPortHandler.getChartWidth())
64 | x -= width / 2;
65 | // avoid clipping of the first
66 | } else if (i == 0) {
67 |
68 | float width = Utils.calcTextWidth(mAxisLabelPaint, label);
69 | x += width / 2;
70 | }
71 | }
72 | drawLabel(c, label, x, pos, anchor, labelRotationAngleDegrees);
73 | }
74 | }
75 |
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/OnPasswordInputFinish.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | //自定义接口
4 | public interface OnPasswordInputFinish {
5 | //添加密码输入完成的接口
6 | void inputFinish();
7 | //取消支付接口
8 | void outfo();
9 | //忘记密码接口
10 | void forgetPwd();
11 | }
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/easynote/PasswordView.java:
--------------------------------------------------------------------------------
1 | package com.example.easynote;
2 |
3 | import java.util.ArrayList;
4 | import java.util.HashMap;
5 | import java.util.Map;
6 |
7 | import android.content.Context;
8 | import android.text.Editable;
9 | import android.text.TextWatcher;
10 | import android.util.AttributeSet;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.AdapterView;
14 | import android.widget.BaseAdapter;
15 | import android.widget.GridView;
16 | import android.widget.ImageView;
17 | import android.widget.RelativeLayout;
18 | import android.widget.TextView;
19 |
20 | public class PasswordView extends RelativeLayout {
21 |
22 | Context context;
23 | private String strPassword; // 输入的密码
24 | private TextView[] tvList; // 就6个输入框不会变了,用数组内存申请固定空间,比List省空间
25 | private GridView gridView; // 用GrideView布局键盘,其实并不是真正的键盘,只是模拟键盘的功能
26 | private ArrayList