├── readme-res
├── icon.png
├── screenshot_1.png
├── screenshot_2.png
├── screenshot_3.png
├── screenshot_4.png
└── screenshot_5.png
├── app
├── release
│ ├── app-release.aab
│ ├── app-release.apk
│ └── output-metadata.json
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── colors.xml
│ │ │ ├── ic_launcher_background.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ ├── values-night
│ │ │ └── colors.xml
│ │ ├── drawable
│ │ │ ├── color_dot.xml
│ │ │ ├── list_item_bg.xml
│ │ │ ├── ic_delete.xml
│ │ │ ├── ic_edit.xml
│ │ │ ├── ic_note.xml
│ │ │ ├── ic_add.xml
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ └── ic_settings.xml
│ │ ├── mipmap-anydpi-v26
│ │ │ └── ic_launcher.xml
│ │ ├── values-de
│ │ │ └── strings.xml
│ │ ├── layout
│ │ │ ├── qs_detail_view.xml
│ │ │ ├── qs_detail_list_item.xml
│ │ │ └── activity_dialog.xml
│ │ ├── values-fr
│ │ │ └── strings.xml
│ │ └── menu
│ │ │ └── settings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── de
│ │ └── dlyt
│ │ └── yanndroid
│ │ └── notinotes
│ │ ├── ActionReceiver.kt
│ │ ├── QSTile.kt
│ │ ├── Notes.kt
│ │ ├── Notification.kt
│ │ └── DialogActivity.kt
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── settings.gradle
├── PRIVACY_POLICY.md
├── LICENSE
├── .github
└── workflows
│ └── release.yml
├── gradle.properties
├── README.md
├── gradlew.bat
└── gradlew
/readme-res/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/icon.png
--------------------------------------------------------------------------------
/app/release/app-release.aab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/app/release/app-release.aab
--------------------------------------------------------------------------------
/app/release/app-release.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/app/release/app-release.apk
--------------------------------------------------------------------------------
/readme-res/screenshot_1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/screenshot_1.png
--------------------------------------------------------------------------------
/readme-res/screenshot_2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/screenshot_2.png
--------------------------------------------------------------------------------
/readme-res/screenshot_3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/screenshot_3.png
--------------------------------------------------------------------------------
/readme-res/screenshot_4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/screenshot_4.png
--------------------------------------------------------------------------------
/readme-res/screenshot_5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/readme-res/screenshot_5.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Yanndroid/NotiNotes/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #000000
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #ffffff
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FF4B3C
4 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/color_dot.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-rc-2-bin.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | dependencyResolutionManagement {
2 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
3 | repositories {
4 | google()
5 | mavenCentral()
6 | jcenter() // Warning: this repository is going to shut down soon
7 | }
8 | }
9 | rootProject.name = "NotiNotes"
10 | include ':app'
11 |
--------------------------------------------------------------------------------
/PRIVACY_POLICY.md:
--------------------------------------------------------------------------------
1 | ## NotiNotes Privacy Policy
2 |
3 | NotiNotes is an open source android app developed by Yanndroid and under the MIT License. It's published on the Google Play Store and the source code is available on Github.
4 |
5 | This app does not collect any personal information and all the app data is stored locally on your device only.
6 |
7 | If you have any questions, please contact me at yanndroid.dev@gmail.com
--------------------------------------------------------------------------------
/app/release/output-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
3 | "artifactType": {
4 | "type": "APK",
5 | "kind": "Directory"
6 | },
7 | "applicationId": "de.dlyt.yanndroid.notinotes",
8 | "variantName": "release",
9 | "elements": [
10 | {
11 | "type": "SINGLE",
12 | "filters": [],
13 | "attributes": [],
14 | "versionCode": 14,
15 | "versionName": "1.7.3",
16 | "outputFile": "app-release.apk"
17 | }
18 | ],
19 | "elementType": "File"
20 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/list_item_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NotiNotes
3 | Edit
4 | Delete
5 | Title
6 | Note
7 | New Note
8 | Save
9 | Cancel
10 | Notes
11 | Hide on Lockscreen
12 | Lock in Notifications
13 | Note saved as copy
14 | Group
15 | Background tint
16 | Confirm delete
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Bearbeiten
3 | Löschen
4 | Titel
5 | Notiz
6 | Neue Notiz
7 | Speichern
8 | Abbrechen
9 | Notizen
10 | Auf dem Sperrbildschrim ausblenden
11 | In Benarichtigungen sperren
12 | Notiz als Kopie gespeichert
13 | Gruppieren
14 | Hintergrund färben
15 | Löschen bestätigen
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/qs_detail_view.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | NotiNotes
3 | Éditer
4 | Effacer
5 | Titre
6 | Note
7 | Nouvelle Note
8 | Sauvegarder
9 | Annuler
10 | Notes
11 | Masquer sur l\'écran de verrouillage
12 | Verrouiller dans les notifications
13 | Note enregistrée en tant que copie
14 | Grouper
15 | " Teinter le fond"
16 | Confirmer la suppression
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_delete.xml:
--------------------------------------------------------------------------------
1 |
6 |
14 |
15 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 | -keepattributes Signature
23 | -keep class com.google.gson.reflect.TypeToken { *; }
24 | -keep class * extends com.google.gson.reflect.TypeToken
25 | -keep class de.dlyt.yanndroid.notinotes.** {*;}
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 Yanndroid
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: New Release
2 | on:
3 | workflow_dispatch:
4 |
5 | jobs:
6 | release:
7 | runs-on: ubuntu-latest
8 | steps:
9 | - name: Checkout
10 | uses: actions/checkout@v2
11 | - name: Init values
12 | id: values
13 | run: |
14 | version=$(grep -Po -m 1 '(?<=versionName ).*' ./app/build.gradle | tr -d \")
15 | echo ::set-output name=name::NotiNotes v$version
16 | echo ::set-output name=tag::v$version
17 | echo ::set-output name=apk::NotiNotes_v$version
18 | - name: Create release
19 | id: create_release
20 | uses: actions/create-release@v1
21 | env:
22 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23 | with:
24 | release_name: ${{ steps.values.outputs.name }}
25 | tag_name: ${{ steps.values.outputs.tag }}
26 | body: No changelog
27 | - name: Add apk
28 | uses: actions/upload-release-asset@v1
29 | env:
30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31 | with:
32 | upload_url: ${{ steps.create_release.outputs.upload_url }}
33 | asset_path: ./app/release/app-release.apk
34 | asset_name: ${{ steps.values.outputs.apk }}.apk
35 | asset_content_type: application/vnd.android.package-archive
36 |
--------------------------------------------------------------------------------
/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 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 | android.defaults.buildfeatures.buildconfig=true
23 | android.nonTransitiveRClass=false
24 | android.nonFinalResIds=false
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | #
NotiNotes
2 |
3 |
4 |
5 |
6 | A simple notes app, which only lives in your QS and notification panel. Quickly add, view and edit your notes and show them as notifications. All you need to do is adding the tile in your Quick Settings panel and you're ready to note. You can also change the color of the note for better management and select if it should be hidden on the lockscreen for privacy.
7 |
8 |
9 |
10 |
11 | ### Additionally for Samsung devices:
12 | On Samsung devices this app also has a so called 'Detail View' which shows up when you click the text below the icon, like the wifi and bluetooth tile.
13 |
14 |
15 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'kotlin-android'
4 | }
5 |
6 | def locales = file('src/main/res').listFiles(new FilenameFilter() {
7 | @Override
8 | boolean accept(File dir, String name) {
9 | return name.matches('values-.*') && new File(dir, name).list().contains('strings.xml')
10 | }
11 | }).collect { it.name.substring(7) }
12 |
13 | print("Locales: " + locales.join(', '))
14 |
15 | android {
16 | compileSdk 34
17 |
18 | defaultConfig {
19 | applicationId "de.dlyt.yanndroid.notinotes"
20 | minSdk 26
21 | targetSdk 34
22 | versionCode 14
23 | versionName "1.7.3"
24 |
25 | resConfigs locales
26 | }
27 |
28 | buildTypes {
29 | release {
30 | minifyEnabled true
31 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
32 | }
33 | debug {
34 | minifyEnabled true
35 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
36 | }
37 | }
38 | compileOptions {
39 | sourceCompatibility JavaVersion.VERSION_1_8
40 | targetCompatibility JavaVersion.VERSION_1_8
41 | }
42 | kotlinOptions {
43 | jvmTarget = '1.8'
44 | }
45 | namespace 'de.dlyt.yanndroid.notinotes'
46 | }
47 |
48 | configurations.all {
49 | exclude group: 'androidx.core', module: 'core'
50 | }
51 |
52 | dependencies {
53 | implementation 'androidx.core:core-ktx:1.9.0'
54 | implementation 'io.github.oneuiproject.sesl:appcompat:1.4.0'
55 | implementation 'io.github.oneuiproject.sesl:picker-color:1.1.0'
56 | implementation 'com.google.code.gson:gson:2.10.1'
57 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_edit.xml:
--------------------------------------------------------------------------------
1 |
7 |
15 |
23 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_note.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
15 |
23 |
31 |
39 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_add.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/qs_detail_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
27 |
28 |
32 |
33 |
34 |
35 |
36 |
43 |
44 |
51 |
52 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
8 |
9 |
10 |
11 |
12 |
13 |
16 |
17 |
24 |
25 |
31 |
32 |
33 |
34 |
35 |
36 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/app/src/main/java/de/dlyt/yanndroid/notinotes/ActionReceiver.kt:
--------------------------------------------------------------------------------
1 | package de.dlyt.yanndroid.notinotes
2 |
3 | import android.app.PendingIntent
4 | import android.content.BroadcastReceiver
5 | import android.content.Context
6 | import android.content.Intent
7 |
8 | class ActionReceiver : BroadcastReceiver() {
9 |
10 | companion object {
11 | val ACTION_EDIT = "de.dlyt.yanndroid.notinotes.EDIT"
12 | val ACTION_DELETE = "de.dlyt.yanndroid.notinotes.DELETE"
13 | val ACTION_DISMISS = "de.dlyt.yanndroid.notinotes.DISMISS"
14 | val ACTION_SHOW = "de.dlyt.yanndroid.notinotes.SHOW"
15 | val EXTRA_NOTE = "intent_note"
16 |
17 | fun getPendingIntent(context: Context, note: Notes.Note, action: String): PendingIntent {
18 | val intent = Intent(context, ActionReceiver::class.java)
19 | intent.action = action
20 | intent.putExtra(EXTRA_NOTE, note)
21 | return PendingIntent.getBroadcast(
22 | context,
23 | note.id,
24 | intent,
25 | PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
26 | )
27 | }
28 | }
29 |
30 | override fun onReceive(context: Context, intent: Intent) {
31 | when (intent.action) {
32 | Intent.ACTION_BOOT_COMPLETED, Intent.ACTION_MY_PACKAGE_REPLACED -> {
33 | Notification.createNotificationChannel(context)
34 | Notification.showAll(context)
35 | }
36 |
37 | ACTION_DISMISS -> {
38 | val note = (intent.getSerializableExtra(EXTRA_NOTE) ?: return) as Notes.Note
39 | if (note.locked) { //A14 don't delete locked notes when dismissed
40 | Notification.show(context, note)
41 | } else {
42 | Notes.deleteNote(context, note)
43 | }
44 | }
45 |
46 | ACTION_DELETE -> {
47 | val note = (intent.getSerializableExtra(EXTRA_NOTE) ?: return) as Notes.Note
48 | Notes.deleteNote(context, note)
49 | //todo notify TileService Detail View
50 | }
51 |
52 | ACTION_EDIT, ACTION_SHOW -> {
53 | val note = (intent.getSerializableExtra(EXTRA_NOTE) ?: return) as Notes.Note
54 | val dialogIntent = Intent(context, DialogActivity::class.java)
55 | dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
56 | dialogIntent.action = intent.action
57 | dialogIntent.putExtra(EXTRA_NOTE, note)
58 | context.startActivity(dialogIntent)
59 | }
60 | }
61 | }
62 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
13 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/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/drawable/ic_settings.xml:
--------------------------------------------------------------------------------
1 |
6 |
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/java/de/dlyt/yanndroid/notinotes/QSTile.kt:
--------------------------------------------------------------------------------
1 | package de.dlyt.yanndroid.notinotes
2 |
3 | import android.app.PendingIntent
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.net.Uri
7 | import android.os.Build
8 | import android.service.quicksettings.TileService
9 | import android.widget.RemoteViews
10 |
11 | class QSTile : TileService() {
12 |
13 | private val context: Context = this
14 |
15 | override fun onCreate() {
16 | super.onCreate()
17 | Notification.createNotificationChannel(context)
18 | Notification.showAll(context)
19 | }
20 |
21 | override fun onStartListening() {
22 | super.onStartListening()
23 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
24 | qsTile.subtitle = Notes.getNotes(context).size.toString()
25 | qsTile.updateTile()
26 | }
27 | }
28 |
29 | override fun onClick() {
30 | super.onClick()
31 | val dialogIntent = Intent(context, DialogActivity::class.java)
32 | dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
33 | dialogIntent.action = ActionReceiver.ACTION_EDIT
34 | dialogIntent.putExtra(ActionReceiver.EXTRA_NOTE, Notes.defaultSettingNote(context))
35 |
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
37 | val pendingDialogIntent = PendingIntent.getActivity(
38 | context,
39 | 0,
40 | dialogIntent,
41 | PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
42 | )
43 | startActivityAndCollapse(pendingDialogIntent)
44 | } else {
45 | startActivityAndCollapse(dialogIntent)
46 | }
47 | }
48 |
49 | /** #### Detail view (samsung only) #### **/
50 |
51 | fun semGetSettingsIntent(): Intent =
52 | Intent(
53 | Intent.ACTION_VIEW,
54 | Uri.parse("https://github.com/Yanndroid/NotiNotes")
55 | ) //todo AboutActivity?
56 |
57 | fun semIsToggleButtonExists(): Boolean = false
58 | fun semGetDetailViewTitle(): CharSequence = this.getString(R.string.app_name)
59 | fun semGetDetailView(): RemoteViews {
60 | val remoteViews = RemoteViews(context.packageName, R.layout.qs_detail_view)
61 | val adapter = LinearLayoutAdapter(remoteViews, R.id.qs_detail_list)
62 |
63 | for (note in Notes.getNotes(context)) {
64 | val noteView = RemoteViews(context.packageName, R.layout.qs_detail_list_item)
65 | noteView.setTextViewText(R.id.qs_list_item_title, note.title)
66 | noteView.setTextColor(R.id.qs_list_item_title, note.color)
67 | noteView.setTextViewText(R.id.qs_list_item_content, note.content)
68 | noteView.setOnClickPendingIntent(
69 | R.id.qs_list_item_container,
70 | ActionReceiver.getPendingIntent(context, note, ActionReceiver.ACTION_SHOW)
71 | )
72 | noteView.setOnClickPendingIntent(
73 | R.id.qs_list_item_edit,
74 | ActionReceiver.getPendingIntent(context, note, ActionReceiver.ACTION_EDIT)
75 | )
76 | noteView.setOnClickPendingIntent(
77 | R.id.qs_list_item_delete,
78 | ActionReceiver.getPendingIntent(context, note, ActionReceiver.ACTION_DELETE)
79 | )
80 | adapter.addView(noteView)
81 | }
82 |
83 | remoteViews.setOnClickPendingIntent(
84 | R.id.qs_detail_add,
85 | ActionReceiver.getPendingIntent(
86 | context,
87 | Notes.defaultSettingNote(context),
88 | ActionReceiver.ACTION_EDIT
89 | )
90 | )
91 | return remoteViews
92 | }
93 |
94 | private class LinearLayoutAdapter(root: RemoteViews, LLId: Int) {
95 | val root = root
96 | val LLId = LLId
97 | val views: ArrayList = ArrayList()
98 |
99 | fun addView(aView: RemoteViews) {
100 | if (views.contains(aView)) return
101 | views.add(aView)
102 | root.addView(LLId, aView)
103 | }
104 | }
105 | }
--------------------------------------------------------------------------------
/app/src/main/java/de/dlyt/yanndroid/notinotes/Notes.kt:
--------------------------------------------------------------------------------
1 | package de.dlyt.yanndroid.notinotes
2 |
3 | import android.content.Context
4 | import android.graphics.Color
5 | import com.google.gson.Gson
6 | import com.google.gson.reflect.TypeToken
7 | import java.io.Serializable
8 | import java.util.stream.Collectors
9 | import kotlin.math.min
10 |
11 |
12 | class Notes {
13 |
14 | class Note :
15 | Serializable {
16 | var title: String? = null
17 | var content: String? = null
18 | var color: Int = Color.GRAY
19 | var id: Int = -1
20 | var secret: Boolean = false
21 | var locked: Boolean = true
22 | var group: Boolean = true
23 | var bg_tint: Boolean = true
24 | var del_confirm: Boolean = false
25 | }
26 |
27 | companion object {
28 |
29 | fun getNotes(context: Context): ArrayList = Gson().fromJson(
30 | context.getSharedPreferences("sp", Context.MODE_PRIVATE).getString("notes", "[]"),
31 | object : TypeToken>() {}.type
32 | )
33 |
34 | private fun saveNotes(context: Context, list: ArrayList) {
35 | context.getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
36 | .putString("notes", Gson().toJson(list)).apply()
37 | }
38 |
39 | fun saveNote(context: Context, note: Note) {
40 | saveDefaultSetting(context, note)
41 |
42 | val list = getNotes(context)
43 | if (note.id == -1) note.id = generateNewNoteID(list)
44 | for (i in list.indices) {
45 | if (note.id == list[i].id) {
46 | list[i] = note
47 | saveNotes(context, list)
48 | Notification.show(context, note)
49 | return
50 | }
51 | }
52 | list.add(note)
53 | saveNotes(context, list)
54 | Notification.show(context, note)
55 | }
56 |
57 | fun deleteNote(context: Context, note: Note) {
58 | val list = getNotes(context)
59 | for (i in list.indices) {
60 | if (note.id == list[i].id) {
61 | list.removeAt(i)
62 | saveNotes(context, list)
63 | Notification.cancel(context, note)
64 | return
65 | }
66 | }
67 | }
68 |
69 | fun generateNewNoteID(context: Context): Int = generateNewNoteID(getNotes(context))
70 |
71 | private fun generateNewNoteID(list: ArrayList): Int {
72 | val takenIDs = list.stream().map { note -> note.id }.collect(Collectors.toList())
73 | var newID = 0
74 | while (takenIDs.contains(newID)) newID++
75 | return newID
76 | }
77 |
78 | fun defaultSettingNote(context: Context): Note {
79 | val json =
80 | context.getSharedPreferences("sp", Context.MODE_PRIVATE).getString("default", null)
81 | return if (json == null) Note() else Gson().fromJson(
82 | json,
83 | object : TypeToken() {}.type
84 | )
85 | }
86 |
87 | private fun saveDefaultSetting(context: Context, note: Note) {
88 | val default = Note()
89 | default.secret = note.secret
90 | default.locked = note.locked
91 | default.group = note.group
92 | default.bg_tint = note.bg_tint
93 | default.del_confirm = note.del_confirm
94 |
95 | context.getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
96 | .putString("default", Gson().toJson(default)).apply()
97 | }
98 |
99 | fun getRecentColors(context: Context): IntArray = Gson().fromJson(
100 | context.getSharedPreferences("sp", Context.MODE_PRIVATE)
101 | .getString("colors", "[]"),
102 | object : TypeToken() {}.type
103 | )
104 |
105 | fun saveRecentColor(context: Context, colors: IntArray, newColor: Int) {
106 | val merged: IntArray = if (colors.isNotEmpty() && newColor == colors[0]) {
107 | colors
108 | } else {
109 | val result = colors.toMutableList()
110 | result.add(0, newColor)
111 | result.subList(0, min(colors.size + 1, 6)).toIntArray()
112 | }
113 |
114 | context.getSharedPreferences("sp", Context.MODE_PRIVATE).edit()
115 | .putString("colors", Gson().toJson(merged)).apply()
116 | }
117 |
118 | }
119 |
120 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
26 |
27 |
36 |
37 |
47 |
48 |
58 |
59 |
69 |
70 |
71 |
72 |
81 |
82 |
88 |
89 |
97 |
98 |
111 |
112 |
113 |
114 |
115 |
116 |
120 |
121 |
--------------------------------------------------------------------------------
/app/src/main/java/de/dlyt/yanndroid/notinotes/Notification.kt:
--------------------------------------------------------------------------------
1 | package de.dlyt.yanndroid.notinotes
2 |
3 | import android.app.NotificationChannel
4 | import android.app.NotificationManager
5 | import android.app.PendingIntent
6 | import android.content.Context
7 | import android.content.Intent
8 | import android.content.res.Configuration
9 | import android.graphics.Color
10 | import android.view.LayoutInflater
11 | import androidx.core.app.NotificationCompat
12 | import androidx.core.app.NotificationManagerCompat
13 | import androidx.core.graphics.ColorUtils
14 |
15 |
16 | class Notification {
17 |
18 | companion object {
19 |
20 | val NOTIFICATION_GROUP = "de.dlyt.yanndroid.notinotes.NOTES_GROUP"
21 | val NOTIFICATION_GROUP_HOLDER = -1
22 | val NOTIFICATION_CHANNEL = "1234"
23 |
24 | fun showAll(context: Context) {
25 | for (note in Notes.getNotes(context)) show(context, note)
26 | }
27 |
28 | fun cancelAll(context: Context) {
29 | NotificationManagerCompat.from(context).cancelAll()
30 | }
31 |
32 | fun show(context: Context, note: Notes.Note) {
33 | val nmc = NotificationManagerCompat.from(context)
34 | nmc.notify( //for some reason this in needed to make grouping work
35 | NOTIFICATION_GROUP_HOLDER, NotificationCompat.Builder(
36 | context,
37 | NOTIFICATION_CHANNEL
38 | )
39 | .setOngoing(true)
40 | .setSmallIcon(R.drawable.ic_note)
41 | .setGroup(NOTIFICATION_GROUP)
42 | .setGroupSummary(true)
43 | .build()
44 | )
45 | val notiBuilder = NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
46 | .setStyle(NotificationCompat.BigTextStyle())
47 | .setOngoing(note.locked)
48 | .setVisibility(if (note.secret) NotificationCompat.VISIBILITY_SECRET else NotificationCompat.VISIBILITY_PUBLIC)
49 | .setSmallIcon(R.drawable.ic_note)
50 | .setContentTitle(note.title)
51 | .setContentText(note.content)
52 | .addAction(
53 | R.drawable.ic_edit,
54 | context.getString(R.string.edit),
55 | getPendingIntentActivity(context, note, ActionReceiver.ACTION_EDIT)
56 | )
57 | .addAction(
58 | R.drawable.ic_delete,
59 | context.getString(R.string.del),
60 | ActionReceiver.getPendingIntent(context, note, ActionReceiver.ACTION_DELETE)
61 | )
62 | .setContentIntent(
63 | getPendingIntentActivity(context, note, ActionReceiver.ACTION_SHOW)
64 | )
65 | .setDeleteIntent(
66 | ActionReceiver.getPendingIntent(context, note, ActionReceiver.ACTION_DISMISS)
67 | )
68 | .setColor(note.color)
69 |
70 | if (note.group) notiBuilder.setGroup(NOTIFICATION_GROUP)
71 |
72 | if (note.bg_tint) {
73 | val darkMode =
74 | context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
75 | val blendColor = if (darkMode) Color.BLACK else Color.WHITE
76 | notiBuilder.setContent(
77 | notiBuilder.createContentView()!!.also {
78 | it.setInt(
79 | LayoutInflater.from(context).inflate(it.layoutId, null).id,
80 | "setBackgroundColor",
81 | ColorUtils.blendARGB(
82 | note.color,
83 | blendColor,
84 | if (darkMode) 0.5f else 0.3f
85 | )
86 | )
87 | })
88 | notiBuilder.setCustomBigContentView(
89 | notiBuilder.createBigContentView()!!.also {
90 | it.setInt(
91 | LayoutInflater.from(context).inflate(it.layoutId, null).id,
92 | "setBackgroundColor",
93 | ColorUtils.blendARGB(
94 | note.color,
95 | blendColor,
96 | if (darkMode) 0.3f else 0.1f
97 | )
98 | )
99 | })
100 | }
101 |
102 | nmc.notify(note.id, notiBuilder.build())
103 |
104 | }
105 |
106 | fun cancel(context: Context, note: Notes.Note) {
107 | val nmc = NotificationManagerCompat.from(context)
108 | nmc.cancel(note.id)
109 | if (Notes.getNotes(context).size == 0) nmc.cancel(NOTIFICATION_GROUP_HOLDER)
110 | }
111 |
112 | fun createNotificationChannel(context: Context) {
113 | context.getSystemService(NotificationManager::class.java).createNotificationChannel(
114 | NotificationChannel(
115 | NOTIFICATION_CHANNEL,
116 | context.getString(R.string.notes),
117 | NotificationManager.IMPORTANCE_LOW
118 | )
119 | )
120 | }
121 |
122 | private fun getPendingIntentActivity(context: Context, note: Notes.Note, action: String): PendingIntent {
123 | val intent = Intent(context, DialogActivity::class.java)
124 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
125 | intent.action = action
126 | intent.putExtra(ActionReceiver.EXTRA_NOTE, note)
127 | return PendingIntent.getActivity(
128 | context,
129 | note.id,
130 | intent,
131 | PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
132 | )
133 | }
134 |
135 | }
136 | }
--------------------------------------------------------------------------------
/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/de/dlyt/yanndroid/notinotes/DialogActivity.kt:
--------------------------------------------------------------------------------
1 | package de.dlyt.yanndroid.notinotes
2 |
3 | import android.app.KeyguardManager
4 | import android.content.Context
5 | import android.content.Intent
6 | import android.content.pm.PackageManager
7 | import android.content.res.Resources
8 | import android.os.Build
9 | import android.os.Bundle
10 | import android.util.TypedValue
11 | import android.view.Gravity
12 | import android.view.MenuItem
13 | import android.view.View
14 | import android.widget.Button
15 | import android.widget.ImageView
16 | import android.widget.TextView
17 | import android.widget.Toast
18 | import androidx.appcompat.app.AppCompatActivity
19 | import androidx.appcompat.view.ContextThemeWrapper
20 | import androidx.appcompat.widget.PopupMenu
21 | import androidx.core.view.isGone
22 | import androidx.core.view.isVisible
23 | import androidx.picker3.app.SeslColorPickerDialog
24 |
25 |
26 | class DialogActivity : AppCompatActivity() {
27 |
28 | private val mContext = this
29 | private lateinit var mKeyguardManager: KeyguardManager
30 | private var mEditMode = false
31 | private lateinit var mNote: Notes.Note
32 |
33 | private lateinit var icon: ImageView
34 | private lateinit var titleText: TextView
35 | private lateinit var titleEdit: TextView
36 | private lateinit var colorPick: ImageView
37 | private lateinit var settings: ImageView
38 | private lateinit var noteText: TextView
39 | private lateinit var noteEdit: TextView
40 | private lateinit var buttonNeutral: Button
41 | private lateinit var buttonNegative: Button
42 | private lateinit var buttonPositive: Button
43 |
44 |
45 | override fun onCreate(savedInstanceState: Bundle?) {
46 | mNote = (intent.getSerializableExtra(ActionReceiver.EXTRA_NOTE) ?: finish()) as Notes.Note
47 |
48 | super.onCreate(savedInstanceState)
49 | setContentView(R.layout.activity_dialog)
50 | window.setGravity(Gravity.BOTTOM)
51 |
52 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
53 | if (checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_DENIED) {
54 | requestPermissions(arrayOf(android.Manifest.permission.POST_NOTIFICATIONS), 0)
55 | }
56 | }
57 |
58 | try {
59 | sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
60 | } catch (e: SecurityException) {
61 | e.printStackTrace()
62 | }
63 |
64 | mKeyguardManager = getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
65 | mKeyguardManager.requestDismissKeyguard(this, null)
66 |
67 | icon = findViewById(R.id.dialog_icon)
68 | titleText = findViewById(R.id.dialog_title).apply { text = mNote.title }
69 | titleEdit = findViewById(R.id.dialog_title_edit).apply { text = mNote.title }
70 | colorPick = findViewById(R.id.dialog_color_picker)
71 | settings = findViewById(R.id.dialog_settings)
72 | noteText = findViewById(R.id.dialog_note).apply { text = mNote.content }
73 | noteEdit = findViewById(R.id.dialog_note_edit).apply { text = mNote.content }
74 | buttonNeutral = findViewById(android.R.id.button3)
75 | buttonNegative = findViewById(android.R.id.button2)
76 | buttonPositive = findViewById(android.R.id.button1)
77 |
78 | setColor(mNote.color)
79 |
80 | when (intent.action) {
81 | ActionReceiver.ACTION_SHOW -> setLayout(mNote, false)
82 | ActionReceiver.ACTION_EDIT -> setLayout(mNote, true)
83 | else -> finish()
84 | }
85 | }
86 |
87 | private fun setLayout(note: Notes.Note, editMode: Boolean) {
88 | mEditMode = editMode
89 | setFinishOnTouchOutside(!editMode)
90 | titleText.isGone = editMode
91 | titleEdit.isGone = !editMode
92 | colorPick.isGone = !editMode
93 | settings.isGone = !editMode
94 | noteText.isGone = editMode
95 | noteEdit.isGone = !editMode
96 | buttonNeutral.isGone = editMode
97 | findViewById(R.id.sem_divider2).isGone = editMode
98 | findViewById(R.id.sem_divider1).isVisible = true
99 |
100 |
101 | if (editMode) {
102 | colorPick.setOnClickListener {
103 | val rColors = Notes.getRecentColors(mContext)
104 |
105 | SeslColorPickerDialog(
106 | ContextThemeWrapper(mContext, R.style.ColorDialogWidthFix),
107 | { color ->
108 | note.color = color
109 | setColor(color)
110 | Notes.saveRecentColor(mContext, rColors, color)
111 | }, note.color, rColors, false
112 | ).show()
113 | }
114 |
115 | val popmenu = PopupMenu(mContext, settings)
116 | popmenu.seslSetOffset(0, -300)
117 | popmenu.menuInflater.inflate(R.menu.settings, popmenu.menu)
118 | popmenu.menu.let {
119 | it.findItem(R.id.settings_hide).isChecked = note.secret
120 | it.findItem(R.id.settings_lock).isChecked = note.locked
121 | it.findItem(R.id.settings_group).isChecked = note.group
122 | it.findItem(R.id.settings_bg_tint).isChecked = note.bg_tint
123 | it.findItem(R.id.settings_del_confirm).isChecked = note.del_confirm
124 | }
125 | popmenu.setOnMenuItemClickListener { item: MenuItem ->
126 | item.isChecked = !item.isChecked
127 | when (item.itemId) {
128 | R.id.settings_hide -> note.secret = item.isChecked
129 | R.id.settings_lock -> note.locked = item.isChecked
130 | R.id.settings_group -> note.group = item.isChecked
131 | R.id.settings_bg_tint -> note.bg_tint = item.isChecked
132 | R.id.settings_del_confirm -> note.del_confirm = item.isChecked
133 | }
134 | item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW)
135 | item.actionView = View(mContext)
136 | false
137 | }
138 | settings.setOnClickListener { popmenu.show() }
139 |
140 | buttonNegative.apply {
141 | setText(R.string.cancel)
142 | setOnClickListener {
143 | mEditMode = false
144 | finish()
145 | }
146 | }
147 | buttonPositive.apply {
148 | setText(R.string.save)
149 | setTextColor(getColor(androidx.appcompat.R.color.sesl_functional_green_light))
150 | setOnClickListener {
151 | Notes.saveNote(mContext, note.apply {
152 | title = titleEdit.text.toString()
153 | content = noteEdit.text.toString()
154 | })
155 | mEditMode = false
156 | finish()
157 | }
158 | }
159 | } else {
160 | noteText.setOnClickListener { setLayout(note, true) }
161 | buttonNeutral.apply {
162 | setText(R.string.cancel)
163 | setOnClickListener { finish() }
164 | }
165 | buttonNegative.apply {
166 | setText(R.string.edit)
167 | setOnClickListener { setLayout(note, true) }
168 | }
169 | buttonPositive.apply {
170 | setText(R.string.del)
171 | setTextColor(getColor(androidx.appcompat.R.color.sesl_functional_red_light))
172 | setOnClickListener {
173 | Notes.deleteNote(mContext, note)
174 | finish()
175 | }
176 | }
177 | }
178 | }
179 |
180 | private fun setColor(color: Int) {
181 | icon.setColorFilter(color)
182 | titleText.setTextColor(color)
183 | colorPick.setColorFilter(color)
184 | }
185 |
186 | override fun onBackPressed() {
187 | if (!mEditMode) finish()
188 | }
189 |
190 | override fun getTheme(): Resources.Theme {
191 | val theme = super.getTheme()
192 | val outValue = TypedValue()
193 | theme.resolveAttribute(
194 | androidx.appcompat.R.attr.alertDialogTheme,
195 | outValue,
196 | true
197 | )
198 | theme.applyStyle(outValue.resourceId, true)
199 | return theme
200 | }
201 |
202 | override fun onPause() {
203 | super.onPause()
204 | if (mKeyguardManager.isKeyguardLocked) return
205 | if (mEditMode && noteEdit.text.toString() != mNote.content && !noteEdit.text.isNullOrEmpty()) {
206 | Notes.saveNote(mContext, mNote.apply {
207 | id = Notes.generateNewNoteID(mContext)
208 | title = titleEdit.text.toString()
209 | content = noteEdit.text.toString()
210 | })
211 | Toast.makeText(mContext, R.string.saved_copy, Toast.LENGTH_SHORT).show()
212 | }
213 | finish()
214 | }
215 | }
--------------------------------------------------------------------------------