Kwgt Clock Widget ❲BEST · 2025❳

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)

private fun startClockUpdates( context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray ) runnable?.let handler.removeCallbacks(it) runnable = Runnable appWidgetIds.forEach appWidgetId -> updateAppWidget(context, appWidgetManager, appWidgetId) handler.postDelayed(runnable!!, UPDATE_INTERVAL) handler.post(runnable!!)

private fun setupColorPicker(buttonId: Int, prefKey: String, defaultColor: Int) val button = findViewById<Button>(buttonId) val currentColor = prefs.getInt(prefKey, defaultColor) button.setBackgroundColor(currentColor) button.setOnClickListener val colorPicker = ColorPickerDialog(this, currentColor) color -> button.setBackgroundColor(color) prefs.edit().putInt(prefKey, color).apply() colorPicker.show() kwgt clock widget

package com.yourpackage.kwgtclockwidget import android.appwidget.AppWidgetManager import android.appwidget.AppWidgetProvider import android.content.Context import android.widget.RemoteViews import java.text.SimpleDateFormat import java.util.* import android.os.Handler import android.os.Looper

private fun setupSizeSlider(sliderId: Int, textViewId: Int, prefKey: String, defaultValue: Int) val slider = findViewById<Slider>(sliderId) val valueText = findViewById<TextView>(textViewId) val savedValue = prefs.getInt(prefKey, defaultValue).toFloat() slider.value = savedValue valueText.text = "$savedValue.toInt()sp" slider.addOnChangeListener _, value, _ -> valueText.text = "$value.toInt()sp" prefs.edit().putInt(prefKey, value.toInt()).apply() private fun updateAppWidget( context: Context

<!-- res/layout/widget_clock.xml --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/widgetBackground" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:gravity="center" android:padding="16dp" android:background="@drawable/widget_background"> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:id="@+id/clockTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="12:00" android:textSize="80sp" android:textColor="#FFFFFF" android:textStyle="bold" android:fontFamily="sans-serif-medium" /> <TextView android:id="@+id/clockAmPm" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/clockTime" android:layout_alignBottom="@id/clockTime" android:layout_marginStart="8dp" android:layout_marginBottom="12dp" android:text="AM" android:textSize="24sp" android:textColor="#FF6B6B" /> </RelativeLayout>

override fun onUpdate( context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray ) appWidgetIds.forEach appWidgetId -> updateAppWidget(context, appWidgetManager, appWidgetId) startClockUpdates(context, appWidgetManager, appWidgetIds) Locale.getDefault()) val amPmFormat = SimpleDateFormat("a"

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)