Kwgt Clock Widget Direct
private var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID private lateinit var prefs: SharedPreferences
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 kwgt clock widget
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() private var appWidgetId = AppWidgetManager
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() defaultColor: Int) val button = findViewById<
class KWGTClockWidget : AppWidgetProvider()
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!!)