├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── raw
│ │ │ │ ├── ding.mp3
│ │ │ │ ├── bling.mp3
│ │ │ │ ├── bling2.aiff
│ │ │ │ └── tap_wooden_fish.wav
│ │ │ ├── drawable
│ │ │ │ ├── cj.jpg
│ │ │ │ ├── cjz.jpg
│ │ │ │ ├── jsj.jpg
│ │ │ │ ├── lxf.jpg
│ │ │ │ ├── yhq.jpg
│ │ │ │ ├── ic_launcher_foreground.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ ├── ic_launcher_round.webp
│ │ │ │ └── smarttodoicon_256.png
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ └── themes.xml
│ │ │ ├── menu
│ │ │ │ └── main.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ └── layout
│ │ │ │ ├── cardview_item.xml
│ │ │ │ ├── activity_second.xml
│ │ │ │ ├── activity_advise.xml
│ │ │ │ └── first_layout.xml
│ │ ├── java
│ │ │ ├── baidu
│ │ │ │ └── com
│ │ │ │ │ ├── ChatCompletion.java
│ │ │ │ │ ├── RequestBodyGenerator.java
│ │ │ │ │ └── Sample.java
│ │ │ └── com
│ │ │ │ └── example
│ │ │ │ └── emptyactivity
│ │ │ │ ├── SecondActivity.java
│ │ │ │ ├── AdviseActivity.java
│ │ │ │ └── FirstActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── example
│ │ │ └── emptyactivity
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── example
│ │ └── emptyactivity
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .gitignore
├── compiler.xml
├── vcs.xml
├── migrations.xml
├── misc.xml
├── deploymentTargetSelector.xml
└── gradle.xml
├── img
├── img.png
├── img_1.png
├── img_2.png
└── img_3.png
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .gitignore
├── README.md
├── settings.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # 默认忽略的文件
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/img/img.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/img/img.png
--------------------------------------------------------------------------------
/img/img_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/img/img_1.png
--------------------------------------------------------------------------------
/img/img_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/img/img_2.png
--------------------------------------------------------------------------------
/img/img_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/img/img_3.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/ding.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/raw/ding.mp3
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cj.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/drawable/cj.jpg
--------------------------------------------------------------------------------
/app/src/main/res/raw/bling.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/raw/bling.mp3
--------------------------------------------------------------------------------
/app/src/main/res/raw/bling2.aiff:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/raw/bling2.aiff
--------------------------------------------------------------------------------
/app/src/main/res/drawable/cjz.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/drawable/cjz.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/jsj.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/drawable/jsj.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/lxf.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/drawable/lxf.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/yhq.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/drawable/yhq.jpg
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/raw/tap_wooden_fish.wav:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/raw/tap_wooden_fish.wav
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/smarttodoicon_256.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/FormerOR/Smart-Todo-App/HEAD/app/src/main/res/mipmap-xxxhdpi/smarttodoicon_256.png
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 智慧待办
3 | Version:3.0.1 By LucasLynn
4 | 这是一只赛博木鱼
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 10 12:03:26 HKT 2024
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/.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 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/.idea/migrations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/test/java/com/example/emptyactivity/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.example.emptyactivity;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/baidu/com/ChatCompletion.java:
--------------------------------------------------------------------------------
1 | package baidu.com;
2 |
3 | public class ChatCompletion {
4 | String id;
5 | String object;
6 | long created;
7 | String result;
8 | boolean isTruncated;
9 | boolean needClearHistory;
10 | Usage usage;
11 |
12 | // 注意:Usage类定义应包含prompt_tokens, completion_tokens, total_tokens字段
13 | static class Usage {
14 | int prompt_tokens;
15 | int completion_tokens;
16 | int total_tokens;
17 | }
18 |
19 | public String getResult() {
20 | return result;
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #66EAEEF4
11 | #FEFEFE
12 | #254CABF3
13 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Smart Todo App
2 |
3 | > ✏️作者:FormerOR(别名LucasLynn) 更新日期:2024年6月23日21:59:16
4 | >
5 | > 📝智慧待办,一款安卓应用,目标是在用户输入待办事项后,能通过AI分析来规划日程和事项安排,基于java开发
6 | >
7 | > 开发动机是NJUPT的Java程序设计课程大作业,老师给了几个选择,前几个都是清一色老掉牙的系统或者游戏,但最后两个分别是用Java开发安卓应用或者鸿蒙应用,然后觉得系统什么的也太无聊了,直接去CSDN都不用Chat出手,就打算自学一下安卓
8 | > 正好@feipiao594 他想做一个跨平台的Todolist,我就顺着他的思路想,发挥自己在AI上略知一二能力的优势,结合当下很火的NLP,做一个API调用来实现AI分析功能
9 |
10 | ## 船新升级 v3.0.1
11 | - 修改布局
12 | - 能够添加多个待办事项
13 | - 点击待办事项能够切换界面
14 | - 在新界面能够单独进行获取建议
15 | - 过长的文本能够实现自动滚动
16 | - 为控件添加了合适的间距和边框
17 | - 点击版本号能够跳转至Github仓库
18 | - 重构代码(依旧屎山)
19 |
20 |
21 | ## 应用截图
22 | 
23 | 
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google {
4 | content {
5 | includeGroupByRegex("com\\.android.*")
6 | includeGroupByRegex("com\\.google.*")
7 | includeGroupByRegex("androidx.*")
8 | }
9 | }
10 | mavenCentral()
11 | gradlePluginPortal()
12 | }
13 | }
14 | dependencyResolutionManagement {
15 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
16 | repositories {
17 | google()
18 | mavenCentral()
19 | }
20 | }
21 |
22 | rootProject.name = "EmptyActivity"
23 | include ':app'
24 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetSelector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/example/emptyactivity/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.example.emptyactivity;
2 |
3 | import android.content.Context;
4 |
5 | import androidx.test.platform.app.InstrumentationRegistry;
6 | import androidx.test.ext.junit.runners.AndroidJUnit4;
7 |
8 | import org.junit.Test;
9 | import org.junit.runner.RunWith;
10 |
11 | import static org.junit.Assert.*;
12 |
13 | /**
14 | * Instrumented test, which will execute on an Android device.
15 | *
16 | * @see Testing documentation
17 | */
18 | @RunWith(AndroidJUnit4.class)
19 | public class ExampleInstrumentedTest {
20 | @Test
21 | public void useAppContext() {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24 | assertEquals("com.example.emptyactivity", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.5.0"
3 | junit = "4.13.2"
4 | junitVersion = "1.1.5"
5 | espressoCore = "3.5.1"
6 | appcompat = "1.6.1"
7 | material = "1.10.0"
8 | activity = "1.8.0"
9 | constraintlayout = "2.1.4"
10 | cardview = "1.0.0"
11 |
12 | [libraries]
13 | junit = { group = "junit", name = "junit", version.ref = "junit" }
14 | ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
15 | espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" }
16 | appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
17 | material = { group = "com.google.android.material", name = "material", version.ref = "material" }
18 | activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
19 | constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
20 | cardview = { group = "androidx.cardview", name = "cardview", version.ref = "cardview" }
21 |
22 | [plugins]
23 | android-application = { id = "com.android.application", version.ref = "agp" }
24 |
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. For more details, visit
12 | # https://developer.android.com/r/tools/gradle-multi-project-decoupled-projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Enables namespacing of each library's R class so that its R class includes only the
19 | # resources declared in the library itself and none from the library's dependencies,
20 | # thereby reducing the size of the R class for that library
21 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
19 |
22 |
25 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.application)
3 | }
4 |
5 | android {
6 | namespace 'com.example.emptyactivity'
7 | compileSdk 34
8 |
9 | defaultConfig {
10 | applicationId "com.example.emptyactivity"
11 | minSdk 24
12 | targetSdk 34
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 |
19 | buildTypes {
20 | release {
21 | minifyEnabled false
22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23 | }
24 | }
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | }
30 |
31 | dependencies {
32 |
33 | implementation libs.appcompat
34 | implementation libs.material
35 | implementation libs.activity
36 | implementation libs.constraintlayout
37 | implementation libs.cardview
38 | testImplementation libs.junit
39 | androidTestImplementation libs.ext.junit
40 | androidTestImplementation libs.espresso.core
41 | // 添加OkHttp的依赖
42 | implementation 'com.squareup.okhttp3:okhttp:4.12.0'
43 | // 添加Moshi的依赖
44 | implementation 'com.squareup.moshi:moshi:1.13.0'
45 | implementation 'com.squareup.moshi:moshi-adapters:1.13.0'
46 | implementation 'com.google.code.gson:gson:2.8.8'
47 | implementation 'com.google.android.material:material:1.8.0'
48 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/cardview_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
21 |
22 |
27 |
28 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/emptyactivity/SecondActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.emptyactivity;
2 |
3 | import android.media.MediaPlayer;
4 | import android.os.Bundle;
5 | import android.widget.Button;
6 | import android.widget.ImageView;
7 | import android.widget.TextView;
8 |
9 | import androidx.activity.EdgeToEdge;
10 | import androidx.appcompat.app.AppCompatActivity;
11 | import androidx.core.graphics.Insets;
12 | import androidx.core.view.ViewCompat;
13 | import androidx.core.view.WindowInsetsCompat;
14 |
15 | public class SecondActivity extends AppCompatActivity {
16 |
17 | @Override
18 | protected void onCreate(Bundle savedInstanceState) {
19 | super.onCreate(savedInstanceState);
20 | EdgeToEdge.enable(this);
21 | setContentView(R.layout.activity_second);
22 | ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
23 | Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
24 | v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
25 | return insets;
26 | });
27 |
28 | Button button2 = (Button) findViewById(R.id.Button_page2);
29 | TextView textView = (TextView) findViewById(R.id.textView4);
30 | ImageView imageView = (ImageView) findViewById(R.id.imageView);
31 | final MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.tap_wooden_fish);
32 | button2.setOnClickListener(v -> {
33 | // 点击按钮后文本框数字加一
34 | int num = Integer.parseInt(textView.getText().toString());
35 | textView.setText(String.valueOf(num + 1));
36 | // 播放音效
37 | mediaPlayer.start();
38 |
39 | // 切换图片,根据图片列表的顺序切换
40 | String[] imageList = {"cj", "jsj","yhq","lxf","cjz"};
41 | int index = num % imageList.length;
42 | int imageId = getResources().getIdentifier(imageList[index], "drawable", getPackageName());
43 | imageView.setImageResource(imageId);
44 |
45 | });
46 | }
47 | }
--------------------------------------------------------------------------------
/app/src/main/java/baidu/com/RequestBodyGenerator.java:
--------------------------------------------------------------------------------
1 | package baidu.com;
2 |
3 | import com.squareup.moshi.JsonAdapter;
4 | import com.squareup.moshi.Moshi;
5 | import okhttp3.MediaType;
6 | import okhttp3.RequestBody;
7 |
8 | import java.io.IOException;
9 |
10 | public class RequestBodyGenerator {
11 |
12 | private static final Moshi MOSHI = new Moshi.Builder().build();
13 | private static final JsonAdapter JSON_ADAPTER = MOSHI.adapter(RequestBodyModel.class);
14 |
15 | // 定义一个数据模型类,对应请求体的结构
16 | public static class RequestBodyModel {
17 | public Message[] messages;
18 | public double temperature;
19 | public double top_p;
20 | public int penalty_score;
21 | public String system;
22 |
23 | // 必要的构造方法、getter和setter省略
24 | }
25 |
26 | public static class Message {
27 | public String role;
28 | public String content;
29 |
30 | public Message(String user, String userInput) {
31 | this.role = user;
32 | this.content = userInput;
33 | }
34 |
35 | // 必要的构造方法、getter和setter
36 |
37 |
38 | }
39 |
40 | /**
41 | * 根据用户输入动态生成RequestBody
42 | * @param userInput 用户的具体输入内容
43 | * @return 返回根据用户输入创建的RequestBody实例
44 | */
45 | public static RequestBody createRequestBody(String userInput) throws IOException {
46 | // 创建请求体数据模型实例
47 | RequestBodyModel requestBodyModel = new RequestBodyModel();
48 | requestBodyModel.messages = new Message[]{new Message("user", userInput)};
49 | requestBodyModel.temperature = 0.95;
50 | requestBodyModel.top_p = 0.7;
51 | requestBodyModel.penalty_score = 1;
52 | // requestBodyModel.system = "你是一个“时间管理大师”,根据待办事项可以立刻做出合理精细且简洁的执行计划,执行计划是指将待办事项作为一个父任务,给出将执行待办事项需要完成的子任务计划。计划中的每个事件的内容格式为“开始时间-结束时间:具体内容:准备:建议:”。除了计划内容以外不要输出其他内容。请将具体内容分为几个点具体列出,同时给出准备和建议。";
53 | requestBodyModel.system = "请制定一个合理的、精细的、简洁的执行计划,将待办任务分配成子任务,并标明每个子任务的开始和结束时间,以及具体的任务内容、准备工作和建议。请将具体任务内容细分为多个点详细列出,并提供准备和建议。注意,除了计划内容外,不应包含任何其他信息。";
54 | // 使用Moshi将数据模型转换为JSON字符串
55 | String json = JSON_ADAPTER.toJson(requestBodyModel);
56 | return RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json);
57 | }
58 |
59 | // public static void main(String[] args) {
60 | // try {
61 | // String userInput = "7:30-10:30去教学楼303拍摄一场招聘会";
62 | // RequestBody body = createRequestBody(userInput);
63 | // // 现在你可以使用这个body发起网络请求
64 | // // ...
65 | // } catch (IOException e) {
66 | // e.printStackTrace();
67 | // }
68 | // }
69 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_second.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
29 |
30 |
45 |
46 |
60 |
61 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/app/src/main/java/baidu/com/Sample.java:
--------------------------------------------------------------------------------
1 | package baidu.com;
2 |
3 | import androidx.annotation.NonNull;
4 |
5 | import okhttp3.*;
6 |
7 | import org.json.JSONException;
8 | import org.json.JSONObject;
9 |
10 | import java.io.*;
11 | import com.google.gson.Gson;
12 |
13 |
14 | public class Sample {
15 | public static final String API_KEY = "WlNEBsP7s9jsGH7RQlJJNmMN";
16 | public static final String SECRET_KEY = "TVSrrTOAzcxKsReuLUSjo7K4WOXMcFyi";
17 |
18 | static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
19 |
20 | private static String Response_string = null;
21 |
22 | public static String start(String user_input) throws IOException{
23 | MediaType mediaType = MediaType.parse("application/json");
24 | // RequestBody body = RequestBody.create(mediaType, "{\"messages\":[{\"role\":\"user\",\"content\":\"7:30-10:30去教学楼303拍摄一场招聘会\"}],\"temperature\":0.95,\"top_p\":0.7,\"penalty_score\":1,\"system\":\"你是一个“时间管理大师”,根据待办事项可以立刻做出合理精细且简洁的执行计划,执行计划是指将待办事项作为一个父任务,给出将执行待办事项需要完成的子任务计划。计划中的每个事件的内容格式为“开始时间-结束时间:具体内容:准备:建议:”。除了计划内容以外不要输出其他内容。请将具体内容分为几个点具体列出,同时给出准备和建议。\"}");
25 | RequestBodyGenerator requestBodyGenerator = new RequestBodyGenerator();
26 | RequestBody body = RequestBodyGenerator.createRequestBody(user_input);
27 | Request request = new Request.Builder()
28 | .url("https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ai_apaas?access_token=" + getAccessToken())
29 | .method("POST", body)
30 | .addHeader("Content-Type", "application/json")
31 | .build();
32 | Response response = HTTP_CLIENT.newCall(request).execute();
33 | Response_string = response.body().string();
34 | System.out.println(Response_string);
35 |
36 | String displayText = getDisplayText();
37 |
38 | return displayText;
39 |
40 |
41 | }
42 |
43 | @NonNull
44 | private static String getDisplayText() {
45 | Gson gson = new Gson();
46 | ChatCompletion chatCompletion = gson.fromJson(Response_string, ChatCompletion.class);
47 |
48 | // String displayText = "活动详情:\n"
49 | // + "开始时间:" + chatCompletion.result.split("\\n")[0] + "\n"
50 | // + "结束时间:" + chatCompletion.result.split("\\n")[1] + "\n"
51 | // + "具体内容:" + chatCompletion.result.split("\\n")[2].replaceFirst("具体内容:", "") + "\n"
52 | // + "准备:" + chatCompletion.result.split("\\n")[3].replaceFirst("准备:", "") + "\n"
53 | // + "建议:" + chatCompletion.result.split("\\n")[4].replaceFirst("建议:", "");
54 | //
55 |
56 | // 提取result字段,并根据\n分隔内容
57 | String result = chatCompletion.getResult();
58 | String[] lines = result.split("\n");
59 | System.out.println(lines);
60 |
61 | // 构建显示的文本
62 | StringBuilder displayText = new StringBuilder();
63 | for (String line : lines) {
64 | // 添加到显示文本中
65 | displayText.append(line).append("\n");
66 | }
67 |
68 | return displayText.toString().trim();
69 | }
70 |
71 |
72 | /**
73 | * 从用户的AK,SK生成鉴权签名(Access Token)
74 | *
75 | * @return 鉴权签名(Access Token)
76 | * @throws IOException IO异常
77 | */
78 | static String getAccessToken() throws IOException {
79 | MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
80 | RequestBody body = RequestBody.create(mediaType, "grant_type=client_credentials&client_id=" + API_KEY
81 | + "&client_secret=" + SECRET_KEY);
82 | Request request = new Request.Builder()
83 | .url("https://aip.baidubce.com/oauth/2.0/token")
84 | .method("POST", body)
85 | .addHeader("Content-Type", "application/x-www-form-urlencoded")
86 | .build();
87 | Response response = HTTP_CLIENT.newCall(request).execute();
88 | try {
89 | return new JSONObject(response.body().string()).getString("access_token");
90 | } catch (JSONException e) {
91 | throw new RuntimeException(e);
92 | }
93 | }
94 |
95 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_advise.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
25 |
26 |
37 |
38 |
42 |
43 |
49 |
50 |
62 |
63 |
69 |
70 |
71 |
72 |
73 |
74 |
95 |
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/emptyactivity/AdviseActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.emptyactivity;
2 |
3 | import android.content.Intent;
4 | import android.media.MediaPlayer;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.widget.Button;
8 | import android.widget.EditText;
9 | import android.widget.LinearLayout;
10 | import android.widget.ProgressBar;
11 | import android.widget.TextView;
12 | import android.widget.Toast;
13 |
14 | import androidx.activity.EdgeToEdge;
15 | import androidx.appcompat.app.AppCompatActivity;
16 | import androidx.core.graphics.Insets;
17 | import androidx.core.view.ViewCompat;
18 | import androidx.core.view.WindowInsetsCompat;
19 |
20 | import baidu.com.Sample;
21 |
22 | public class AdviseActivity extends AppCompatActivity {
23 |
24 | @Override
25 | protected void onCreate(Bundle savedInstanceState) {
26 | super.onCreate(savedInstanceState);
27 | EdgeToEdge.enable(this);
28 | setContentView(R.layout.activity_advise);
29 | ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
30 | Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
31 | v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
32 | return insets;
33 | });
34 |
35 | // 获取数据
36 | Intent i = getIntent();
37 | String previous_info = i.getStringExtra("data");
38 |
39 | //设置mediaPlayer
40 | final MediaPlayer mediaPlayer = MediaPlayer.create(this, R.raw.bling);
41 | // 获取控件
42 | TextView adv_text = (TextView) this.findViewById(R.id.textView2);
43 | Button button2 = (Button) this.findViewById(R.id.Button_get_adv);
44 | ProgressBar wait_bar = (ProgressBar) this.findViewById(R.id.progressBar);
45 | TextView previous_info_text = (TextView) this.findViewById(R.id.textView6);
46 |
47 | // 设置上一个页面传递的数据
48 | previous_info_text.setText(previous_info);
49 |
50 | // 添加点击事件——获取建议
51 | onClickGetAdvice(button2, wait_bar, previous_info_text, adv_text, mediaPlayer);
52 |
53 |
54 | }
55 |
56 | private void onClickGetAdvice(Button button2, ProgressBar wait_bar, TextView user_input_edit, TextView adv_text, MediaPlayer mediaPlayer) {
57 | button2.setOnClickListener(new View.OnClickListener() {
58 | @Override
59 | public void onClick(View v) {
60 | // 点击按钮后,显示进度条
61 | wait_bar.setVisibility(View.VISIBLE);
62 | new Thread(new Runnable() {
63 | @Override
64 | public void run() {
65 | int times = 0;
66 | // 执行5次请求,直到成功就停止
67 | for (times = 0; times < 5; times++) {
68 | try {
69 | // 调用Sample.start方法,传入用户输入的内容
70 | Sample Sample1 = new Sample();
71 | String content = Sample1.start(user_input_edit.getText().toString());
72 | runOnUiThread(new Runnable() {
73 | @Override
74 | public void run() {
75 | adv_text.setText(content);
76 | Toast.makeText(AdviseActivity.this, "已获取到建议", Toast.LENGTH_SHORT).show();
77 | // 播放音效
78 | if (!mediaPlayer.isPlaying()) {
79 | mediaPlayer.start();
80 | }
81 | // 隐藏进度条
82 | wait_bar.setVisibility(View.GONE);
83 | }
84 | });
85 | break;
86 | } catch (Exception e) {
87 | e.printStackTrace();
88 | int finalI = times;
89 | runOnUiThread(new Runnable() {
90 | @Override
91 | public void run() {
92 | Toast.makeText(AdviseActivity.this, String.format("服务器开了点小差,正在重试...(%d)", finalI+1), Toast.LENGTH_SHORT).show();
93 | }
94 | });
95 | }
96 | // 如果失败,toast提示用户
97 | if (times == 4) {
98 | runOnUiThread(new Runnable() {
99 | @Override
100 | public void run() {
101 | Toast.makeText(AdviseActivity.this, "服务器开了点小差,请重试", Toast.LENGTH_SHORT).show();
102 | // 隐藏进度条
103 | wait_bar.setVisibility(View.GONE);
104 | }
105 | });
106 | }
107 | }
108 | }
109 | }).start();
110 | }
111 | });
112 | }
113 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/first_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
22 |
23 |
38 |
39 |
54 |
55 |
70 |
71 |
82 |
83 |
87 |
88 |
94 |
95 |
106 |
107 |
113 |
114 |
115 |
116 |
117 |
118 |
128 |
129 |
143 |
144 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/emptyactivity/FirstActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.emptyactivity;
2 |
3 | import android.app.AlertDialog;
4 | import android.content.Context;
5 | import android.content.DialogInterface;
6 | import android.content.Intent;
7 | import android.graphics.Paint;
8 | import android.media.MediaPlayer;
9 | import android.net.Uri;
10 | import android.os.Bundle;
11 | import android.os.Vibrator;
12 | import android.view.LayoutInflater;
13 | import android.view.Menu;
14 | import android.view.MenuItem;
15 | import android.view.View;
16 | import android.widget.Button;
17 | import android.widget.EditText;
18 | import android.widget.ImageView;
19 | import android.widget.LinearLayout;
20 | import android.widget.ProgressBar;
21 | import android.widget.TextView;
22 | import android.widget.Toast;
23 |
24 | import androidx.appcompat.app.AppCompatActivity;
25 | import androidx.cardview.widget.CardView;
26 |
27 | import baidu.com.Sample;
28 |
29 | public class FirstActivity extends AppCompatActivity {
30 |
31 | @Override
32 | protected void onCreate(Bundle savedInstanceState) {
33 | super.onCreate(savedInstanceState);
34 | setContentView(R.layout.first_layout);
35 |
36 | // 从布局文件中加载视图
37 | LayoutInflater inflater = LayoutInflater.from(this);
38 | //设置mediaPlayer
39 | final MediaPlayer mediaPlayer_bling = MediaPlayer.create(this, R.raw.bling);
40 | final MediaPlayer mediaPlayer_ding = MediaPlayer.create(this, R.raw.ding);
41 | // 获取控件
42 | TextView adv_text = (TextView) findViewById(R.id.textView2);
43 | EditText user_input_edit = (EditText) findViewById(R.id.editTextText);
44 | Button button1 = (Button) findViewById(R.id.Button_1);
45 | Button button2 = (Button) findViewById(R.id.Button_get_adv);
46 | ProgressBar wait_bar = (ProgressBar) findViewById(R.id.progressBar);
47 | Button button3 = (Button) findViewById(R.id.Button_add_todo);
48 | LinearLayout todo_list = (LinearLayout) findViewById(R.id.todo_linearlayout);
49 | TextView version_text = (TextView) findViewById(R.id.textView_version);
50 |
51 | // 添加点击事件——获取建议
52 | // onClickGetAdvice(button2, wait_bar, user_input_edit, adv_text, mediaPlayer);
53 | onClickGetAdvice(button2);
54 | // 添加点击事件——切换到活动2
55 | onClickNextPage(button1);
56 | // 添加点击事件——添加待办事项
57 | onClickAddTodoItem(button3, inflater, todo_list, user_input_edit, mediaPlayer_ding);
58 | // 添加点击事件——打开github
59 | onClickOpenGithub(version_text);
60 |
61 | }
62 |
63 | private void onClickOpenGithub(TextView versionText) {
64 | versionText.setOnClickListener(new View.OnClickListener() {
65 | @Override
66 | public void onClick(View v) {
67 | Toast.makeText(FirstActivity.this, "正在跳转至Github仓库界面", Toast.LENGTH_SHORT).show();
68 | String url = "https://github.com/FormerOR/Smart-Todo-App";
69 | openWebPage(url);
70 | }
71 | });
72 | }
73 |
74 | private void openWebPage(String url) {
75 | Uri webpage = Uri.parse(url);
76 | Intent intent = new Intent(Intent.ACTION_VIEW, webpage);
77 | if (intent.resolveActivity(getPackageManager()) != null) {
78 | startActivity(intent);
79 | } else {
80 | Toast.makeText(this, "没有可用的浏览器应用", Toast.LENGTH_SHORT).show();
81 | }
82 | }
83 |
84 | static private int todo_item_count = 0;
85 |
86 | public void vibrator(long milliseconds) {
87 | // 获取Vibrator服务
88 | Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
89 |
90 | // 检查是否存在Vibrator服务并且设备支持震动
91 | if (vibrator != null && vibrator.hasVibrator()) {
92 | // 设定震动模式,参数为震动持续时间和间隔时间,单位为毫秒
93 | // 例如,下面的代码会让设备震动500毫秒,然后停止200毫秒,再震动500毫秒
94 | long[] pattern = {0, milliseconds, 200, milliseconds};
95 |
96 | // 执行震动。第二个参数为重复次数,-1表示不重复
97 | vibrator.vibrate(pattern, -1);
98 | }
99 | }
100 |
101 | private void onClickAddTodoItem(Button button3, LayoutInflater inflater, LinearLayout todo_list, EditText editText, MediaPlayer mediaPlayer) {
102 | button3.setOnClickListener(new View.OnClickListener() {
103 | @Override
104 | public void onClick(View v) {
105 | todo_item_count++;
106 | final CardView cardView = (CardView) inflater.inflate(R.layout.cardview_item, null, false);
107 | LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
108 | LinearLayout.LayoutParams.MATCH_PARENT,
109 | LinearLayout.LayoutParams.WRAP_CONTENT);
110 | layoutParams.setMargins(10, 10, 10, 10);
111 | cardView.setCardBackgroundColor(0x254CABF3);
112 | cardView.setCardElevation(1);
113 | cardView.setRadius(12);
114 | cardView.setLayoutParams(layoutParams);
115 |
116 | TextView textView = cardView.findViewById(R.id.textView_todo);
117 | ImageView imageView = cardView.findViewById(R.id.imageView_todo);
118 | textView.setText(editText.getText().toString());
119 | String todo = editText.getText().toString().trim();
120 |
121 | cardView.setOnClickListener(new View.OnClickListener() {
122 | @Override
123 | public void onClick(View v) {
124 | Toast.makeText(FirstActivity.this, "切换到建议活动", Toast.LENGTH_SHORT).show();
125 | Intent intent = new Intent(FirstActivity.this, AdviseActivity.class);
126 | intent.putExtra("data", todo);
127 | startActivity(intent);
128 | }
129 | });
130 |
131 | //为imageView设置点击事件
132 | imageView.setOnClickListener(new View.OnClickListener() {
133 | @Override
134 | public void onClick(View v) {
135 | // 切换图片(点亮和熄灭)
136 | // 先获取两张图片分别为@android:drawable/btn_star_big_off和@android:drawable/btn_star_big_on
137 | // 然后判断当前图片是否为@android:drawable/btn_star_big_off,如果是则切换为@android:drawable/btn_star_big_on,否则切换为@android:drawable/btn_star_big_off
138 | if (imageView.getDrawable().getConstantState().equals(getResources().getDrawable(android.R.drawable.btn_star_big_off).getConstantState())) {
139 | imageView.setImageResource(android.R.drawable.btn_star_big_on);
140 | vibrator(300);
141 | Toast.makeText(FirstActivity.this, "已完成待办!", Toast.LENGTH_SHORT).show();
142 | // 将文本划去
143 | textView.setPaintFlags(textView.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
144 | // 播放音效
145 | mediaPlayer.start();
146 |
147 | } else {
148 | imageView.setImageResource(android.R.drawable.btn_star_big_off);
149 | vibrator(100);
150 | Toast.makeText(FirstActivity.this, "取消完成状态", Toast.LENGTH_SHORT).show();
151 | // 取消文本划去
152 | textView.setPaintFlags(textView.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));
153 | }
154 | }
155 | });
156 |
157 | // 设置长按监听器
158 | cardView.setOnLongClickListener(new View.OnLongClickListener() {
159 | @Override
160 | public boolean onLongClick(View v) {
161 | showDeleteConfirmationDialog(cardView, todo_list);
162 | return true; // 返回true表示已经处理了长按事件
163 | }
164 | });
165 |
166 | if (!todo.isEmpty()) {
167 | editText.setText(""); // 清空输入框
168 | Toast.makeText(FirstActivity.this, "待办事项已添加", Toast.LENGTH_SHORT).show();
169 | } else {
170 | Toast.makeText(FirstActivity.this, "待办事项不能为空", Toast.LENGTH_SHORT).show();
171 | return;
172 | }
173 |
174 | todo_list.addView(cardView);
175 | // Toast.makeText(FirstActivity.this, "已添加待办事项", Toast.LENGTH_SHORT).show();
176 | }
177 | });
178 | }
179 |
180 | // 显示删除确认对话框的方法
181 | private void showDeleteConfirmationDialog(final CardView cardView , LinearLayout todo_list) {
182 | AlertDialog.Builder builder = new AlertDialog.Builder(this);
183 | builder.setTitle("删除提醒");
184 | builder.setMessage("确定要删除这个待办事项吗?");
185 | builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
186 | @Override
187 | public void onClick(DialogInterface dialog, int which) {
188 | todo_list.removeView(cardView);
189 | Toast.makeText(FirstActivity.this, "待办事项已删除", Toast.LENGTH_SHORT).show();
190 | }
191 | });
192 | builder.setNegativeButton("取消", null);
193 | builder.show();
194 | }
195 |
196 | private void onClickNextPage(Button button1) {
197 | button1.setOnClickListener(new View.OnClickListener() {
198 | @Override
199 | public void onClick(View v) {
200 | Toast.makeText(FirstActivity.this, "切换到活动2", Toast.LENGTH_SHORT).show();
201 | Intent intent = new Intent(FirstActivity.this, SecondActivity.class);
202 | // 传递数据
203 | intent.putExtra("data", "Hello SecondActivity");
204 | startActivity(intent);
205 | }
206 |
207 | });
208 | }
209 |
210 | private void onClickGetAdvice(Button btn){
211 | btn.setOnClickListener(new View.OnClickListener() {
212 | @Override
213 | public void onClick(View v) {
214 | Toast.makeText(FirstActivity.this, "Tip:获取建议前,请先点击待办事项", Toast.LENGTH_SHORT).show();
215 | }
216 | });
217 | }
218 |
219 | private void onClickGetAdvice(Button button2, ProgressBar wait_bar, EditText user_input_edit, TextView adv_text, MediaPlayer mediaPlayer) {
220 | button2.setOnClickListener(new View.OnClickListener() {
221 | @Override
222 | public void onClick(View v) {
223 | // 点击按钮后,显示进度条
224 | wait_bar.setVisibility(View.VISIBLE);
225 | new Thread(new Runnable() {
226 | @Override
227 | public void run() {
228 | int times = 0;
229 | // 执行5次请求,直到成功就停止
230 | for (times = 0; times < 5; times++) {
231 | try {
232 | // 调用Sample.start方法,传入用户输入的内容
233 | Sample Sample1 = new Sample();
234 | String content = Sample1.start(user_input_edit.getText().toString());
235 | runOnUiThread(new Runnable() {
236 | @Override
237 | public void run() {
238 | adv_text.setText(content);
239 | Toast.makeText(FirstActivity.this, "已获取到建议", Toast.LENGTH_SHORT).show();
240 | // 播放音效
241 | if (!mediaPlayer.isPlaying()) {
242 | mediaPlayer.start();
243 | }
244 | // 隐藏进度条
245 | wait_bar.setVisibility(View.GONE);
246 | }
247 | });
248 | break;
249 | } catch (Exception e) {
250 | e.printStackTrace();
251 | int finalI = times;
252 | runOnUiThread(new Runnable() {
253 | @Override
254 | public void run() {
255 | Toast.makeText(FirstActivity.this, String.format("服务器开了点小差,正在重试...(%d)", finalI+1), Toast.LENGTH_SHORT).show();
256 | }
257 | });
258 | }
259 | // 如果失败,toast提示用户
260 | if (times == 4) {
261 | runOnUiThread(new Runnable() {
262 | @Override
263 | public void run() {
264 | Toast.makeText(FirstActivity.this, "服务器开了点小差,请重试", Toast.LENGTH_SHORT).show();
265 | // 隐藏进度条
266 | wait_bar.setVisibility(View.GONE);
267 | }
268 | });
269 | }
270 | }
271 | }
272 | }).start();
273 | }
274 | });
275 | }
276 |
277 | @Override
278 | public boolean onCreateOptionsMenu(Menu menu){
279 | getMenuInflater().inflate(R.menu.main,menu);
280 | return true;
281 | }
282 |
283 | @Override
284 | public boolean onOptionsItemSelected(MenuItem item){
285 | if (item.getItemId() == R.id.add_item){
286 | Toast.makeText(this, "你按到添加按钮了", Toast.LENGTH_SHORT).show();
287 | } else if (item.getItemId() == R.id.remove_item) {
288 | Toast.makeText(this, "你按到删除按钮了", Toast.LENGTH_SHORT).show();
289 | }
290 | return true;
291 | }
292 |
293 | }
--------------------------------------------------------------------------------