react-native-live-widgets 1.2.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +40 -1
  3. package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
  4. package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -28
  5. package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
  6. package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
  7. package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
  8. package/docs/GUIDE-EN.md +241 -0
  9. package/docs/GUIDE-VI.md +266 -0
  10. package/docs/index.html +1140 -259
  11. package/docs/llms-full.txt +26 -0
  12. package/docs/llms.txt +8 -0
  13. package/ios/Models/DynamicLayoutModels.swift +6 -1
  14. package/ios/Renderer/DynamicNodeView.swift +169 -14
  15. package/ios/Widgets/DynamicHomeScreenWidget.swift +5 -0
  16. package/lib/builder.d.ts.map +1 -1
  17. package/lib/builder.js +65 -11
  18. package/lib/builder.js.map +1 -1
  19. package/lib/dispatcher.js +16 -10
  20. package/lib/dispatcher.js.map +1 -1
  21. package/lib/hooks.js +36 -31
  22. package/lib/hooks.js.map +1 -1
  23. package/lib/index.d.ts +17 -2
  24. package/lib/index.d.ts.map +1 -1
  25. package/lib/index.js +124 -50
  26. package/lib/index.js.map +1 -1
  27. package/lib/ir.d.ts +15 -0
  28. package/lib/ir.d.ts.map +1 -0
  29. package/lib/ir.js +379 -0
  30. package/lib/ir.js.map +1 -0
  31. package/lib/jsx.d.ts +9 -1
  32. package/lib/jsx.d.ts.map +1 -1
  33. package/lib/jsx.js +131 -84
  34. package/lib/jsx.js.map +1 -1
  35. package/lib/preview.d.ts +0 -23
  36. package/lib/preview.d.ts.map +1 -1
  37. package/lib/preview.js +373 -104
  38. package/lib/preview.js.map +1 -1
  39. package/lib/types.d.ts +204 -12
  40. package/lib/types.d.ts.map +1 -1
  41. package/lib/types.js +2 -1
  42. package/lib/types.js.map +1 -1
  43. package/package.json +2 -1
  44. package/src/builder.ts +57 -2
  45. package/src/index.ts +66 -1
  46. package/src/ir.ts +430 -0
  47. package/src/jsx.tsx +30 -0
  48. package/src/preview.tsx +356 -32
  49. package/src/react-native-env.d.ts +1 -0
  50. package/src/types.ts +253 -13
@@ -175,13 +175,42 @@ object DynamicWidgetStateStore {
175
175
  writeSharedString(context, "widget_counter_value", "0")
176
176
  state.remoteVariables["counter"] = "0"
177
177
  }
178
+ actionId == "action_demo_checkin" -> {
179
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
180
+ state.remoteVariables["demo_ts_label"] = "✓ Đã chạy TS ($time)"
181
+ }
182
+ actionId == "action_jsx_checkin" -> {
183
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
184
+ state.remoteVariables["jsx_status"] = "Đã điểm danh • $time"
185
+ }
186
+ actionId == "action_jsx_checkout" -> {
187
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
188
+ state.remoteVariables["jsx_status"] = "Đã Check-out • $time"
189
+ }
190
+ actionId == "action_jsx_refresh" -> {
191
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
192
+ state.remoteVariables["jsx_status"] = "Đồng bộ lúc $time"
193
+ }
194
+ actionId == "action_jsx_leave" -> {
195
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
196
+ state.remoteVariables["jsx_status"] = "Đã xin nghỉ phép • $time"
197
+ }
198
+ actionId == "action_jsx_report" -> {
199
+ val time = SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(Date())
200
+ state.remoteVariables["jsx_status"] = "Đã gửi báo cáo • $time"
201
+ }
178
202
  }
179
203
 
180
204
  saveState(context, state)
181
205
  }
182
206
 
183
- fun isToggled(context: Context, key: String): Boolean {
184
- return loadState(context).toggledItems[key] ?: false
207
+ fun isToggled(context: Context, key: String, defaultChecked: Boolean = false): Boolean {
208
+ val state = loadState(context)
209
+ val existing = state.toggledItems[key]
210
+ if (existing != null) return existing
211
+ state.toggledItems[key] = defaultChecked
212
+ saveState(context, state)
213
+ return defaultChecked
185
214
  }
186
215
 
187
216
  fun resolveLayoutJsonWithVariables(context: Context, widgetKey: String): String? {
@@ -193,11 +222,34 @@ object DynamicWidgetStateStore {
193
222
 
194
223
  val counterVal = readSharedString(context, "widget_counter_value")
195
224
  if (counterVal != null) {
196
- raw = raw.replace(Regex("\"text\":\"-?\\d+\",\"props\":\\{\"fontSize\":(26|32)"), "\"text\":\"$counterVal\",\"props\":{\"fontSize\":$1")
197
- raw = raw.replace(Regex("\"text\":\"-?\\d+ lượt\","), "\"text\":\"$counterVal lượt\",")
225
+ raw = Regex("\"text\":\"-?\\d+\",(\"props\":\\{)?\"fontSize\":(26|32)").replace(raw) { m ->
226
+ "\"text\":\"$counterVal\",${m.groupValues[1]}\"fontSize\":${m.groupValues[2]}"
227
+ }
228
+ raw = raw.replace(Regex("\"text\":\"-?\\d+ lượt\""), "\"text\":\"$counterVal lượt\"")
229
+ raw = raw.replace(Regex("Count: -?\\d+"), "Count: $counterVal")
230
+ raw = raw.replace(Regex("Số đếm hiện tại: -?\\d+"), "Số đếm hiện tại: $counterVal")
198
231
  raw = raw.replace("{{counter}}", counterVal)
199
232
  }
200
233
 
234
+ state.remoteVariables["demo_ts_label"]?.takeIf { it.isNotEmpty() }?.let { label ->
235
+ val escaped = label.replace("\"", "\\\"")
236
+ raw = raw.replace("\"title\":\"Chạy hàm TS\"", "\"title\":\"$escaped\"")
237
+ }
238
+
239
+ state.remoteVariables["jsx_status"]?.takeIf { it.isNotEmpty() }?.let { status ->
240
+ val escaped = status.replace("\"", "\\\"")
241
+ raw = raw.replace("\"text\":\"Đã chấm công (07:54)\"", "\"text\":\"$escaped\"")
242
+ raw = raw.replace("\"text\":\"Vào ca sáng (07:54)\"", "\"text\":\"$escaped\"")
243
+ }
244
+
245
+ // Fallback mặc định cho các template variables thông dụng nếu chưa fetch từ API
246
+ if (!state.remoteVariables.containsKey("id")) {
247
+ state.remoteVariables["id"] = "2026"
248
+ }
249
+ if (!state.remoteVariables.containsKey("title")) {
250
+ state.remoteVariables["title"] = "Hoàn thành kế hoạch quý 4"
251
+ }
252
+
201
253
  for ((k, v) in state.remoteVariables) {
202
254
  val escaped = v.replace("\"", "\\\"")
203
255
  raw = raw.replace("{{$k}}", escaped)
@@ -211,31 +263,34 @@ object DynamicWidgetStateStore {
211
263
  */
212
264
  fun performRemoteSync(context: Context, widgetKey: String = "main") {
213
265
  val configJson = readSharedString(context, "widget_remote_config_$widgetKey")
214
- if (configJson.isNullOrEmpty()) {
215
- stampSyncTimeOnly(context)
216
- return
217
- }
266
+ val rawUrl = if (!configJson.isNullOrEmpty()) {
267
+ try {
268
+ JSONObject(configJson).optString("url", "")
269
+ } catch (_: Exception) { "" }
270
+ } else {
271
+ // Demo API endpoint tự động nạp id và title khi bấm nút Làm mới dữ liệu ngầm
272
+ "https://jsonplaceholder.typicode.com/todos/{{_randomId}}"
273
+ }.ifEmpty { "https://jsonplaceholder.typicode.com/todos/{{_randomId}}" }
218
274
 
219
275
  try {
220
- val config = JSONObject(configJson)
221
- val rawUrl = config.optString("url", "")
222
- if (rawUrl.isEmpty()) {
223
- stampSyncTimeOnly(context)
224
- return
225
- }
226
-
227
- val randomId = Random.nextInt(1, 21)
276
+ val randomId = Random.nextInt(1, 100)
228
277
  val resolvedUrl = rawUrl.replace("{{_randomId}}", randomId.toString())
229
278
  val conn = (URL(resolvedUrl).openConnection() as HttpURLConnection).apply {
230
- requestMethod = config.optString("method", "GET")
279
+ requestMethod = "GET"
231
280
  connectTimeout = 8000
232
281
  readTimeout = 8000
233
- config.optJSONObject("headers")?.let { headers ->
234
- val keys = headers.keys()
235
- while (keys.hasNext()) {
236
- val k = keys.next()
237
- setRequestProperty(k, headers.optString(k))
238
- }
282
+ if (!configJson.isNullOrEmpty()) {
283
+ try {
284
+ val cfg = JSONObject(configJson)
285
+ requestMethod = cfg.optString("method", "GET")
286
+ cfg.optJSONObject("headers")?.let { headers ->
287
+ val keys = headers.keys()
288
+ while (keys.hasNext()) {
289
+ val k = keys.next()
290
+ setRequestProperty(k, headers.optString(k))
291
+ }
292
+ }
293
+ } catch (_: Exception) {}
239
294
  }
240
295
  }
241
296
 
@@ -262,11 +317,14 @@ object DynamicWidgetStateStore {
262
317
  }
263
318
  saveState(context, state)
264
319
 
265
- val intervalMins = if (config.has("refreshIntervalMinutes")) {
266
- config.optInt("refreshIntervalMinutes", 15)
267
- } else {
268
- config.optInt("intervalMinutes", 15)
269
- }.coerceAtLeast(1)
320
+ val intervalMins = try {
321
+ val cfg = if (!configJson.isNullOrEmpty()) JSONObject(configJson) else null
322
+ if (cfg?.has("refreshIntervalMinutes") == true) {
323
+ cfg.optInt("refreshIntervalMinutes", 15)
324
+ } else {
325
+ cfg?.optInt("intervalMinutes", 15) ?: 15
326
+ }
327
+ } catch (_: Exception) { 15 }.coerceAtLeast(1)
270
328
  scheduleBackgroundWidgetSync(context, widgetKey, intervalMins)
271
329
  } catch (_: Exception) {
272
330
  stampSyncTimeOnly(context)
@@ -10,6 +10,8 @@ import android.net.Uri
10
10
  import android.os.Build
11
11
  import android.os.Bundle
12
12
  import android.util.SizeF
13
+ import android.util.TypedValue
14
+ import android.view.View
13
15
  import android.widget.RemoteViews
14
16
  import org.json.JSONObject
15
17
  import kotlin.math.max
@@ -88,7 +90,7 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
88
90
 
89
91
  val family = when {
90
92
  widgetWidthDp < 245f -> "small"
91
- widgetHeightDp < 235f -> "medium"
93
+ widgetHeightDp < 195f -> "medium"
92
94
  else -> "large"
93
95
  }
94
96
 
@@ -100,10 +102,10 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
100
102
  "medium" -> 330f
101
103
  else -> 340f
102
104
  }
103
- val aspectRatio = when (family) {
104
- "small" -> 1.02f
105
- "medium" -> (widgetHeightDp / widgetWidthDp).coerceIn(0.45f, 0.62f)
106
- else -> (widgetHeightDp / widgetWidthDp).coerceIn(0.78f, 1.45f)
105
+ val aspectRatio = if (family == "small") {
106
+ 1.02f
107
+ } else {
108
+ (widgetHeightDp / widgetWidthDp).coerceIn(0.38f, 1.65f)
107
109
  }
108
110
  val logicalHeightDp = logicalWidthDp * aspectRatio
109
111
 
@@ -123,7 +125,47 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
123
125
  )
124
126
  views.setImageViewBitmap(R.id.rn_widget_canvas, bmp)
125
127
 
126
- bindHitZones(context, views, appWidgetId, bindings)
128
+ // 📐 Ánh xạ toạ độ Bitmap -> toạ độ thật của widget trên Launcher.
129
+ // ImageView dùng scaleType=fitCenter nên Bitmap có thể bị thu/phóng và chừa viền (letterbox).
130
+ // Mọi vùng bấm & đồng hồ phải đi qua phép ánh xạ này thì mới khớp 100% với hình đã vẽ.
131
+ val mapping = computeCanvasMapping(context, rawWidthDp, rawHeightDp, widthPx, heightPx)
132
+
133
+ // ⏱️ Live Chronometer tự đếm bằng engine native của hệ điều hành
134
+ val timerInfo = DynamicWidgetCanvasRenderer.activeTimerInfo
135
+ if (timerInfo != null) {
136
+ views.setViewVisibility(R.id.rn_widget_chronometer, View.VISIBLE)
137
+ views.setViewPadding(
138
+ R.id.rn_widget_chronometer,
139
+ (mapping.offX + timerInfo.leftPx * mapping.scale).roundToInt(),
140
+ (mapping.offY + timerInfo.topPx * mapping.scale).roundToInt(),
141
+ 0,
142
+ 0
143
+ )
144
+ views.setTextViewTextSize(
145
+ R.id.rn_widget_chronometer,
146
+ TypedValue.COMPLEX_UNIT_PX,
147
+ timerInfo.fontSizePx * mapping.scale
148
+ )
149
+ views.setTextColor(R.id.rn_widget_chronometer, timerInfo.color)
150
+ views.setChronometer(R.id.rn_widget_chronometer, timerInfo.baseMillis, null, true)
151
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
152
+ views.setChronometerCountDown(R.id.rn_widget_chronometer, timerInfo.isCountDown)
153
+ }
154
+ } else {
155
+ views.setViewVisibility(R.id.rn_widget_chronometer, View.GONE)
156
+ }
157
+
158
+ // ♿ Gán Accessibility Summary từ IR Semantic Tree (hoặc fallback Canvas extractor)
159
+ val a11ySummary = if (activeNode?.has("semanticSummary") == true) {
160
+ activeNode.optString("semanticSummary")
161
+ } else {
162
+ DynamicWidgetCanvasRenderer.extractAccessibilitySummary(activeNode)
163
+ }
164
+ if (a11ySummary.isNotEmpty()) {
165
+ views.setContentDescription(R.id.rn_widget_canvas, a11ySummary)
166
+ }
167
+
168
+ bindHitZones(context, views, appWidgetId, bindings, mapping)
127
169
  appWidgetManager.updateAppWidget(appWidgetId, views)
128
170
  }
129
171
 
@@ -131,6 +173,16 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
131
173
  if (rawJson.isNullOrEmpty()) return null
132
174
  return try {
133
175
  val payload = JSONObject(rawJson)
176
+
177
+ // Hỗ trợ trực tiếp cấu trúc UI Intermediate Representation (IR v2.0)
178
+ if (payload.optString("version") == "2.0" && payload.has("root")) {
179
+ val root = payload.optJSONObject("root")
180
+ if (root != null && payload.has("semanticSummary")) {
181
+ root.put("semanticSummary", payload.optString("semanticSummary"))
182
+ }
183
+ return root
184
+ }
185
+
134
186
  val pages = payload.optJSONObject("pages")
135
187
  if (pages != null && pages.length() > 0) {
136
188
  val state = DynamicWidgetStateStore.loadState(context)
@@ -158,66 +210,83 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
158
210
  }
159
211
  }
160
212
 
213
+ /** Thông số ánh xạ từ toạ độ Bitmap sang toạ độ pixel thật của host view trên Launcher. */
214
+ private data class CanvasMapping(
215
+ val hostW: Float,
216
+ val hostH: Float,
217
+ val bmpW: Float,
218
+ val bmpH: Float,
219
+ val scale: Float,
220
+ val offX: Float,
221
+ val offY: Float
222
+ )
223
+
224
+ private fun computeCanvasMapping(
225
+ context: Context,
226
+ widgetWidthDp: Float,
227
+ widgetHeightDp: Float,
228
+ bmpWidthPx: Int,
229
+ bmpHeightPx: Int
230
+ ): CanvasMapping {
231
+ val density = context.resources.displayMetrics.density
232
+ val bmpW = bmpWidthPx.toFloat()
233
+ val bmpH = bmpHeightPx.toFloat()
234
+ val hostW = (widgetWidthDp * density).takeIf { it > 1f } ?: bmpW
235
+ val hostH = (widgetHeightDp * density).takeIf { it > 1f } ?: bmpH
236
+ // fitCenter: scale đồng đều theo chiều nhỏ hơn, căn giữa phần còn lại
237
+ val scale = min(hostW / bmpW, hostH / bmpH)
238
+ val offX = (hostW - bmpW * scale) / 2f
239
+ val offY = (hostH - bmpH * scale) / 2f
240
+ return CanvasMapping(hostW, hostH, bmpW, bmpH, scale, offX, offY)
241
+ }
242
+
243
+ /**
244
+ * 🎯 Exact Hit Layer: mỗi Button / Toggle / Link nhận 1 view bấm riêng được đặt CHÍNH XÁC
245
+ * theo hình chữ nhật đã vẽ trên Canvas (không còn chia lưới cố định / đoán theo hàng-cột).
246
+ * - Bấm đúng nút nào => ăn đúng nút đó.
247
+ * - Bấm vào vùng trống => không kích hoạt hành động nào.
248
+ * - Nút nhỏ nằm trong vùng lớn (vd Button bên trong Link) luôn được ưu tiên vì nằm trên cùng.
249
+ */
161
250
  private fun bindHitZones(
162
251
  context: Context,
163
252
  views: RemoteViews,
164
253
  appWidgetId: Int,
165
- bindings: List<ButtonActionBinding>
254
+ bindings: List<ButtonActionBinding>,
255
+ mapping: CanvasMapping
166
256
  ) {
167
- val gridIds = listOf(
168
- listOf(R.id.rn_hit_r0_c0, R.id.rn_hit_r0_c1, R.id.rn_hit_r0_c2, R.id.rn_hit_r0_c3),
169
- listOf(R.id.rn_hit_r1_c0, R.id.rn_hit_r1_c1, R.id.rn_hit_r1_c2),
170
- listOf(R.id.rn_hit_r2_c0, R.id.rn_hit_r2_c1, R.id.rn_hit_r2_c2),
171
- listOf(R.id.rn_hit_r3_c0, R.id.rn_hit_r3_c1, R.id.rn_hit_r3_c2),
172
- listOf(R.id.rn_hit_r4_c0, R.id.rn_hit_r4_c1, R.id.rn_hit_r4_c2),
173
- listOf(R.id.rn_hit_r5_c0, R.id.rn_hit_r5_c1, R.id.rn_hit_r5_c2)
174
- )
257
+ views.removeAllViews(R.id.rn_hit_layer)
258
+ if (bindings.isEmpty()) return
175
259
 
176
- val cellBindings = mutableMapOf<Int, ButtonActionBinding>()
260
+ val density = context.resources.displayMetrics.density
261
+ val slop = 1.5f * density // nới nhẹ vùng chạm cho dễ bấm, không đủ lớn để lấn sang nút bên cạnh
177
262
 
178
- val topButtons = bindings.filter { it.zone == "top" || it.yFraction < 0.20f }
179
- val otherButtons = bindings.filter { it !in topButtons }
263
+ // Vùng lớn thêm trước (nằm dưới), vùng nhỏ thêm sau (nằm trên) => ưu tiên nút nhỏ/cụ thể
264
+ val ordered = bindings
265
+ .filter { it.rightFraction > it.leftFraction && it.bottomFraction > it.topFraction }
266
+ .sortedByDescending { (it.rightFraction - it.leftFraction) * (it.bottomFraction - it.topFraction) }
267
+ .take(48)
180
268
 
181
- val row0 = gridIds[0]
182
- for (c in 0 until min(row0.size, topButtons.size)) {
183
- cellBindings[row0[c]] = topButtons[c]
184
- }
185
-
186
- for (b in otherButtons) {
187
- val row = when {
188
- b.yFraction < 0.35f -> 1
189
- b.yFraction < 0.52f -> 2
190
- b.yFraction < 0.62f -> 3
191
- b.yFraction < 0.75f -> 4
192
- else -> 5
193
- }
269
+ ordered.forEachIndexed { index, b ->
270
+ val left = mapping.offX + b.leftFraction * mapping.bmpW * mapping.scale - slop
271
+ val right = mapping.offX + b.rightFraction * mapping.bmpW * mapping.scale + slop
272
+ val top = mapping.offY + b.topFraction * mapping.bmpH * mapping.scale - slop
273
+ val bottom = mapping.offY + b.bottomFraction * mapping.bmpH * mapping.scale + slop
194
274
 
195
- val rowCols = gridIds[row]
196
- if (b.widthFraction > 0.50f) {
197
- for (viewId in rowCols) {
198
- cellBindings[viewId] = b
199
- }
200
- } else {
201
- if (b.xFraction < 0.40f) {
202
- cellBindings[rowCols[0]] = b
203
- cellBindings[rowCols[1]] = b
204
- } else {
205
- cellBindings[rowCols[1]] = b
206
- cellBindings[rowCols[2]] = b
207
- }
208
- }
209
- }
275
+ val padL = left.coerceIn(0f, mapping.hostW).roundToInt()
276
+ val padT = top.coerceIn(0f, mapping.hostH).roundToInt()
277
+ val padR = (mapping.hostW - right).coerceIn(0f, mapping.hostW).roundToInt()
278
+ val padB = (mapping.hostH - bottom).coerceIn(0f, mapping.hostH).roundToInt()
210
279
 
211
- var requestIdx = 0
212
- for (r in gridIds.indices) {
213
- for (c in gridIds[r].indices) {
214
- val viewId = gridIds[r][c]
215
- val b = cellBindings[viewId]
216
- views.setOnClickPendingIntent(
217
- viewId,
218
- createPendingIntent(context, appWidgetId * 100 + requestIdx++, b)
219
- )
220
- }
280
+ val zone = RemoteViews(context.packageName, R.layout.rn_live_widget_hit_zone)
281
+ zone.setViewPadding(R.id.rn_hit_zone_root, padL, padT, padR, padB)
282
+ zone.setOnClickPendingIntent(
283
+ R.id.rn_hit_zone,
284
+ createPendingIntent(context, appWidgetId * 1000 + index, b)
285
+ )
286
+ val btnLabel = if (!b.accessibilityLabel.isNullOrEmpty()) b.accessibilityLabel else b.title
287
+ val fullDesc = if (!b.accessibilityHint.isNullOrEmpty()) "$btnLabel. ${b.accessibilityHint}" else btnLabel
288
+ zone.setContentDescription(R.id.rn_hit_zone, fullDesc)
289
+ views.addView(R.id.rn_hit_layer, zone)
221
290
  }
222
291
  }
223
292
 
@@ -251,6 +320,7 @@ class DynamicHomeScreenWidgetProvider : AppWidgetProvider() {
251
320
 
252
321
  val intent = Intent(context, LiveActivityReceiver::class.java).apply {
253
322
  action = LiveActivityReceiver.ACTION_WIDGET_ACTION
323
+ data = Uri.parse("rnlivewidget://action/$requestCode/${Uri.encode(binding.actionId)}")
254
324
  putExtra("actionId", binding.actionId)
255
325
  }
256
326
  return PendingIntent.getBroadcast(
@@ -0,0 +1,16 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!--
3
+ 1 vùng bấm. Root phủ toàn widget nhưng KHÔNG clickable (chạm vào phần padding sẽ rơi xuống view bên dưới).
4
+ Padding (left, top, right, bottom) được set động => view con rn_hit_zone nằm đúng hình chữ nhật của nút.
5
+ -->
6
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
7
+ android:id="@+id/rn_hit_zone_root"
8
+ android:layout_width="match_parent"
9
+ android:layout_height="match_parent">
10
+
11
+ <TextView
12
+ android:id="@+id/rn_hit_zone"
13
+ android:layout_width="match_parent"
14
+ android:layout_height="match_parent"
15
+ android:background="@android:color/transparent" />
16
+ </FrameLayout>
@@ -12,92 +12,21 @@
12
12
  android:scaleType="fitCenter"
13
13
  android:contentDescription="Live Widget Content" />
14
14
 
15
- <!-- Lớp vùng bấm tương tác (Interactive Hit Zones: 6 Hàng x 3 Cột) cho mọi layout Widget -->
16
- <LinearLayout
17
- android:id="@+id/rn_widget_grid_container"
15
+ <!-- Đồng hồ Live Chronometer tự đếm bằng engine native của hệ thống -->
16
+ <Chronometer
17
+ android:id="@+id/rn_widget_chronometer"
18
+ android:layout_width="wrap_content"
19
+ android:layout_height="wrap_content"
20
+ android:layout_gravity="top|start"
21
+ android:visibility="gone" />
22
+
23
+ <!--
24
+ Lớp vùng bấm động (Exact Hit Layer): mỗi Button / Toggle / Link được thêm 1 view riêng
25
+ (rn_live_widget_hit_zone.xml) đặt CHÍNH XÁC theo toạ độ đã vẽ trên Canvas.
26
+ Vùng trống không gắn hành động nào => bấm vào không kích hoạt gì.
27
+ -->
28
+ <FrameLayout
29
+ android:id="@+id/rn_hit_layer"
18
30
  android:layout_width="match_parent"
19
- android:layout_height="match_parent"
20
- android:orientation="vertical"
21
- android:weightSum="6">
22
-
23
- <!-- Row 0 (0% - 16.7%) -->
24
- <LinearLayout
25
- android:id="@+id/rn_grid_row_0"
26
- android:layout_width="match_parent"
27
- android:layout_height="0dp"
28
- android:layout_weight="1"
29
- android:orientation="horizontal"
30
- android:weightSum="4">
31
- <TextView android:id="@+id/rn_hit_r0_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
32
- <TextView android:id="@+id/rn_hit_r0_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
33
- <TextView android:id="@+id/rn_hit_r0_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
34
- <TextView android:id="@+id/rn_hit_r0_c3" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
35
- </LinearLayout>
36
-
37
- <!-- Row 1 (16.7% - 33.3%) -->
38
- <LinearLayout
39
- android:id="@+id/rn_grid_row_1"
40
- android:layout_width="match_parent"
41
- android:layout_height="0dp"
42
- android:layout_weight="1"
43
- android:orientation="horizontal"
44
- android:weightSum="3">
45
- <TextView android:id="@+id/rn_hit_r1_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
46
- <TextView android:id="@+id/rn_hit_r1_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
47
- <TextView android:id="@+id/rn_hit_r1_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
48
- </LinearLayout>
49
-
50
- <!-- Row 2 (33.3% - 50.0%) -->
51
- <LinearLayout
52
- android:id="@+id/rn_grid_row_2"
53
- android:layout_width="match_parent"
54
- android:layout_height="0dp"
55
- android:layout_weight="1"
56
- android:orientation="horizontal"
57
- android:weightSum="3">
58
- <TextView android:id="@+id/rn_hit_r2_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
59
- <TextView android:id="@+id/rn_hit_r2_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
60
- <TextView android:id="@+id/rn_hit_r2_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
61
- </LinearLayout>
62
-
63
- <!-- Row 3 (50.0% - 66.7%) -->
64
- <LinearLayout
65
- android:id="@+id/rn_grid_row_3"
66
- android:layout_width="match_parent"
67
- android:layout_height="0dp"
68
- android:layout_weight="1"
69
- android:orientation="horizontal"
70
- android:weightSum="3">
71
- <TextView android:id="@+id/rn_hit_r3_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
72
- <TextView android:id="@+id/rn_hit_r3_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
73
- <TextView android:id="@+id/rn_hit_r3_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
74
- </LinearLayout>
75
-
76
- <!-- Row 4 (66.7% - 83.3%) -->
77
- <LinearLayout
78
- android:id="@+id/rn_grid_row_4"
79
- android:layout_width="match_parent"
80
- android:layout_height="0dp"
81
- android:layout_weight="1"
82
- android:orientation="horizontal"
83
- android:weightSum="3">
84
- <TextView android:id="@+id/rn_hit_r4_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
85
- <TextView android:id="@+id/rn_hit_r4_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
86
- <TextView android:id="@+id/rn_hit_r4_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
87
- </LinearLayout>
88
-
89
- <!-- Row 5 (83.3% - 100.0%) -->
90
- <LinearLayout
91
- android:id="@+id/rn_grid_row_5"
92
- android:layout_width="match_parent"
93
- android:layout_height="0dp"
94
- android:layout_weight="1"
95
- android:orientation="horizontal"
96
- android:weightSum="3">
97
- <TextView android:id="@+id/rn_hit_r5_c0" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
98
- <TextView android:id="@+id/rn_hit_r5_c1" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
99
- <TextView android:id="@+id/rn_hit_r5_c2" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="@android:color/transparent" />
100
- </LinearLayout>
101
- </LinearLayout>
31
+ android:layout_height="match_parent" />
102
32
  </FrameLayout>
103
-