From f18a223f8b745cc5b2eafafb090a425e4f7728c8 Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Wed, 29 Sep 2021 19:49:48 +0200 Subject: [PATCH] Added monospaced font to widgets (#292) --- .../notes/pro/activities/SettingsActivity.kt | 1 + .../pro/activities/WidgetConfigureActivity.kt | 2 ++ .../notes/pro/adapters/WidgetAdapter.kt | 19 ++++++++---- .../main/res/layout/widget_text_layout.xml | 30 +++++++++++++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt index 0d34e553..50717c61 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/SettingsActivity.kt @@ -109,6 +109,7 @@ class SettingsActivity : SimpleActivity() { settings_monospaced_font_holder.setOnClickListener { settings_monospaced_font.toggle() config.monospacedFont = settings_monospaced_font.isChecked + updateWidgets() } } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt index be3f203f..116fd695 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/activities/WidgetConfigureActivity.kt @@ -4,6 +4,7 @@ import android.app.Activity import android.appwidget.AppWidgetManager import android.content.Intent import android.graphics.Color +import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.util.TypedValue @@ -166,6 +167,7 @@ class WidgetConfigureActivity : SimpleActivity() { } else { val sampleValue = if (note.value.isEmpty() || mIsCustomizingColors) getString(R.string.widget_config) else note.value text_note_view.text = sampleValue + text_note_view.typeface = if (config.monospacedFont) Typeface.MONOSPACE else Typeface.DEFAULT text_note_view.beVisible() checklist_note_view.beGone() } diff --git a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/WidgetAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/WidgetAdapter.kt index 0c0064d7..1877c768 100644 --- a/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/WidgetAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/notes/pro/adapters/WidgetAdapter.kt @@ -23,7 +23,8 @@ import com.simplemobiletools.notes.pro.models.ChecklistItem import com.simplemobiletools.notes.pro.models.Note class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsService.RemoteViewsFactory { - private val textIds = arrayOf(R.id.widget_text_left, R.id.widget_text_center, R.id.widget_text_right) + private val textIds = arrayOf(R.id.widget_text_left, R.id.widget_text_center, R.id.widget_text_right, + R.id.widget_text_left_monospace, R.id.widget_text_center_monospace, R.id.widget_text_right_monospace) private var widgetTextColor = DEFAULT_WIDGET_TEXT_COLOR private var note: Note? = null private var checklistItems = ArrayList<ChecklistItem>() @@ -75,10 +76,18 @@ class WidgetAdapter(val context: Context, val intent: Intent) : RemoteViewsServi return remoteView } - private fun getProperTextView(context: Context) = when (context.config.gravity) { - GRAVITY_CENTER -> R.id.widget_text_center - GRAVITY_RIGHT -> R.id.widget_text_right - else -> R.id.widget_text_left + private fun getProperTextView(context: Context): Int { + val gravity = context.config.gravity + val isMonospaced = context.config.monospacedFont + + return when { + gravity == GRAVITY_CENTER && isMonospaced -> R.id.widget_text_center_monospace + gravity == GRAVITY_CENTER -> R.id.widget_text_center + gravity == GRAVITY_RIGHT && isMonospaced -> R.id.widget_text_right_monospace + gravity == GRAVITY_RIGHT -> R.id.widget_text_right + isMonospaced -> R.id.widget_text_left_monospace + else -> R.id.widget_text_left + } } override fun onCreate() {} diff --git a/app/src/main/res/layout/widget_text_layout.xml b/app/src/main/res/layout/widget_text_layout.xml index dcdabc3b..c5a9032a 100644 --- a/app/src/main/res/layout/widget_text_layout.xml +++ b/app/src/main/res/layout/widget_text_layout.xml @@ -31,4 +31,34 @@ android:padding="@dimen/small_margin" android:visibility="gone" /> + <TextView + android:id="@+id/widget_text_left_monospace" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@null" + android:gravity="start" + android:fontFamily="monospace" + android:padding="@dimen/small_margin" + android:visibility="gone" /> + + <TextView + android:id="@+id/widget_text_center_monospace" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@null" + android:gravity="center_horizontal" + android:fontFamily="monospace" + android:padding="@dimen/small_margin" + android:visibility="gone" /> + + <TextView + android:id="@+id/widget_text_right_monospace" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@null" + android:gravity="end" + android:fontFamily="monospace" + android:padding="@dimen/small_margin" + android:visibility="gone" /> + </RelativeLayout>