├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── image.png
│ │ │ │ ├── logo.png
│ │ │ │ ├── convert.png
│ │ │ │ ├── bg_border.xml
│ │ │ │ ├── ic_delete_24.xml
│ │ │ │ ├── ic_header_save_24.xml
│ │ │ │ ├── ic_header_back_24.xml
│ │ │ │ ├── ic_add_circle_24.xml
│ │ │ │ ├── ic_menu_24.xml
│ │ │ │ ├── ic_note_24.xml
│ │ │ │ ├── ic_alarm_clock_24.xml
│ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── raw
│ │ │ │ └── call_of_slience.mp3
│ │ │ ├── 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
│ │ │ ├── menu
│ │ │ │ ├── memo_menu_delete.xml
│ │ │ │ ├── main_menu.xml
│ │ │ │ └── memo_menu_pick.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── layout
│ │ │ │ ├── alarm_activity.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── port_header.xml
│ │ │ │ ├── fragment_alarm_me.xml
│ │ │ │ ├── fragment_memo.xml
│ │ │ │ ├── item_memo.xml
│ │ │ │ ├── activity_alarm_me.xml
│ │ │ │ ├── item_alarm.xml
│ │ │ │ └── activity_info_memo.xml
│ │ │ ├── mipmap-anydpi-v33
│ │ │ │ └── ic_launcher.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── strings.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ └── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── zcyi
│ │ │ │ └── rorschach
│ │ │ │ ├── Util
│ │ │ │ ├── Constant.java
│ │ │ │ └── UtilMethod.java
│ │ │ │ ├── DataBase
│ │ │ │ ├── InstanceDatabase.java
│ │ │ │ └── BaseRoomDatabase.java
│ │ │ │ ├── Dao
│ │ │ │ ├── AlarmDao.java
│ │ │ │ └── MemoDao.java
│ │ │ │ ├── BroadcastRec
│ │ │ │ └── AlarmBroadcast.java
│ │ │ │ ├── Pager
│ │ │ │ ├── Activity
│ │ │ │ │ ├── MidActivity.java
│ │ │ │ │ ├── AlarmMeActivity.java
│ │ │ │ │ └── MemoInfoActivity.java
│ │ │ │ └── Fragment
│ │ │ │ │ ├── AlarmMePagerFragment.java
│ │ │ │ │ └── MemoPagerFragment.java
│ │ │ │ ├── Entity
│ │ │ │ ├── Alarm.java
│ │ │ │ └── Memo.java
│ │ │ │ ├── Adapter
│ │ │ │ ├── AlarmAdapter.java
│ │ │ │ └── MemoAdapter.java
│ │ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── zcyi
│ │ │ └── rorschach
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── zcyi
│ │ └── rorschach
│ │ └── ExampleInstrumentedTest.java
├── proguard-rules.pro
└── build.gradle
├── README.md
├── .idea
├── .gitignore
├── vcs.xml
├── compiler.xml
├── misc.xml
└── gradle.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── gradle.properties
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # ZcyiMemo
2 | 记事本,提醒
3 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/image.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/drawable/image.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/drawable/logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/convert.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/drawable/convert.png
--------------------------------------------------------------------------------
/app/src/main/res/raw/call_of_slience.mp3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/raw/call_of_slience.mp3
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Zaoyii/ZcyiMemo/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/Zaoyii/ZcyiMemo/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/Zaoyii/ZcyiMemo/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/Zaoyii/ZcyiMemo/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/Zaoyii/ZcyiMemo/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Util/Constant.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Util;
2 |
3 | public class Constant {
4 | public static final String TAG = "zcyi";
5 |
6 | }
7 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Jun 05 08:56:52 CST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
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 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/memo_menu_delete.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bg_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/alarm_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v33/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete_24.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_header_save_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/memo_menu_pick.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_header_back_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zcyi/rorschach/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach;
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/drawable/ic_add_circle_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | maven { url 'https://www.jitpack.io' }
7 | }
8 | }
9 | dependencyResolutionManagement {
10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11 | repositories {
12 | google()
13 | mavenCentral()
14 | maven { url 'https://www.jitpack.io' }
15 | }
16 | }
17 | rootProject.name = "ZcyiMemo"
18 | include ':app'
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_menu_24.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_note_24.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/DataBase/InstanceDatabase.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.DataBase;
2 |
3 |
4 | import android.content.Context;
5 |
6 | import androidx.room.Room;
7 |
8 | public class InstanceDatabase {
9 | public static BaseRoomDatabase baseRoomDatabase;
10 |
11 | public static BaseRoomDatabase getInstance(Context context) {
12 | if (baseRoomDatabase == null) {
13 | baseRoomDatabase = Room.databaseBuilder(context, BaseRoomDatabase.class, "zcyi_database.db").allowMainThreadQueries().build();
14 | }
15 | return baseRoomDatabase;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/DataBase/BaseRoomDatabase.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.DataBase;
2 |
3 |
4 | import androidx.room.Database;
5 | import androidx.room.RoomDatabase;
6 |
7 | import com.zcyi.rorschach.Dao.AlarmDao;
8 | import com.zcyi.rorschach.Dao.MemoDao;
9 | import com.zcyi.rorschach.Entity.Alarm;
10 | import com.zcyi.rorschach.Entity.Memo;
11 |
12 |
13 | @Database(entities = {Memo.class, Alarm.class}, version = 1, exportSchema = false)
14 | public abstract class BaseRoomDatabase extends RoomDatabase {
15 | public abstract MemoDao getMemoDao();
16 |
17 | public abstract AlarmDao getAlarmDao();
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_alarm_clock_24.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 | #00FFFFFF
11 | #845EC2
12 | #008F7A
13 | #FFC1B3
14 | #FFBB89
15 | #79959595
16 | #B1B1B1
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Dao/AlarmDao.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Dao;
2 |
3 | import androidx.room.Dao;
4 | import androidx.room.Delete;
5 | import androidx.room.Insert;
6 | import androidx.room.OnConflictStrategy;
7 | import androidx.room.Query;
8 | import androidx.room.Update;
9 |
10 | import com.zcyi.rorschach.Entity.Alarm;
11 |
12 | import java.util.List;
13 |
14 |
15 | @Dao
16 | public interface AlarmDao {
17 | @Query("select * from t_alarm")
18 | List selectAll();
19 |
20 | @Insert(onConflict = OnConflictStrategy.REPLACE)
21 | Long[] addAlarm(Alarm... alarms);
22 |
23 | @Update
24 | int updateAlarm(Alarm memo);
25 |
26 | @Delete
27 | int DeleteAlarm(Alarm memo);
28 |
29 | @Query("Delete from t_alarm")
30 | int DeleteAllAlarm();
31 | }
32 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/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-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/zcyi/rorschach/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach;
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.zcyi.rorschach", appContext.getPackageName());
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Dao/MemoDao.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Dao;
2 |
3 | import androidx.room.Dao;
4 | import androidx.room.Delete;
5 | import androidx.room.Insert;
6 | import androidx.room.OnConflictStrategy;
7 | import androidx.room.Query;
8 | import androidx.room.Update;
9 |
10 | import com.zcyi.rorschach.Entity.Memo;
11 |
12 | import java.util.List;
13 |
14 |
15 | @Dao
16 | public interface MemoDao {
17 | @Query("select * from t_memo")
18 | List selectAll();
19 |
20 | @Insert(onConflict = OnConflictStrategy.REPLACE)
21 | Long[] addMemo(Memo... memo);
22 |
23 | @Update
24 | int updateMemo(Memo memo);
25 |
26 | // @Query("UPDATE t_memo SET memoTitle= :title,memoContent= :content,memoSaveTime= :saveTime WHERE wordname = :wordname")
27 | // int updateMemoById(Memo memo);
28 |
29 |
30 | @Delete
31 | int DeleteMemo(Memo memo);
32 |
33 | @Query("Delete from t_memo")
34 | int DeleteAllMemo();
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/BroadcastRec/AlarmBroadcast.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.BroadcastRec;
2 |
3 | import static android.app.PendingIntent.FLAG_IMMUTABLE;
4 | import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
5 |
6 | import android.app.AlarmManager;
7 | import android.app.PendingIntent;
8 | import android.content.BroadcastReceiver;
9 | import android.content.Context;
10 | import android.content.Intent;
11 |
12 | import com.zcyi.rorschach.Pager.Activity.MidActivity;
13 |
14 | public class AlarmBroadcast extends BroadcastReceiver {
15 |
16 | @Override
17 | public void onReceive(Context context, Intent intent) {
18 |
19 | System.out.println("闹钟执行了");
20 | AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
21 | // 取消闹钟
22 | am.cancel(PendingIntent.getBroadcast(context, getResultCode(), new Intent(context, AlarmBroadcast.class), FLAG_IMMUTABLE));
23 |
24 | Intent i = new Intent(context, MidActivity.class); // 要启动的类
25 | i.addFlags(FLAG_ACTIVITY_NEW_TASK);
26 | context.startActivity(i);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Pager/Activity/MidActivity.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Pager.Activity;
2 |
3 | import static android.content.Intent.FLAG_ACTIVITY_REORDER_TO_FRONT;
4 |
5 | import android.app.Activity;
6 | import android.content.Intent;
7 | import android.content.SharedPreferences;
8 | import android.os.Bundle;
9 |
10 | import androidx.annotation.Nullable;
11 |
12 | import com.zcyi.rorschach.MainActivity;
13 |
14 | public class MidActivity extends Activity {
15 | SharedPreferences sharedPreferences;
16 | SharedPreferences.Editor editor;
17 |
18 | @Override
19 | protected void onCreate(@Nullable Bundle savedInstanceState) {
20 | super.onCreate(savedInstanceState);
21 | sharedPreferences = getSharedPreferences("zcyi", MODE_PRIVATE);
22 | editor = sharedPreferences.edit();
23 | editor.putBoolean("RingRing", true);
24 | editor.apply();
25 | Intent intent = new Intent(this, MainActivity.class);
26 | intent.addFlags(FLAG_ACTIVITY_REORDER_TO_FRONT);
27 | intent.putExtra("alarmMe", 1); // 设置启动的模式
28 | startActivity(intent);
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 随便记记8
3 | 跳过
4 | 未添加任何提醒哦~
5 | 未添加任何备忘录哦~
6 | 备忘录
7 | 添加备忘录
8 | 输入备忘录~
9 | 编辑
10 | 提醒我
11 | 标题(最长20字符)
12 | 12:25
13 | 编辑中
14 | 创建时间:
15 | 上次保存:
16 | 2022.9.1
17 | 删除
18 | 时间:
19 | 输入提示信息
20 | 提示信息
21 | 选择时间
22 | 提交
23 | 未提醒
24 | 切换显示方式
25 | 相机
26 | 相册
27 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
28 |
29 |
--------------------------------------------------------------------------------
/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. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec: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/res/layout/port_header.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
17 |
18 |
26 |
27 |
34 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | namespace 'com.zcyi.rorschach'
7 | compileSdk 33
8 |
9 | defaultConfig {
10 | applicationId "com.zcyi.rorschach"
11 | minSdk 26
12 | targetSdk 33
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 'androidx.appcompat:appcompat:1.2.0'
34 | implementation 'com.google.android.material:material:1.3.0'
35 | implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
36 | testImplementation 'junit:junit:4.13.2'
37 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
39 |
40 | //room
41 | implementation "androidx.room:room-runtime:2.4.3"
42 | annotationProcessor "androidx.room:room-compiler:2.4.3"
43 |
44 | //https://github.com/gzu-liyujiang/AndroidPicker 选择器
45 | implementation 'com.github.gzu-liyujiang.AndroidPicker:WheelPicker:4.1.11'
46 | implementation 'com.github.gzu-liyujiang.AndroidPicker:ImagePicker:4.1.11'
47 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_alarm_me.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
16 |
17 |
24 |
25 |
30 |
31 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
20 |
23 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
36 |
37 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Entity/Alarm.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Entity;
2 |
3 | import androidx.room.ColumnInfo;
4 | import androidx.room.Entity;
5 | import androidx.room.PrimaryKey;
6 |
7 | @Entity(tableName = "t_alarm")
8 | public class Alarm {
9 |
10 | @PrimaryKey(autoGenerate = true)
11 | @ColumnInfo(name = "alarm_id")
12 | Integer alarmId;
13 | @ColumnInfo(name = "alarm_time")
14 | String alarmTime;
15 | @ColumnInfo(name = "alarm_time_millis")
16 | Long alarmTimeMillis;
17 | @ColumnInfo(name = "alarm_content")
18 | String alarmContent;
19 | @ColumnInfo(name = "state")
20 | Integer state;
21 |
22 | public Alarm(String alarmTime, Long alarmTimeMillis, String alarmContent, Integer state) {
23 | this.alarmTime = alarmTime;
24 | this.alarmTimeMillis = alarmTimeMillis;
25 | this.alarmContent = alarmContent;
26 | this.state = state;
27 | }
28 |
29 | @Override
30 | public String toString() {
31 | return "Alarm{" +
32 | "alarmId=" + alarmId +
33 | ", alarmTime='" + alarmTime + '\'' +
34 | ", alarmTimeMillis=" + alarmTimeMillis +
35 | ", alarmContent='" + alarmContent + '\'' +
36 | ", state=" + state +
37 | '}';
38 | }
39 |
40 | public Integer getAlarmId() {
41 | return alarmId;
42 | }
43 |
44 | public void setAlarmId(Integer alarmId) {
45 | this.alarmId = alarmId;
46 | }
47 |
48 | public String getAlarmTime() {
49 | return alarmTime;
50 | }
51 |
52 | public void setAlarmTime(String alarmTime) {
53 | this.alarmTime = alarmTime;
54 | }
55 |
56 | public Long getAlarmTimeMillis() {
57 | return alarmTimeMillis;
58 | }
59 |
60 | public void setAlarmTimeMillis(Long alarmTimeMillis) {
61 | this.alarmTimeMillis = alarmTimeMillis;
62 | }
63 |
64 | public String getAlarmContent() {
65 | return alarmContent;
66 | }
67 |
68 | public void setAlarmContent(String alarmContent) {
69 | this.alarmContent = alarmContent;
70 | }
71 |
72 | public Integer getState() {
73 | return state;
74 | }
75 |
76 | public void setState(Integer state) {
77 | this.state = state;
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Entity/Memo.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Entity;
2 |
3 |
4 | import androidx.room.ColumnInfo;
5 | import androidx.room.Entity;
6 | import androidx.room.PrimaryKey;
7 |
8 | import java.io.Serializable;
9 |
10 | @Entity(tableName = "t_memo")
11 | public class Memo implements Serializable {
12 | @PrimaryKey(autoGenerate = true)
13 | @ColumnInfo(name = "memo_id")
14 | Integer memoId;
15 | @ColumnInfo(name = "memo_title")
16 | String title;
17 | @ColumnInfo(name = "memo_content")
18 | String content;
19 | @ColumnInfo(name = "memo_image")
20 | String image;
21 | @ColumnInfo(name = "memo_createTime")
22 | String createTime;
23 | @ColumnInfo(name = "memo_save_time")
24 | String saveTime;
25 |
26 | public Memo(String title, String content, String image, String createTime, String saveTime) {
27 | this.title = title;
28 | this.content = content;
29 | this.image = image;
30 | this.createTime = createTime;
31 | this.saveTime = saveTime;
32 | }
33 |
34 | public String getImage() {
35 | return image;
36 | }
37 |
38 | public void setImage(String image) {
39 | this.image = image;
40 | }
41 |
42 | public Integer getMemoId() {
43 | return memoId;
44 | }
45 |
46 | public void setMemoId(Integer memoId) {
47 | this.memoId = memoId;
48 | }
49 |
50 | public String getTitle() {
51 | return title;
52 | }
53 |
54 | public void setTitle(String title) {
55 | this.title = title;
56 | }
57 |
58 | public String getContent() {
59 | return content;
60 | }
61 |
62 | public void setContent(String content) {
63 | this.content = content;
64 | }
65 |
66 | public String getCreateTime() {
67 | return createTime;
68 | }
69 |
70 | public void setCreateTime(String createTime) {
71 | this.createTime = createTime;
72 | }
73 |
74 | public String getSaveTime() {
75 | return saveTime;
76 | }
77 |
78 | public void setSaveTime(String saveTime) {
79 | this.saveTime = saveTime;
80 | }
81 |
82 | @Override
83 | public String toString() {
84 | return "Memo{" +
85 | "memoId=" + memoId +
86 | ", title='" + title + '\'' +
87 | ", content='" + content + '\'' +
88 | ", image='" + image + '\'' +
89 | ", createTime='" + createTime + '\'' +
90 | ", saveTime='" + saveTime + '\'' +
91 | '}';
92 | }
93 | }
94 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_memo.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
21 |
22 |
29 |
30 |
34 |
35 |
40 |
41 |
45 |
46 |
51 |
52 |
53 |
54 |
55 |
60 |
61 |
67 |
68 |
69 |
70 |
71 |
80 |
--------------------------------------------------------------------------------
/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/item_memo.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
22 |
23 |
28 |
29 |
38 |
39 |
43 |
44 |
50 |
51 |
52 |
60 |
61 |
66 |
67 |
75 |
76 |
77 |
78 |
79 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Pager/Fragment/AlarmMePagerFragment.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Pager.Fragment;
2 |
3 |
4 | import android.app.Notification;
5 | import android.app.NotificationManager;
6 | import android.content.Intent;
7 | import android.os.Bundle;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.TextView;
12 |
13 | import androidx.annotation.NonNull;
14 | import androidx.annotation.Nullable;
15 | import androidx.fragment.app.Fragment;
16 | import androidx.recyclerview.widget.LinearLayoutManager;
17 | import androidx.recyclerview.widget.RecyclerView;
18 |
19 | import com.zcyi.rorschach.Adapter.AlarmAdapter;
20 | import com.zcyi.rorschach.Dao.AlarmDao;
21 | import com.zcyi.rorschach.DataBase.BaseRoomDatabase;
22 | import com.zcyi.rorschach.DataBase.InstanceDatabase;
23 | import com.zcyi.rorschach.Entity.Alarm;
24 | import com.zcyi.rorschach.Pager.Activity.AlarmMeActivity;
25 | import com.zcyi.rorschach.R;
26 |
27 | import java.util.ArrayList;
28 | import java.util.List;
29 |
30 |
31 | public class AlarmMePagerFragment extends Fragment {
32 | //主视图
33 | View v;
34 |
35 | NotificationManager manager;
36 | Notification notification;
37 | TextView isnull;
38 |
39 |
40 | RecyclerView alarm_recycler;
41 | AlarmAdapter alarmAdapter;
42 |
43 | //数据库操作
44 | BaseRoomDatabase baseRoomDatabase;
45 | AlarmDao alarmDao;
46 |
47 | @Nullable
48 | @Override
49 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
50 | v = inflater.inflate(R.layout.fragment_alarm_me, container, false);
51 | init(v);
52 | return v;
53 | }
54 |
55 | public void init(View v) {
56 | v.findViewById(R.id.clock_add).setOnClickListener(view -> {
57 | Intent intent = new Intent(getContext(), AlarmMeActivity.class);
58 | intent.putExtra("title", "添加提醒");
59 | startActivity(intent);
60 | });
61 | isnull = v.findViewById(R.id.Null);
62 | alarm_recycler = v.findViewById(R.id.alarm_List_recycler);
63 | baseRoomDatabase = InstanceDatabase.getInstance(getContext());
64 | alarmDao = baseRoomDatabase.getAlarmDao();
65 | getAlarmList();
66 | }
67 |
68 | private void getAlarmList() {
69 | List alarms = alarmDao.selectAll();
70 | if (alarms.size() > 0) {
71 | alarmAdapter = new AlarmAdapter(getContext(), (ArrayList) alarms, alarmDao, () -> {
72 | isnull.setVisibility(View.VISIBLE);
73 | alarm_recycler.setVisibility(View.GONE);
74 | });
75 | LinearLayoutManager alarmManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
76 | alarm_recycler.setAdapter(alarmAdapter);
77 | alarm_recycler.setLayoutManager(alarmManager);
78 | //隐藏无备忘录提示
79 | isnull.setVisibility(View.GONE);
80 | alarm_recycler.setVisibility(View.VISIBLE);
81 | } else {
82 | //显示无备忘录提示,隐藏list
83 | isnull.setVisibility(View.VISIBLE);
84 | alarm_recycler.setVisibility(View.GONE);
85 | }
86 | alarms.size();
87 | }
88 |
89 |
90 | @Override
91 | public void onResume() {
92 | super.onResume();
93 | getAlarmList();
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_alarm_me.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
13 |
14 |
23 |
24 |
29 |
30 |
38 |
39 |
46 |
47 |
48 |
49 |
58 |
59 |
66 |
67 |
72 |
73 |
85 |
86 |
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Util/UtilMethod.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Util;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.net.Uri;
7 | import android.view.View;
8 | import android.widget.Toast;
9 |
10 | import java.io.BufferedInputStream;
11 | import java.io.BufferedOutputStream;
12 | import java.io.File;
13 | import java.io.IOException;
14 | import java.io.InputStream;
15 | import java.io.OutputStream;
16 | import java.nio.file.Files;
17 | import java.nio.file.Paths;
18 | import java.text.ParseException;
19 | import java.text.SimpleDateFormat;
20 | import java.util.Date;
21 |
22 | public class UtilMethod {
23 | //设置状态栏字体颜色
24 | public static void changeStatusBarFrontColor(boolean isBlack, Activity activity) {
25 |
26 | if (isBlack) {
27 | //设置状态栏黑色字体
28 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
29 | } else {
30 | //恢复状态栏白色字体
31 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
32 | }
33 |
34 | }
35 |
36 | public static long dateToStamp(String time) throws ParseException {
37 | @SuppressLint("SimpleDateFormat") SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
38 | Date date = simpleDateFormat.parse(time);
39 | assert date != null;
40 | return date.getTime();
41 | }
42 |
43 |
44 | public static String getPath(Context context, Uri srcUri) {
45 | String path = context.getCacheDir() + "/" + System.currentTimeMillis() + ".png";//获取本地目录
46 | try {
47 | InputStream inputStream = context.getContentResolver().openInputStream(srcUri);//context的方法获取URI文件输入流
48 | if (inputStream == null) return "null";
49 | OutputStream outputStream = Files.newOutputStream(Paths.get(path));
50 | copyStream(inputStream, outputStream);//调用下面的方法存储
51 | inputStream.close();
52 | outputStream.close();
53 | return path;//成功返回路径
54 | } catch (Exception e) {
55 | e.printStackTrace();
56 | return "null";//失败返回路径null
57 | }
58 | }
59 |
60 | private static void copyStream(InputStream input, OutputStream output) {//文件存储
61 | final int BUFFER_SIZE = 1024 * 2;
62 | byte[] buffer = new byte[BUFFER_SIZE];
63 | BufferedInputStream in = new BufferedInputStream(input, BUFFER_SIZE);
64 | BufferedOutputStream out = new BufferedOutputStream(output, BUFFER_SIZE);
65 | int n;
66 | try {
67 | while ((n = in.read(buffer, 0, BUFFER_SIZE)) != -1) {
68 | out.write(buffer, 0, n);
69 | }
70 | out.flush();
71 | out.close();
72 | in.close();
73 | } catch (IOException e) {
74 | e.printStackTrace();
75 | }
76 | }
77 |
78 | public static void ShowToast(Context context, String info) {
79 | Toast.makeText(context, info, Toast.LENGTH_SHORT).show();
80 | }
81 |
82 | public static void DeleteFile(String FileName) {
83 | File file = new File(FileName);
84 | if (!file.exists()) { // 要删除的文件不存在
85 | System.out.println("文件" + FileName + "不存在,删除失败!");
86 |
87 | } else { // 要删除的文件存在
88 | if (file.isFile()) { // 如果目标文件是文件,判断是文件
89 | System.out.println(file.delete() + "!!!");//删除文件
90 | }
91 | }
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_alarm.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
24 |
25 |
30 |
31 |
35 |
36 |
42 |
43 |
44 |
45 |
52 |
53 |
59 |
60 |
64 |
65 |
69 |
70 |
75 |
76 |
77 |
78 |
88 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Adapter/AlarmAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Adapter;
2 |
3 |
4 | import static android.app.PendingIntent.FLAG_IMMUTABLE;
5 |
6 | import android.app.AlarmManager;
7 | import android.app.AlertDialog;
8 | import android.app.PendingIntent;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.view.Gravity;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.widget.ImageView;
15 | import android.widget.LinearLayout;
16 | import android.widget.PopupMenu;
17 | import android.widget.TextView;
18 |
19 | import androidx.annotation.NonNull;
20 | import androidx.recyclerview.widget.RecyclerView;
21 |
22 | import com.zcyi.rorschach.BroadcastRec.AlarmBroadcast;
23 | import com.zcyi.rorschach.Dao.AlarmDao;
24 | import com.zcyi.rorschach.Entity.Alarm;
25 | import com.zcyi.rorschach.R;
26 |
27 | import java.util.ArrayList;
28 |
29 | public class AlarmAdapter extends RecyclerView.Adapter {
30 |
31 | ArrayList list;
32 | Context context;
33 | AlarmDao AlarmDao;
34 |
35 | AlertDialog.Builder Delete;
36 | AlarmManager am;
37 | NullListener nullListener;
38 | int deleteId;
39 |
40 | public AlarmAdapter(Context context, ArrayList list, AlarmDao AlarmDao, NullListener nullListener) {
41 | this.list = list;
42 | this.context = context;
43 | this.AlarmDao = AlarmDao;
44 | this.nullListener = nullListener;
45 | am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
46 |
47 | }
48 |
49 | public ArrayList getList() {
50 | return list;
51 | }
52 |
53 | @NonNull
54 | @Override
55 | public Alarm_ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
56 | View view = View.inflate(context, R.layout.item_alarm, null);
57 | return new Alarm_ViewHolder(view);
58 | }
59 |
60 | @Override
61 | public void onBindViewHolder(@NonNull Alarm_ViewHolder holder, int position) {
62 | holder.Alarm_Content.setText(list.get(position).getAlarmContent());
63 | holder.Alarm_State.setText(list.get(position).getState() == 1 ? "未提醒" : "已提醒");
64 | holder.Alarm_Time.setText(list.get(position).getAlarmTime());
65 | holder.Alarm_menu.setOnClickListener(v -> {
66 | deleteId = holder.getAdapterPosition();
67 | showMenu(holder.Alarm_menu);
68 | });
69 | }
70 |
71 | private void showMenu(View v) {
72 | if (Delete == null) {
73 | Delete = new AlertDialog.Builder(v.getContext());
74 | Delete.setTitle("确定要删除吗?")
75 | .setPositiveButton("确定", (dialog, which) -> {
76 | deleteCurrent();
77 | })
78 | .setNegativeButton("取消", (dialog, which) -> {
79 | dialog.cancel();
80 | });
81 | }
82 | PopupMenu popupMenu = new PopupMenu(context, v);
83 | popupMenu.setGravity(Gravity.START);
84 | popupMenu.getMenuInflater().inflate(R.menu.memo_menu_delete, popupMenu.getMenu());
85 | popupMenu.setOnMenuItemClickListener(menuItem -> {
86 | if (menuItem.getItemId() == R.id.memo_delete) {
87 | Delete.show();
88 | }
89 | return false;
90 | });
91 | popupMenu.show();
92 | }
93 |
94 | public void deleteCurrent() {
95 | am.cancel(PendingIntent.getBroadcast(context, (int) (list.get(deleteId).getAlarmTimeMillis() / 1000 / 60), new Intent(context, AlarmBroadcast.class), FLAG_IMMUTABLE));
96 | AlarmDao.DeleteAlarm(list.get(deleteId));
97 | list.remove(deleteId);
98 | notifyItemRemoved(deleteId);
99 | if (getList().size() == 0) {
100 | nullListener.setNull();
101 | }
102 | }
103 |
104 | @Override
105 | public int getItemCount() {
106 | return list.size();
107 | }
108 |
109 | public static class Alarm_ViewHolder extends RecyclerView.ViewHolder {
110 | LinearLayout Alarm_lin;
111 | TextView Alarm_Content;
112 | TextView Alarm_Time;
113 | TextView Alarm_State;
114 | ImageView Alarm_menu;
115 |
116 | public Alarm_ViewHolder(@NonNull View itemView) {
117 | super(itemView);
118 | Alarm_lin = itemView.findViewById(R.id.item_alarm_lin);
119 | Alarm_Content = itemView.findViewById(R.id.alarm_content);
120 | Alarm_Time = itemView.findViewById(R.id.alarm_time);
121 | Alarm_State = itemView.findViewById(R.id.alarm_state);
122 | Alarm_menu = itemView.findViewById(R.id.alarm_menu);
123 | }
124 | }
125 |
126 | public interface NullListener {
127 | void setNull();
128 | }
129 | }
130 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_info_memo.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
9 |
10 |
17 |
18 |
22 |
23 |
27 |
28 |
33 |
34 |
35 |
39 |
40 |
44 |
45 |
50 |
51 |
57 |
58 |
59 |
60 |
61 |
62 |
66 |
67 |
81 |
82 |
88 |
89 |
90 |
94 |
95 |
99 |
100 |
110 |
111 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
131 |
132 |
136 |
137 |
141 |
142 |
147 |
148 |
152 |
153 |
154 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Adapter/MemoAdapter.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Adapter;
2 |
3 |
4 | import android.app.AlertDialog;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.net.Uri;
8 | import android.view.Gravity;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.LinearLayout;
13 | import android.widget.PopupMenu;
14 | import android.widget.TextView;
15 |
16 | import androidx.annotation.NonNull;
17 | import androidx.recyclerview.widget.RecyclerView;
18 |
19 | import com.zcyi.rorschach.Dao.MemoDao;
20 | import com.zcyi.rorschach.Entity.Memo;
21 | import com.zcyi.rorschach.Pager.Activity.MemoInfoActivity;
22 | import com.zcyi.rorschach.R;
23 | import com.zcyi.rorschach.Util.UtilMethod;
24 |
25 | import java.util.ArrayList;
26 |
27 | public class MemoAdapter extends RecyclerView.Adapter {
28 |
29 | ArrayList list;
30 | Context context;
31 | MemoDao memoDao;
32 | int deleteId;
33 | AlertDialog.Builder Delete;
34 | AlarmAdapter.NullListener nullListener;
35 | int setImagePosition;
36 |
37 | public MemoAdapter(ArrayList list, MemoDao memoDao, AlarmAdapter.NullListener nullListener) {
38 | this.list = list;
39 | this.memoDao = memoDao;
40 | this.nullListener = nullListener;
41 | }
42 |
43 | public ArrayList getList() {
44 | return list;
45 | }
46 |
47 | public void setSetImagePosition(int setImagePosition) {
48 | this.setImagePosition = setImagePosition;
49 | }
50 |
51 | @NonNull
52 | @Override
53 | public Memo_ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
54 | View view = View.inflate(parent.getContext(), R.layout.item_memo, null);
55 | context = parent.getContext();
56 | return new Memo_ViewHolder(view);
57 | }
58 |
59 | @Override
60 | public void onBindViewHolder(@NonNull Memo_ViewHolder holder, int position) {
61 |
62 | holder.memo_Title.setText(list.get(position).getTitle());
63 | holder.memo_Content.setText(list.get(position).getContent());
64 | holder.memo_saveTime.setText(list.get(position).getSaveTime());
65 | if (setImagePosition == 1) {
66 | if (list.get(position).getImage() != null) {
67 | holder.insert_image_item.setVisibility(View.VISIBLE);
68 | holder.insert_image_item.setImageURI(Uri.parse("file://" + list.get(position).getImage()));
69 | } else {
70 | holder.insert_image_item.setVisibility(View.GONE);
71 | }
72 | } else {
73 | holder.insert_image_item.setVisibility(View.GONE);
74 | }
75 |
76 | holder.memo_lin.setOnClickListener(v -> {
77 | if (list.size() != position) {
78 | Intent intent = new Intent(context, MemoInfoActivity.class);
79 | intent.putExtra("memo", list.get(position));
80 | intent.putExtra("isSaved", true);
81 | context.startActivity(intent);
82 | } else {
83 | notifyItemChanged(position);
84 | }
85 | });
86 | holder.memo_menu.setOnClickListener(v -> {
87 | deleteId = holder.getAdapterPosition();
88 | showMenu(holder.memo_menu);
89 | });
90 | }
91 |
92 | private void showMenu(View v) {
93 | if (Delete == null) {
94 | Delete = new AlertDialog.Builder(v.getContext());
95 | Delete.setTitle("确定要删除吗?")
96 | .setPositiveButton("确定", (dialog, which) -> {
97 | deleteCurrent();
98 | })
99 | .setNegativeButton("取消", (dialog, which) -> {
100 | dialog.cancel();
101 | });
102 | }
103 |
104 | PopupMenu popupMenu = new PopupMenu(context, v);
105 | popupMenu.setGravity(Gravity.START);
106 | popupMenu.getMenuInflater().inflate(R.menu.memo_menu_delete, popupMenu.getMenu());
107 | popupMenu.setOnMenuItemClickListener(menuItem -> {
108 | if (menuItem.getItemId() == R.id.memo_delete) {
109 | Delete.show();
110 | }
111 | return false;
112 | });
113 | popupMenu.show();
114 | }
115 |
116 | public void deleteCurrent() {
117 | memoDao.DeleteMemo(list.get(deleteId));
118 | if (list.get(deleteId).getImage() != null) {
119 | UtilMethod.DeleteFile(list.get(deleteId).getImage());
120 | }
121 |
122 | list.remove(deleteId);
123 | notifyItemRemoved(deleteId);
124 | if (getList().size() == 0) {
125 | nullListener.setNull();
126 | }
127 | }
128 |
129 | @Override
130 | public int getItemCount() {
131 | return list.size();
132 | }
133 |
134 | public static class Memo_ViewHolder extends RecyclerView.ViewHolder {
135 | LinearLayout memo_lin;
136 | TextView memo_Title;
137 | TextView memo_Content;
138 | TextView memo_saveTime;
139 | ImageView memo_menu;
140 | ImageView insert_image_item;
141 |
142 | public Memo_ViewHolder(@NonNull View itemView) {
143 | super(itemView);
144 | memo_lin = itemView.findViewById(R.id.item_memo_lin);
145 | memo_Title = itemView.findViewById(R.id.memo_title);
146 | memo_Content = itemView.findViewById(R.id.memo_content);
147 | memo_saveTime = itemView.findViewById(R.id.memo_save_time);
148 | memo_menu = itemView.findViewById(R.id.memo_menu);
149 | insert_image_item = itemView.findViewById(R.id.insert_image_item);
150 | }
151 | }
152 |
153 | public interface LayoutListener {
154 | void whatLayout();
155 | }
156 | }
157 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Pager/Fragment/MemoPagerFragment.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Pager.Fragment;
2 |
3 |
4 | import android.annotation.SuppressLint;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.SharedPreferences;
8 | import android.os.Bundle;
9 | import android.util.Log;
10 | import android.view.LayoutInflater;
11 | import android.view.View;
12 | import android.view.ViewGroup;
13 | import android.widget.ImageView;
14 | import android.widget.LinearLayout;
15 | import android.widget.TextView;
16 |
17 | import androidx.annotation.NonNull;
18 | import androidx.annotation.Nullable;
19 | import androidx.fragment.app.Fragment;
20 | import androidx.recyclerview.widget.LinearLayoutManager;
21 | import androidx.recyclerview.widget.RecyclerView;
22 | import androidx.recyclerview.widget.StaggeredGridLayoutManager;
23 |
24 | import com.zcyi.rorschach.Adapter.MemoAdapter;
25 | import com.zcyi.rorschach.Dao.MemoDao;
26 | import com.zcyi.rorschach.DataBase.BaseRoomDatabase;
27 | import com.zcyi.rorschach.DataBase.InstanceDatabase;
28 | import com.zcyi.rorschach.Entity.Memo;
29 | import com.zcyi.rorschach.Pager.Activity.MemoInfoActivity;
30 | import com.zcyi.rorschach.R;
31 |
32 | import java.util.ArrayList;
33 | import java.util.List;
34 |
35 | public class MemoPagerFragment extends Fragment implements View.OnClickListener {
36 | public static String TAG = "rorschach";
37 | //主视图
38 | View v;
39 | //ui控件
40 | ImageView add_memo;
41 | LinearLayout convert;
42 | TextView isnull;
43 | RecyclerView memoRecycler;
44 | LinearLayout memoLin;
45 | //数据库操作
46 | BaseRoomDatabase baseRoomDatabase;
47 | MemoDao memoDao;
48 | //adapter
49 | MemoAdapter memoAdapter;
50 | boolean isEditing;
51 |
52 | SharedPreferences sharedPreferences;
53 | SharedPreferences.Editor editor;
54 | StaggeredGridLayoutManager staggeredManager;
55 | LinearLayoutManager linearManager;
56 |
57 | //0:瀑布流 1:线性列表
58 | int listStyle;
59 | List memos;
60 |
61 | @Nullable
62 | @Override
63 | public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
64 | v = inflater.inflate(R.layout.fragment_memo, container, false);
65 | init();
66 | return v;
67 | }
68 |
69 | @Override
70 | public void onResume() {
71 | super.onResume();
72 | getMemoList();
73 | }
74 |
75 | @Override
76 | public void onPause() {
77 | if (sharedPreferences.getInt("ListStyle", -1) != listStyle) {
78 | editor.putInt("ListStyle", listStyle);
79 | editor.apply();
80 | }
81 | Log.e(TAG, "onPause: editor.apply() " + listStyle);
82 | super.onPause();
83 | }
84 |
85 | private void init() {
86 | //get id
87 | add_memo = v.findViewById(R.id.memo_add);
88 | convert = v.findViewById(R.id.convert);
89 | add_memo.setOnClickListener(this);
90 | convert.setOnClickListener(this);
91 | memoRecycler = v.findViewById(R.id.memo_List_recycler);
92 | memoLin = v.findViewById(R.id.memo_list_lin);
93 | isnull = v.findViewById(R.id.Null);
94 | memos = new ArrayList<>();
95 | sharedPreferences = requireContext().getSharedPreferences("zcyi", Context.MODE_PRIVATE);
96 | editor = sharedPreferences.edit();
97 | //获取roomDataBase实例
98 | baseRoomDatabase = InstanceDatabase.getInstance(getContext());
99 | memoDao = baseRoomDatabase.getMemoDao();
100 | isEditing = false;
101 | staggeredManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
102 | linearManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
103 | //根据ListStyle改变list展示方式
104 | listStyle = sharedPreferences.getInt("ListStyle", -1);
105 | getMemoList();
106 | if (memos.size() > 0) {
107 | System.out.println("listStyle-----" + listStyle);
108 | changeListStyle();
109 | }
110 | }
111 |
112 | private void getMemoList() {
113 | int size = memos.size();
114 | memos = memoDao.selectAll();
115 | Log.e(TAG, "getMemoList: " + memos);
116 | if (size != memos.size()) {
117 | if (memos.size() > 0) {
118 | memoAdapter = new MemoAdapter((ArrayList) memos, memoDao, () -> {
119 | isnull.setVisibility(View.VISIBLE);
120 | memoLin.setVisibility(View.GONE);
121 | });
122 | memoRecycler.setAdapter(memoAdapter);
123 | //隐藏无备忘录提示
124 | isnull.setVisibility(View.GONE);
125 | memoLin.setVisibility(View.VISIBLE);
126 |
127 | } else {
128 | //显示无备忘录提示,隐藏list
129 | isnull.setVisibility(View.VISIBLE);
130 | memoLin.setVisibility(View.GONE);
131 | }
132 | }
133 | }
134 |
135 | @SuppressLint("NonConstantResourceId")
136 | @Override
137 | public void onClick(View view) {
138 | switch (view.getId()) {
139 | case R.id.memo_add:
140 | Intent intent = new Intent(getContext(), MemoInfoActivity.class);
141 | intent.putExtra("title", "添加备忘录");
142 | intent.putExtra("isSaved", false);
143 | startActivity(intent);
144 | break;
145 | case R.id.convert:
146 | listStyle= listStyle==1? 0:1;
147 | changeListStyle();
148 | break;
149 | }
150 | }
151 |
152 | public void changeListStyle() {
153 | if (memos.size() != 0) {
154 | Log.e(TAG, "changeListStyle: " + listStyle);
155 | if (listStyle == 1) {
156 | memoAdapter.setSetImagePosition(0);
157 | memoRecycler.setLayoutManager(staggeredManager);
158 | } else if (listStyle == 0) {
159 | memoAdapter.setSetImagePosition(1);
160 | memoRecycler.setLayoutManager(linearManager);
161 | }
162 | }
163 |
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/zcyi/rorschach/Pager/Activity/AlarmMeActivity.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Pager.Activity;
2 |
3 | import static android.app.PendingIntent.FLAG_IMMUTABLE;
4 | import static com.zcyi.rorschach.Util.UtilMethod.dateToStamp;
5 |
6 | import android.annotation.SuppressLint;
7 | import android.app.AlarmManager;
8 | import android.app.PendingIntent;
9 | import android.content.Context;
10 | import android.content.Intent;
11 | import android.net.Uri;
12 | import android.os.Bundle;
13 | import android.provider.Settings;
14 | import android.view.View;
15 | import android.widget.Button;
16 | import android.widget.EditText;
17 | import android.widget.ImageView;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import androidx.appcompat.app.AppCompatActivity;
22 | import androidx.core.app.NotificationManagerCompat;
23 | import androidx.core.content.ContextCompat;
24 |
25 | import com.github.gzuliyujiang.dialog.DialogConfig;
26 | import com.github.gzuliyujiang.dialog.DialogStyle;
27 | import com.github.gzuliyujiang.wheelpicker.DatimePicker;
28 | import com.github.gzuliyujiang.wheelpicker.annotation.DateMode;
29 | import com.github.gzuliyujiang.wheelpicker.annotation.TimeMode;
30 | import com.github.gzuliyujiang.wheelpicker.entity.DatimeEntity;
31 | import com.github.gzuliyujiang.wheelpicker.widget.DatimeWheelLayout;
32 | import com.zcyi.rorschach.BroadcastRec.AlarmBroadcast;
33 | import com.zcyi.rorschach.Dao.AlarmDao;
34 | import com.zcyi.rorschach.DataBase.BaseRoomDatabase;
35 | import com.zcyi.rorschach.DataBase.InstanceDatabase;
36 | import com.zcyi.rorschach.Entity.Alarm;
37 | import com.zcyi.rorschach.R;
38 | import com.zcyi.rorschach.Util.UtilMethod;
39 |
40 | import java.text.ParseException;
41 |
42 | public class AlarmMeActivity extends AppCompatActivity implements View.OnClickListener {
43 | Button timePicker;
44 | ImageView save;
45 | ImageView back;
46 | TextView alarmTime;
47 | EditText alarmContent;
48 | Long alarmTimeMillis;
49 | AlarmManager alarmManager;
50 | BaseRoomDatabase baseRoomDatabase;
51 | AlarmDao alarmDao;
52 |
53 | @Override
54 | protected void onCreate(Bundle savedInstanceState) {
55 | super.onCreate(savedInstanceState);
56 | setContentView(R.layout.activity_alarm_me);
57 | init();
58 | }
59 |
60 | private void init() {
61 | UtilMethod.changeStatusBarFrontColor(true, this);
62 | timePicker = findViewById(R.id.time_picker);
63 | alarmContent = findViewById(R.id.Alarm_content);
64 | save = findViewById(R.id.header_save);
65 | back = findViewById(R.id.header_back);
66 | alarmTime = findViewById(R.id.alarm_time);
67 | timePicker.setOnClickListener(this);
68 | back.setOnClickListener(this);
69 | save.setOnClickListener(this);
70 | TextView header_title = findViewById(R.id.header_title);
71 | DialogConfig.setDialogStyle(DialogStyle.Three);
72 | Intent intent = getIntent();
73 | if (intent != null) {
74 | header_title.setText(intent.getStringExtra("title"));
75 | }
76 | //获取RoomDatabase实例
77 | baseRoomDatabase = InstanceDatabase.getInstance(this);
78 | alarmDao = baseRoomDatabase.getAlarmDao();
79 | alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
80 | }
81 |
82 | public void testTimePicker() {
83 | DatimePicker picker = new DatimePicker(this);
84 | final DatimeWheelLayout wheelLayout = picker.getWheelLayout();
85 | picker.setOnDatimePickedListener((year, month, day, hour, minute, second) -> {
86 | String text = year + "-" + month + "-" + day + " " + hour + ":" + minute;
87 | alarmTime.setText(text);
88 | try {
89 | alarmTimeMillis = dateToStamp(text);
90 | } catch (ParseException e) {
91 | e.printStackTrace();
92 | }
93 | Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
94 |
95 | });
96 | wheelLayout.setDateMode(DateMode.YEAR_MONTH_DAY);
97 | wheelLayout.setTimeMode(TimeMode.HOUR_24_NO_SECOND);
98 | wheelLayout.setRange(DatimeEntity.now(), DatimeEntity.yearOnFuture(10));
99 | wheelLayout.setDateLabel("年", "月", "日");
100 | wheelLayout.setTimeLabel("时", "分", "秒");
101 | wheelLayout.setIndicatorEnabled(true);
102 | wheelLayout.setIndicatorColor(ContextCompat.getColor(this, R.color.mainColor));
103 | wheelLayout.setIndicatorSize(getResources().getDisplayMetrics().density * 2);
104 | wheelLayout.setTextColor(ContextCompat.getColor(this, R.color.mainColor));
105 | wheelLayout.setSelectedTextColor(ContextCompat.getColor(this, R.color.mainColor));
106 | wheelLayout.getYearLabelView().setTextColor(ContextCompat.getColor(this, R.color.mainColor));
107 | wheelLayout.getMonthLabelView().setTextColor(ContextCompat.getColor(this, R.color.mainColor));
108 | wheelLayout.getDayLabelView().setTextColor(ContextCompat.getColor(this, R.color.mainColor));
109 | wheelLayout.getHourLabelView().setTextColor(ContextCompat.getColor(this, R.color.mainColor));
110 | wheelLayout.getMinuteLabelView().setTextColor(ContextCompat.getColor(this, R.color.mainColor));
111 |
112 | picker.show();
113 | }
114 |
115 | @SuppressLint("NonConstantResourceId")
116 | @Override
117 | public void onClick(View v) {
118 | switch (v.getId()) {
119 | case R.id.time_picker:
120 | testTimePicker();
121 | break;
122 | case R.id.header_save:
123 | if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
124 | if (alarmTime.getText().toString().isEmpty()) {
125 | Toast.makeText(getApplicationContext(), "未选择时间!", Toast.LENGTH_SHORT).show();
126 | } else {
127 | if (alarmTimeMillis > System.currentTimeMillis()) {
128 | int result = (int) (alarmTimeMillis / 1000 / 60);
129 | alarmManager.setWindow(AlarmManager.RTC_WAKEUP, alarmTimeMillis,
130 | 100, // 时间误差范围 100毫秒
131 | PendingIntent.getBroadcast(getApplication(), result,
132 | new Intent(getApplication(), AlarmBroadcast.class), FLAG_IMMUTABLE));
133 | Toast.makeText(getApplicationContext(), "~~~~~~!", Toast.LENGTH_SHORT).show();
134 | alarmDao.addAlarm(new Alarm(alarmTime.getText().toString(), alarmTimeMillis, alarmContent.getText().toString(), 1));
135 | Toast.makeText(getApplicationContext(), "添加成功!", Toast.LENGTH_SHORT).show();
136 | finish();
137 |
138 | } else {
139 | Toast.makeText(getApplicationContext(), "时间选择有误!", Toast.LENGTH_SHORT).show();
140 | }
141 | }
142 | } else {
143 | Toast.makeText(this, "先把通知权限全部打开~", Toast.LENGTH_SHORT).show();
144 | Uri packageURI = Uri.parse("package:" + this.getPackageName());
145 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
146 | startActivity(intent);
147 | }
148 |
149 | break;
150 | case R.id.header_back:
151 | finish();
152 | break;
153 | }
154 | }
155 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/Pager/Activity/MemoInfoActivity.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach.Pager.Activity;
2 |
3 |
4 | import android.annotation.SuppressLint;
5 | import android.app.AlertDialog;
6 | import android.content.Intent;
7 | import android.icu.text.SimpleDateFormat;
8 | import android.net.Uri;
9 | import android.os.Bundle;
10 | import android.text.TextUtils;
11 | import android.util.Log;
12 | import android.view.Gravity;
13 | import android.view.KeyEvent;
14 | import android.view.View;
15 | import android.widget.EditText;
16 | import android.widget.ImageView;
17 | import android.widget.PopupMenu;
18 | import android.widget.TextView;
19 | import android.widget.Toast;
20 |
21 | import androidx.annotation.NonNull;
22 | import androidx.annotation.Nullable;
23 | import androidx.appcompat.app.AppCompatActivity;
24 |
25 | import com.github.gzuliyujiang.imagepicker.ActivityBuilder;
26 | import com.github.gzuliyujiang.imagepicker.CropImageView;
27 | import com.github.gzuliyujiang.imagepicker.ImagePicker;
28 | import com.github.gzuliyujiang.imagepicker.PickCallback;
29 | import com.zcyi.rorschach.Dao.MemoDao;
30 | import com.zcyi.rorschach.DataBase.BaseRoomDatabase;
31 | import com.zcyi.rorschach.DataBase.InstanceDatabase;
32 | import com.zcyi.rorschach.Entity.Memo;
33 | import com.zcyi.rorschach.R;
34 | import com.zcyi.rorschach.Util.Constant;
35 | import com.zcyi.rorschach.Util.UtilMethod;
36 |
37 | import java.util.Date;
38 |
39 | public class MemoInfoActivity extends AppCompatActivity implements View.OnClickListener {
40 |
41 | private EditText Memo_title;
42 | private EditText Memo_content;
43 | private ImageView imagePicker;
44 | private ImageView imageInsert;
45 |
46 |
47 | //数据库操作
48 | BaseRoomDatabase baseRoomDatabase;
49 | MemoDao memoDao;
50 | //时间
51 | String createTime;
52 | Memo memo;
53 | AlertDialog.Builder Exit;
54 |
55 | private String oldTitle;
56 | private String oldContent;
57 |
58 | String oldImagePath;
59 | @SuppressLint("SimpleDateFormat")
60 | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
61 | boolean isSaved = false;
62 |
63 | @Override
64 | protected void onCreate(@Nullable Bundle savedInstanceState) {
65 | super.onCreate(savedInstanceState);
66 | setContentView(R.layout.activity_info_memo);
67 | initView();
68 | }
69 |
70 | private void initView() {
71 | //基础UI控件
72 | UtilMethod.changeStatusBarFrontColor(true, this);
73 | ImageView header_back = findViewById(R.id.header_back);
74 | TextView header_title = findViewById(R.id.header_title);
75 | ImageView header_save = findViewById(R.id.header_save);
76 | TextView open_time = findViewById(R.id.open_time);
77 | Memo_title = findViewById(R.id.Memo_title);
78 | Memo_content = findViewById(R.id.Memo_content);
79 | TextView save_time = findViewById(R.id.save_time);
80 | imagePicker = findViewById(R.id.pick_image);
81 | imageInsert = findViewById(R.id.insert_image);
82 |
83 | //获取RoomDatabase实例
84 | baseRoomDatabase = InstanceDatabase.getInstance(this);
85 | memoDao = baseRoomDatabase.getMemoDao();
86 |
87 | //设置点击事件
88 | header_back.setOnClickListener(this);
89 | header_save.setOnClickListener(this);
90 | imagePicker.setOnClickListener(this);
91 | imageInsert.setOnClickListener(this);
92 | oldContent = "";
93 | oldTitle = "";
94 | //设置header标题
95 | Intent intent = getIntent();
96 | if (intent != null) {
97 | isSaved = intent.getBooleanExtra("isSaved", false);
98 | if (!isSaved) {
99 | String title = intent.getStringExtra("title");
100 | if (!title.isEmpty()) {
101 | header_title.setText(title);
102 | }
103 | //设置打开时间
104 | createTime = simpleDateFormat.format(new Date(System.currentTimeMillis()));
105 | open_time.setText(createTime);
106 | } else {
107 | header_title.setText("");
108 | memo = (Memo) intent.getSerializableExtra("memo");
109 | Memo_title.setText(memo.getTitle());
110 | Memo_content.setText(memo.getContent());
111 | open_time.setText(memo.getCreateTime());
112 | save_time.setText(memo.getSaveTime());
113 | oldTitle = memo.getTitle();
114 | oldContent = memo.getContent();
115 | oldImagePath = memo.getImage();
116 | imageInsert.setImageURI(Uri.parse("file://" + memo.getImage()));
117 |
118 | }
119 | }
120 |
121 | Exit = new AlertDialog.Builder(Memo_title.getContext());
122 | Exit.setTitle("确定要退出吗?").setMessage("退出默认不保存备忘录!")
123 | .setPositiveButton("确定", (dialog, which) -> {
124 | finish();
125 | })
126 | .setNegativeButton("取消", (dialog, which) -> {
127 | UtilMethod.ShowToast(getApplication(), "取消");
128 | dialog.cancel();
129 | });
130 | }
131 |
132 | @SuppressLint("NonConstantResourceId")
133 | @Override
134 | public void onClick(View view) {
135 | switch (view.getId()) {
136 | case R.id.header_back:
137 | listenBack();
138 | break;
139 | case R.id.header_save:
140 | if (submit()) {
141 | finish();
142 | }
143 | break;
144 | case R.id.pick_image:
145 | showPickMenu(imagePicker);
146 | break;
147 | }
148 | }
149 |
150 | //保存Memo
151 | private boolean submit() {
152 | // validate
153 | if (TextUtils.isEmpty(Memo_content.getText().toString().trim())) {
154 | Toast.makeText(this, "内容为空不能保存哦", Toast.LENGTH_SHORT).show();
155 | return false;
156 | } else if (TextUtils.isEmpty(Memo_title.getText().toString().trim())) {
157 | Toast.makeText(this, "标题为空不能保存哦", Toast.LENGTH_SHORT).show();
158 | return false;
159 | } else {
160 | saveMessage();
161 | return true;
162 | }
163 | }
164 |
165 | private void saveMessage() {
166 | Log.e(Constant.TAG, "saveMessage: " + isSaved);
167 | if (isSaved) {
168 | if (!(oldTitle.equals(Memo_title.getText().toString().trim()) && oldContent.equals(Memo_content.getText().toString().trim()) && oldImagePath.equals(memo.getImage()))) {
169 | memo.setTitle(Memo_title.getText().toString().trim());
170 | memo.setContent(Memo_content.getText().toString().trim());
171 | memo.setSaveTime(simpleDateFormat.format(new Date(System.currentTimeMillis())));
172 | memo.setImage(oldImagePath);
173 | memoDao.updateMemo(memo);
174 | } else {
175 | Log.e(Constant.TAG, "saveMessage:内容未发生改变,不调用update");
176 | }
177 | } else {
178 | String title = Memo_title.getText().toString().trim();
179 | String content = Memo_content.getText().toString().trim();
180 | memoDao.addMemo(new Memo(title, content, oldImagePath, createTime, simpleDateFormat.format(new Date(System.currentTimeMillis()))));
181 | Log.e(Constant.TAG, "saveMessage: 调用add");
182 | }
183 | }
184 |
185 | @Override
186 | public boolean onKeyDown(int keyCode, KeyEvent event) {
187 | if (keyCode == KeyEvent.KEYCODE_BACK) {
188 | listenBack();
189 | }
190 | return super.onKeyDown(keyCode, event);
191 | }
192 |
193 | public void listenBack() {
194 | if (!(oldTitle.equals(Memo_title.getText().toString().trim()) && oldContent.equals(Memo_content.getText().toString().trim()))) {
195 | Exit.show();
196 | } else {
197 | finish();
198 | }
199 | }
200 |
201 | @Override
202 | protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
203 | super.onActivityResult(requestCode, resultCode, data);
204 | ImagePicker.getInstance().onActivityResult(this, requestCode, resultCode, data);
205 | }
206 |
207 | @Override
208 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
209 | super.onRequestPermissionsResult(requestCode, permissions, grantResults);
210 | ImagePicker.getInstance().onRequestPermissionsResult(this, requestCode, permissions, grantResults);
211 | }
212 |
213 | @SuppressLint("NonConstantResourceId")
214 | private void showPickMenu(View v) {
215 | PopupMenu popupMenu = new PopupMenu(getApplication(), v);
216 | popupMenu.setGravity(Gravity.START);
217 | popupMenu.getMenuInflater().inflate(R.menu.memo_menu_pick, popupMenu.getMenu());
218 | popupMenu.setOnMenuItemClickListener(menuItem -> {
219 | switch (menuItem.getItemId()) {
220 | case R.id.memo_gallery:
221 | onGallery(v);
222 | break;
223 | case R.id.memo_camera:
224 | onCamera(v);
225 | break;
226 | }
227 | return false;
228 | });
229 | popupMenu.show();
230 | }
231 |
232 | public void onCamera(View view) {
233 | ImagePicker.getInstance().startCamera(this, true, new PickCallback() {
234 | @Override
235 | public void onPermissionDenied(String[] permissions, String message) {
236 | Toast.makeText(getApplication(), message, Toast.LENGTH_SHORT).show();
237 | }
238 |
239 | @Override
240 | public void cropConfig(ActivityBuilder builder) {
241 | builder.setMultiTouchEnabled(true).setGuidelines(CropImageView.Guidelines.ON_TOUCH);
242 | }
243 |
244 | @Override
245 | public void onCropImage(@Nullable Uri imageUri) {
246 | Toast.makeText(getApplication(), String.valueOf(imageUri), Toast.LENGTH_SHORT).show();
247 | }
248 | });
249 | }
250 |
251 | public void onGallery(View view) {
252 | ImagePicker.getInstance().startGallery(this, false, new PickCallback() {
253 | @Override
254 | public void onPermissionDenied(String[] permissions, String message) {
255 | Toast.makeText(getApplication(), message, Toast.LENGTH_SHORT).show();
256 | }
257 | @Override
258 | public void onPickImage(@Nullable Uri imageUri) {
259 | Toast.makeText(getApplication(), String.valueOf(imageUri), Toast.LENGTH_SHORT).show();
260 | imageInsert.setImageURI(imageUri);
261 | oldImagePath = UtilMethod.getPath(getApplication(), imageUri);
262 | }
263 | });
264 | }
265 | }
266 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zcyi/rorschach/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zcyi.rorschach;
2 |
3 | import static android.app.PendingIntent.FLAG_IMMUTABLE;
4 |
5 | import android.annotation.SuppressLint;
6 | import android.app.AlertDialog;
7 | import android.app.Notification;
8 | import android.app.NotificationChannel;
9 | import android.app.NotificationManager;
10 | import android.app.PendingIntent;
11 | import android.content.Context;
12 | import android.content.Intent;
13 | import android.content.SharedPreferences;
14 | import android.media.AudioAttributes;
15 | import android.media.MediaPlayer;
16 | import android.media.RingtoneManager;
17 | import android.net.Uri;
18 | import android.os.Bundle;
19 | import android.os.Handler;
20 | import android.os.PowerManager;
21 | import android.os.Vibrator;
22 | import android.provider.Settings;
23 | import android.view.KeyEvent;
24 | import android.view.MenuItem;
25 | import android.widget.Toast;
26 |
27 | import androidx.annotation.NonNull;
28 | import androidx.appcompat.app.AppCompatActivity;
29 | import androidx.core.app.NotificationCompat;
30 | import androidx.core.app.NotificationManagerCompat;
31 | import androidx.fragment.app.Fragment;
32 | import androidx.fragment.app.FragmentManager;
33 | import androidx.fragment.app.FragmentPagerAdapter;
34 | import androidx.viewpager.widget.ViewPager;
35 |
36 | import com.google.android.material.bottomnavigation.BottomNavigationView;
37 | import com.zcyi.rorschach.Dao.AlarmDao;
38 | import com.zcyi.rorschach.DataBase.BaseRoomDatabase;
39 | import com.zcyi.rorschach.DataBase.InstanceDatabase;
40 | import com.zcyi.rorschach.Entity.Alarm;
41 | import com.zcyi.rorschach.Pager.Fragment.AlarmMePagerFragment;
42 | import com.zcyi.rorschach.Pager.Fragment.MemoPagerFragment;
43 | import com.zcyi.rorschach.Util.UtilMethod;
44 |
45 | import java.util.ArrayList;
46 | import java.util.List;
47 |
48 | public class MainActivity extends AppCompatActivity implements BottomNavigationView.OnNavigationItemSelectedListener {
49 |
50 | private ViewPager viewPager;
51 | boolean isExit = false;
52 |
53 | Notification notification;
54 |
55 | private MediaPlayer mMediaPlayer;
56 | NotificationManager manager;
57 | private Vibrator vibrator;
58 |
59 | private PowerManager.WakeLock mWakelock;
60 | private String content;
61 | BaseRoomDatabase baseRoomDatabase;
62 | AlarmDao alarmDao;
63 |
64 | MemoPagerFragment memoPagerFragment;
65 | AlarmMePagerFragment alarmMePagerFragment;
66 | SharedPreferences sharedPreferences;
67 | SharedPreferences.Editor editor;
68 | Handler mHandler = new Handler(message -> {
69 | isExit = false;
70 | return false;
71 | });
72 |
73 | @Override
74 | protected void onCreate(Bundle savedInstanceState) {
75 | super.onCreate(savedInstanceState);
76 | setContentView(R.layout.activity_main);
77 | init();
78 |
79 | }
80 |
81 | private void init() {
82 | UtilMethod.changeStatusBarFrontColor(true, this);
83 | List list = new ArrayList<>();
84 | memoPagerFragment = new MemoPagerFragment();
85 | alarmMePagerFragment = new AlarmMePagerFragment();
86 |
87 | list.add(memoPagerFragment);
88 | list.add(alarmMePagerFragment);
89 | baseRoomDatabase = InstanceDatabase.getInstance(this);
90 | alarmDao = baseRoomDatabase.getAlarmDao();
91 |
92 | sharedPreferences = getSharedPreferences("zcyi", MODE_PRIVATE);
93 | editor = sharedPreferences.edit();
94 |
95 | manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
96 | NotificationChannel channel = new NotificationChannel("你猜猜你现在该干嘛?", "李在赣神魔", NotificationManager.IMPORTANCE_HIGH);
97 | channel.enableLights(true);
98 | channel.enableVibration(true);
99 |
100 | AudioAttributes audioAttributes = new AudioAttributes.Builder()
101 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
102 | .setUsage(AudioAttributes.USAGE_NOTIFICATION)
103 | .build();
104 | channel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), audioAttributes);
105 | manager.createNotificationChannel(channel);
106 |
107 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), FLAG_IMMUTABLE);
108 | notification = new NotificationCompat.Builder(this, "zyci")
109 | .setContentTitle("李在赣神魔")
110 | .setContentText("你猜猜你现在该干嘛?")
111 | .setSmallIcon(R.drawable.logo)
112 | .setContentIntent(pendingIntent)
113 | .setAutoCancel(true).build();
114 | sharedPreferences = getSharedPreferences("zcyi", MODE_PRIVATE);
115 | editor = sharedPreferences.edit();
116 | if (sharedPreferences.getInt("ListStyle", -1) == -1) {
117 | editor.putInt("ListStyle", 1);
118 | editor.apply();
119 | }
120 |
121 | BottomNavigationView navigationView = findViewById(R.id.MainBNV);
122 | viewPager = findViewById(R.id.MainPager);
123 | navigationView.setOnNavigationItemSelectedListener(this);
124 | navigationView.setSelectedItemId(R.id.memo);
125 | myViewpagerFragment fragment = new myViewpagerFragment(getSupportFragmentManager(), 0, list);
126 | viewPager.setAdapter(fragment);
127 | viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
128 | @Override
129 | public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
130 |
131 | }
132 |
133 | @SuppressLint("NonConstantResourceId")
134 | @Override
135 | public void onPageSelected(int position) {
136 | switch (position) {
137 | case 0:
138 | navigationView.setSelectedItemId(R.id.memo);
139 | break;
140 | case 1:
141 | navigationView.setSelectedItemId(R.id.alarmClock);
142 | break;
143 | }
144 | }
145 |
146 | @Override
147 | public void onPageScrollStateChanged(int state) {
148 |
149 | }
150 | });
151 | }
152 |
153 | @SuppressLint("NonConstantResourceId")
154 | @Override
155 | public boolean onNavigationItemSelected(@NonNull MenuItem item) {
156 |
157 | switch (item.getItemId()) {
158 | case R.id.memo:
159 | viewPager.setCurrentItem(0);
160 | return true;
161 | case R.id.alarmClock:
162 | viewPager.setCurrentItem(1);
163 | return true;
164 |
165 | }
166 | return true;
167 | }
168 |
169 | @Override
170 | public boolean onKeyDown(int keyCode, KeyEvent event) {
171 | if (keyCode == KeyEvent.KEYCODE_BACK) {
172 | exit();
173 | return false;
174 | }
175 | return super.onKeyDown(keyCode, event);
176 | }
177 |
178 | public void exit() {
179 | if (!isExit) {
180 | isExit = true;
181 | Toast.makeText(getApplicationContext(), "再按就退出了~~~", Toast.LENGTH_SHORT).show();
182 | mHandler.sendEmptyMessageDelayed(0, 2000);
183 | } else {
184 | finish();
185 | }
186 | }
187 |
188 | public void AlarmMe() {
189 | mMediaPlayer = MediaPlayer.create(this, R.raw.call_of_slience);
190 | mMediaPlayer.setLooping(true); // 设置是否对播放的音乐进行循环播放
191 | mMediaPlayer.start();
192 | baseRoomDatabase = InstanceDatabase.getInstance(this);
193 | alarmDao = baseRoomDatabase.getAlarmDao();
194 | List alarms = alarmDao.selectAll();
195 | for (Alarm a : alarms) {
196 | if (System.currentTimeMillis() - a.getAlarmTimeMillis() < 1000 * 60) {
197 | content = a.getAlarmContent();
198 | a.setState(2);
199 | alarmDao.updateAlarm(a);
200 | Notification();
201 | startVibrator();
202 | createDialog();
203 | }
204 | }
205 | }
206 |
207 | private void startVibrator() {
208 | // 想设置震动大小可以通过改变pattern来设定,如果开启时间太短,震动效果可能感觉不到
209 | vibrator = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE);
210 | long[] pattern = {500, 1000, 500, 1000}; // 停止 开启 停止 开启
211 | vibrator.vibrate(pattern, 0);
212 | }
213 |
214 | private void createDialog() {
215 | AlertDialog alertDialog = new AlertDialog.Builder(this)
216 | .setIcon(R.drawable.logo)
217 | .setTitle("闹钟")
218 | .setMessage(content)
219 | .setNegativeButton("关闭", (dialog, whichButton) -> {
220 | mMediaPlayer.stop();
221 | vibrator.cancel();
222 | }).create();
223 | alertDialog.setCanceledOnTouchOutside(false);
224 | alertDialog.show();
225 | }
226 |
227 | public void Notification() {
228 | if (NotificationManagerCompat.from(this).areNotificationsEnabled()) {
229 | manager.notify(1, notification);
230 | } else {
231 | Toast.makeText(this, "先把通知权限打开~", Toast.LENGTH_SHORT).show();
232 | Uri packageURI = Uri.parse("package:" + this.getPackageName());
233 | Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, packageURI);
234 | startActivity(intent);
235 | }
236 | }
237 |
238 | public static class myViewpagerFragment extends FragmentPagerAdapter {
239 | List list;
240 |
241 | public myViewpagerFragment(@NonNull FragmentManager fm, int behavior, List list) {
242 | super(fm, behavior);
243 | this.list = list;
244 | }
245 |
246 | @NonNull
247 | @Override
248 | public Fragment getItem(int position) {
249 | return list.get(position);
250 | }
251 |
252 | @Override
253 | public int getCount() {
254 | return list.size();
255 | }
256 | }
257 |
258 | @Override
259 | protected void onDestroy() {
260 |
261 | if (mMediaPlayer != null) {
262 | mMediaPlayer.stop();
263 | mMediaPlayer.release(); // 释放掉
264 | }
265 |
266 | super.onDestroy();
267 |
268 | }
269 |
270 | @Override
271 | protected void onResume() {
272 | if (sharedPreferences.getBoolean("RingRing", false)) {
273 | System.out.println("调用AlarmMe----------");
274 | AlarmMe();
275 | editor.putBoolean("RingRing", false);
276 | editor.apply();
277 | }
278 | // 唤醒屏幕
279 | acquireWakeLock();
280 | super.onResume();
281 |
282 | }
283 |
284 | private void acquireWakeLock() {
285 |
286 | if (mWakelock == null) {
287 | PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
288 | mWakelock = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP
289 | | PowerManager.SCREEN_DIM_WAKE_LOCK, this.getClass()
290 | .getCanonicalName());
291 | mWakelock.acquire();
292 | }
293 | }
294 |
295 | private void releaseWakeLock() {
296 | if (mWakelock != null && mWakelock.isHeld()) {
297 | mWakelock.release();
298 | mWakelock = null;
299 | }
300 | }
301 |
302 | @Override
303 | protected void onPause() {
304 | // 释放锁屏
305 | releaseWakeLock();
306 | super.onPause();
307 |
308 | }
309 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------