├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── dimens.xml
│ │ │ ├── colors.xml
│ │ │ ├── strings.xml
│ │ │ └── themes.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── menu
│ │ │ ├── main_selected_menu.xml
│ │ │ ├── main_search_menu.xml
│ │ │ └── editor_menu.xml
│ │ ├── drawable
│ │ │ ├── ic_baseline_check_24.xml
│ │ │ ├── ic_baseline_delete_24.xml
│ │ │ ├── ic_baseline_edit_24.xml
│ │ │ ├── ic_baseline_search_24.xml
│ │ │ ├── ic_launcher_foreground.xml
│ │ │ └── ic_launcher_background.xml
│ │ ├── values-uk
│ │ │ └── strings.xml
│ │ ├── values-ru
│ │ │ └── strings.xml
│ │ ├── values-night
│ │ │ └── themes.xml
│ │ └── layout
│ │ │ ├── note_layout.xml
│ │ │ ├── activity_main.xml
│ │ │ └── activity_note.xml
│ │ ├── ic_launcher-playstore.png
│ │ ├── java
│ │ └── com
│ │ │ └── dm
│ │ │ └── notes
│ │ │ ├── NotesApplication.java
│ │ │ ├── models
│ │ │ └── Note.java
│ │ │ ├── helpers
│ │ │ ├── Utils.java
│ │ │ └── DatabaseHelper.java
│ │ │ └── ui
│ │ │ ├── GridSpacingItemDecoration.java
│ │ │ ├── NotesAdapter.java
│ │ │ ├── NoteEditorActivity.java
│ │ │ └── MainActivity.java
│ │ └── AndroidManifest.xml
├── release
│ └── output-metadata.json
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ └── gradle-wrapper.properties
├── README.md
├── gradle.properties
├── .gitignore
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "Notes"
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/ic_launcher-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dmitrijkotov634/android-notes/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Jun 18 11:18:32 MSK 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/NotesApplication.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes;
2 |
3 | import android.app.Application;
4 |
5 | import com.google.android.material.color.DynamicColors;
6 |
7 | public class NotesApplication extends Application {
8 | @Override
9 | public void onCreate() {
10 | super.onCreate();
11 |
12 | DynamicColors.applyToActivitiesIfAvailable(this);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_selected_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/models/Note.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.models;
2 |
3 | public class Note {
4 | private final long id;
5 | private final String text;
6 |
7 | public Note(long id, String text) {
8 | this.id = id;
9 | this.text = text;
10 | }
11 |
12 | public long getId() {
13 | return id;
14 | }
15 |
16 | public String getText() {
17 | return text;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_check_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/release/output-metadata.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 3,
3 | "artifactType": {
4 | "type": "APK",
5 | "kind": "Directory"
6 | },
7 | "applicationId": "com.dm.notes",
8 | "variantName": "release",
9 | "elements": [
10 | {
11 | "type": "SINGLE",
12 | "filters": [],
13 | "attributes": [],
14 | "versionCode": 5,
15 | "versionName": "1.5",
16 | "outputFile": "app-release.apk"
17 | }
18 | ],
19 | "elementType": "File"
20 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/main_search_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_delete_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF8858c8
5 | #FF6200EE
6 | #FF3700B3
7 | #FF03DAC5
8 | #FF018786
9 | #FF000000
10 | #FFFFFFFF
11 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/helpers/Utils.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.helpers;
2 |
3 | import android.text.Html;
4 | import android.text.SpannableString;
5 |
6 | public class Utils {
7 | public static SpannableString fromHtml(String text) {
8 | SpannableString spannableString = SpannableString.valueOf(Html.fromHtml(text));
9 | if (spannableString.toString().endsWith("\n\n"))
10 | spannableString = (SpannableString) spannableString.subSequence(0, spannableString.length() - 2);
11 | return spannableString;
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_edit_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_search_24.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/editor_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Notes
3 |
4 | Name
5 | Are you sure you want to delete items?
6 |
7 | Yes
8 | No
9 |
10 | Bold
11 | Italic
12 | Underline
13 | Strikethrough
14 | Normal
15 |
16 | Search
17 | Remove
18 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
11 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-uk/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Нотатки
4 |
5 | Назва
6 | Ви впевнені, що хочете видалити елементи?
7 |
8 | Так
9 | Нi
10 |
11 | Напівжирний
12 | Курсив
13 | Підкреслений
14 | Закреслений
15 | Звичайний
16 |
17 | Пошук
18 | Вилучити
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values-ru/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Заметки
4 |
5 | Название
6 | Вы уверены, что хотите удалить эти элементы?
7 |
8 | Да
9 | Нет
10 |
11 | Полужирный
12 | Курсив
13 | Подчеркнутый
14 | Зачеркнутый
15 | Обычный
16 |
17 | Поиск
18 | Удалить
19 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
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
--------------------------------------------------------------------------------
/app/src/main/res/layout/note_layout.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
19 |
20 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |  [](https://hitsofcode.com/github/dmitrijkotov634/android-notes/view) 
2 | # Android Notes
3 | Simple android app for saving some notes written on Java.
4 | |  |  |
5 | |-------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
6 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | }
4 |
5 | android {
6 | compileSdkVersion 32
7 | buildToolsVersion "30.0.3"
8 |
9 | buildFeatures {
10 | viewBinding true
11 | }
12 |
13 | defaultConfig {
14 | applicationId "com.dm.notes"
15 | minSdkVersion 16
16 | targetSdkVersion 32
17 | versionCode 6
18 | versionName "1.5.1"
19 | }
20 |
21 | buildTypes {
22 | release {
23 | minifyEnabled true
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | compileOptions {
28 | sourceCompatibility JavaVersion.VERSION_1_8
29 | targetCompatibility JavaVersion.VERSION_1_8
30 | }
31 | }
32 |
33 | dependencies {
34 | implementation 'androidx.appcompat:appcompat:1.4.2'
35 | implementation 'com.google.android.material:material:1.7.0-alpha02'
36 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
13 |
14 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/ui/GridSpacingItemDecoration.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.ui;
2 |
3 | import android.graphics.Rect;
4 | import android.view.View;
5 |
6 | import androidx.annotation.NonNull;
7 | import androidx.recyclerview.widget.RecyclerView;
8 |
9 | public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
10 |
11 | private final int spanCount;
12 | private final int spacing;
13 |
14 | public GridSpacingItemDecoration(int spanCount, int spacing) {
15 | this.spanCount = spanCount;
16 | this.spacing = spacing;
17 | }
18 |
19 | @Override
20 | public void getItemOffsets(Rect outRect, @NonNull View view, RecyclerView parent, @NonNull RecyclerView.State state) {
21 | int position = parent.getChildAdapterPosition(view);
22 | int column = position % spanCount;
23 |
24 | outRect.left = spacing - column * spacing / spanCount;
25 | outRect.right = (column + 1) * spacing / spanCount;
26 |
27 | if (position < spanCount) {
28 | outRect.top = spacing;
29 | }
30 |
31 | outRect.bottom = spacing;
32 | }
33 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/helpers/DatabaseHelper.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.helpers;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 | import android.database.sqlite.SQLiteOpenHelper;
6 |
7 | public class DatabaseHelper extends SQLiteOpenHelper {
8 | private static final String DATABASE_NAME = "notes.db";
9 | private static final int VERSION = 1;
10 |
11 | public static final String TABLE = "notes";
12 |
13 | public static final String COLUMN_ID = "_id";
14 | public static final String COLUMN_NAME = "name";
15 | public static final String COLUMN_TEXT = "text";
16 |
17 | public DatabaseHelper(Context context) {
18 | super(context, DATABASE_NAME, null, VERSION);
19 | }
20 |
21 | @Override
22 | public void onCreate(SQLiteDatabase db) {
23 | db.execSQL("CREATE TABLE " + TABLE + " (" + COLUMN_ID
24 | + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_NAME
25 | + " TEXT, " + COLUMN_TEXT + " INTEGER);");
26 | }
27 |
28 | @Override
29 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
30 | db.execSQL("DROP TABLE IF EXISTS " + TABLE);
31 | onCreate(db);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
14 |
15 |
19 |
20 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | /gradle/wrapper/*.jar
22 | .gradle/
23 | build/
24 |
25 | # Local configuration file (sdk path, etc)
26 | local.properties
27 |
28 | # Proguard folder generated by Eclipse
29 | proguard/
30 |
31 | # Log Files
32 | *.log
33 |
34 | # Android Studio Navigation editor temp files
35 | .navigation/
36 |
37 | # Android Studio captures folder
38 | captures/
39 |
40 | # IntelliJ
41 | /.idea/
42 |
43 | # Keystore files
44 | # Uncomment the following lines if you do not want to check your keystore files in.
45 | *.jks
46 | *.keystore
47 |
48 | # External native build folder generated in Android Studio 2.2 and later
49 | .externalNativeBuild
50 | .cxx/
51 |
52 | # Google Services (e.g. APIs or Firebase)
53 | # google-services.json
54 |
55 | # Freeline
56 | freeline.py
57 | freeline/
58 | freeline_project_description.json
59 |
60 | # fastlane
61 | fastlane/report.xml
62 | fastlane/Preview.html
63 | fastlane/screenshots
64 | fastlane/test_output
65 | fastlane/readme.md
66 |
67 | # Version control
68 | vcs.xml
69 |
70 | # lint
71 | lint/intermediates/
72 | lint/generated/
73 | lint/outputs/
74 | lint/tmp/
75 | # lint/reports/
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
30 |
31 |
40 |
41 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_note.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
30 |
31 |
34 |
35 |
40 |
41 |
42 |
43 |
53 |
54 |
55 |
56 |
67 |
68 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/ui/NotesAdapter.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.ui;
2 |
3 | import android.view.LayoutInflater;
4 | import android.view.View;
5 | import android.view.ViewGroup;
6 |
7 | import androidx.annotation.NonNull;
8 | import androidx.recyclerview.widget.RecyclerView;
9 |
10 | import com.dm.notes.databinding.NoteLayoutBinding;
11 | import com.dm.notes.helpers.Utils;
12 | import com.dm.notes.models.Note;
13 |
14 | import java.util.List;
15 | import java.util.Set;
16 |
17 | public class NotesAdapter extends RecyclerView.Adapter {
18 |
19 | public final List notes;
20 |
21 | private final Set selected;
22 | private final NotesCallback callback;
23 |
24 | public NotesAdapter(NotesCallback callback, List notes, Set selected) {
25 | this.callback = callback;
26 | this.notes = notes;
27 | this.selected = selected;
28 | }
29 |
30 | @NonNull
31 | @Override
32 | public NotesAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
33 | NoteLayoutBinding rowItem = NoteLayoutBinding.inflate(LayoutInflater.from(parent.getContext()));
34 | return new ViewHolder(rowItem);
35 | }
36 |
37 | @Override
38 | public void onBindViewHolder(@NonNull NotesAdapter.ViewHolder holder, int position) {
39 | holder.binding.note.setText(Utils.fromHtml(notes.get(position).getText()));
40 | holder.binding.getRoot().setChecked(selected.contains(notes.get(position)));
41 | }
42 |
43 | @Override
44 | public int getItemCount() {
45 | return notes.size();
46 | }
47 |
48 | public class ViewHolder extends RecyclerView.ViewHolder {
49 | public final NoteLayoutBinding binding;
50 |
51 | public ViewHolder(NoteLayoutBinding binding) {
52 | super(binding.getRoot());
53 |
54 | this.binding = binding;
55 |
56 | View.OnLongClickListener longClickListener = v -> {
57 | Note note = notes.get(getLayoutPosition());
58 |
59 | if (selected.contains(note)) selected.remove(note);
60 | else selected.add(note);
61 |
62 | binding.getRoot().toggle();
63 |
64 | callback.onNoteSelected(note);
65 | return true;
66 | };
67 |
68 | binding.getRoot().setOnClickListener((v) -> {
69 | if (!selected.isEmpty()) {
70 | longClickListener.onLongClick(v);
71 | return;
72 | }
73 |
74 | callback.onNoteClicked(notes.get(getLayoutPosition()), getLayoutPosition());
75 | });
76 |
77 | binding.getRoot().setOnLongClickListener(longClickListener);
78 | }
79 | }
80 |
81 | public interface NotesCallback {
82 | void onNoteClicked(Note note, int position);
83 |
84 | void onNoteSelected(Note note);
85 | }
86 | }
87 |
88 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
10 |
12 |
14 |
16 |
18 |
20 |
22 |
24 |
26 |
28 |
30 |
32 |
34 |
36 |
38 |
40 |
42 |
44 |
46 |
48 |
50 |
52 |
54 |
56 |
58 |
60 |
62 |
64 |
66 |
68 |
70 |
72 |
74 |
75 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/ui/NoteEditorActivity.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.ui;
2 |
3 | import android.content.ContentValues;
4 | import android.content.Intent;
5 | import android.database.Cursor;
6 | import android.database.sqlite.SQLiteDatabase;
7 | import android.graphics.Typeface;
8 | import android.os.Bundle;
9 | import android.text.Editable;
10 | import android.text.Html;
11 | import android.text.Spannable;
12 | import android.text.SpannableString;
13 | import android.text.Spanned;
14 | import android.text.TextWatcher;
15 | import android.text.method.LinkMovementMethod;
16 | import android.text.style.CharacterStyle;
17 | import android.text.style.StrikethroughSpan;
18 | import android.text.style.StyleSpan;
19 | import android.text.style.UnderlineSpan;
20 | import android.text.util.Linkify;
21 | import android.view.Menu;
22 | import android.view.MenuItem;
23 | import android.view.inputmethod.InputMethodManager;
24 | import android.widget.EditText;
25 |
26 | import androidx.annotation.NonNull;
27 | import androidx.appcompat.app.AppCompatActivity;
28 |
29 | import com.dm.notes.R;
30 | import com.dm.notes.databinding.ActivityNoteBinding;
31 | import com.dm.notes.helpers.DatabaseHelper;
32 | import com.dm.notes.helpers.Utils;
33 |
34 | public class NoteEditorActivity extends AppCompatActivity {
35 | private ActivityNoteBinding binding;
36 |
37 | private SQLiteDatabase db;
38 |
39 | private Intent intent;
40 |
41 | private boolean hasChanges;
42 | private boolean editing;
43 |
44 | @Override
45 | protected void onCreate(Bundle savedInstanceState) {
46 | super.onCreate(savedInstanceState);
47 | setContentView(R.layout.activity_note);
48 |
49 | binding = ActivityNoteBinding.inflate(getLayoutInflater());
50 | setContentView(binding.getRoot());
51 |
52 | setSupportActionBar(binding.toolbar);
53 |
54 | TextWatcher watcher = new TextWatcher() {
55 | @Override
56 | public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
57 | }
58 |
59 | @Override
60 | public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
61 | hasChanges = true;
62 | }
63 |
64 | @Override
65 | public void afterTextChanged(Editable editable) {
66 | }
67 | };
68 |
69 | binding.fab2.setOnClickListener(view -> changeMode(!editing));
70 |
71 | binding.noteName.addTextChangedListener(watcher);
72 | binding.noteText.addTextChangedListener(watcher);
73 |
74 | db = new DatabaseHelper(this).getWritableDatabase();
75 |
76 | intent = getIntent();
77 |
78 | changeMode(intent.getBooleanExtra("editing", true));
79 |
80 | try (Cursor cursor = db.query(DatabaseHelper.TABLE,
81 | new String[]{DatabaseHelper.COLUMN_NAME, DatabaseHelper.COLUMN_TEXT},
82 | "_id = ?",
83 | new String[]{String.valueOf(intent.getLongExtra("id", 0))},
84 | null, null, null)) {
85 |
86 | cursor.moveToFirst();
87 |
88 | binding.noteName.setText(Utils.fromHtml(cursor.getString(0)));
89 | binding.noteText.setText(Utils.fromHtml(cursor.getString(1)));
90 | }
91 | }
92 |
93 | @Override
94 | public boolean onCreateOptionsMenu(Menu menu) {
95 | if (editing)
96 | getMenuInflater().inflate(R.menu.editor_menu, menu);
97 |
98 | return true;
99 | }
100 |
101 | private void changeMode(boolean editing) {
102 | binding.noteText.setLinksClickable(!editing);
103 | binding.noteText.setMovementMethod(editing ? null : LinkMovementMethod.getInstance());
104 |
105 | Linkify.addLinks(binding.noteText, Linkify.WEB_URLS | Linkify.EMAIL_ADDRESSES);
106 |
107 | binding.noteName.setFocusable(editing);
108 | binding.noteName.setCursorVisible(editing);
109 | binding.noteName.setFocusableInTouchMode(editing);
110 |
111 | binding.noteText.setFocusable(editing);
112 | binding.noteText.setCursorVisible(editing);
113 | binding.noteText.setFocusableInTouchMode(editing);
114 | binding.noteText.setTextIsSelectable(editing);
115 |
116 | binding.fab2.setImageResource(editing ? R.drawable.ic_baseline_check_24 : R.drawable.ic_baseline_edit_24);
117 |
118 | invalidateOptionsMenu();
119 |
120 | if (!editing) {
121 | InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
122 | imm.hideSoftInputFromWindow(binding.getRoot().getWindowToken(), 0);
123 | }
124 |
125 | saveChanges();
126 |
127 | this.editing = editing;
128 | }
129 |
130 | @Override
131 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
132 | applySpan(getSpan(item.getItemId()));
133 | return true;
134 | }
135 |
136 | private CharacterStyle getSpan(int id) {
137 | if (id == R.id.bold)
138 | return new StyleSpan(Typeface.BOLD);
139 | else if (id == R.id.italic)
140 | return new StyleSpan(Typeface.ITALIC);
141 | else if (id == R.id.underline)
142 | return new UnderlineSpan();
143 | else if (id == R.id.strikethrough)
144 | return new StrikethroughSpan();
145 |
146 | return null;
147 | }
148 |
149 | @Override
150 | public void onBackPressed() {
151 | saveChanges();
152 | super.onBackPressed();
153 | }
154 |
155 | @Override
156 | protected void onStop() {
157 | saveChanges();
158 | super.onStop();
159 | }
160 |
161 | private void saveChanges() {
162 | if (hasChanges) {
163 | ContentValues values = new ContentValues();
164 |
165 | String name;
166 | if (binding.noteName.getText().toString().isEmpty()) {
167 | String[] lines = binding.noteText.getText().toString().split("\n", 2);
168 | name = lines[0].length() > 50 ? lines[0].substring(0, 50) : lines[0];
169 | } else
170 | name = Html.toHtml(binding.noteName.getText());
171 |
172 | values.put(DatabaseHelper.COLUMN_NAME, name);
173 | values.put(DatabaseHelper.COLUMN_TEXT, Html.toHtml(binding.noteText.getText()));
174 |
175 | db.update(DatabaseHelper.TABLE, values, "_id = ?",
176 | new String[]{String.valueOf(intent.getLongExtra("id", 0))});
177 |
178 | hasChanges = false;
179 | }
180 | }
181 |
182 | private void applySpan(CharacterStyle span) {
183 | EditText input = binding.noteText.isFocused() ? binding.noteText : (binding.noteName.isFocused() ? binding.noteName : null);
184 |
185 | if (input == null)
186 | return;
187 |
188 | int start = input.getSelectionStart();
189 | int end = input.getSelectionEnd();
190 |
191 | Spannable text = new SpannableString(input.getText());
192 |
193 | if (start != end) {
194 | if (span == null) {
195 | CharacterStyle[] spans = text.getSpans(start, end, CharacterStyle.class);
196 | for (CharacterStyle selectSpan : spans)
197 | text.removeSpan(selectSpan);
198 | } else {
199 | text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
200 | }
201 |
202 | input.setText(text);
203 | input.setSelection(start, end);
204 | }
205 | }
206 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/dm/notes/ui/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.dm.notes.ui;
2 |
3 | import android.annotation.SuppressLint;
4 | import android.content.ContentValues;
5 | import android.content.Intent;
6 | import android.database.Cursor;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.os.Bundle;
9 | import android.text.Html;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.widget.SearchView;
14 |
15 | import androidx.annotation.NonNull;
16 | import androidx.appcompat.app.AppCompatActivity;
17 |
18 | import com.dm.notes.R;
19 | import com.dm.notes.databinding.ActivityMainBinding;
20 | import com.dm.notes.helpers.DatabaseHelper;
21 | import com.dm.notes.models.Note;
22 | import com.google.android.material.dialog.MaterialAlertDialogBuilder;
23 |
24 | import java.util.ArrayList;
25 | import java.util.HashSet;
26 | import java.util.List;
27 | import java.util.Set;
28 |
29 | @SuppressLint("NotifyDataSetChanged")
30 | public class MainActivity extends AppCompatActivity implements NotesAdapter.NotesCallback {
31 |
32 | private final Set selected = new HashSet<>();
33 | private final List notes = new ArrayList<>();
34 |
35 | private ActivityMainBinding binding;
36 |
37 | private NotesAdapter adapter;
38 | private SQLiteDatabase db;
39 |
40 | private Note currentNote;
41 |
42 | SearchView.OnCloseListener listener = () -> {
43 | binding.fab.setVisibility(View.VISIBLE);
44 |
45 | adapter = new NotesAdapter(MainActivity.this, notes, selected);
46 | binding.notesList.setAdapter(adapter);
47 |
48 | invalidateOptionsMenu();
49 |
50 | binding.notesList.scrollToPosition(notes.size() - 1);
51 | return false;
52 | };
53 |
54 | @Override
55 | protected void onCreate(Bundle savedInstanceState) {
56 | super.onCreate(savedInstanceState);
57 |
58 | binding = ActivityMainBinding.inflate(getLayoutInflater());
59 | setContentView(binding.getRoot());
60 |
61 | setSupportActionBar(binding.toolbar);
62 |
63 | binding.fab.setOnClickListener(view -> {
64 | ContentValues values = new ContentValues();
65 | values.put(DatabaseHelper.COLUMN_NAME, "");
66 | values.put(DatabaseHelper.COLUMN_TEXT, "");
67 | long noteId = db.insert(DatabaseHelper.TABLE, null, values);
68 |
69 | Intent intent = new Intent(getApplicationContext(), NoteEditorActivity.class);
70 | intent.putExtra("id", noteId);
71 | intent.putExtra("editing", true);
72 | startActivity(intent);
73 |
74 | notes.add(currentNote = new Note(noteId, ""));
75 | });
76 |
77 | db = new DatabaseHelper(this).getWritableDatabase();
78 |
79 | try (Cursor cursor = db.query(DatabaseHelper.TABLE,
80 | new String[]{DatabaseHelper.COLUMN_ID, DatabaseHelper.COLUMN_NAME},
81 | null, null, null, null, null)) {
82 |
83 | while (cursor.moveToNext()) {
84 | notes.add(new Note(cursor.getLong(0), cursor.getString(1)));
85 | }
86 | }
87 |
88 | adapter = new NotesAdapter(this, notes, selected);
89 |
90 | binding.notesList.addItemDecoration(new GridSpacingItemDecoration(2,
91 | Math.round(3 * getResources().getDisplayMetrics().density)));
92 | binding.notesList.setAdapter(adapter);
93 |
94 | binding.notesList.scrollToPosition(notes.size() - 1);
95 | }
96 |
97 | @Override
98 | public boolean onOptionsItemSelected(@NonNull MenuItem item) {
99 | if (item.getItemId() == R.id.remove) {
100 | new MaterialAlertDialogBuilder(this, R.style.MaterialAlertDialog_Material3_Body_Text)
101 | .setTitle(R.string.remove)
102 | .setIcon(R.drawable.ic_baseline_delete_24)
103 | .setMessage(R.string.warning)
104 | .setPositiveButton(R.string.yes, (dialogInterface, i) -> {
105 | for (Note note : selected) {
106 | if (notes != adapter.notes)
107 | adapter.notes.remove(note);
108 |
109 | notes.remove(note);
110 | db.delete(DatabaseHelper.TABLE, "_id = ?",
111 | new String[]{String.valueOf(note.getId())});
112 | }
113 |
114 | adapter.notifyDataSetChanged();
115 | selected.clear();
116 | invalidateOptionsMenu();
117 | })
118 | .setNegativeButton(R.string.no, (dialogInterface, i) -> {
119 | })
120 | .show();
121 | return true;
122 | }
123 |
124 | return super.onOptionsItemSelected(item);
125 | }
126 |
127 | @Override
128 | public boolean onCreateOptionsMenu(Menu menu) {
129 | if (!selected.isEmpty()) {
130 | getMenuInflater().inflate(R.menu.main_selected_menu, menu);
131 | return true;
132 | }
133 |
134 | getMenuInflater().inflate(R.menu.main_search_menu, menu);
135 |
136 | SearchView searchView = (SearchView) menu.findItem(R.id.app_bar_search).getActionView();
137 |
138 | searchView.setOnSearchClickListener(v -> binding.fab.setVisibility(View.GONE));
139 | searchView.setOnCloseListener(listener);
140 |
141 | searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
142 | @Override
143 | public boolean onQueryTextSubmit(String search) {
144 | doSearch(search);
145 | return true;
146 | }
147 |
148 | @Override
149 | public boolean onQueryTextChange(String search) {
150 | doSearch(search);
151 | return true;
152 | }
153 |
154 | private void doSearch(String search) {
155 | List filtered = new ArrayList<>();
156 |
157 | search = search.trim().toLowerCase();
158 | for (Note note : notes) {
159 | if (Html.fromHtml(note.getText()).toString().toLowerCase().contains(search))
160 | filtered.add(note);
161 | }
162 |
163 | adapter = new NotesAdapter(MainActivity.this, filtered, selected);
164 |
165 | binding.notesList.setAdapter(adapter);
166 | binding.notesList.scrollToPosition(filtered.size() - 1);
167 | }
168 | });
169 |
170 | return true;
171 | }
172 |
173 | @Override
174 | protected void onResume() {
175 | super.onResume();
176 |
177 | if (currentNote == null)
178 | return;
179 |
180 | try (Cursor cursor = db.query(DatabaseHelper.TABLE,
181 | new String[]{DatabaseHelper.COLUMN_NAME},
182 | "_id = ?", new String[]{String.valueOf(currentNote.getId())}, null, null, null)) {
183 |
184 | while (cursor.moveToNext()) {
185 | int position = notes.indexOf(currentNote);
186 |
187 | Note newNote = new Note(currentNote.getId(), cursor.getString(0));
188 |
189 | notes.remove(position);
190 | notes.add(position, newNote);
191 |
192 | if (selected.contains(currentNote)) {
193 | selected.remove(currentNote);
194 | selected.add(newNote);
195 | }
196 |
197 | adapter.notifyItemChanged(position);
198 | binding.notesList.scrollToPosition(position);
199 |
200 | currentNote = null;
201 | }
202 | }
203 | }
204 |
205 | @Override
206 | public void onNoteClicked(Note note, int position) {
207 | Intent intent = new Intent(this, NoteEditorActivity.class);
208 |
209 | intent.putExtra("id", note.getId());
210 | intent.putExtra("editing", note.getText().isEmpty());
211 |
212 | startActivity(intent);
213 |
214 | currentNote = note;
215 |
216 | listener.onClose();
217 | }
218 |
219 | @Override
220 | public void onNoteSelected(Note note) {
221 | if (binding.fab.getVisibility() == View.VISIBLE)
222 | invalidateOptionsMenu();
223 | }
224 |
225 | @Override
226 | public void onBackPressed() {
227 | if (!selected.isEmpty()) {
228 | selected.clear();
229 | invalidateOptionsMenu();
230 | adapter.notifyDataSetChanged();
231 | return;
232 | }
233 | super.onBackPressed();
234 | }
235 | }
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 |
294 | Copyright (C)
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | , 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
--------------------------------------------------------------------------------