Widget - Kwgt Clock
companion object private const val UPDATE_INTERVAL = 60000L // Update every minute private var handler = Handler(Looper.getMainLooper()) private var runnable: Runnable? = null
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
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() companion object private const val UPDATE_INTERVAL = 60000L
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) defaultColor: Int) val button = findViewById<
override fun onCreate(savedInstanceState: Bundle?) super.onCreate(savedInstanceState) setContentView(R.layout.activity_widget_configure) prefs = getSharedPreferences("widget_prefs", Context.MODE_PRIVATE) appWidgetId = intent?.extras?.getInt( AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID ) ?: AppWidgetManager.INVALID_APPWIDGET_ID setupViews() findViewById<Button>(R.id.saveButton).setOnClickListener saveSettings()
1. Main Widget Structure (Kustom JSON) "version": 3.2, "name": "Modern Digital Clock Widget", "size": "width": 500, "height": 300 , "background": "type": "shape", "color": "#1A1A1A", "radius": 25, "shadow": true , "layers": [ "type": "text", "name": "Time Display", "text": "$df(hh:mm)$", "color": "#FFFFFF", "size": 80, "font": "Roboto-Bold", "align": "center", "x": 250, "y": 100, "width": 400 , "type": "text", "name": "AM/PM", "text": "$df(a)$", "color": "#FF6B6B", "size": 24, "font": "Roboto-Regular", "align": "center", "x": 420, "y": 80, "width": 60 , "type": "text", "name": "Date", "text": "$df(EEEE, MMMM d)$", "color": "#B0B0B0", "size": 18, "font": "Roboto-Regular", "align": "center", "x": 250, "y": 160, "width": 400 ]