@@ -87,15 +87,14 @@ class AwidgetProvider : AppWidgetProvider() {
8787 const val ACTION_BATTERY_UPDATE = " com.leanbitlab.lwidget.ACTION_BATTERY_UPDATE"
8888
8989 fun updateAppWidget (context : Context , appWidgetManager : AppWidgetManager , appWidgetId : Int ) {
90- val views = RemoteViews (context.packageName, R .layout.widget_layout)
9190 val prefs = context.getSharedPreferences(" com.leanbitlab.lwidget.PREFS" , Context .MODE_PRIVATE )
9291
9392 // --- Load Preferences ---
9493 val showTime = prefs.getBoolean(" show_time" , true )
9594 val sizeTime = prefs.getFloat(" size_time" , 48f )
9695
9796 val showDate = prefs.getBoolean(" show_date" , true )
98- val sizeDate = prefs.getFloat(" size_date" , 14f ) // Note: Default in XML was 18sp, user asked for smaller events, standardizing defaults? XML is 18sp. Setting default to 18f to match.
97+ val sizeDate = prefs.getFloat(" size_date" , 14f )
9998
10099 val showBattery = prefs.getBoolean(" show_battery" , true )
101100 val sizeBattery = prefs.getFloat(" size_battery" , 48f )
@@ -105,35 +104,119 @@ class AwidgetProvider : AppWidgetProvider() {
105104
106105 val showEvents = prefs.getBoolean(" show_events" , true )
107106 val sizeEvents = prefs.getFloat(" size_events" , 14f )
108-
107+
109108 val showOutline = prefs.getBoolean(" show_outline" , false )
110109 val useLightTheme = prefs.getBoolean(" use_light_theme" , false )
110+ val isTransparent = prefs.getBoolean(" transparent_background" , false )
111+ val fontStyle = prefs.getInt(" font_style" , 0 )
112+ // 0=Def, 1=Serif, 2=Mono, 3=Cursive, 4=Cond, 5=CondLight, 6=Light, 7=Med, 8=Black, 9=Thin, 10=SmallCaps
113+
114+ // --- Theme & Font Setup ---
115+ // Helper to get layout ID
116+ fun getLayout (baseLayoutId : Int , fontIdx : Int ): Int {
117+ // If base is widget_layout
118+ if (baseLayoutId == R .layout.widget_layout) {
119+ return when (fontIdx) {
120+ 1 -> R .layout.widget_layout_serif
121+ 2 -> R .layout.widget_layout_mono
122+ 3 -> R .layout.widget_layout_cursive
123+ 4 -> R .layout.widget_layout_condensed
124+ 5 -> R .layout.widget_layout_condensed_light
125+ 6 -> R .layout.widget_layout_light
126+ 7 -> R .layout.widget_layout_medium
127+ 8 -> R .layout.widget_layout_black
128+ 9 -> R .layout.widget_layout_thin
129+ 10 -> R .layout.widget_layout_smallcaps
130+ else -> R .layout.widget_layout
131+ }
132+ }
133+ // If base is transparent dark
134+ if (baseLayoutId == R .layout.widget_layout_transparent_dark) {
135+ return when (fontIdx) {
136+ 1 -> R .layout.widget_layout_transparent_dark_serif
137+ 2 -> R .layout.widget_layout_transparent_dark_mono
138+ 3 -> R .layout.widget_layout_transparent_dark_cursive
139+ 4 -> R .layout.widget_layout_transparent_dark_condensed
140+ 5 -> R .layout.widget_layout_transparent_dark_condensed_light
141+ 6 -> R .layout.widget_layout_transparent_dark_light
142+ 7 -> R .layout.widget_layout_transparent_dark_medium
143+ 8 -> R .layout.widget_layout_transparent_dark_black
144+ 9 -> R .layout.widget_layout_transparent_dark_thin
145+ 10 -> R .layout.widget_layout_transparent_dark_smallcaps
146+ else -> R .layout.widget_layout_transparent_dark
147+ }
148+ }
149+ // If base is transparent light
150+ if (baseLayoutId == R .layout.widget_layout_transparent_light) {
151+ return when (fontIdx) {
152+ 1 -> R .layout.widget_layout_transparent_light_serif
153+ 2 -> R .layout.widget_layout_transparent_light_mono
154+ 3 -> R .layout.widget_layout_transparent_light_cursive
155+ 4 -> R .layout.widget_layout_transparent_light_condensed
156+ 5 -> R .layout.widget_layout_transparent_light_condensed_light
157+ 6 -> R .layout.widget_layout_transparent_light_light
158+ 7 -> R .layout.widget_layout_transparent_light_medium
159+ 8 -> R .layout.widget_layout_transparent_light_black
160+ 9 -> R .layout.widget_layout_transparent_light_thin
161+ 10 -> R .layout.widget_layout_transparent_light_smallcaps
162+ else -> R .layout.widget_layout_transparent_light
163+ }
164+ }
165+ return baseLayoutId
166+ }
111167
112- // --- Theme Setup ---
113- val bgRes = if (useLightTheme) {
114- if (showOutline) R .drawable.background_glow_light else R .drawable.background_light
168+ val baseLayoutId = if (isTransparent) {
169+ if (useLightTheme) R .layout.widget_layout_transparent_light else R .layout.widget_layout_transparent_dark
115170 } else {
116- if (showOutline) R .drawable.background_glow else R .drawable.background_dark
171+ R .layout.widget_layout
117172 }
173+
174+ val layoutId = getLayout(baseLayoutId, fontStyle)
118175
119- val primaryColor = if (useLightTheme) {
120- context.getColor(R .color.widget_text_light)
121- } else {
122- android.graphics.Color .WHITE
176+ val views = RemoteViews (context.packageName, layoutId)
177+
178+ // Only set background if NOT transparent
179+ if (! isTransparent) {
180+ val bgRes = if (useLightTheme) {
181+ if (showOutline) R .drawable.background_glow_light else R .drawable.background_light
182+ } else {
183+ if (showOutline) R .drawable.background_glow else R .drawable.background_dark
184+ }
185+ views.setInt(R .id.widget_root, " setBackgroundResource" , bgRes)
123186 }
124187
125- val secondaryColor = if (useLightTheme) {
126- context.getColor(R .color.widget_text_secondary_light)
188+ // Colors for manual text setting (though transparent layouts handle most via XML styles)
189+ // We still need these for dynamic updates if we were using same layout, but since we swap layouts,
190+ // the XML attributes in transparent layouts (shadows, colors) handle static text.
191+ // However, we still programmatically set colors for consistecy in shared logic (like battery/events).
192+
193+ // For Transparent:
194+ // Dark (White Text, Black Outline) -> Primary: White, Secondary: White
195+ // Light (Black Text, White Outline) -> Primary: Black, Secondary: Black
196+
197+ // For Standard (Non-Transparent):
198+ // Dark -> Primary: White, Secondary: Light Gray
199+ // Light -> Primary: Black, Secondary: Dark Gray
200+
201+ val primaryColor = if (isTransparent) {
202+ if (useLightTheme) android.graphics.Color .BLACK else android.graphics.Color .WHITE
127203 } else {
128- android.graphics.Color .parseColor( " #CCFFFFFF " )
204+ if (useLightTheme) context.getColor( R .color.widget_text_light) else android.graphics.Color .WHITE
129205 }
130206
131- // --- Apply Outline / Background ---
132- views.setInt(R .id.widget_root, " setBackgroundResource" , bgRes)
207+ val secondaryColor = if (isTransparent) {
208+ if (useLightTheme) android.graphics.Color .BLACK else android.graphics.Color .WHITE
209+ } else {
210+ if (useLightTheme) context.getColor(R .color.widget_text_secondary_light) else android.graphics.Color .parseColor(" #CCFFFFFF" )
211+ }
133212
134213 // --- Apply Time ---
135214 views.setViewVisibility(R .id.clock_time, if (showTime) android.view.View .VISIBLE else android.view.View .GONE )
136215 views.setTextViewTextSize(R .id.clock_time, android.util.TypedValue .COMPLEX_UNIT_SP , sizeTime)
216+ // In transparent mode, XML handles shadow/color better to ensure outline presence,
217+ // but setting textColor here might override XML if not careful.
218+ // RemoteViews.setTextColor REPLACES the color. It does NOT remove shadow.
219+ // So it is safe to set color here.
137220 views.setTextColor(R .id.clock_time, primaryColor)
138221
139222 // --- Apply Date ---
@@ -145,7 +228,7 @@ class AwidgetProvider : AppWidgetProvider() {
145228 views.setViewVisibility(R .id.text_battery, if (showBattery) android.view.View .VISIBLE else android.view.View .GONE )
146229 views.setTextViewTextSize(R .id.text_battery, android.util.TypedValue .COMPLEX_UNIT_SP , sizeBattery)
147230 views.setTextColor(R .id.text_battery, primaryColor)
148-
231+
149232 views.setViewVisibility(R .id.text_temp, if (showTemp) android.view.View .VISIBLE else android.view.View .GONE )
150233 views.setTextViewTextSize(R .id.text_temp, android.util.TypedValue .COMPLEX_UNIT_SP , sizeTemp)
151234 views.setTextColor(R .id.text_temp, secondaryColor)
0 commit comments