mirror of
https://github.com/SimpleMobileTools/Simple-Notes.git
synced 2025-06-05 17:00:23 +02:00
allow changing text gravity
This commit is contained in:
@ -26,6 +26,10 @@ class Config(context: Context) {
|
||||
get() = mPrefs.getInt(FONT_SIZE, FONT_SIZE_MEDIUM)
|
||||
set(size) = mPrefs.edit().putInt(FONT_SIZE, size).apply()
|
||||
|
||||
var gravity: Int
|
||||
get() = mPrefs.getInt(GRAVITY, GRAVITY_LEFT)
|
||||
set(size) = mPrefs.edit().putInt(GRAVITY, size).apply()
|
||||
|
||||
var currentNoteId: Int
|
||||
get() = mPrefs.getInt(CURRENT_NOTE_ID, 1)
|
||||
set(id) = mPrefs.edit().putInt(CURRENT_NOTE_ID, id).apply()
|
||||
|
@ -10,9 +10,15 @@ val IS_DARK_THEME = "is_dark_theme"
|
||||
val CURRENT_NOTE_ID = "current_note_id"
|
||||
val WIDGET_NOTE_ID = "widget_note_id"
|
||||
val FONT_SIZE = "font_size"
|
||||
val GRAVITY = "gravity"
|
||||
val WIDGET_BG_COLOR = "widget_bg_color"
|
||||
val WIDGET_TEXT_COLOR = "widget_text_color"
|
||||
|
||||
// gravity
|
||||
val GRAVITY_LEFT = 0
|
||||
val GRAVITY_CENTER = 1
|
||||
val GRAVITY_RIGHT = 2
|
||||
|
||||
// font sizes
|
||||
val FONT_SIZE_SMALL = 0
|
||||
val FONT_SIZE_MEDIUM = 1
|
||||
|
@ -54,7 +54,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
||||
private fun updateWidget(widgetManager: AppWidgetManager, widgetId: Int, remoteViews: RemoteViews) {
|
||||
val widgetNoteId = mPrefs.getInt(WIDGET_NOTE_ID, 1)
|
||||
val note = mDb.getNote(widgetNoteId)
|
||||
remoteViews.setTextViewText(R.id.notes_view, if (note != null) note.value else "")
|
||||
remoteViews.setTextViewText(R.id.notes_view, note?.value ?: "")
|
||||
widgetManager.updateAppWidget(widgetId, remoteViews)
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ class SettingsActivity : SimpleActivity() {
|
||||
setupDarkTheme()
|
||||
setupFontSize()
|
||||
setupWidgetNote()
|
||||
setupGravity()
|
||||
}
|
||||
|
||||
private fun setupDarkTheme() {
|
||||
@ -66,6 +67,18 @@ class SettingsActivity : SimpleActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupGravity() {
|
||||
settings_gravity.setSelection(config.gravity)
|
||||
settings_gravity.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
config.gravity = settings_gravity.selectedItemPosition
|
||||
}
|
||||
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getNoteIndexWithId(id: Int, notes: List<Note>): Int {
|
||||
for (i in 0..notes.count() - 1) {
|
||||
if (notes[i].id == id) {
|
||||
|
@ -5,6 +5,7 @@ import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.TypedValue
|
||||
import android.view.Gravity
|
||||
import com.simplemobiletools.notes.*
|
||||
|
||||
fun Context.getTextSize() =
|
||||
@ -15,6 +16,12 @@ fun Context.getTextSize() =
|
||||
else -> resources.getDimension(R.dimen.medium_text_size)
|
||||
}
|
||||
|
||||
fun Context.getTextGravity() =
|
||||
when (Config.newInstance(this).gravity) {
|
||||
GRAVITY_CENTER -> Gravity.CENTER_HORIZONTAL
|
||||
GRAVITY_RIGHT -> Gravity.RIGHT
|
||||
else -> Gravity.LEFT
|
||||
}
|
||||
|
||||
fun Context.updateWidget() {
|
||||
val widgetManager = AppWidgetManager.getInstance(this)
|
||||
|
@ -10,6 +10,7 @@ import com.simplemobiletools.filepicker.extensions.value
|
||||
import com.simplemobiletools.notes.NOTE_ID
|
||||
import com.simplemobiletools.notes.R
|
||||
import com.simplemobiletools.notes.databases.DBHelper
|
||||
import com.simplemobiletools.notes.extensions.getTextGravity
|
||||
import com.simplemobiletools.notes.extensions.getTextSize
|
||||
import com.simplemobiletools.notes.extensions.updateWidget
|
||||
import com.simplemobiletools.notes.models.Note
|
||||
@ -44,6 +45,7 @@ class NoteFragment : Fragment() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
view.notes_view.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getTextSize())
|
||||
view.notes_view.gravity = context.getTextGravity()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
Reference in New Issue
Block a user