Kwgt Clock Widget Apr 2026

private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID private lateinit var prefs: SharedPreferences

private fun updateAppWidget( context: Context, appWidgetManager: AppWidgetManager, appWidgetId: Int ) val views = RemoteViews(context.packageName, R.layout.widget_clock) // Get current time and date val calendar = Calendar.getInstance() val timeFormat = SimpleDateFormat("hh:mm", Locale.getDefault()) val amPmFormat = SimpleDateFormat("a", Locale.getDefault()) val dateFormat = SimpleDateFormat("EEEE, MMMM d", Locale.getDefault()) val currentTime = timeFormat.format(calendar.time) val amPm = amPmFormat.format(calendar.time) val currentDate = dateFormat.format(calendar.time).capitalize() // Set text views views.setTextViewText(R.id.clockTime, currentTime) views.setTextViewText(R.id.clockAmPm, amPm) views.setTextViewText(R.id.clockDate, currentDate) // Apply settings from SharedPreferences applyWidgetSettings(context, views) appWidgetManager.updateAppWidget(appWidgetId, views) kwgt clock widget

private fun applyWidgetSettings(context: Context, views: RemoteViews) val prefs = context.getSharedPreferences("widget_prefs", Context.MODE_PRIVATE) // Color settings val textColor = prefs.getInt("text_color", -1) val accentColor = prefs.getInt("accent_color", -1) val bgColor = prefs.getInt("bg_color", -1) if (textColor != -1) views.setTextColor(R.id.clockTime, textColor) views.setTextColor(R.id.clockDate, textColor) if (accentColor != -1) views.setTextColor(R.id.clockAmPm, accentColor) if (bgColor != -1) views.setInt(R.id.widgetBackground, "setBackgroundColor", bgColor) // Font size settings val timeSize = prefs.getInt("time_size", 80) val dateSize = prefs.getInt("date_size", 18) val ampmSize = prefs.getInt("ampm_size", 24) views.setFloat(R.id.clockTime, "setTextSize", timeSize.toFloat()) views.setFloat(R.id.clockDate, "setTextSize", dateSize.toFloat()) views.setFloat(R.id.clockAmPm, "setTextSize", ampmSize.toFloat()) // Font family val fontFamily = prefs.getString("font_family", "sans-serif-medium") views.setString(R.id.clockTime, "setTypeface", fontFamily) private var appWidgetId = AppWidgetManager