mirror of
				https://github.com/SimpleMobileTools/Simple-Clock.git
				synced 2025-06-05 22:19:17 +02:00 
			
		
		
		
	increase the widget time text size when the widget is higher
This commit is contained in:
		| @@ -7,6 +7,7 @@ import android.content.ComponentName | ||||
| import android.content.Context | ||||
| import android.content.Intent | ||||
| import android.graphics.* | ||||
| import android.os.Bundle | ||||
| import android.widget.RemoteViews | ||||
| import com.simplemobiletools.clock.R | ||||
| import com.simplemobiletools.clock.activities.SplashActivity | ||||
| @@ -29,9 +30,13 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { | ||||
|     private fun performUpdate(context: Context) { | ||||
|         val appWidgetManager = AppWidgetManager.getInstance(context) | ||||
|         appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach { | ||||
|             val bundle = appWidgetManager.getAppWidgetOptions(it) | ||||
|             val minHeight = bundle.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) | ||||
|             val isSmallLayout = getCellsForSize(minHeight) == 1 | ||||
|  | ||||
|             val layout = if (context.config.useTextShadow) R.layout.widget_date_time_with_shadow else R.layout.widget_date_time | ||||
|             RemoteViews(context.packageName, layout).apply { | ||||
|                 updateTexts(context, this) | ||||
|                 updateTexts(context, this, isSmallLayout) | ||||
|                 updateColors(context, this) | ||||
|                 setupAppOpenIntent(context, this) | ||||
|                 appWidgetManager.updateAppWidget(it, this) | ||||
| @@ -39,12 +44,19 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun updateTexts(context: Context, views: RemoteViews) { | ||||
|     private fun updateTexts(context: Context, views: RemoteViews, isSmallLayout: Boolean) { | ||||
|         val calendar = Calendar.getInstance() | ||||
|         val use24HourFormat = context.config.use24HourFormat | ||||
|  | ||||
|         val timeText = context.getFormattedTime(getPassedSeconds(), false, false).toString() | ||||
|         val dimenResource = if (isSmallLayout) R.dimen.widget_time_text_size_small else R.dimen.widget_time_text_size_big | ||||
|         val timeTextSize = context.resources.getDimension(dimenResource) / context.resources.displayMetrics.density | ||||
|  | ||||
|         val topPadding = if (isSmallLayout) 0 else context.resources.getDimension(R.dimen.tiny_margin).toInt() | ||||
|         val bottomPadding = context.resources.getDimension(if (isSmallLayout) R.dimen.tiny_margin else R.dimen.medium_margin).toInt() | ||||
|  | ||||
|         views.apply { | ||||
|             setViewPadding(R.id.widget_date_time_holder, 0, topPadding, 0, bottomPadding) | ||||
|             if (use24HourFormat) { | ||||
|                 setText(R.id.widget_time, timeText) | ||||
|             } else { | ||||
| @@ -53,6 +65,7 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { | ||||
|                 setText(R.id.widget_time_am_pm, " ${timeParts[1]}") | ||||
|             } | ||||
|             setText(R.id.widget_date, context.getFormattedDate(calendar)) | ||||
|             setTextSize(R.id.widget_time, timeTextSize) | ||||
|             setVisibleIf(R.id.widget_time_am_pm, !use24HourFormat) | ||||
|  | ||||
|             val nextAlarm = getFormattedNextAlarm(context) | ||||
| @@ -126,6 +139,11 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     override fun onAppWidgetOptionsChanged(context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int, newOptions: Bundle?) { | ||||
|         performUpdate(context) | ||||
|         super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions) | ||||
|     } | ||||
|  | ||||
|     private fun getMultiplyColoredBitmap(resourceId: Int, newColor: Int, context: Context): Bitmap { | ||||
|         val options = BitmapFactory.Options() | ||||
|         options.inMutable = true | ||||
| @@ -137,4 +155,12 @@ class MyWidgetDateTimeProvider : AppWidgetProvider() { | ||||
|         canvas.drawBitmap(bmp, 0f, 0f, paint) | ||||
|         return bmp | ||||
|     } | ||||
|  | ||||
|     private fun getCellsForSize(size: Int): Int { | ||||
|         var n = 2 | ||||
|         while (70 * n - 30 < size) { | ||||
|             ++n | ||||
|         } | ||||
|         return n - 1 | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -20,7 +20,7 @@ | ||||
|             android:layout_height="@dimen/widget_time_height" | ||||
|             android:gravity="center_horizontal" | ||||
|             android:includeFontPadding="false" | ||||
|             android:textSize="@dimen/widget_time_text_size" | ||||
|             android:textSize="@dimen/widget_time_text_size_small" | ||||
|             tools:text="00:00"/> | ||||
|  | ||||
|         <TextView | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:id="@+id/widget_date_time_holder" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     android:paddingBottom="@dimen/tiny_margin"> | ||||
|     android:layout_height="wrap_content"> | ||||
|  | ||||
|     <RelativeLayout | ||||
|         android:id="@+id/widget_time_holder" | ||||
| @@ -16,9 +15,9 @@ | ||||
|         <TextView | ||||
|             android:id="@+id/widget_time" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="@dimen/widget_time_height" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:includeFontPadding="false" | ||||
|             android:textSize="@dimen/widget_time_text_size" | ||||
|             android:textSize="@dimen/widget_time_text_size_small" | ||||
|             tools:text="00:00"/> | ||||
|  | ||||
|         <TextView | ||||
|   | ||||
| @@ -4,8 +4,7 @@ | ||||
|     xmlns:tools="http://schemas.android.com/tools" | ||||
|     android:id="@+id/widget_date_time_holder" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="wrap_content" | ||||
|     android:paddingBottom="@dimen/tiny_margin"> | ||||
|     android:layout_height="wrap_content"> | ||||
|  | ||||
|     <RelativeLayout | ||||
|         android:id="@+id/widget_time_holder" | ||||
| @@ -16,12 +15,12 @@ | ||||
|         <TextView | ||||
|             android:id="@+id/widget_time" | ||||
|             android:layout_width="wrap_content" | ||||
|             android:layout_height="@dimen/widget_time_height" | ||||
|             android:layout_height="wrap_content" | ||||
|             android:includeFontPadding="false" | ||||
|             android:shadowColor="@android:color/black" | ||||
|             android:shadowDy="1" | ||||
|             android:shadowRadius="1" | ||||
|             android:textSize="@dimen/widget_time_text_size" | ||||
|             android:textSize="@dimen/widget_time_text_size_small" | ||||
|             tools:text="00:00"/> | ||||
|  | ||||
|         <TextView | ||||
|   | ||||
| @@ -13,7 +13,8 @@ | ||||
|     <dimen name="clock_text_size_smaller">60sp</dimen> | ||||
|     <dimen name="alarm_text_size">44sp</dimen> | ||||
|     <dimen name="stopwatch_text_size">60sp</dimen> | ||||
|     <dimen name="widget_time_text_size">48sp</dimen> | ||||
|     <dimen name="widget_time_text_size_small">48sp</dimen> | ||||
|     <dimen name="widget_time_text_size_big">64sp</dimen> | ||||
|     <dimen name="widget_details_text_size">14sp</dimen> | ||||
|     <dimen name="reminder_activity_title_size">32sp</dimen> | ||||
|     <dimen name="reminder_activity_text_size">26sp</dimen> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user