├── .idea
├── .name
├── copyright
│ └── profiles_settings.xml
├── encodings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── compiler.xml
├── gradle.xml
└── misc.xml
├── settings.gradle
├── app
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── ok.png
│ │ │ │ ├── sad2.png
│ │ │ │ ├── sad3.png
│ │ │ │ ├── diary.png
│ │ │ │ ├── laugh2.png
│ │ │ │ ├── laugh3.png
│ │ │ │ ├── smile2.png
│ │ │ │ ├── smile3.png
│ │ │ │ ├── test1.jpg
│ │ │ │ ├── test2.jpg
│ │ │ │ ├── test3.jpg
│ │ │ │ ├── test4.jpg
│ │ │ │ ├── heart_red.png
│ │ │ │ ├── leftarrow.png
│ │ │ │ ├── portrait.png
│ │ │ │ ├── camera_white.png
│ │ │ │ ├── heart_grey.png
│ │ │ │ ├── rightarrow.png
│ │ │ │ ├── usercenter.png
│ │ │ │ ├── ic_list_black_48dp.png
│ │ │ │ ├── plus_320px_1197037_easyicon.png
│ │ │ │ ├── ripple_welcomeview_button.xml
│ │ │ │ ├── bg_welcomeview_button.xml
│ │ │ │ ├── diary_app_icon_blue.xml
│ │ │ │ ├── diary_app_icon_orange.xml
│ │ │ │ └── diary_app_icon_yellow.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── facePlusPlusAPIConf.xml
│ │ │ │ ├── preferenceNames.xml
│ │ │ │ ├── attr.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── styles.xml
│ │ │ ├── menu
│ │ │ │ └── menu.xml
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── title.xml
│ │ │ │ ├── activity_homepage.xml
│ │ │ │ ├── activity_welcome.xml
│ │ │ │ ├── activity_stats.xml
│ │ │ │ ├── diary_outline.xml
│ │ │ │ ├── activity_show_diary.xml
│ │ │ │ ├── calendar.xml
│ │ │ │ └── activity_record_emotion.xml
│ │ ├── java
│ │ │ ├── libs
│ │ │ │ ├── faceppsdk.jar
│ │ │ │ └── faceppsdk_min.jar
│ │ │ └── org
│ │ │ │ └── hackpku
│ │ │ │ └── emotiondiary
│ │ │ │ ├── Welcome
│ │ │ │ ├── model
│ │ │ │ │ ├── UserImpl.java
│ │ │ │ │ └── IUser.java
│ │ │ │ ├── view
│ │ │ │ │ ├── IWelcomeView.java
│ │ │ │ │ └── WelcomeActivity.java
│ │ │ │ ├── README.md
│ │ │ │ └── presenter
│ │ │ │ │ ├── IWelcomePresenter.java
│ │ │ │ │ └── WelcomePresenterImpl.java
│ │ │ │ ├── common
│ │ │ │ ├── FaceHelper
│ │ │ │ │ ├── FaceHelperAPIInstruction.png
│ │ │ │ │ ├── FaceHelperAPIInstruction.pages
│ │ │ │ │ ├── FaceHelper.md
│ │ │ │ │ └── FaceHelper.java
│ │ │ │ ├── README.md
│ │ │ │ └── Diary
│ │ │ │ │ ├── DiaryPicture.java
│ │ │ │ │ ├── Diary.java
│ │ │ │ │ └── DiaryHelper.java
│ │ │ │ ├── README.md
│ │ │ │ ├── MainApplication.java
│ │ │ │ ├── Homepage
│ │ │ │ ├── TitleView.java
│ │ │ │ ├── DiaryOutlineView.java
│ │ │ │ ├── WeekDayView.java
│ │ │ │ ├── CalendarView.java
│ │ │ │ ├── HomePageActivity.java
│ │ │ │ ├── RoundImageView.java
│ │ │ │ └── MonthDateView.java
│ │ │ │ ├── ShowDiary
│ │ │ │ └── showDiaryActivity.java
│ │ │ │ ├── Stats
│ │ │ │ └── StatsActivity.java
│ │ │ │ └── RecordEmotion
│ │ │ │ └── RecordEmotionActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── org
│ │ │ └── hackpku
│ │ │ └── emotiondiary
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── org
│ │ └── hackpku
│ │ └── emotiondiary
│ │ ├── api
│ │ └── FaceHelperTest.java
│ │ └── data
│ │ └── DiaryDataTest.java
├── proguard-rules.pro
├── build.gradle
└── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── introduction-resource
├── homepage.jpg
├── welcome.jpg
├── unlock_fail.jpg
├── unlocking.jpg
├── record_diary.jpg
├── saving_diary.jpg
├── stat_view_red.jpg
├── stat_view_yellow.jpg
├── Emotion-diary UI设计稿.docx
├── unlock_successfully.jpg
└── Emotion-Diary-UI-icons.zip
├── .gitignore
├── gradle.properties
├── Emotion-Diary-Android.iml
├── gradlew.bat
├── gradlew
└── README.md
/.idea/.name:
--------------------------------------------------------------------------------
1 | Emotion-Diary-Android
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ok.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/ok.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sad2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/sad2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/sad3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/sad3.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/introduction-resource/homepage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/homepage.jpg
--------------------------------------------------------------------------------
/introduction-resource/welcome.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/welcome.jpg
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 |
--------------------------------------------------------------------------------
/app/src/main/java/libs/faceppsdk.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/java/libs/faceppsdk.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/diary.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/diary.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/laugh2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/laugh2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/laugh3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/laugh3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/smile2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/smile2.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/smile3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/smile3.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/test1.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/test1.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/test2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/test2.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/test3.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/test3.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/test4.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/test4.jpg
--------------------------------------------------------------------------------
/introduction-resource/unlock_fail.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/unlock_fail.jpg
--------------------------------------------------------------------------------
/introduction-resource/unlocking.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/unlocking.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/heart_red.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/heart_red.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/leftarrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/leftarrow.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/portrait.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/portrait.png
--------------------------------------------------------------------------------
/introduction-resource/record_diary.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/record_diary.jpg
--------------------------------------------------------------------------------
/introduction-resource/saving_diary.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/saving_diary.jpg
--------------------------------------------------------------------------------
/introduction-resource/stat_view_red.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/stat_view_red.jpg
--------------------------------------------------------------------------------
/app/src/main/java/libs/faceppsdk_min.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/java/libs/faceppsdk_min.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/camera_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/camera_white.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/heart_grey.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/heart_grey.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/rightarrow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/rightarrow.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/usercenter.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/usercenter.png
--------------------------------------------------------------------------------
/introduction-resource/stat_view_yellow.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/stat_view_yellow.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/introduction-resource/Emotion-diary UI设计稿.docx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/Emotion-diary UI设计稿.docx
--------------------------------------------------------------------------------
/introduction-resource/unlock_successfully.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/unlock_successfully.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_list_black_48dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/ic_list_black_48dp.png
--------------------------------------------------------------------------------
/introduction-resource/Emotion-Diary-UI-icons.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/introduction-resource/Emotion-Diary-UI-icons.zip
--------------------------------------------------------------------------------
/app/src/main/res/drawable/plus_320px_1197037_easyicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/res/drawable/plus_320px_1197037_easyicon.png
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | EmotionDiary
3 | 现在心情怎样?
4 |
5 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/model/UserImpl.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Welcome.model;
2 |
3 | /**
4 | * Created by Archimekai on 5/24/2016.
5 | * User接口的实现
6 | */
7 | public class UserImpl {
8 | }
9 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/FaceHelper/FaceHelperAPIInstruction.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/java/org/hackpku/emotiondiary/common/FaceHelper/FaceHelperAPIInstruction.png
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/FaceHelper/FaceHelperAPIInstruction.pages:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HackAll-PKU/Emotion-Diary-Android/HEAD/app/src/main/java/org/hackpku/emotiondiary/common/FaceHelper/FaceHelperAPIInstruction.pages
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/model/IUser.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Welcome.model;
2 |
3 | /**
4 | * Created by Archimekai on 5/24/2016.
5 | * 指定User数据层应该提供的接口
6 | * 实现在UserImpl中
7 | */
8 | public interface IUser {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/facePlusPlusAPIConf.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | fc006920f9aa8273e1d2343964e79755
4 | uQBSdw7QzaBkjbqM4ToltgAbRTFECpqL
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/preferenceNames.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | org.hackpku.emotiondiary.FaceHelperPreference
4 | org.hackpku.emotiondiary.FaceHelperPersonID
5 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/app/src/main/res/values/attr.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/org/hackpku/emotiondiary/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | @color/themeColorBlue
4 | #303F9F
5 | #FF4081
6 |
7 | #0B5FA5
8 | #FFC000
9 | #FF4D00
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/view/IWelcomeView.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Welcome.view;
2 |
3 | /**
4 | * Created by Archimekai on 5/24/2016.
5 | */
6 | public interface IWelcomeView {
7 |
8 | void onLogInResult(boolean logInResult, String msg);
9 | void onRecordEmotion();
10 | void onEnterHomepage();
11 | void makeToast(String str);
12 | void changeIconAccordingToSmiling(double smiling);
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/README.md:
--------------------------------------------------------------------------------
1 | # org.hackpku.emotiondiary.welcome
2 |
3 | 显示软件登陆时的欢迎页。
4 |
5 | 同时也是MVP设计范式的样板。
6 | MVP设计范式的主要目的是把业务逻辑,如登陆,以及界面元素的显示逻辑,如大小的控制,动画的控制等,从activity中剥离出去,从而使代码更加清晰,降低耦合程度。
7 |
8 | 比如说,所有相应按钮,点击的逻辑,如果稍微复杂些,都可以放在Presenter中进行处理。
9 | 而更新界面的逻辑则放在View中,不过这次的示例没有单独的View,而是直接把View实现在了activity中。
10 |
11 | 参考资料:https://segmentfault.com/a/1190000003927200
12 |
13 | http://blog.csdn.net/maosidiaoxian/article/details/40109337
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ripple_welcomeview_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/presenter/IWelcomePresenter.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Welcome.presenter;
2 |
3 | import android.content.Intent;
4 |
5 | /**
6 | * Created by Archimekai on 5/24/2016.
7 | */
8 | public interface IWelcomePresenter {
9 | void doLogIn(); // 此处应该修改函数需要的参数,比如face++id之类
10 | void recordEmotion();
11 | void enterHomepage();
12 |
13 | void onActivityResult(int requestCode, int resultCode, Intent data);
14 | void makeAlertDialog(String title, String message);
15 | }
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/README.md:
--------------------------------------------------------------------------------
1 | # EmotionDiary for Android
2 |
3 | * API Level: 21+ (Android 5.0)
4 | * IDE: Android Studio 2.1 +
5 |
6 | ##组成
7 | 本项目按照活动(或者说视图),包括五个主要部分(Activity):
8 |
9 | * Welcome: 打开应用后的欢迎页,同时有引导用户登录的功能,基本代码已经给出,供参考。
10 | * Homepage: 首页,显示日历和当天的日记
11 | * Stats: 显示用户的统计信息
12 | * RecordEmotion: 记录日记
13 | * ShowDiary: 显示日记
14 |
15 | 每一部分均位于单独的包中,同时,每个包都是一个MVP结构,分别有model、view、presenter文件夹,activity class在view文件夹下。每个文件夹中,需要有接口和实现至少两个class文件,接口类的类名以大写I开头,实现类的类名以Impl结尾(activity class除外)。在每个目录下,还应尽量提供README.md以帮助快速了解。
16 |
17 | 此外,如果有认为需要共用的代码,请实现在common文件夹下。
18 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/FaceHelper/FaceHelper.md:
--------------------------------------------------------------------------------
1 | # FaceHelper
2 | ## 使用流程图:
3 | 
4 | ## 注意事项
5 | - FaceHelper采用单例模式,使用`FaceHelper.getInstance()`来获取单例
6 | - throw的错误要catch并在视图中给予反馈
7 | - train()接口非瞬间完成,而是API返回一个session_id,服务端会进行train但所需时间不可知,所以train()调用完之后并不是train()结束了,但这一般情况下不影响使用(verify时使用上一次train的结果)
8 | - 流程图中没有画出`getSmiling()`,但随时可以调用此接口
9 | ## 测试
10 | - 测试文件位于app/src/androidTest/java/org.hackpku.emotiondiary/api/FaceHelperTest.java
11 | - 测试时testVerify为train留出5s时间,一般情况下已经够用但不排除api繁忙导致testVerify测试通不过的情况,若因此原因未通过测试可再次尝试
12 |
13 | ## Authored by 陈乐天
14 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_welcomeview_button.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/diary_app_icon_blue.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
11 |
12 |
13 | -
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
14 |
15 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/diary_app_icon_orange.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
11 |
12 |
13 | -
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/diary_app_icon_yellow.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
11 |
12 |
13 | -
14 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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 C:\Users\wenkaiW10\AppData\Local\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 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | ## Project-wide Gradle settings.
2 | #
3 | # For more details on how to configure your build environment visit
4 | # http://www.gradle.org/docs/current/userguide/build_environment.html
5 | #
6 | # Specifies the JVM arguments used for the daemon process.
7 | # The setting is particularly useful for tweaking memory settings.
8 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
9 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
10 | #
11 | # When configured, Gradle will run in incubating parallel mode.
12 | # This option should only be used with decoupled projects. More details, visit
13 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
14 | # org.gradle.parallel=true
15 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/title.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
17 |
26 |
27 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/README.md:
--------------------------------------------------------------------------------
1 | # Common
2 | - common文件夹下为Model层及帮助类
3 |
4 | ## FaceHelper
5 | [使用说明](./FaceHelper/FaceHelper.md)
6 |
7 | ## Diary相关
8 | - 使用Realm存储
9 |
10 | ### Diary
11 | - 日记类
12 | - 继承自RealmObject
13 | - 包含
14 | - happiness高兴值
15 | - text日记内容
16 | - selfie自拍照片(DiaryPicture)
17 | - pictures其他图片(DiaryPicture组成的RealmList)
18 | - date日记创建时间
19 | - 使用getter和setter访问和设置
20 | - **不可直接调用setter**,必须调用diaryHelper.updateDiary方法来更新Diary
21 | - **注意**:DiaryHelper获取到的Diary都是和数据库处在“绑定”状态,即当数据库受到更新时那些获取到的Diary会自动更新
22 |
23 | ### DiaryPicture
24 | - 日记中的图片类(包括selfie和pictures)
25 | - 负责将bitmap转为byte数组,负责将byte数组解码为bitmap
26 | - 调用getImage()方法即可获得bitmap
27 | - 同样使用getter和setter访问和设置,但一般情况下使用getImage()方法就足够了
28 |
29 | ### DiaryHelper
30 | - 日记帮助类**与日记有关操作均在此进行**
31 | - 目前支持的功能
32 | - 保存Diary(saveDiary)
33 | - 更新Diary(updateDiary)
34 | - 获得最近一条Diary(getLastestDiary)
35 | - 获取某一天的所有Diary(getDiariesOfDay,可用Date或GregorianCalendar调用)
36 | - 获取之前一段时间的快乐值(getHappinessForTime,用于绘制心情图表)
37 |
--------------------------------------------------------------------------------
/Emotion-Diary-Android.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/Diary/DiaryPicture.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.common.Diary;
2 |
3 | import android.graphics.Bitmap;
4 | import android.graphics.BitmapFactory;
5 |
6 | import java.io.ByteArrayOutputStream;
7 |
8 | import io.realm.RealmObject;
9 |
10 | /**
11 | * Created by ChenLetian on 16/5/28.
12 | * 日记中的照片类,包括自拍和图片
13 | */
14 | public class DiaryPicture extends RealmObject {
15 |
16 | private byte[] data;
17 |
18 | public DiaryPicture() {}
19 |
20 | public DiaryPicture(Bitmap image) {
21 | ByteArrayOutputStream stream = new ByteArrayOutputStream();
22 | image.compress(Bitmap.CompressFormat.PNG, 100, stream);
23 | this.data = stream.toByteArray();
24 | }
25 |
26 | public byte[] getData() {
27 | return data;
28 | }
29 |
30 | public void setData(byte[] data) {
31 | this.data = data;
32 | }
33 |
34 | /**
35 | * 从data获取图像
36 | * @return 位图
37 | */
38 | public Bitmap getImage() {
39 | return BitmapFactory.decodeByteArray(data, 0 ,data.length);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/MainApplication.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary;
2 |
3 | import android.app.Application;
4 |
5 | import io.realm.Realm;
6 | import io.realm.RealmConfiguration;
7 |
8 | /**
9 | * Created by HuShunxin on 16/6/4.
10 | */
11 | public class MainApplication extends Application {
12 |
13 | private double smiling = 0;
14 |
15 | public static final int THEME_BLUE = R.style.AppTheme;
16 | public static final int THEME_YELLOW = R.style.AppTheme_Yellow;
17 | public static final int THEME_ORANGE = R.style.AppTheme_Orange;
18 |
19 | /**
20 | * 获取当前心情值(0~100)
21 | */
22 | public double getSmiling() {
23 | return smiling;
24 | }
25 |
26 | /**
27 | * 设置心情值(0~100),修改时务必调用
28 | * @param smiling 心情值
29 | */
30 | public void setSmiling(double smiling) {
31 | this.smiling = smiling;
32 | }
33 |
34 | /**
35 | * 获取当前心情值对应的Theme ID
36 | * @return Theme ID
37 | */
38 | public int getThemeId(){
39 | if (smiling < 33) return THEME_BLUE;
40 | else if (smiling > 66) return THEME_ORANGE;
41 | else return THEME_YELLOW;
42 | }
43 |
44 | @Override
45 | public void onCreate() {
46 | super.onCreate();
47 | RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(this).build();
48 | Realm.setDefaultConfiguration(realmConfiguration);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_homepage.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
21 |
22 |
23 |
31 |
32 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
12 |
13 |
20 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'realm-android'
3 |
4 | android {
5 | compileSdkVersion 23
6 | buildToolsVersion "23.0.3"
7 |
8 | defaultConfig {
9 | applicationId "org.hackpku.emotiondiary"
10 | minSdkVersion 21
11 | targetSdkVersion 22
12 | versionCode 1
13 | versionName "1.0"
14 |
15 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(dir: 'libs', include: ['*.jar'])
27 | testCompile 'junit:junit:4.12'
28 | compile 'com.android.support:appcompat-v7:23.4.0'
29 | compile files('src/main/java/libs/faceppsdk.jar')
30 |
31 | androidTestCompile 'com.android.support:support-annotations:23.4.0'
32 | androidTestCompile 'com.android.support.test:runner:0.4.1'
33 | androidTestCompile 'com.android.support.test:rules:0.4.1'
34 | // Optional -- Hamcrest library
35 | androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
36 | // Optional -- UI testing with Espresso
37 | androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
38 | // Optional -- UI testing with UI Automator
39 | androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.1'
40 |
41 | }
42 |
43 | repositories {
44 | maven { url "https://jitpack.io" }
45 | }
46 |
47 | dependencies {
48 | compile 'com.github.PhilJay:MPAndroidChart:v2.2.5'
49 | }
50 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/workspace.xml
40 |
41 | # Keystore files
42 | *.jks
43 | ### JetBrains template
44 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
45 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
46 |
47 | # User-specific stuff:
48 | .idea/workspace.xml
49 | .idea/tasks.xml
50 | .idea/dictionaries
51 | .idea/vcs.xml
52 | .idea/jsLibraryMappings.xml
53 |
54 | # Sensitive or high-churn files:
55 | .idea/dataSources.ids
56 | .idea/dataSources.xml
57 | .idea/dataSources.local.xml
58 | .idea/sqlDataSources.xml
59 | .idea/dynamic.xml
60 | .idea/uiDesigner.xml
61 |
62 | # Gradle:
63 | .idea/gradle.xml
64 | .idea/libraries
65 |
66 | # Mongo Explorer plugin:
67 | .idea/mongoSettings.xml
68 |
69 | ## File-based project format:
70 | *.iws
71 |
72 | ## Plugin-specific files:
73 |
74 | # IntelliJ
75 | /out/
76 |
77 | # mpeltonen/sbt-idea plugin
78 | .idea_modules/
79 |
80 | # JIRA plugin
81 | atlassian-ide-plugin.xml
82 |
83 | # Crashlytics plugin (for Android Studio and IntelliJ)
84 | com_crashlytics_export_strings.xml
85 | crashlytics.properties
86 | crashlytics-build.properties
87 | fabric.properties
88 |
89 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_welcome.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
22 |
23 |
31 |
32 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Homepage/TitleView.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Homepage;
2 |
3 | import android.app.Activity;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.util.AttributeSet;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.FrameLayout;
11 | import android.widget.RelativeLayout;
12 | import android.widget.TextView;
13 |
14 | import org.hackpku.emotiondiary.MainApplication;
15 | import org.hackpku.emotiondiary.R;
16 | import org.hackpku.emotiondiary.Stats.StatsActivity;
17 |
18 | /**
19 | * Created by Liu Zhengyuan on 2016/5/30.
20 | */
21 | public class TitleView extends FrameLayout {
22 | private Button btnTimeline;
23 | private RelativeLayout layout;
24 | private TextView titleText;
25 | private Activity HomePageActivity;
26 |
27 |
28 | public TitleView(final Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | LayoutInflater.from(context).inflate(R.layout.title, this);
31 | titleText = (TextView) findViewById(R.id.title_text);
32 | btnTimeline=(Button)findViewById(R.id.button_timeline);
33 | layout=(RelativeLayout)findViewById(R.id.layout);
34 |
35 | int color;
36 | double smiling = ((MainApplication)((Activity)context).getApplication()).getSmiling();
37 | if (smiling < 33) color = getResources().getColor(R.color.themeColorBlue);
38 | else if (smiling > 66) color = getResources().getColor(R.color.themeColorOrange);
39 | else color = getResources().getColor(R.color.themeColorYellow);
40 | layout.setBackgroundColor(color);
41 |
42 | btnTimeline.setOnClickListener(new OnClickListener() {
43 | @Override
44 | public void onClick(View v) {
45 | //调出心情统计页面
46 | Intent intent = new Intent();
47 | intent.setClass(context,StatsActivity.class);
48 | context.startActivity(intent);
49 | }
50 | });
51 |
52 | }
53 |
54 | }
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/common/Diary/Diary.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.common.Diary;
2 |
3 | import android.graphics.Bitmap;
4 |
5 | import java.util.ArrayList;
6 | import java.util.Date;
7 |
8 | import io.realm.RealmList;
9 | import io.realm.RealmObject;
10 |
11 | /**
12 | * Created by ChenLetian on 16/5/28.
13 | * 日记类
14 | */
15 | public class Diary extends RealmObject {
16 |
17 | private Integer happiness; // 高兴值
18 | private String text; // 日记内容
19 | private DiaryPicture selfie; // 自拍照片
20 | private RealmList pictures; // 其他照片
21 | private Date date; // 日期
22 |
23 | public Diary() {}
24 |
25 | public Diary(Integer happiness, String text, Bitmap selfie, ArrayList pictures, Date date) {
26 | this.happiness = happiness;
27 | this.text = text;
28 | this.selfie = new DiaryPicture(selfie);
29 | this.pictures = new RealmList<>();
30 | for (Bitmap picture: pictures) {
31 | DiaryPicture diaryPicture = new DiaryPicture(picture);
32 | this.pictures.add(diaryPicture);
33 | }
34 | this.date = date;
35 | }
36 |
37 | public Integer getHappiness() {
38 | return happiness;
39 | }
40 |
41 | public void setHappiness(Integer happiness) {
42 | this.happiness = happiness;
43 | }
44 |
45 | public String getText() {
46 | return text;
47 | }
48 |
49 | public void setText(String text) {
50 | this.text = text;
51 | }
52 |
53 | public DiaryPicture getSelfie() {
54 | return selfie;
55 | }
56 |
57 | public void setSelfie(DiaryPicture selfie) {
58 | this.selfie = selfie;
59 | }
60 |
61 | public RealmList getPictures() {
62 | return pictures;
63 | }
64 |
65 | public void setPictures(RealmList pictures) {
66 | this.pictures = pictures;
67 | }
68 |
69 | public Date getDate() {
70 | return date;
71 | }
72 |
73 | public void setDate(Date date) {
74 | this.date = date;
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_stats.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
13 |
14 |
30 |
31 |
47 |
48 |
49 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/diary_outline.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
11 |
21 |
22 |
23 |
24 |
34 |
35 |
45 |
46 |
56 |
57 |
--------------------------------------------------------------------------------
/.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 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/ShowDiary/showDiaryActivity.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.ShowDiary;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.widget.ImageView;
8 | import android.widget.LinearLayout;
9 | import android.widget.ProgressBar;
10 | import android.widget.TextView;
11 |
12 | import org.hackpku.emotiondiary.MainApplication;
13 | import org.hackpku.emotiondiary.R;
14 | import org.hackpku.emotiondiary.common.Diary.Diary;
15 | import org.hackpku.emotiondiary.common.Diary.DiaryPicture;
16 |
17 |
18 | public class showDiaryActivity extends AppCompatActivity {
19 | /*
20 | 传入 intent 包含一个 diary 引用。
21 | */
22 |
23 | @Override
24 | protected void onCreate(Bundle savedInstanceState) {
25 | super.onCreate(savedInstanceState);
26 | setContentView(R.layout.activity_show_diary);
27 | Toolbar toolbar = (Toolbar) findViewById(R.id.showDiaryToolbar);
28 | toolbar.setTitle("查看日记");
29 |
30 | double smiling = ((MainApplication)getApplication()).getSmiling();
31 | int color;
32 | if (smiling < 33) color = R.color.themeColorBlue;
33 | else if (smiling > 66) color = R.color.themeColorOrange;
34 | else color = R.color.themeColorYellow;
35 | toolbar.setBackgroundColor(getResources().getColor(color));
36 |
37 | setSupportActionBar(toolbar);
38 |
39 | Intent intent = getIntent();
40 | Diary diary = (Diary) intent.getExtras().get("diary");
41 | ImageView captionImageView = (ImageView) findViewById(R.id.showImageView);
42 | captionImageView.setImageBitmap(diary.getSelfie().getImage());
43 | ProgressBar progressBar = (ProgressBar) findViewById(R.id.showProgressBar);
44 | progressBar.setMax(0);
45 | progressBar.setMax(100);
46 | progressBar.setProgress(diary.getHappiness());
47 | TextView textView = (TextView) findViewById(R.id.showTextView);
48 | textView.setText(diary.getText());
49 | LinearLayout linearLayout = (LinearLayout) findViewById(R.id.showImageList);
50 | for(DiaryPicture diaryPicture:diary.getPictures()){
51 | ImageView imageView = new ImageView(getApplicationContext());
52 | imageView.setImageBitmap(diaryPicture.getImage());
53 | linearLayout.addView(imageView);
54 | }
55 |
56 |
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Homepage/DiaryOutlineView.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Homepage;
2 |
3 | import android.content.*;
4 | import android.util.*;
5 | import android.view.LayoutInflater;
6 | import android.view.*;
7 | import android.widget.*;
8 |
9 | import org.hackpku.emotiondiary.R;
10 |
11 | /**
12 | * Created by Liu Zhengyuan on 2016/6/2.
13 | */
14 | public class DiaryOutlineView extends FrameLayout {
15 |
16 | private RoundImageView riv_photo; //圆形自拍图片
17 | private RoundImageView riv_emotion; //圆形心情图片
18 | private TextView tv_time; //日记记录时间
19 | private TextView tv_diary; //日记内容
20 | private ImageView iv_heart; //是红心还是灰心
21 |
22 | public DiaryOutlineView(Context context, AttributeSet attrs) {
23 | super(context, attrs);
24 | LayoutInflater.from(context).inflate(R.layout.diary_outline, this);
25 | riv_photo = (RoundImageView) findViewById(R.id.photo_view);
26 | riv_emotion = (RoundImageView) findViewById(R.id.emotion_view);
27 | tv_time = (TextView) findViewById(R.id.time_text);
28 | tv_diary = (TextView) findViewById(R.id.diary_text);
29 | iv_heart.setTag(R.drawable.heart_grey);
30 |
31 | /**
32 | * 设置红心灰心点击事件
33 | */
34 | iv_heart.setOnClickListener(new View.OnClickListener() {
35 |
36 | @Override
37 | public void onClick(View v) {
38 | if((int)iv_heart.getTag()==R.drawable.heart_grey) {
39 | iv_heart.setTag(R.drawable.heart_red);
40 | iv_heart.setImageResource(R.drawable.heart_red);
41 | }
42 | else{
43 | iv_heart.setTag(R.drawable.heart_grey);
44 | iv_heart.setImageResource(R.drawable.heart_grey);
45 | }
46 | }
47 | });
48 | }
49 |
50 | /**
51 | * 设置日记记录时间
52 | * @param timeText
53 | */
54 | public void setRecordTimeText(String timeText) {
55 | tv_diary.setText(timeText);
56 | }
57 |
58 | /**
59 | * 设置日记文本
60 | * @param diaryText
61 | */
62 | public void setDiaryText(String diaryText) {
63 | tv_diary.setText(diaryText);
64 | }
65 |
66 | /**
67 | * 设置自拍图片
68 | */
69 | public void setPhotoImage(){
70 | //TODO
71 | }
72 |
73 | /**
74 | * 根据心情指数设置心情图片
75 | * @param emtionIndex 心情指数,待修改
76 | */
77 | public void setEmotionImage(int emtionIndex) {
78 | final int[] emotionImages = new int[]{R.drawable.laugh3, R.drawable.smile3, R.drawable.sad3};
79 | if (emtionIndex == 1)
80 | riv_emotion.setImageResource(emotionImages[2]);
81 | else if (emtionIndex == 2)
82 | riv_emotion.setImageResource(emotionImages[1]);
83 | else
84 | riv_emotion.setImageResource(emotionImages[0]);
85 | }
86 |
87 | }
88 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_show_diary.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
19 |
20 |
28 |
29 |
35 |
36 |
42 |
43 |
48 |
49 |
55 |
56 |
57 |
65 |
66 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/calendar.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
16 |
23 |
30 |
38 |
39 |
40 |
48 |
57 |
58 |
59 |
66 |
67 |
70 |
74 |
75 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_record_emotion.xml:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
21 |
29 |
30 |
37 |
38 |
44 |
45 |
55 |
56 |
64 |
65 |
66 |
67 |
79 |
80 |
86 |
87 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Stats/StatsActivity.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Stats;
2 |
3 | import android.graphics.Color;
4 | import android.os.Bundle;
5 | import android.support.v4.app.FragmentActivity;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.widget.Button;
9 |
10 | import com.github.mikephil.charting.charts.LineChart;
11 | import com.github.mikephil.charting.components.YAxis;
12 | import com.github.mikephil.charting.data.Entry;
13 | import com.github.mikephil.charting.data.LineData;
14 | import com.github.mikephil.charting.data.LineDataSet;
15 | import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
16 |
17 | import org.hackpku.emotiondiary.MainApplication;
18 | import org.hackpku.emotiondiary.R;
19 | import org.hackpku.emotiondiary.common.Diary.DiaryHelper;
20 |
21 | import java.util.ArrayList;
22 |
23 | /**
24 | * Created by lenovo on 2016/6/7.
25 | */
26 | public class StatsActivity extends AppCompatActivity {
27 | private Button thisWeek;//显示这周心情
28 | private Button thisMonth;//显示这月心情
29 | private LineChart chart;
30 | private boolean isThisWeek;
31 |
32 |
33 | /**
34 | * 显示页面
35 | */
36 | protected void onCreate(Bundle savedInstanceState) {
37 | super.onCreate(savedInstanceState);
38 | setTheme(((MainApplication) getApplication()).getThemeId());
39 | setContentView(R.layout.activity_stats);
40 | setTitle("心情统计");
41 | chart = (LineChart) findViewById(R.id.chart);
42 | chart.setDrawGridBackground(false);
43 | chart.setGridBackgroundColor(Color.argb(0, 255, 255, 255));
44 | chart.setTouchEnabled(true);
45 | chart.setScaleEnabled(true);
46 | chart.setDrawBorders(false);
47 | chart.getXAxis().setDrawGridLines(false);
48 | chart.getAxisLeft().setDrawGridLines(false);
49 | chart.setDescription("一周心情");
50 | chart.getLegend().setEnabled(false);
51 | thisWeek = (Button) findViewById(R.id.Week);
52 | thisMonth = (Button) findViewById(R.id.Month);
53 | this.isThisWeek = true;
54 | setOnlistener();//初始化button的监听器
55 | showData();
56 | }
57 |
58 | /**
59 | * 初始化thisWeek和thisMonth按钮点击事件
60 | */
61 | private void setOnlistener() {
62 | thisWeek.setOnClickListener(new View.OnClickListener() {
63 | @Override //一周
64 | public void onClick(View v) {
65 | isThisWeek = true;
66 | chart.setDescription("一周心情");
67 | showData();
68 | }
69 | });
70 | thisMonth.setOnClickListener(new View.OnClickListener() {
71 | @Override //一月
72 | public void onClick(View v) {
73 | isThisWeek = false;
74 | chart.setDescription("一月心情");
75 | showData();
76 | }
77 | });
78 | }
79 |
80 | private void showData() {
81 | DiaryHelper diaryHelper = new DiaryHelper();
82 | int date;
83 | //过去一个月的统计值心情,不在乎1天2天的
84 | date = isThisWeek ? 7 : 30;
85 | ArrayList emotionsRowData = diaryHelper.getHappinessForTimeAsArrayList(date);
86 |
87 | //添加数据绘图
88 | ArrayList emotions = new ArrayList<>();
89 | ArrayList xVals = new ArrayList<>();
90 | for (int loop = 0; loop < date; ++loop) {
91 | Entry c1 = new Entry(emotionsRowData.get(loop).floatValue(), loop);
92 | emotions.add(c1);
93 | xVals.add("");
94 | }
95 | LineDataSet setEmotions = new LineDataSet(emotions, "");
96 | setEmotions.setDrawCubic(true);
97 | setEmotions.setDrawFilled(true);
98 | setEmotions.setFillColor(Color.argb(0, 255, 194, 73));
99 | setEmotions.setFillAlpha(100);
100 | setEmotions.setAxisDependency(YAxis.AxisDependency.LEFT);
101 |
102 | ArrayList dataSets = new ArrayList<>();
103 | dataSets.add(setEmotions);
104 |
105 | LineData data = new LineData(xVals, dataSets);
106 | chart.setData(data);
107 | chart.invalidate(); // refresh
108 | }
109 |
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Homepage/WeekDayView.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Homepage;
2 |
3 | import android.content.*;
4 | import android.graphics.*;
5 | import android.graphics.Paint.*;
6 | import android.util.*;
7 | import android.view.*;
8 |
9 | /**
10 | * Created by Liu Zhengyuan on 2016/5/30.
11 | */
12 | public class WeekDayView extends View {
13 | //上横线颜色
14 | private int mTopLineColor = Color.parseColor("#CCE4F2");
15 | //下横线颜色
16 | private int mBottomLineColor = Color.parseColor("#CCE4F2");
17 | //周一到周五的颜色
18 | private int mWeedayColor = Color.parseColor("#1FC2F3");
19 | //周六、周日的颜色
20 | private int mWeekendColor = Color.parseColor("#fa4451");
21 | //线的宽度
22 | private int mStrokeWidth = 4;
23 | private int mWeekSize = 14;
24 | private Paint paint;
25 | private DisplayMetrics mDisplayMetrics;
26 | private String[] weekString = new String[]{"日","一","二","三","四","五","六"};
27 | public WeekDayView(Context context, AttributeSet attrs) {
28 | super(context, attrs);
29 | mDisplayMetrics = getResources().getDisplayMetrics();
30 | paint = new Paint();
31 | }
32 |
33 | @Override
34 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
35 | int widthSize = MeasureSpec.getSize(widthMeasureSpec);
36 | int widthMode = MeasureSpec.getMode(widthMeasureSpec);
37 |
38 | int heightSize = MeasureSpec.getSize(heightMeasureSpec);
39 | int heightMode = MeasureSpec.getMode(heightMeasureSpec);
40 |
41 | if(heightMode == MeasureSpec.AT_MOST){
42 | heightSize = mDisplayMetrics.densityDpi * 30;
43 | }
44 | if(widthMode == MeasureSpec.AT_MOST){
45 | widthSize = mDisplayMetrics.densityDpi * 300;
46 | }
47 | setMeasuredDimension(widthSize, heightSize);
48 | }
49 |
50 | @Override
51 | protected void onDraw(Canvas canvas) {
52 | int width = getWidth();
53 | int height = getHeight();
54 | //进行画上下线
55 | paint.setStyle(Style.STROKE);
56 | paint.setColor(mTopLineColor);
57 | paint.setStrokeWidth(mStrokeWidth);
58 | canvas.drawLine(0, 0, width, 0, paint);
59 |
60 | //画下横线
61 | paint.setColor(mBottomLineColor);
62 | canvas.drawLine(0, height, width, height, paint);
63 | paint.setStyle(Style.FILL);
64 | paint.setTextSize(mWeekSize * mDisplayMetrics.scaledDensity);
65 | int columnWidth = width / 7;
66 | for(int i=0;i < weekString.length;i++){
67 | String text = weekString[i];
68 | int fontWidth = (int) paint.measureText(text);
69 | int startX = columnWidth * i + (columnWidth - fontWidth)/2;
70 | int startY = (int) (height/2 - (paint.ascent() + paint.descent())/2);
71 | if(text.indexOf("日") > -1|| text.indexOf("六") > -1){
72 | paint.setColor(mWeekendColor);
73 | }else{
74 | paint.setColor(mWeedayColor);
75 | }
76 | canvas.drawText(text, startX, startY, paint);
77 | }
78 | }
79 |
80 | /**
81 | * 设置顶线的颜色
82 | * @param mTopLineColor
83 | */
84 | public void setmTopLineColor(int mTopLineColor) {
85 | this.mTopLineColor = mTopLineColor;
86 | }
87 |
88 | /**
89 | * 设置底线的颜色
90 | * @param mBottomLineColor
91 | */
92 | public void setmBottomLineColor(int mBottomLineColor) {
93 | this.mBottomLineColor = mBottomLineColor;
94 | }
95 |
96 | /**
97 | * 设置周一-五的颜色
98 | * @return
99 | */
100 | public void setmWeedayColor(int mWeedayColor) {
101 | this.mWeedayColor = mWeedayColor;
102 | }
103 |
104 | /**
105 | * 设置周六、周日的颜色
106 | * @param mWeekendColor
107 | */
108 | public void setmWeekendColor(int mWeekendColor) {
109 | this.mWeekendColor = mWeekendColor;
110 | }
111 |
112 | /**
113 | * 设置边线的宽度
114 | * @param mStrokeWidth
115 | */
116 | public void setmStrokeWidth(int mStrokeWidth) {
117 | this.mStrokeWidth = mStrokeWidth;
118 | }
119 |
120 |
121 | /**
122 | * 设置字体的大小
123 | * @param mWeekSize
124 | */
125 | public void setmWeekSize(int mWeekSize) {
126 | this.mWeekSize = mWeekSize;
127 | }
128 |
129 |
130 | /**
131 | * 设置星期的形式
132 | * @param weekString
133 | * 默认值 "日","一","二","三","四","五","六"
134 | */
135 | public void setWeekString(String[] weekString) {
136 | this.weekString = weekString;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Homepage/CalendarView.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Homepage;
2 |
3 | import android.content.Context;
4 | import android.os.Bundle;
5 | import android.util.AttributeSet;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.widget.*;
9 | import org.hackpku.emotiondiary.R;
10 | import org.hackpku.emotiondiary.common.Diary.Diary;
11 | import org.hackpku.emotiondiary.common.Diary.DiaryHelper;
12 |
13 | import java.util.*;
14 |
15 | import io.realm.RealmResults;
16 |
17 | /**
18 | * Created by Liu Zhengyuan on 2016/5/31.
19 | */
20 | public class CalendarView extends FrameLayout {
21 | private ImageView iv_left; //进入上个月
22 | private ImageView iv_right; //进入下个月
23 | private TextView tv_date; //显示当天的日期
24 | private TextView tv_week; //显示当天的星期
25 | private MonthDateView monthDateView; //月历视图
26 | private DiaryHelper diaryHelper=new DiaryHelper();
27 |
28 | public CalendarView(Context context, AttributeSet attrs) {
29 | super(context, attrs);
30 | LayoutInflater.from(context).inflate(R.layout.calendar, this);
31 | iv_left = (ImageView) findViewById(R.id.iv_left);
32 | iv_right = (ImageView) findViewById(R.id.iv_right);
33 | monthDateView = (MonthDateView) findViewById(R.id.monthDateView);
34 | tv_date = (TextView) findViewById(R.id.date_text);
35 | tv_week = (TextView) findViewById(R.id.week_text);
36 | monthDateView.setTextView(tv_date, tv_week);
37 |
38 | int year = monthDateView.getmSelYear();
39 | int month = monthDateView.getmSelMonth();
40 | List hasThingList = getMonthList(year, month); //记录需要标记日期的List,可用来表示当天有日记的日期
41 | monthDateView.setDaysHasThingList(hasThingList);
42 | setOnlistener(); //初始化monthDateView各按钮点击事件
43 | }
44 |
45 | /**
46 | * 初始化monthDateView各按钮点击事件
47 | */
48 | private void setOnlistener(){
49 | iv_left.setOnClickListener(new View.OnClickListener() {
50 |
51 | @Override //上个月
52 | public void onClick(View v) {
53 | new Thread() {
54 | public void run() {
55 | int year = monthDateView.getmSelYear();
56 | int month = monthDateView.getmSelMonth();
57 | if (month == 0)
58 | monthDateView.setDaysHasThingList(getMonthList(year - 1, 11));
59 | else
60 | monthDateView.setDaysHasThingList(getMonthList(year, month - 1));
61 | monthDateView.onLeftClick();
62 | }
63 | }.start();
64 | }
65 | });
66 |
67 | iv_right.setOnClickListener(new View.OnClickListener() {
68 | @Override //下个月
69 | public void onClick(View v) {
70 | new Thread() {
71 | public void run() {
72 | int year = monthDateView.getmSelYear();
73 | int month = monthDateView.getmSelMonth();
74 | if (month == 11)
75 | monthDateView.setDaysHasThingList(getMonthList(year + 1, 0));
76 | else
77 | monthDateView.setDaysHasThingList(getMonthList(year, month + 1));
78 | monthDateView.onRightClick();
79 | }
80 | }.start();
81 | }
82 | });
83 |
84 | }
85 |
86 | /**
87 | * 获取指定月份每天的日记数
88 | */
89 | private List getMonthList(int year,int month) {
90 | List list = new ArrayList<>();
91 | DiaryHelper diaryHelper=new DiaryHelper();
92 | for (int i = 1; i <= getMonthDays(year, month); i++) { //对每一天
93 | GregorianCalendar date = new GregorianCalendar();
94 | date.set(year, month, i);
95 | RealmResults diaries = diaryHelper.getDiariesOfDay(date);
96 | list.add(diaries.size());
97 | }
98 | return list;
99 | }
100 |
101 | /**
102 | * 设置日期点击事件
103 | * @param dataClick
104 | */
105 | public void setDateClick(MonthDateView.DateClick dataClick){
106 | monthDateView.setDateClick(dataClick);
107 | }
108 |
109 | public void setList(List list){
110 | monthDateView.setDaysHasThingList(list);
111 | }
112 |
113 | /**
114 | * 获取用户选中年
115 | * @return
116 | */
117 | public int getSelYear(){
118 | return monthDateView.getmSelYear();
119 | }
120 |
121 | /**
122 | * 获取用户选中月
123 | * @return
124 | */
125 | public int getSelMonth() {
126 | return monthDateView.getmSelMonth() + 1;
127 | }
128 |
129 | /**
130 | * 获取用户选中日
131 | * @return
132 | */
133 | public int getSelDay(){
134 | return monthDateView.getmSelDay();
135 | }
136 |
137 | /**
138 | * 返回某年某月有几天
139 | * @param year
140 | * @param month
141 | * @return
142 | */
143 | private int getMonthDays(int year, int month) {
144 | int[] day = new int[]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
145 | if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
146 | day[1] += 1;
147 | return day[month];
148 | }
149 | }
150 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/hackpku/emotiondiary/api/FaceHelperTest.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.api;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.content.res.Resources;
6 | import android.graphics.Bitmap;
7 | import android.graphics.BitmapFactory;
8 | import android.support.test.InstrumentationRegistry;
9 | import android.support.test.runner.AndroidJUnit4;
10 | import android.test.suitebuilder.annotation.LargeTest;
11 |
12 | import org.hackpku.emotiondiary.R;
13 | import org.hackpku.emotiondiary.common.FaceHelper.FaceHelper;
14 | import org.junit.Before;
15 | import org.junit.Test;
16 | import org.junit.runner.RunWith;
17 |
18 | import static org.junit.Assert.assertEquals;
19 | import static org.junit.Assert.assertTrue;
20 |
21 | /**
22 | * Created by ChenLetian on 16/5/27.
23 | * FaceHelper的测试文件
24 | */
25 | @RunWith(AndroidJUnit4.class)
26 | @LargeTest
27 | public class FaceHelperTest {
28 |
29 | private FaceHelper faceHelper;
30 | private Context context;
31 | private Resources resources;
32 |
33 | @Before
34 | public void setup() {
35 | context = InstrumentationRegistry.getTargetContext();
36 | faceHelper = FaceHelper.getInstance(context);
37 | resources = context.getResources();
38 | }
39 |
40 | @Test
41 | public void testCreatePeople() {
42 | try {
43 | faceHelper.createPerson();
44 | SharedPreferences sharedPreferences = context.getSharedPreferences(resources.getString(R.string.FaceHelperPreference), Context.MODE_PRIVATE);
45 | String faceHelperPeopleID = sharedPreferences.getString(resources.getString(R.string.FaceHelperPersonID), "this is wrong");
46 | assertTrue(!faceHelperPeopleID.equals("this is wrong"));
47 | } catch (FaceHelper.requestError requestError) {
48 | requestError.printStackTrace();
49 | assertTrue("requestError!", false);
50 | }
51 | }
52 |
53 | @Test
54 | public void testUploadImg() {
55 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test1);
56 | assertTrue(img != null);
57 | try {
58 | String faceID = faceHelper.uploadPhoto(img);
59 | assertTrue(faceID != null);
60 | } catch (FaceHelper.requestError requestError) {
61 | requestError.printStackTrace();
62 | assertTrue("requestError!", false);
63 | }
64 | }
65 |
66 | @Test
67 | public void testAddFace() {
68 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test1);
69 | assertTrue(img != null);
70 | try {
71 | String faceID = faceHelper.uploadPhoto(img);
72 | assertTrue(faceID != null);
73 | boolean result = faceHelper.addFace(faceID);
74 | assertTrue(result);
75 | } catch (FaceHelper.requestError requestError) {
76 | requestError.printStackTrace();
77 | assertTrue("requestError!", false);
78 | } catch (FaceHelper.personIDNotFound personIDNotFound) {
79 | personIDNotFound.printStackTrace();
80 | assertTrue("personIDNotFound!", false);
81 | }
82 | }
83 |
84 | @Test
85 | public void testTrain() {
86 | try {
87 | faceHelper.train();
88 | } catch (FaceHelper.requestError requestError) {
89 | requestError.printStackTrace();
90 | assertTrue("requestError!", false);
91 | } catch (FaceHelper.personIDNotFound personIDNotFound) {
92 | personIDNotFound.printStackTrace();
93 | assertTrue("personIDNotFound!", false);
94 | }
95 | }
96 |
97 | @Test
98 | public void testVerify() {
99 | try {
100 | Bitmap img1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
101 | assertTrue(img1 != null);
102 | String faceID1 = faceHelper.uploadPhoto(img1);
103 | assertTrue(faceID1 != null);
104 | boolean addFaceResult1 = faceHelper.addFace(faceID1);
105 | assertTrue(addFaceResult1);
106 |
107 | faceHelper.train();
108 | Thread.sleep(5000);
109 |
110 | Bitmap img2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
111 | assertTrue(img2 != null);
112 | String faceID2 = faceHelper.uploadPhoto(img2);
113 | boolean result = faceHelper.verify(faceID2);
114 | assertTrue(result);
115 | } catch (FaceHelper.requestError requestError) {
116 | requestError.printStackTrace();
117 | assertTrue("requestError!", false);
118 | } catch (FaceHelper.personIDNotFound personIDNotFound) {
119 | personIDNotFound.printStackTrace();
120 | assertTrue("personIDNotFound!", false);
121 | } catch (InterruptedException e) {
122 | e.printStackTrace();
123 | assertTrue("InterruptedException!", false);
124 | }
125 | }
126 |
127 | @Test
128 | public void testGetSmiling() {
129 | try {
130 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
131 | assertTrue(img != null);
132 | String faceID = faceHelper.uploadPhoto(img);
133 | assertTrue(faceID != null);
134 | double smiling = faceHelper.getSmiling(faceID);
135 | assertEquals(smiling, 95.9057, 1);
136 | } catch (FaceHelper.requestError requestError) {
137 | requestError.printStackTrace();
138 | assertTrue("requestError!", false);
139 | }
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/org/hackpku/emotiondiary/data/DiaryDataTest.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.data;
2 |
3 | import android.content.Context;
4 | import android.graphics.Bitmap;
5 | import android.graphics.BitmapFactory;
6 | import android.support.test.InstrumentationRegistry;
7 | import android.support.test.runner.AndroidJUnit4;
8 | import android.test.suitebuilder.annotation.LargeTest;
9 |
10 | import org.hackpku.emotiondiary.R;
11 | import org.hackpku.emotiondiary.common.Diary.Diary;
12 | import org.hackpku.emotiondiary.common.Diary.DiaryHelper;
13 | import org.junit.Assert;
14 | import org.junit.Before;
15 | import org.junit.Test;
16 | import org.junit.runner.RunWith;
17 |
18 | import java.util.ArrayList;
19 | import java.util.Calendar;
20 | import java.util.Date;
21 | import java.util.GregorianCalendar;
22 | import java.util.TreeMap;
23 |
24 | import io.realm.Realm;
25 | import io.realm.RealmResults;
26 |
27 |
28 | /**
29 | * Created by ChenLetian on 16/5/27.
30 | * DiaryData测试类
31 | */
32 | @RunWith(AndroidJUnit4.class)
33 | @LargeTest
34 | public class DiaryDataTest {
35 |
36 | private Context context;
37 | private DiaryHelper diaryHelper;
38 |
39 | @Before
40 | public void setup() {
41 | context = InstrumentationRegistry.getTargetContext();
42 | diaryHelper = new DiaryHelper(context);
43 | }
44 |
45 | @Test
46 | public void testBasicSaveAndGet() {
47 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
48 | ArrayList pictures = new ArrayList<>();
49 | pictures.add(img);
50 | Diary toSaveDiary = new Diary(100, "哈哈哈", img, pictures, new GregorianCalendar().getTime());
51 | diaryHelper.saveDiary(toSaveDiary);
52 | Diary gettedDiary = diaryHelper.getLastestDiary();
53 | Assert.assertEquals(toSaveDiary.getDate(), gettedDiary.getDate());
54 | Assert.assertEquals(toSaveDiary.getHappiness(), gettedDiary.getHappiness());
55 | Assert.assertArrayEquals(toSaveDiary.getPictures().first().getData(), gettedDiary.getPictures().first().getData());
56 | Assert.assertArrayEquals(toSaveDiary.getSelfie().getData(), gettedDiary.getSelfie().getData());
57 | Assert.assertEquals(toSaveDiary.getText(), gettedDiary.getText());
58 | Bitmap gettedImage = gettedDiary.getSelfie().getImage();
59 | Assert.assertNotNull(gettedImage);
60 | }
61 |
62 | @Test
63 | public void testDeleteDiary() {
64 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
65 | ArrayList pictures = new ArrayList<>();
66 | pictures.add(img);
67 | Diary toSaveDiary = new Diary(99, "测试删除Diary", img, pictures, new GregorianCalendar().getTime());
68 | diaryHelper.saveDiary(toSaveDiary);
69 | Diary gettedDiary = diaryHelper.getLastestDiary();
70 | Assert.assertEquals(toSaveDiary.getDate(), gettedDiary.getDate());
71 | diaryHelper.deleteDiary(gettedDiary);
72 | gettedDiary = diaryHelper.getLastestDiary();
73 | Assert.assertNotEquals(toSaveDiary.getDate(), gettedDiary.getDate());
74 | }
75 |
76 | @Test
77 | public void testUpdate() {
78 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
79 | ArrayList pictures = new ArrayList<>();
80 | pictures.add(img);
81 | Diary toSaveDiary = new Diary(100, "哈哈哈", img, pictures, new GregorianCalendar().getTime());
82 | diaryHelper.saveDiary(toSaveDiary);
83 | final Diary gettedDiary = diaryHelper.getLastestDiary();
84 | diaryHelper.updateDiary(new Realm.Transaction() {
85 | @Override
86 | public void execute(Realm realm) {
87 | gettedDiary.setText("哈哈哈哈");
88 | }
89 | });
90 | Assert.assertTrue(gettedDiary.getText().equals("哈哈哈哈"));
91 | }
92 |
93 | @Test
94 | public void testGetDiaryOfDayUsingGregorianCalendar() {
95 | RealmResults diaries = diaryHelper.getDiariesOfDay(new GregorianCalendar());
96 | }
97 |
98 | @Test
99 | public void testGetSmilingForTime() {
100 | TreeMap result = diaryHelper.getHappinessForTime(2);
101 | Assert.assertNotNull(result);
102 | }
103 |
104 | @Test
105 | public void testAddALotOfDiary() {
106 | GregorianCalendar thisDay = new GregorianCalendar();
107 | for (int loop = 0; loop < 3; loop++) {
108 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
109 | ArrayList pictures = new ArrayList<>();
110 | pictures.add(img);
111 | Diary toSaveDiary = new Diary(100, "哈哈哈", img, pictures, thisDay.getTime());
112 | diaryHelper.saveDiary(toSaveDiary);
113 | }
114 | thisDay.add(Calendar.DAY_OF_YEAR, -1);
115 | for (int loop = 0; loop < 3; loop++) {
116 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
117 | ArrayList pictures = new ArrayList<>();
118 | pictures.add(img);
119 | Diary toSaveDiary = new Diary(60, "喵喵喵", img, pictures, thisDay.getTime());
120 | diaryHelper.saveDiary(toSaveDiary);
121 | }
122 | thisDay.add(Calendar.MONTH, -1);
123 | thisDay.add(Calendar.DAY_OF_MONTH, 10);
124 | for (int loop = 0; loop < 3; loop++) {
125 | Bitmap img = BitmapFactory.decodeResource(context.getResources(), R.drawable.test2);
126 | ArrayList pictures = new ArrayList<>();
127 | pictures.add(img);
128 | Diary toSaveDiary = new Diary(20, "汪汪汪", img, pictures, thisDay.getTime());
129 | diaryHelper.saveDiary(toSaveDiary);
130 | }
131 | RealmResults diaries = diaryHelper.getDiariesOfDay(thisDay);
132 | Assert.assertEquals(20, (int)(diaries.last().getHappiness()));
133 | }
134 |
135 | @Test
136 | public void testGetHappinessForTimeAsArrayList() {
137 | ArrayList result = diaryHelper.getHappinessForTimeAsArrayList(2);
138 | Assert.assertNotNull(result);
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Welcome/view/WelcomeActivity.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Welcome.view;
2 |
3 | import android.content.Intent;
4 | import android.graphics.drawable.Drawable;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.view.View;
8 | import android.view.ViewTreeObserver;
9 | import android.view.animation.AlphaAnimation;
10 | import android.view.animation.Animation;
11 | import android.widget.Button;
12 | import android.widget.Toast;
13 |
14 | import org.hackpku.emotiondiary.MainApplication;
15 | import org.hackpku.emotiondiary.R;
16 | import org.hackpku.emotiondiary.Welcome.presenter.IWelcomePresenter;
17 | import org.hackpku.emotiondiary.Welcome.presenter.WelcomePresenterImpl;
18 |
19 | /**
20 | * 欢迎/解锁界面
21 | */
22 | public class WelcomeActivity extends AppCompatActivity implements View.OnClickListener, IWelcomeView {
23 | private Button btnLogIn;
24 | private Button btnRecordEmotion;
25 | private Button btnEnterHomepage;
26 | private AlphaAnimation alphaAnimation;
27 | private double smiling = 0;
28 |
29 | IWelcomePresenter welcomePresenter; // 通过持有接口,而不是持有类,来提高代码的复用性
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | // 隐藏ActionBar
35 | getSupportActionBar().hide();
36 | // 全屏
37 | //getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
38 |
39 | setContentView(R.layout.activity_welcome);
40 |
41 | // 绑定按钮
42 | btnLogIn = (Button) this.findViewById(R.id.btnLogIn);
43 | btnRecordEmotion = (Button) this.findViewById(R.id.btnRecordEmotion);
44 | btnEnterHomepage = (Button) this.findViewById(R.id.btnEnterHomepage);
45 |
46 | // 注册按钮监听器
47 | btnLogIn.setOnClickListener(this);
48 | btnRecordEmotion.setOnClickListener(this);
49 | btnEnterHomepage.setOnClickListener(this);
50 |
51 | // 隐藏按钮
52 | btnRecordEmotion.setVisibility(View.INVISIBLE);
53 | btnEnterHomepage.setVisibility(View.INVISIBLE);
54 |
55 | welcomePresenter = new WelcomePresenterImpl(this);
56 |
57 | // 测量layout大小,设置icon直径
58 | final View layout = findViewById(R.id.welcomeViewLayout);
59 | layout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
60 | @Override
61 | public void onGlobalLayout() {
62 | layout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
63 | int diameter = Math.min(layout.getWidth(), layout.getHeight()) / 2;
64 | Drawable[] drawables = btnLogIn.getCompoundDrawables();
65 | drawables[1].setBounds(0, 0, diameter, diameter);
66 | btnLogIn.setCompoundDrawables(null, drawables[1], null, null);
67 | }
68 | });
69 |
70 | // 设置icon呼吸动画
71 | alphaAnimation = new AlphaAnimation(1.0f, 0.4f);
72 | alphaAnimation.setDuration(2000);
73 | alphaAnimation.setRepeatCount(-1);
74 | alphaAnimation.setRepeatMode(Animation.REVERSE);
75 | btnLogIn.setAnimation(alphaAnimation);
76 | alphaAnimation.startNow();
77 | }
78 |
79 | @Override
80 | protected void onStart() {
81 | super.onStart();
82 | this.changeIconAccordingToSmiling(((MainApplication)getApplication()).getSmiling());
83 | }
84 |
85 | /**
86 | * 点击事件回调
87 | */
88 | @Override
89 | public void onClick(View v) {
90 | switch (v.getId()) {
91 | case R.id.btnLogIn:
92 | welcomePresenter.doLogIn();
93 | break;
94 | case R.id.btnRecordEmotion:
95 | welcomePresenter.recordEmotion();
96 | break;
97 | case R.id.btnEnterHomepage:
98 | welcomePresenter.enterHomepage();
99 | break;
100 | }
101 | }
102 |
103 | /**
104 | * 处理解锁结果
105 | *
106 | * @param logInResult
107 | * @param msg
108 | */
109 | @Override
110 | public void onLogInResult(boolean logInResult, String msg) {
111 | if (logInResult) {
112 | btnRecordEmotion.setVisibility(View.VISIBLE);
113 | btnEnterHomepage.setVisibility(View.VISIBLE);
114 | btnLogIn.setEnabled(false);
115 | btnLogIn.clearAnimation();
116 | alphaAnimation.cancel();
117 | btnLogIn.setText("欢迎使用");
118 | }
119 | makeAlertDialog(logInResult ? "解锁成功" : "解锁失败", msg);
120 | }
121 |
122 | /**
123 | * RecordEmotion调用后的界面事务
124 | */
125 | @Override
126 | public void onRecordEmotion() {
127 | //*
128 | /*/
129 | //finish();
130 | //*/
131 | }
132 |
133 | /**
134 | * EnterHomepage调用后的界面事务
135 | */
136 | @Override
137 | public void onEnterHomepage() {
138 | /*
139 | Toast.makeText(this, "Enter homepage called", Toast.LENGTH_SHORT).show();
140 | /*/
141 | //finish();
142 | //*/
143 | }
144 |
145 | /**
146 | * 显示消息
147 | *
148 | * @param str Toast消息
149 | */
150 | @Override
151 | public void makeToast(String str) {
152 | Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
153 | }
154 |
155 | private void makeAlertDialog(String title, String message) {
156 | welcomePresenter.makeAlertDialog(title, message);
157 | }
158 |
159 | @Override
160 | protected void onActivityResult(int requestCode, int resultCode, Intent data) {
161 | super.onActivityResult(requestCode, resultCode, data);
162 | welcomePresenter.onActivityResult(requestCode, resultCode, data);
163 | }
164 |
165 | /**
166 | * 根据微笑值设置icon
167 | *
168 | * @param smiling 微笑值
169 | */
170 | public void changeIconAccordingToSmiling(double smiling) {
171 | if (this.smiling == smiling) return;
172 | this.smiling = smiling;
173 | Drawable[] drawables = btnLogIn.getCompoundDrawables();
174 | Drawable newDrawable;
175 | if (smiling < 33) newDrawable = getResources().getDrawable(R.drawable.diary_app_icon_blue);
176 | else if (smiling > 66) newDrawable = getResources().getDrawable(R.drawable.diary_app_icon_orange);
177 | else newDrawable = getResources().getDrawable(R.drawable.diary_app_icon_yellow);
178 | newDrawable.setBounds(drawables[1].getBounds());
179 | btnLogIn.setCompoundDrawables(null, newDrawable, null, null);
180 |
181 | /*
182 | RelativeLayout layout = (RelativeLayout) findViewById(R.id.welcomeViewLayout);
183 | int color;
184 | if (smiling < 33) color = Color.argb(255, 126, 206, 244);
185 | else if (smiling > 66) color = Color.argb(255, 241, 145, 73);
186 | else color = Color.argb(255, 248, 248, 124);
187 |
188 | //layout.setBackgroundColor(color);
189 | */
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/app/src/main/java/org/hackpku/emotiondiary/Homepage/HomePageActivity.java:
--------------------------------------------------------------------------------
1 | package org.hackpku.emotiondiary.Homepage;
2 |
3 | import android.content.Intent;
4 | import android.graphics.Bitmap;
5 | import android.graphics.drawable.BitmapDrawable;
6 | import android.os.Bundle;
7 | import android.os.Handler;
8 | import android.os.Message;
9 | import android.support.v4.app.FragmentActivity;
10 | import android.view.View;
11 | import android.widget.*;
12 |
13 | import java.util.*;
14 |
15 | import org.hackpku.emotiondiary.MainApplication;
16 | import org.hackpku.emotiondiary.R;
17 | import org.hackpku.emotiondiary.common.Diary.*;
18 |
19 | import io.realm.*;
20 |
21 | /**
22 | * Created by Liu Zhengyuan on 2016/6/4.
23 | */
24 | public class HomePageActivity extends FragmentActivity {
25 |
26 | private CalendarView calendarView;
27 | private TextView tv_date;
28 | private ListView lv_diary;
29 | private DiaryHelper diaryHelper=new DiaryHelper();
30 | private List