diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/Config.kt b/app/src/main/kotlin/com/simplemobiletools/notes/Config.kt index 4833bbeb..ef950783 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/Config.kt @@ -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() diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt index d32cd431..e8d97b86 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/Constants.kt @@ -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 diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/MyWidgetProvider.kt b/app/src/main/kotlin/com/simplemobiletools/notes/MyWidgetProvider.kt index 1512fa37..5d798333 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/MyWidgetProvider.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/MyWidgetProvider.kt @@ -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) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt index 4e4d9ead..4acd808a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/activities/SettingsActivity.kt @@ -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): Int { for (i in 0..notes.count() - 1) { if (notes[i].id == id) { diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/notes/extensions/Context.kt index 2512bc33..e3eca940 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/extensions/Context.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt index 069f6f25..4655a6e1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/fragments/NoteFragment.kt @@ -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() { diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 141b8f4b..ffb76906 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -64,6 +64,33 @@ + + + + + + + + diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 027564dd..0587b795 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -30,6 +30,10 @@ Normal Groß Sehr groß + Gravity + Left + Center + Right Über diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5b62595f..fd314382 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -30,6 +30,10 @@ Normal Grande Enorme + Gravity + Left + Center + Right Acerca de Simple Notes diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 3ea5993a..46aa3d1a 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -30,6 +30,10 @@ Normal Large Extra Large + Gravity + Left + Center + Right Informazioni diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 4ed141ed..0b4768e0 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -30,6 +30,10 @@ 通常 特大 + Gravity + Left + Center + Right アプリについて diff --git a/app/src/main/res/values-pt-rPT/strings.xml b/app/src/main/res/values-pt-rPT/strings.xml index 0a183497..3a4e0707 100644 --- a/app/src/main/res/values-pt-rPT/strings.xml +++ b/app/src/main/res/values-pt-rPT/strings.xml @@ -30,6 +30,10 @@ Normal Grande Muito grande + Gravity + Left + Center + Right Acerca diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index af65fbdf..5c1fffef 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -30,6 +30,10 @@ Normal Large Extra Large + Gravity + Left + Center + Right Om diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index b1c8ff1a..f861147c 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -6,4 +6,10 @@ @string/large @string/extra_large + + + @string/left + @string/center + @string/right + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 32361725..c16a69db 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,12 +24,16 @@ Settings Dark theme - Note font size Note used in widget + Note font size Small Normal Large Extra Large + Gravity + Left + Center + Right About