Kwgt Clock Widget [SAFE]
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 ]
private fun setupViews() { // Color pickers setupColorPicker(R.id.textColorPicker, "text_color", Color.WHITE) setupColorPicker(R.id.accentColorPicker, "accent_color", Color.parseColor("#FF6B6B")) setupColorPicker(R.id.bgColorPicker, "bg_color", Color.parseColor("#1A1A1A")) // Size sliders setupSizeSlider(R.id.timeSizeSlider, R.id.timeSizeValue, "time_size", 80) setupSizeSlider(R.id.dateSizeSlider, R.id.dateSizeValue, "date_size", 18) setupSizeSlider(R.id.ampmSizeSlider, R.id.ampmSizeValue, "ampm_size", 24) // Font picker val fontSpinner = findViewById<Spinner>(R.id.fontSpinner) val fonts = arrayOf("Sans-serif", "Sans-serif-medium", "Sans-serif-light", "Monospace") fontSpinner.adapter = ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, fonts) val savedFont = prefs.getString("font_family", "sans-serif-medium") fontSpinner.setSelection(fonts.indexOf(savedFont?.replace("sans-serif-", ""))) fontSpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>, view: android.view.View?, pos: Int, id: Long) val font = when(fonts[pos]) "Sans-serif" -> "sans-serif" "Sans-serif-medium" -> "sans-serif-medium" "Sans-serif-light" -> "sans-serif-light" else -> "monospace" prefs.edit().putString("font_family", font).apply() override fun onNothingSelected(parent: AdapterView<*>) {} } } 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() "name": "Modern Digital Clock Widget"
class KWGTClockWidget : AppWidgetProvider() "size": "width": 500
class WidgetConfigureActivity : AppCompatActivity() {
<!-- 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)