Skip to content
This repository was archived by the owner on Jun 22, 2025. It is now read-only.

Commit d7a0483

Browse files
committed
added bg color picker
1 parent 38d686b commit d7a0483

File tree

14 files changed

+362
-14
lines changed

14 files changed

+362
-14
lines changed

app/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ android {
1414
applicationId "com.jjewuz.justnotes"
1515
minSdk 30
1616
targetSdk 35
17-
versionCode 204
18-
versionName "5.8.1"
17+
versionCode 205
18+
versionName "5.8.2"
1919

2020
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
2121

@@ -101,10 +101,12 @@ dependencies {
101101

102102
testImplementation "junit:junit:$rootProject.junitVersion"
103103
androidTestImplementation "androidx.arch.core:core-testing:$rootProject.coreTestingVersion"
104-
androidTestImplementation ("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
104+
androidTestImplementation("androidx.test.espresso:espresso-core:$rootProject.espressoVersion", {
105105
exclude group: 'com.android.support', module: 'support-annotations'
106106
})
107107
androidTestImplementation "androidx.test.ext:junit:$rootProject.androidxJunitVersion"
108108

109109
implementation 'de.raphaelebner:roomdatabasebackup:1.0.0-beta13'
110+
111+
implementation "com.google.ai.edge.litert:litert:1.1.2"
110112
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"formatVersion": 1,
3+
"database": {
4+
"version": 5,
5+
"identityHash": "04f17c700b43eb6d0a0b8c9509ddba6c",
6+
"entities": [
7+
{
8+
"tableName": "notesTable",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`Title` TEXT NOT NULL, `description` TEXT NOT NULL, `timestamp` TEXT NOT NULL, `security` TEXT NOT NULL DEFAULT '', `label` TEXT NOT NULL DEFAULT '', `categoryId` INTEGER, `bgId` INTEGER NOT NULL DEFAULT -1, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL)",
10+
"fields": [
11+
{
12+
"fieldPath": "noteTitle",
13+
"columnName": "Title",
14+
"affinity": "TEXT",
15+
"notNull": true
16+
},
17+
{
18+
"fieldPath": "noteDescription",
19+
"columnName": "description",
20+
"affinity": "TEXT",
21+
"notNull": true
22+
},
23+
{
24+
"fieldPath": "timeStamp",
25+
"columnName": "timestamp",
26+
"affinity": "TEXT",
27+
"notNull": true
28+
},
29+
{
30+
"fieldPath": "security",
31+
"columnName": "security",
32+
"affinity": "TEXT",
33+
"notNull": true,
34+
"defaultValue": "''"
35+
},
36+
{
37+
"fieldPath": "label",
38+
"columnName": "label",
39+
"affinity": "TEXT",
40+
"notNull": true,
41+
"defaultValue": "''"
42+
},
43+
{
44+
"fieldPath": "categoryId",
45+
"columnName": "categoryId",
46+
"affinity": "INTEGER",
47+
"notNull": false
48+
},
49+
{
50+
"fieldPath": "bgId",
51+
"columnName": "bgId",
52+
"affinity": "INTEGER",
53+
"notNull": true,
54+
"defaultValue": "-1"
55+
},
56+
{
57+
"fieldPath": "id",
58+
"columnName": "id",
59+
"affinity": "INTEGER",
60+
"notNull": true
61+
}
62+
],
63+
"primaryKey": {
64+
"autoGenerate": true,
65+
"columnNames": [
66+
"id"
67+
]
68+
},
69+
"indices": [],
70+
"foreignKeys": []
71+
},
72+
{
73+
"tableName": "categories",
74+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT NOT NULL)",
75+
"fields": [
76+
{
77+
"fieldPath": "id",
78+
"columnName": "id",
79+
"affinity": "INTEGER",
80+
"notNull": true
81+
},
82+
{
83+
"fieldPath": "name",
84+
"columnName": "name",
85+
"affinity": "TEXT",
86+
"notNull": true
87+
}
88+
],
89+
"primaryKey": {
90+
"autoGenerate": true,
91+
"columnNames": [
92+
"id"
93+
]
94+
},
95+
"indices": [],
96+
"foreignKeys": []
97+
}
98+
],
99+
"views": [],
100+
"setupQueries": [
101+
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
102+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '04f17c700b43eb6d0a0b8c9509ddba6c')"
103+
]
104+
}
105+
}

app/src/main/java/com/jjewuz/justnotes/Activities/AddEditNoteActivity.kt

Lines changed: 133 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ import android.content.ContentValues
1010
import android.content.Context
1111
import android.content.Intent
1212
import android.content.SharedPreferences
13+
import android.content.res.Configuration
14+
import android.graphics.Color
1315
import android.net.Uri
1416
import android.os.Bundle
1517
import android.os.Environment
1618
import android.provider.MediaStore
1719
import android.text.Editable
1820
import android.text.Html
1921
import android.text.TextWatcher
22+
import android.view.LayoutInflater
2023
import android.view.Menu
2124
import android.view.MenuInflater
2225
import android.view.MenuItem
@@ -28,6 +31,8 @@ import android.widget.ArrayAdapter
2831
import android.widget.Button
2932
import android.widget.EditText
3033
import android.widget.FrameLayout
34+
import android.widget.GridLayout
35+
import android.widget.ImageView
3136
import android.widget.LinearLayout
3237
import android.widget.Spinner
3338
import android.widget.TextView
@@ -36,13 +41,16 @@ import androidx.activity.enableEdgeToEdge
3641
import androidx.activity.result.contract.ActivityResultContracts
3742
import androidx.activity.viewModels
3843
import androidx.appcompat.app.AppCompatActivity
44+
import androidx.coordinatorlayout.widget.CoordinatorLayout
3945
import androidx.core.content.ContextCompat
46+
import androidx.core.graphics.drawable.toDrawable
47+
import androidx.core.graphics.toColor
4048
import androidx.core.text.toHtml
4149
import androidx.core.view.ViewCompat
42-
import androidx.core.view.WindowCompat
4350
import androidx.core.view.WindowInsetsCompat
4451
import androidx.core.widget.NestedScrollView
4552
import androidx.lifecycle.ViewModelProvider
53+
import com.google.android.material.appbar.MaterialToolbar
4654
import com.google.android.material.bottomappbar.BottomAppBar
4755
import com.google.android.material.bottomsheet.BottomSheetBehavior
4856
import com.google.android.material.dialog.MaterialAlertDialogBuilder
@@ -57,16 +65,19 @@ import com.jjewuz.justnotes.Notes.NoteDatabase
5765
import com.jjewuz.justnotes.Notes.NoteViewModal
5866
import com.jjewuz.justnotes.Notes.NoteWidget
5967
import com.jjewuz.justnotes.R
68+
import com.jjewuz.justnotes.Utils.MobileBertInterpreter
6069
import com.jjewuz.justnotes.Utils.TextHelper
6170
import com.jjewuz.justnotes.Utils.Utils
6271
import com.jjewuz.justnotes.Utils.Utils.colorFormatting
6372
import com.jjewuz.justnotes.Utils.Utils.hideKeyboard
6473
import com.jjewuz.justnotes.Utils.Utils.textFormatting
74+
import com.jjewuz.justnotes.Utils.WordPieceTokenizer
6575
import java.io.BufferedReader
6676
import java.io.InputStreamReader
6777
import java.text.SimpleDateFormat
6878
import java.util.Date
6979
import java.util.Locale
80+
import androidx.core.graphics.toColorInt
7081

7182
class AddEditNoteActivity : AppCompatActivity() {
7283

@@ -75,6 +86,9 @@ class AddEditNoteActivity : AppCompatActivity() {
7586
private lateinit var savedTxt: TextView
7687
private lateinit var bottomAppBar: BottomAppBar
7788
private lateinit var bottomSheet: FrameLayout
89+
private var bgId: Int = -1
90+
private lateinit var bg: CoordinatorLayout
91+
private lateinit var topBar: MaterialToolbar
7892

7993
private var label = ""
8094

@@ -128,7 +142,8 @@ class AddEditNoteActivity : AppCompatActivity() {
128142
setTheme(R.style.BlackIce)
129143
}
130144
setContentView(R.layout.activity_add_edit_note)
131-
setSupportActionBar(findViewById(R.id.topAppBar))
145+
topBar = findViewById(R.id.topAppBar)
146+
setSupportActionBar(topBar)
132147
supportActionBar?.title = ""
133148

134149
enableEdgeToEdge()
@@ -146,6 +161,7 @@ class AddEditNoteActivity : AppCompatActivity() {
146161
bottomAppBar = findViewById(R.id.bottomAppBar)
147162
bottomSheet = findViewById(R.id.standard_bottom_sheet)
148163
scrollView = findViewById(R.id.nestedScrollView)
164+
bg = findViewById(R.id.holder)
149165

150166
categorySpinner = findViewById(R.id.categorySpinner)
151167

@@ -277,6 +293,8 @@ class AddEditNoteActivity : AppCompatActivity() {
277293
noteLock = intent.getStringExtra("security").toString()
278294
noteTitleEdt.setText(noteTitle)
279295
supportActionBar?.title = ""
296+
bgId = intent.getIntExtra("bgId", -1)
297+
setBgColorFromId(bgId)
280298
savedTxt.text = resources.getString(R.string.saved) + ": " + currentDateAndTime
281299
noteEdt.setText(noteDescription?.let { Utils.fromHtml(it) })
282300
isEditable = false
@@ -469,9 +487,6 @@ class AddEditNoteActivity : AppCompatActivity() {
469487
.show()
470488
true
471489
}
472-
R.id.labels -> {
473-
true
474-
}
475490
R.id.copy_text -> {
476491
val clipboard = this.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
477492
val clip = ClipData.newPlainText("UID", getText())
@@ -491,6 +506,49 @@ class AddEditNoteActivity : AppCompatActivity() {
491506
scrollView.fullScroll(View.FOCUS_DOWN)
492507
true
493508
}
509+
R.id.choose_bg -> {
510+
showColorPickerDialog(this) { selectedColorId ->
511+
hasChanges = true
512+
setBgColorFromId(selectedColorId)
513+
bgId = selectedColorId
514+
saveNote(false)
515+
}
516+
true
517+
}
518+
R.id.ai -> {
519+
/*val tokenizer = WordPieceTokenizer(this)
520+
val bert = MobileBertInterpreter(this)
521+
val text = getText()
522+
523+
val tokens: IntArray = tokenizer.tokenize(text).toIntArray()
524+
525+
val maxSequenceLength = 512
526+
527+
val paddedTokens = if (tokens.size > maxSequenceLength) {
528+
tokens.take(maxSequenceLength).toIntArray() // Обрезаем до maxSequenceLength
529+
} else {
530+
tokens + IntArray(maxSequenceLength - tokens.size) { 0 }
531+
}
532+
533+
val reshapedInput: Array<Array<FloatArray>> = arrayOf(
534+
arrayOf(paddedTokens.map { it.toFloat() }.toFloatArray()) // Преобразуем IntArray в FloatArray
535+
)
536+
537+
val result: Array<Array<FloatArray>> = bert.predict(reshapedInput)
538+
539+
val output = result[0][0]
540+
541+
val summary = output.take(10).joinToString(", ") { it.toString() }
542+
543+
MaterialAlertDialogBuilder(this)
544+
.setTitle("AI сводка")
545+
.setIcon(R.drawable.info)
546+
.setMessage(summary)
547+
.setPositiveButton("OK") { _, _ -> }
548+
.show()
549+
*/
550+
true
551+
}
494552
else -> super.onOptionsItemSelected(item)
495553
}
496554
}
@@ -513,6 +571,7 @@ class AddEditNoteActivity : AppCompatActivity() {
513571
var noteTitle = noteTitleEdt.text.toString()
514572
val noteDescription = noteEdt.text
515573
val selectedCategory = categorySpinner.selectedItem as Category
574+
val bg = bgId
516575

517576
if (noteDescription.isNotEmpty() or noteTitle.isNotEmpty()) {
518577

@@ -524,15 +583,15 @@ class AddEditNoteActivity : AppCompatActivity() {
524583
if (noteTitle.isEmpty()) {
525584
noteTitle = emptyTitle
526585
}
527-
val updatedNote = Note(noteTitle, noteDescription.toHtml(), date.toString(), noteLock, label, selectedCategory.id)
586+
val updatedNote = Note(noteTitle, noteDescription.toHtml(), date.toString(), noteLock, label, selectedCategory.id, bg)
528587
updatedNote.id = noteID
529588
viewModal.updateNote(updatedNote)
530589
} else {
531590
if (!added){
532591
if (noteTitle.isEmpty()) {
533592
noteTitle = emptyTitle
534593
}
535-
viewModal.addNote(Note(noteTitle, noteDescription.toHtml(), date.toString(), noteLock, label, selectedCategory.id))
594+
viewModal.addNote(Note(noteTitle, noteDescription.toHtml(), date.toString(), noteLock, label, selectedCategory.id, bg))
536595
added = true
537596
}
538597

@@ -622,6 +681,73 @@ class AddEditNoteActivity : AppCompatActivity() {
622681
}
623682
}
624683

684+
685+
private fun setBgColorFromId(selectedColorId: Int){
686+
val selectedColor = if (selectedColorId == -1) null else {
687+
val isDarkTheme = (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
688+
val colors = if (isDarkTheme) resources.getIntArray(R.array.note_colors_dark)
689+
else resources.getIntArray(R.array.note_colors_light)
690+
colors[selectedColorId]
691+
}
692+
if (selectedColor == null) {
693+
bg.setBackgroundColor("#00000000".toColorInt())
694+
topBar.setBackgroundColor("#00000000".toColorInt())
695+
} else {
696+
topBar.setBackgroundColor(selectedColor)
697+
bg.setBackgroundColor(selectedColor)
698+
}
699+
}
700+
701+
private fun showColorPickerDialog(context: Context, onColorSelected: (Int) -> Unit) {
702+
// Определяем текущую тему
703+
val isDarkTheme = (context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES
704+
705+
// Загружаем массив цветов в зависимости от темы
706+
val lightColors = context.resources.getIntArray(R.array.note_colors_light)
707+
val darkColors = context.resources.getIntArray(R.array.note_colors_dark)
708+
val colors = if (isDarkTheme) darkColors else lightColors
709+
710+
// Создаем список идентификаторов цветов (-1 для "Без фона", 0-8 для остальных)
711+
val allColors = IntArray(colors.size + 1).apply {
712+
this[0] = -1 // "Без фона"
713+
for (i in colors.indices) {
714+
this[i + 1] = i // Записываем индекс цвета (0-8)
715+
}
716+
}
717+
718+
// Создаем View для диалога
719+
val dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_color_picker, null)
720+
val container = dialogView.findViewById<GridLayout>(R.id.color_container)
721+
722+
// Устанавливаем количество столбцов (например, 3 или 4)
723+
container.columnCount = 4
724+
725+
for ((index, color) in allColors.withIndex()) {
726+
val circleView = LayoutInflater.from(context).inflate(R.layout.item_color_circle, container, false) as ImageView
727+
728+
if (color == -1) {
729+
} else {
730+
circleView.setColorFilter(colors[color])
731+
}
732+
733+
circleView.setOnClickListener {
734+
onColorSelected(if (index == 0) -1 else index - 1)
735+
}
736+
737+
container.addView(circleView)
738+
}
739+
740+
// Показываем диалог
741+
MaterialAlertDialogBuilder(context)
742+
.setTitle("Выберите фон заметки")
743+
.setView(dialogView)
744+
.setNegativeButton("Отмена", null)
745+
.show()
746+
}
747+
748+
749+
750+
625751
//Auto-saving note
626752
override fun onPause() {
627753
saveNote(false)

0 commit comments

Comments
 (0)