From 183901534ce6e52b335da616712bc0796cb3e42e Mon Sep 17 00:00:00 2001 From: azuo Date: Fri, 17 Sep 2021 12:01:41 +0800 Subject: [PATCH] Correct the widget layout. Adjust the layout carefully, so that remote grid views perfectly overlap the bitmap generated from the binding view, whether left-aligned, right-aligned or centered, and regardless of the size of the widget, text, margins or spacing. Display the clock in the correct text size. --- .../anotherwidget/db/EventRepository.kt | 6 ++ .../anotherwidget/global/Preferences.kt | 6 +- .../anotherwidget/helpers/BitmapHelper.kt | 6 +- .../anotherwidget/helpers/WidgetHelper.kt | 11 +++- .../ui/fragments/MainFragment.kt | 6 +- .../ui/fragments/tabs/CalendarFragment.kt | 1 + .../ui/fragments/tabs/ClockFragment.kt | 2 +- .../ui/fragments/tabs/TypographyFragment.kt | 11 ++++ .../anotherwidget/ui/widgets/AlignedWidget.kt | 57 +++++++++++-------- .../anotherwidget/ui/widgets/ClockWidget.kt | 20 +++++-- .../anotherwidget/ui/widgets/MainWidget.kt | 10 +--- .../ui/widgets/StandardWidget.kt | 49 ++++++++-------- app/src/main/res/layout/fragment_app_main.xml | 3 +- .../main/res/layout/left_aligned_widget.xml | 30 +++++----- .../res/layout/left_aligned_widget_sans.xml | 25 ++++---- .../res/layout/right_aligned_widget_sans.xml | 28 +++++---- app/src/main/res/layout/the_widget.xml | 33 ++++++----- app/src/main/res/layout/the_widget_sans.xml | 32 +++++------ 18 files changed, 187 insertions(+), 149 deletions(-) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/db/EventRepository.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/db/EventRepository.kt index 9811857..7d32eb5 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/db/EventRepository.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/db/EventRepository.kt @@ -106,6 +106,9 @@ class EventRepository(val context: Context) { resetNextEventData() } MainWidget.updateWidget(context) + org.greenrobot.eventbus.EventBus.getDefault().post( + com.tommasoberlose.anotherwidget.ui.fragments.MainFragment.UpdateUiMessageEvent() + ) } fun goToPreviousEvent() { @@ -121,6 +124,9 @@ class EventRepository(val context: Context) { resetNextEventData() } MainWidget.updateWidget(context) + org.greenrobot.eventbus.EventBus.getDefault().post( + com.tommasoberlose.anotherwidget.ui.fragments.MainFragment.UpdateUiMessageEvent() + ) } fun getFutureEvents(): List { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt index 1fab87e..d23bf01 100755 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/global/Preferences.kt @@ -93,9 +93,9 @@ object Preferences : KotprefModel() { var altTimezoneId by stringPref(default = "") // Global - var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 26f) - var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 18f) - var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 26f) + var textMainSize by floatPref(key = "PREF_TEXT_MAIN_SIZE", default = 24f) + var textSecondSize by floatPref(key = "PREF_TEXT_SECOND_SIZE", default = 16f) + var clockTextSize by floatPref(key = "PREF_TEXT_CLOCK_SIZE", default = 72f) var clockBottomMargin by intPref(default = Constants.ClockBottomMargin.MEDIUM.rawValue) var secondRowTopMargin by intPref(default = Constants.SecondRowTopMargin.NONE.rawValue) var showClock by booleanPref(key = "PREF_SHOW_CLOCK", default = false) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/BitmapHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/BitmapHelper.kt index 3ba2239..5b83982 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/BitmapHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/BitmapHelper.kt @@ -44,8 +44,8 @@ object BitmapHelper { FirebaseCrashlytics.getInstance().setCustomKey("HEIGHT SPEC", measuredHeight) FirebaseCrashlytics.getInstance().setCustomKey("VIEW measuredWidth", view.measuredWidth) FirebaseCrashlytics.getInstance().setCustomKey("VIEW measuredHeight", view.measuredHeight) - FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final width", measuredWidth) - FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final height", view.measuredHeight) + FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final width", widgetWidth) + FirebaseCrashlytics.getInstance().setCustomKey("WIDGET final height", widgetHeight) } return try { @@ -58,7 +58,7 @@ object BitmapHelper { //Bind a canvas to it val canvas = Canvas(btm) // draw the view on the canvas - view.layout(0, 0, measuredWidth, measuredHeight) + view.layout(0, 0, widgetWidth, widgetHeight) view.draw(canvas) //return the bitmap } diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/WidgetHelper.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/WidgetHelper.kt index 20fd92d..4548ed2 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/WidgetHelper.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/helpers/WidgetHelper.kt @@ -25,8 +25,15 @@ object WidgetHelper { ) { fun getWidgetsSize(widgetId: Int): Pair { - val width = getWidgetWidth(widgetId) - val height = getWidgetHeight(widgetId) + val portrait = context.resources.configuration.orientation == ORIENTATION_PORTRAIT + val width = getWidgetSizeInDp( + widgetId, + if (portrait) AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH else AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH + ) + val height = getWidgetSizeInDp( + widgetId, + if (portrait) AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT else AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT + ) val widthInPx = context.dip(width) val heightInPx = context.dip(height) FirebaseCrashlytics.getInstance().setCustomKey("widthInPx", widthInPx) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt index d18049b..6aff19d 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/MainFragment.kt @@ -153,7 +153,11 @@ class MainFragment : Fragment() { WidgetHelper.runWithCustomTypeface(requireContext()) { typeface -> uiJob?.cancel() uiJob = lifecycleScope.launch(Dispatchers.IO) { - val generatedView = MainWidget.getWidgetView(requireContext(), binding.widget.width, typeface) + val generatedView = MainWidget.getWidgetView( + requireContext(), + binding.widget.width - binding.widget.paddingStart - binding.widget.paddingEnd, + typeface + ) if (generatedView != null) { withContext(Dispatchers.Main) { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt index b6b7034..49f5ef7 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/CalendarFragment.kt @@ -236,6 +236,7 @@ class CalendarFragment : Fragment() { binding.showDiffTimeToggle.setOnCheckedChangeListener { _, isChecked -> Preferences.showDiffTime = isChecked + updateCalendar() } binding.actionShowNextEventOnMultipleLines.setOnClickListener { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt index 57720c4..a12cc58 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/ClockFragment.kt @@ -146,7 +146,7 @@ class ClockFragment : Fragment() { binding.actionClockTextSize.setOnClickListener { BottomSheetPicker( requireContext(), - items = (46 downTo 12).map { BottomSheetPicker.MenuItem("${it}sp", it.toFloat()) }, + items = (120 downTo 30).filter { it % 2 == 0 }.map { BottomSheetPicker.MenuItem("${it}sp", it.toFloat()) }, getSelected = { Preferences.clockTextSize }, header = getString(R.string.settings_clock_text_size_title), onItemSelected = {value -> diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt index 3c73378..56a428e 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/fragments/tabs/TypographyFragment.kt @@ -317,6 +317,17 @@ class TypographyFragment : Fragment() { } } + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + if (resultCode == android.app.Activity.RESULT_OK) { + when (requestCode) { + RequestCode.CUSTOM_FONT_CHOOSER_REQUEST_CODE.code -> { + com.tommasoberlose.anotherwidget.ui.widgets.MainWidget.updateWidget(requireContext()) + } + } + } + super.onActivityResult(requestCode, resultCode, data) + } + private fun maintainScrollPosition(callback: () -> Unit) { binding.scrollView.isScrollable = false callback.invoke() diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/AlignedWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/AlignedWidget.kt index dab8f56..94a353e 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/AlignedWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/AlignedWidget.kt @@ -79,9 +79,10 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { try { val generatedBinding = generateWidgetView(typeface) ?: return null + val width = w - (Preferences.widgetPadding.convertDpToPixel(context) + Preferences.widgetMargin.convertDpToPixel(context)).toInt() * 2 views.setImageViewBitmap( R.id.bitmap_container, - BitmapHelper.getBitmapFromView(generatedBinding.root, width = w) + BitmapHelper.getBitmapFromView(generatedBinding.root, width) ) views = updateGridView(generatedBinding, views, appWidgetId) } catch (ex: Exception) { @@ -241,10 +242,6 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { views.setViewVisibility(R.id.sub_line_rect, View.VISIBLE) views.setViewVisibility(R.id.weather_sub_line_rect, if (Preferences.showWeather && Preferences.weatherIcon != "") View.VISIBLE else View.GONE) views.setViewVisibility(R.id.first_line_rect, View.GONE) - - views.setViewVisibility(R.id.sub_line_top_margin_small_sans, View.GONE) - views.setViewVisibility(R.id.sub_line_top_margin_medium_sans, View.GONE) - views.setViewVisibility(R.id.sub_line_top_margin_large_sans, View.GONE) } else if (GlanceProviderHelper.showGlanceProviders(context)) { var showSomething = false var isWeatherShown = false @@ -297,6 +294,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { } Constants.GlanceProviderId.CUSTOM_INFO -> { if (Preferences.customNotes.isNotEmpty()) { + showSomething = true break@loop } } @@ -601,9 +599,12 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { bindingView.subLine.isVisible = true bindingView.weatherSubLine.isVisible = Preferences.showWeather && Preferences.weatherIcon != "" - bindingView.subLineTopMarginSmall.visibility = View.GONE - bindingView.subLineTopMarginMedium.visibility = View.GONE - bindingView.subLineTopMarginLarge.visibility = View.GONE + bindingView.subLineTopMarginSmall.visibility = + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.SMALL.rawValue) View.VISIBLE else View.GONE + bindingView.subLineTopMarginMedium.visibility = + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.MEDIUM.rawValue) View.VISIBLE else View.GONE + bindingView.subLineTopMarginLarge.visibility = + if (Preferences.secondRowTopMargin == Constants.SecondRowTopMargin.LARGE.rawValue) View.VISIBLE else View.GONE } else if (GlanceProviderHelper.showGlanceProviders(context)) { bindingView.subLineIcon.isVisible = true var showSomething = false @@ -844,24 +845,30 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { bindingView.nextEvent to Preferences.textMainSize, bindingView.nextEventDifferenceTime to Preferences.textMainSize, bindingView.subLineText to Preferences.textSecondSize, - bindingView.weatherSubLineDivider to (Preferences.textSecondSize - 2), + bindingView.weatherSubLineDivider to (Preferences.textSecondSize * 0.9f), bindingView.weatherSubLineTemperature to Preferences.textSecondSize, ).forEach { it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second) + if (!it.first.includeFontPadding && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) + it.first.isFallbackLineSpacing = false } // Icons scale - bindingView.subLineIcon.scaleX = Preferences.textSecondSize / 18f - bindingView.subLineIcon.scaleY = Preferences.textSecondSize / 18f - - bindingView.weatherSubLineWeatherIcon.scaleX = Preferences.textSecondSize / 18f - bindingView.weatherSubLineWeatherIcon.scaleY = Preferences.textSecondSize / 18f - - bindingView.weatherDateLineWeatherIcon.scaleX = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f - bindingView.weatherDateLineWeatherIcon.scaleY = ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 20f - - bindingView.actionNext.scaleX = Preferences.textMainSize / 28f - bindingView.actionNext.scaleY = Preferences.textMainSize / 28f + listOf( + bindingView.subLineIcon to Preferences.textSecondSize / 16f, + bindingView.subLineIconShadow to Preferences.textSecondSize / 16f, + bindingView.weatherSubLineWeatherIcon to Preferences.textSecondSize / 16f, + bindingView.weatherDateLineWeatherIcon to ((Preferences.textMainSize + Preferences.textSecondSize) / 2) / 24f, + bindingView.actionNext to Preferences.textMainSize / 24f, + bindingView.actionNextShadow to Preferences.textMainSize / 24f + ).forEach { + if (it.first.tag == null) + it.first.tag = it.first.layoutParams.height + it.first.layoutParams = it.first.layoutParams.apply { + height = ((it.first.tag as Int) * it.second).roundToInt() + width = height + } + } // Shadows @@ -910,7 +917,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { it.second.isVisible = it.first.isVisible it.second.scaleX = it.first.scaleX it.second.scaleY = it.first.scaleY - it.second.applyShadow(it.first) + it.second.applyShadow(it.first, 0.7f) } } @@ -968,10 +975,7 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { // Dividers arrayOf(bindingView.weatherSubLineDivider).forEach { - it.visibility = if (Preferences.showDividers) View.VISIBLE else View.INVISIBLE - it.layoutParams = (it.layoutParams as ViewGroup.MarginLayoutParams).apply { - this.marginEnd = if (Preferences.showDividers) 8f.convertDpToPixel(context).toInt() else 0 - } + it.visibility = if (Preferences.showDividers) View.VISIBLE else View.GONE } // Right Aligned @@ -981,8 +985,11 @@ class AlignedWidget(val context: Context, val rightAligned: Boolean = false) { } bindingView.mainContent.gravity = Gravity.END bindingView.dateLayout.gravity = Gravity.END + bindingView.date.gravity = Gravity.END bindingView.calendarLayout.gravity = Gravity.END or Gravity.CENTER_VERTICAL + bindingView.nextEvent.gravity = Gravity.END bindingView.subLineContainer.gravity = Gravity.END or Gravity.CENTER_VERTICAL + bindingView.subLineText.gravity = Gravity.END } return bindingView diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/ClockWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/ClockWidget.kt index ca081a5..a2fa77e 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/ClockWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/ClockWidget.kt @@ -32,12 +32,12 @@ class ClockWidget(val context: Context) { views.setTextViewTextSize( R.id.time, TypedValue.COMPLEX_UNIT_SP, - Preferences.clockTextSize.toPixel(context) + Preferences.clockTextSize ) views.setTextViewTextSize( R.id.time_am_pm, TypedValue.COMPLEX_UNIT_SP, - Preferences.clockTextSize.toPixel(context) / 5 * 2 + Preferences.clockTextSize / 5 * 2 ) val clockPIntent = IntentHelper.getPendingIntent( context, @@ -80,19 +80,29 @@ class ClockWidget(val context: Context) { views.setTextViewTextSize( R.id.alt_timezone_time, TypedValue.COMPLEX_UNIT_SP, - Preferences.clockTextSize.toPixel(context) / 3 + Preferences.clockTextSize / 3 ) views.setTextViewTextSize( R.id.alt_timezone_time_am_pm, TypedValue.COMPLEX_UNIT_SP, - (Preferences.clockTextSize.toPixel(context) / 3) / 5 * 2 + (Preferences.clockTextSize / 3) / 5 * 2 ) views.setTextViewTextSize( R.id.alt_timezone_label, TypedValue.COMPLEX_UNIT_SP, - (Preferences.clockTextSize.toPixel(context) / 3) / 5 * 2 + (Preferences.clockTextSize / 3) / 5 * 2 ) + val padding = (TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_SP, + Preferences.clockTextSize, + context.resources.displayMetrics + ) * 0.2).toInt() + if (Preferences.widgetAlign == Constants.WidgetAlign.RIGHT.rawValue) + views.setViewPadding(R.id.timezones_container, 0, padding, padding, 0) + else + views.setViewPadding(R.id.timezones_container, padding, padding, 0,0) + views.setOnClickPendingIntent(R.id.timezones_container, clockPIntent) views.setViewVisibility(R.id.timezones_container, View.VISIBLE) } else { diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt index 6abf42c..484fd54 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/MainWidget.kt @@ -63,17 +63,13 @@ class MainWidget : AppWidgetProvider() { internal fun updateAppWidget(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int) { - val displayMetrics = Resources.getSystem().displayMetrics - val width = displayMetrics.widthPixels - val height = displayMetrics.heightPixels - val dimensions = WidgetHelper.WidgetSizeProvider(context, appWidgetManager).getWidgetsSize(appWidgetId) WidgetHelper.runWithCustomTypeface(context) { val views = when (Preferences.widgetAlign) { - Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it) - Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(context, rightAligned = true).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it) - else -> StandardWidget(context).generateWidget(appWidgetId, min(dimensions.first - 8.toPixel(context), min(width, height) - 16.toPixel(context)), it) + Constants.WidgetAlign.LEFT.rawValue -> AlignedWidget(context).generateWidget(appWidgetId, dimensions.first, it) + Constants.WidgetAlign.RIGHT.rawValue -> AlignedWidget(context, rightAligned = true).generateWidget(appWidgetId, dimensions.first, it) + else -> StandardWidget(context).generateWidget(appWidgetId, dimensions.first, it) } try { if (views != null) appWidgetManager.updateAppWidget(appWidgetId, views) diff --git a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/StandardWidget.kt b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/StandardWidget.kt index bbca281..77e23e9 100644 --- a/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/StandardWidget.kt +++ b/app/src/main/java/com/tommasoberlose/anotherwidget/ui/widgets/StandardWidget.kt @@ -82,9 +82,10 @@ class StandardWidget(val context: Context) { try { val generatedBinding = generateWidgetView(typeface) ?: return null + val width = w - (Preferences.widgetPadding.convertDpToPixel(context) + Preferences.widgetMargin.convertDpToPixel(context)).toInt() * 2 views.setImageViewBitmap( R.id.bitmap_container, - BitmapHelper.getBitmapFromView(generatedBinding.root, width = w) + BitmapHelper.getBitmapFromView(generatedBinding.root, width) ) views = updateGridView(generatedBinding, views, appWidgetId) } catch (ex: Exception) { @@ -325,6 +326,7 @@ class StandardWidget(val context: Context) { } Constants.GlanceProviderId.CUSTOM_INFO -> { if (Preferences.customNotes.isNotEmpty()) { + showSomething = true break@loop } } @@ -874,33 +876,37 @@ class StandardWidget(val context: Context) { // Text Size listOf>( bindingView.date to Preferences.textMainSize, - bindingView.weatherDateLineDivider to (Preferences.textMainSize - 2), + bindingView.weatherDateLineDivider to (Preferences.textMainSize * 0.9f), bindingView.weatherDateLineTemperature to Preferences.textMainSize, bindingView.nextEvent to Preferences.textMainSize, bindingView.nextEventDifferenceTime to Preferences.textMainSize, bindingView.subLineText to Preferences.textSecondSize, - bindingView.weatherSubLineDivider to (Preferences.textSecondSize - 2), + bindingView.weatherSubLineDivider to (Preferences.textSecondSize * 0.9f), bindingView.weatherSubLineTemperature to Preferences.textSecondSize, ).forEach { it.first.setTextSize(TypedValue.COMPLEX_UNIT_SP, it.second) + if (!it.first.includeFontPadding && android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) + it.first.isFallbackLineSpacing = false } // Icons scale - bindingView.subLineIcon.scaleX = Preferences.textSecondSize / 18f - bindingView.subLineIcon.scaleY = Preferences.textSecondSize / 18f - - bindingView.weatherSubLineWeatherIcon.scaleX = Preferences.textSecondSize / 18f - bindingView.weatherSubLineWeatherIcon.scaleY = Preferences.textSecondSize / 18f - - bindingView.weatherDateLineWeatherIcon.scaleX = Preferences.textMainSize / 18f - bindingView.weatherDateLineWeatherIcon.scaleY = Preferences.textMainSize / 18f - - bindingView.actionNext.scaleX = Preferences.textMainSize / 28f - bindingView.actionNext.scaleY = Preferences.textMainSize / 28f - - bindingView.actionPrevious.scaleX = Preferences.textMainSize / 28f - bindingView.actionPrevious.scaleY = Preferences.textMainSize / 28f - + listOf( + bindingView.subLineIcon to Preferences.textSecondSize / 16f, + bindingView.subLineIconShadow to Preferences.textSecondSize / 16f, + bindingView.weatherSubLineWeatherIcon to Preferences.textSecondSize / 16f, + bindingView.weatherDateLineWeatherIcon to Preferences.textMainSize / 24f, + bindingView.actionNext to Preferences.textMainSize / 24f, + bindingView.actionNextShadow to Preferences.textMainSize / 24f, + bindingView.actionPrevious to Preferences.textMainSize / 24f, + bindingView.actionPreviousShadow to Preferences.textMainSize / 24f + ).forEach { + if (it.first.tag == null) + it.first.tag = it.first.layoutParams.height + it.first.layoutParams = it.first.layoutParams.apply { + height = ((it.first.tag as Int) * it.second).roundToInt() + width = height + } + } // Shadows val shadowRadius = @@ -949,7 +955,7 @@ class StandardWidget(val context: Context) { it.second.isVisible = it.first.isVisible it.second.scaleX = it.first.scaleX it.second.scaleY = it.first.scaleY - it.second.applyShadow(it.first) + it.second.applyShadow(it.first, 0.7f) } } @@ -1013,10 +1019,7 @@ class StandardWidget(val context: Context) { // Dividers arrayOf(bindingView.weatherDateLineDivider, bindingView.weatherSubLineDivider).forEach { - it.visibility = if (Preferences.showDividers) View.VISIBLE else View.INVISIBLE - it.layoutParams = (it.layoutParams as ViewGroup.MarginLayoutParams).apply { - this.marginEnd = if (Preferences.showDividers) 8f.convertDpToPixel(context).toInt() else 0 - } + it.visibility = if (Preferences.showDividers) View.VISIBLE else View.GONE } diff --git a/app/src/main/res/layout/fragment_app_main.xml b/app/src/main/res/layout/fragment_app_main.xml index 4b8598e..9aac520 100644 --- a/app/src/main/res/layout/fragment_app_main.xml +++ b/app/src/main/res/layout/fragment_app_main.xml @@ -94,8 +94,7 @@ android:layout_centerInParent="true" android:layout_gravity="center" android:orientation="vertical" - android:paddingLeft="8dp" - android:paddingRight="8dp" + android:padding="8dp" android:id="@+id/widget" android:alpha="0" android:animateLayoutChanges="true" diff --git a/app/src/main/res/layout/left_aligned_widget.xml b/app/src/main/res/layout/left_aligned_widget.xml index 8096e04..cf00467 100644 --- a/app/src/main/res/layout/left_aligned_widget.xml +++ b/app/src/main/res/layout/left_aligned_widget.xml @@ -22,7 +22,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="gone" - android:paddingBottom="8dp" android:orientation="vertical" android:layoutDirection="locale" android:id="@+id/date_layout"> @@ -30,6 +29,7 @@ android:id="@+id/date" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:gravity="start" android:lines="1" android:textColor="@color/colorPrimary" android:maxLines="1" @@ -44,15 +44,14 @@ android:visibility="gone" android:id="@+id/weather_date_line"> + android:layout_marginStart="4dp"/> @@ -85,6 +84,7 @@ android:id="@+id/next_event_difference_time" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:maxLines="1" android:includeFontPadding="false" style="@style/AnotherWidget.Widget.Title" /> @@ -138,6 +138,7 @@ android:layout_width="0dp" android:layout_weight="1" android:layout_height="wrap_content" + android:gravity="center_vertical" android:id="@+id/sub_line" android:visibility="gone" android:orientation="horizontal"> @@ -145,14 +146,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:cropToPadding="false" - android:clipChildren="false" - android:layout_marginTop="2dp" - android:layout_marginEnd="4dp"> + android:clipChildren="false"> @@ -167,7 +168,9 @@ android:id="@+id/sub_line_text" android:layout_width="wrap_content" android:gravity="start" - android:maxLines="2" + android:ellipsize="end" + android:lines="1" + android:maxLines="1" android:includeFontPadding="false" android:layout_height="wrap_content" style="@style/AnotherWidget.Widget.Subtitle" /> @@ -178,12 +181,11 @@ android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" - android:layout_marginStart="4dp" + android:layout_marginStart="2dp" android:id="@+id/weather_sub_line"> diff --git a/app/src/main/res/layout/left_aligned_widget_sans.xml b/app/src/main/res/layout/left_aligned_widget_sans.xml index 88574e5..ff83339 100644 --- a/app/src/main/res/layout/left_aligned_widget_sans.xml +++ b/app/src/main/res/layout/left_aligned_widget_sans.xml @@ -15,7 +15,7 @@ android:id="@+id/main_layout" android:animateLayoutChanges="true"> + style="@style/AnotherWidget.Widget.Title"/> + android:layout_marginStart="2dp"/> @@ -100,7 +99,6 @@ android:layout_weight="1" android:maxLines="1" android:lines="1" - android:gravity="end" android:ellipsize="end" android:includeFontPadding="false" android:layout_height="wrap_content" @@ -113,7 +111,7 @@ android:id="@+id/next_event_difference_time" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:ellipsize="marquee" + android:maxLines="1" android:includeFontPadding="false" style="@style/AnotherWidget.Widget.Title" /> @@ -173,13 +171,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:cropToPadding="false" - android:clipChildren="false" - android:layout_marginEnd="4dp"> + android:clipChildren="false"> @@ -206,12 +205,12 @@ android:layout_height="wrap_content" android:gravity="center" android:visibility="gone" - android:layout_marginStart="4dp" + android:layout_marginStart="2dp" android:id="@+id/weather_sub_line"> + android:layout_marginStart="6dp" + android:layout_marginEnd="4dp"/> diff --git a/app/src/main/res/layout/the_widget_sans.xml b/app/src/main/res/layout/the_widget_sans.xml index 7b895c3..bf781f2 100644 --- a/app/src/main/res/layout/the_widget_sans.xml +++ b/app/src/main/res/layout/the_widget_sans.xml @@ -15,7 +15,7 @@ android:id="@+id/main_layout" android:animateLayoutChanges="true"> + android:layout_centerInParent="true"> @@ -225,12 +222,13 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@color/colorNightDark" + android:visibility="gone" android:id="@+id/sub_line_rect" />