1 /* 2 * Copyright (C) 2021 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.calendar.widget 17 18 import android.app.AlarmManager 19 import android.app.PendingIntent 20 import android.appwidget.AppWidgetManager 21 import android.content.BroadcastReceiver 22 import android.content.Context 23 import android.content.CursorLoader 24 import android.content.Intent 25 import android.content.Loader 26 import android.content.res.Resources 27 import android.database.Cursor 28 import android.database.MatrixCursor 29 import android.net.Uri 30 import android.os.Handler 31 import android.provider.CalendarContract.Attendees 32 import android.provider.CalendarContract.Calendars 33 import android.provider.CalendarContract.Instances 34 import android.text.format.DateUtils 35 import android.text.format.Time 36 import android.util.Log 37 import android.view.View 38 import android.widget.RemoteViews 39 import android.widget.RemoteViewsService 40 import com.android.calendar.R 41 import com.android.calendar.Utils 42 import com.android.calendar.widget.CalendarAppWidgetModel.DayInfo 43 import com.android.calendar.widget.CalendarAppWidgetModel.EventInfo 44 import com.android.calendar.widget.CalendarAppWidgetModel.RowInfo 45 import java.util.concurrent.ExecutorService 46 import java.util.concurrent.Executors 47 import java.util.concurrent.atomic.AtomicInteger 48 49 class CalendarAppWidgetService : RemoteViewsService() { 50 companion object { 51 private const val TAG = "CalendarWidget" 52 const val EVENT_MIN_COUNT = 20 53 const val EVENT_MAX_COUNT = 100 54 55 // Minimum delay between queries on the database for widget updates in ms 56 const val WIDGET_UPDATE_THROTTLE = 500 57 private val EVENT_SORT_ORDER: String = (Instances.START_DAY.toString() + " ASC, " + 58 Instances.START_MINUTE + " ASC, " + Instances.END_DAY + " ASC, " + 59 Instances.END_MINUTE + " ASC LIMIT " + EVENT_MAX_COUNT) 60 private val EVENT_SELECTION: String = Calendars.VISIBLE.toString() + "=1" 61 private val EVENT_SELECTION_HIDE_DECLINED: String = 62 (Calendars.VISIBLE.toString() + "=1 AND " + 63 Instances.SELF_ATTENDEE_STATUS + "!=" + Attendees.ATTENDEE_STATUS_DECLINED) 64 @JvmField 65 val EVENT_PROJECTION = arrayOf<String>( 66 Instances.ALL_DAY, 67 Instances.BEGIN, 68 Instances.END, 69 Instances.TITLE, 70 Instances.EVENT_LOCATION, 71 Instances.EVENT_ID, 72 Instances.START_DAY, 73 Instances.END_DAY, 74 Instances.DISPLAY_COLOR, // If SDK < 16, set to Instances.CALENDAR_COLOR. 75 Instances.SELF_ATTENDEE_STATUS 76 ) 77 const val INDEX_ALL_DAY = 0 78 const val INDEX_BEGIN = 1 79 const val INDEX_END = 2 80 const val INDEX_TITLE = 3 81 const val INDEX_EVENT_LOCATION = 4 82 const val INDEX_EVENT_ID = 5 83 const val INDEX_START_DAY = 6 84 const val INDEX_END_DAY = 7 85 const val INDEX_COLOR = 8 86 const val INDEX_SELF_ATTENDEE_STATUS = 9 87 const val MAX_DAYS = 7 88 private val SEARCH_DURATION: Long = MAX_DAYS * DateUtils.DAY_IN_MILLIS 89 90 /** 91 * Update interval used when no next-update calculated, or bad trigger time in past. 92 * Unit: milliseconds. 93 */ 94 private val UPDATE_TIME_NO_EVENTS: Long = DateUtils.HOUR_IN_MILLIS * 6 95 96 /** 97 * Format given time for debugging output. 98 * 99 * @param unixTime Target time to report. 100 * @param now Current system time from [System.currentTimeMillis] 101 * for calculating time difference. 102 */ formatDebugTimenull103 fun formatDebugTime(unixTime: Long, now: Long): String { 104 val time = Time() 105 time.set(unixTime) 106 var delta = unixTime - now 107 return if (delta > DateUtils.MINUTE_IN_MILLIS) { 108 delta /= DateUtils.MINUTE_IN_MILLIS 109 String.format( 110 "[%d] %s (%+d mins)", unixTime, 111 time.format("%H:%M:%S"), delta 112 ) 113 } else { 114 delta /= DateUtils.SECOND_IN_MILLIS 115 String.format( 116 "[%d] %s (%+d secs)", unixTime, 117 time.format("%H:%M:%S"), delta 118 ) 119 } 120 } 121 122 init { 123 if (!Utils.isJellybeanOrLater()) { 124 EVENT_PROJECTION[INDEX_COLOR] = Instances.CALENDAR_COLOR 125 } 126 } 127 } 128 129 @Override onGetViewFactorynull130 override fun onGetViewFactory(intent: Intent): RemoteViewsFactory { 131 return CalendarFactory(getApplicationContext(), intent) 132 } 133 134 class CalendarFactory : BroadcastReceiver, RemoteViewsService.RemoteViewsFactory, 135 Loader.OnLoadCompleteListener<Cursor?> { 136 private var mContext: Context? = null 137 private var mResources: Resources? = null 138 private var mLastSerialNum = -1 139 private var mLoader: CursorLoader? = null 140 private val mHandler: Handler = Handler() 141 private val executor: ExecutorService = Executors.newSingleThreadExecutor() 142 private var mAppWidgetId = 0 143 private var mDeclinedColor = 0 144 private var mStandardColor = 0 145 private var mAllDayColor = 0 146 private val mTimezoneChanged: Runnable = object : Runnable { 147 @Override runnull148 override fun run() { 149 if (mLoader != null) { 150 mLoader?.forceLoad() 151 } 152 } 153 } 154 createUpdateLoaderRunnablenull155 private fun createUpdateLoaderRunnable( 156 selection: String, 157 result: PendingResult, 158 version: Int 159 ): Runnable { 160 return object : Runnable { 161 @Override 162 override fun run() { 163 // If there is a newer load request in the queue, skip loading. 164 if (mLoader != null && version >= currentVersion.get()) { 165 val uri: Uri = createLoaderUri() 166 mLoader?.setUri(uri) 167 mLoader?.setSelection(selection) 168 synchronized(mLock) { mLastSerialNum = ++mSerialNum } 169 mLoader?.forceLoad() 170 } 171 result.finish() 172 } 173 } 174 } 175 176 constructor(context: Context, intent: Intent) { 177 mContext = context 178 mResources = context.getResources() 179 mAppWidgetId = intent.getIntExtra( 180 AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID 181 ) 182 mDeclinedColor = mResources?.getColor(R.color.appwidget_item_declined_color) as Int 183 mStandardColor = mResources?.getColor(R.color.appwidget_item_standard_color) as Int 184 mAllDayColor = mResources?.getColor(R.color.appwidget_item_allday_color) as Int 185 } 186 187 constructor() { 188 // This is being created as part of onReceive 189 } 190 191 @Override onCreatenull192 override fun onCreate() { 193 val selection = queryForSelection() 194 initLoader(selection) 195 } 196 197 @Override onDataSetChangednull198 override fun onDataSetChanged() { 199 } 200 201 @Override onDestroynull202 override fun onDestroy() { 203 if (mLoader != null) { 204 mLoader?.reset() 205 } 206 } 207 208 @Override getLoadingViewnull209 override fun getLoadingView(): RemoteViews { 210 val views = RemoteViews(mContext?.getPackageName(), R.layout.appwidget_loading) 211 return views 212 } 213 214 @Override getViewAtnull215 override fun getViewAt(position: Int): RemoteViews? { 216 // we use getCount here so that it doesn't return null when empty 217 if (position < 0 || position >= getCount()) { 218 return null 219 } 220 if (mModel == null) { 221 val views = RemoteViews( 222 mContext?.getPackageName(), 223 R.layout.appwidget_loading 224 ) 225 val intent: Intent = CalendarAppWidgetProvider.getLaunchFillInIntent( 226 mContext, 227 0, 228 0, 229 0, 230 false 231 ) 232 views.setOnClickFillInIntent(R.id.appwidget_loading, intent) 233 return views 234 } 235 if (mModel!!.mEventInfos.isEmpty() || mModel!!.mRowInfos.isEmpty()) { 236 val views = RemoteViews( 237 mContext?.getPackageName(), 238 R.layout.appwidget_no_events 239 ) 240 val intent: Intent = CalendarAppWidgetProvider.getLaunchFillInIntent( 241 mContext, 242 0, 243 0, 244 0, 245 false 246 ) 247 views.setOnClickFillInIntent(R.id.appwidget_no_events, intent) 248 return views 249 } 250 val rowInfo: RowInfo? = mModel?.mRowInfos?.get(position) 251 return if (rowInfo!!.mType == RowInfo.TYPE_DAY) { 252 val views = RemoteViews( 253 mContext?.getPackageName(), 254 R.layout.appwidget_day 255 ) 256 val dayInfo: DayInfo? = mModel?.mDayInfos?.get(rowInfo.mIndex) 257 updateTextView(views, R.id.date, View.VISIBLE, dayInfo!!.mDayLabel) 258 views 259 } else { 260 val views: RemoteViews? 261 val eventInfo: EventInfo? = mModel?.mEventInfos?.get(rowInfo.mIndex) 262 if (eventInfo!!.allDay) { 263 views = RemoteViews( 264 mContext?.getPackageName(), 265 R.layout.widget_all_day_item 266 ) 267 } else { 268 views = RemoteViews(mContext?.getPackageName(), R.layout.widget_item) 269 } 270 val displayColor: Int = Utils.getDisplayColorFromColor(eventInfo.color) 271 val now: Long = System.currentTimeMillis() 272 if (!eventInfo.allDay && eventInfo.start <= now && now <= eventInfo.end) { 273 views.setInt( 274 R.id.widget_row, "setBackgroundResource", 275 R.drawable.agenda_item_bg_secondary 276 ) 277 } else { 278 views.setInt( 279 R.id.widget_row, "setBackgroundResource", 280 R.drawable.agenda_item_bg_primary 281 ) 282 } 283 if (!eventInfo.allDay) { 284 updateTextView(views, R.id.`when`, eventInfo.visibWhen 285 as Int, eventInfo.`when`) 286 updateTextView(views, R.id.where, eventInfo.visibWhere 287 as Int, eventInfo.where) 288 } 289 updateTextView(views, R.id.title, eventInfo.visibTitle as Int, eventInfo.title) 290 views.setViewVisibility(R.id.agenda_item_color, View.VISIBLE) 291 val selfAttendeeStatus: Int = eventInfo.selfAttendeeStatus as Int 292 if (eventInfo.allDay) { 293 if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_INVITED) { 294 views.setInt( 295 R.id.agenda_item_color, "setImageResource", 296 R.drawable.widget_chip_not_responded_bg 297 ) 298 views.setInt(R.id.title, "setTextColor", displayColor) 299 } else { 300 views.setInt( 301 R.id.agenda_item_color, "setImageResource", 302 R.drawable.widget_chip_responded_bg 303 ) 304 views.setInt(R.id.title, "setTextColor", mAllDayColor) 305 } 306 if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED) { 307 // 40% opacity 308 views.setInt( 309 R.id.agenda_item_color, "setColorFilter", 310 Utils.getDeclinedColorFromColor(displayColor) 311 ) 312 } else { 313 views.setInt(R.id.agenda_item_color, "setColorFilter", displayColor) 314 } 315 } else if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED) { 316 views.setInt(R.id.title, "setTextColor", mDeclinedColor) 317 views.setInt(R.id.`when`, "setTextColor", mDeclinedColor) 318 views.setInt(R.id.where, "setTextColor", mDeclinedColor) 319 views.setInt( 320 R.id.agenda_item_color, "setImageResource", 321 R.drawable.widget_chip_responded_bg 322 ) 323 // 40% opacity 324 views.setInt( 325 R.id.agenda_item_color, "setColorFilter", 326 Utils.getDeclinedColorFromColor(displayColor) 327 ) 328 } else { 329 views.setInt(R.id.title, "setTextColor", mStandardColor) 330 views.setInt(R.id.`when`, "setTextColor", mStandardColor) 331 views.setInt(R.id.where, "setTextColor", mStandardColor) 332 if (selfAttendeeStatus == Attendees.ATTENDEE_STATUS_INVITED) { 333 views.setInt( 334 R.id.agenda_item_color, "setImageResource", 335 R.drawable.widget_chip_not_responded_bg 336 ) 337 } else { 338 views.setInt( 339 R.id.agenda_item_color, "setImageResource", 340 R.drawable.widget_chip_responded_bg 341 ) 342 } 343 views.setInt(R.id.agenda_item_color, "setColorFilter", displayColor) 344 } 345 var start: Long = eventInfo.start as Long 346 var end: Long = eventInfo.end as Long 347 // An element in ListView. 348 if (eventInfo.allDay) { 349 val tz: String? = Utils.getTimeZone(mContext, null) 350 val recycle = Time() 351 start = Utils.convertAlldayLocalToUTC(recycle, start, tz as String) 352 end = Utils.convertAlldayLocalToUTC(recycle, end, tz as String) 353 } 354 val fillInIntent: Intent = CalendarAppWidgetProvider.getLaunchFillInIntent( 355 mContext, eventInfo.id, start, end, eventInfo.allDay 356 ) 357 views.setOnClickFillInIntent(R.id.widget_row, fillInIntent) 358 views 359 } 360 } 361 362 @Override getViewTypeCountnull363 override fun getViewTypeCount(): Int { 364 return 5 365 } 366 367 @Override getCountnull368 override fun getCount(): Int { 369 // if there are no events, we still return 1 to represent the "no 370 // events" view 371 if (mModel == null) { 372 return 1 373 } 374 return Math.max(1, mModel?.mRowInfos?.size as Int) 375 } 376 377 @Override getItemIdnull378 override fun getItemId(position: Int): Long { 379 if (mModel == null || mModel?.mRowInfos?.isEmpty() as Boolean || 380 position >= getCount()) { 381 return 0 382 } 383 val rowInfo: RowInfo = mModel?.mRowInfos?.get(position) as RowInfo 384 if (rowInfo.mType == RowInfo.TYPE_DAY) { 385 return rowInfo.mIndex.toLong() 386 } 387 val eventInfo: EventInfo = mModel?.mEventInfos?.get(rowInfo.mIndex) as EventInfo 388 val prime: Long = 31 389 var result: Long = 1 390 result = prime * result + (eventInfo.id xor (eventInfo.id ushr 32)) as Int 391 result = prime * result + (eventInfo.start xor (eventInfo.start ushr 32)) as Int 392 return result 393 } 394 395 @Override hasStableIdsnull396 override fun hasStableIds(): Boolean { 397 return true 398 } 399 400 /** 401 * Query across all calendars for upcoming event instances from now 402 * until some time in the future. Widen the time range that we query by 403 * one day on each end so that we can catch all-day events. All-day 404 * events are stored starting at midnight in UTC but should be included 405 * in the list of events starting at midnight local time. This may fetch 406 * more events than we actually want, so we filter them out later. 407 * 408 * @param selection The selection string for the loader to filter the query with. 409 */ initLoadernull410 fun initLoader(selection: String?) { 411 if (LOGD) Log.d(TAG, "Querying for widget events...") 412 413 // Search for events from now until some time in the future 414 val uri: Uri = createLoaderUri() 415 mLoader = CursorLoader( 416 mContext, uri, EVENT_PROJECTION, selection, null, 417 EVENT_SORT_ORDER 418 ) 419 mLoader?.setUpdateThrottle(WIDGET_UPDATE_THROTTLE.toLong()) 420 synchronized(mLock) { mLastSerialNum = ++mSerialNum } 421 mLoader?.registerListener(mAppWidgetId, this) 422 mLoader?.startLoading() 423 } 424 425 /** 426 * This gets the selection string for the loader. This ends up doing a query in the 427 * shared preferences. 428 */ queryForSelectionnull429 private fun queryForSelection(): String { 430 return if (Utils.getHideDeclinedEvents(mContext)) EVENT_SELECTION_HIDE_DECLINED 431 else EVENT_SELECTION 432 } 433 434 /** 435 * @return The uri for the loader 436 */ createLoaderUrinull437 private fun createLoaderUri(): Uri { 438 val now: Long = System.currentTimeMillis() 439 // Add a day on either side to catch all-day events 440 val begin: Long = now - DateUtils.DAY_IN_MILLIS 441 val end: Long = 442 now + SEARCH_DURATION + DateUtils.DAY_IN_MILLIS 443 return Uri.withAppendedPath( 444 Instances.CONTENT_URI, 445 begin.toString() + "/" + end 446 ) 447 } 448 449 /** 450 * Calculates and returns the next time we should push widget updates. 451 */ calculateUpdateTimenull452 private fun calculateUpdateTime( 453 model: CalendarAppWidgetModel, 454 now: Long, 455 timeZone: String 456 ): Long { 457 // Make sure an update happens at midnight or earlier 458 var minUpdateTime = getNextMidnightTimeMillis(timeZone) 459 for (event in model.mEventInfos) { 460 val start: Long 461 val end: Long 462 start = event.start 463 end = event.end 464 465 // We want to update widget when we enter/exit time range of an event. 466 if (now < start) { 467 minUpdateTime = Math.min(minUpdateTime, start) 468 } else if (now < end) { 469 minUpdateTime = Math.min(minUpdateTime, end) 470 } 471 } 472 return minUpdateTime 473 } 474 475 /* 476 * (non-Javadoc) 477 * @see 478 * android.content.Loader.OnLoadCompleteListener#onLoadComplete(android 479 * .content.Loader, java.lang.Object) 480 */ 481 @Override onLoadCompletenull482 override fun onLoadComplete(loader: Loader<Cursor?>?, cursor: Cursor?) { 483 if (cursor == null) { 484 return 485 } 486 // If a newer update has happened since we started clean up and 487 // return 488 synchronized(mLock) { 489 if (cursor.isClosed()) { 490 Log.wtf(TAG, "Got a closed cursor from onLoadComplete") 491 return 492 } 493 if (mLastSerialNum != mSerialNum) { 494 return 495 } 496 val now: Long = System.currentTimeMillis() 497 val tz: String? = Utils.getTimeZone(mContext, mTimezoneChanged) 498 499 // Copy it to a local static cursor. 500 val matrixCursor: MatrixCursor? = Utils.matrixCursorFromCursor(cursor) 501 try { 502 mModel = buildAppWidgetModel(mContext, matrixCursor, tz) 503 } finally { 504 if (matrixCursor != null) { 505 matrixCursor.close() 506 } 507 if (cursor != null) { 508 cursor.close() 509 } 510 } 511 512 // Schedule an alarm to wake ourselves up for the next update. 513 // We also cancel 514 // all existing wake-ups because PendingIntents don't match 515 // against extras. 516 var triggerTime = calculateUpdateTime(mModel as CalendarAppWidgetModel, 517 now, tz as String) 518 519 // If no next-update calculated, or bad trigger time in past, 520 // schedule 521 // update about six hours from now. 522 if (triggerTime < now) { 523 Log.w(TAG, "Encountered bad trigger time " + formatDebugTime(triggerTime, now)) 524 triggerTime = now + UPDATE_TIME_NO_EVENTS 525 } 526 val alertManager: AlarmManager = mContext 527 ?.getSystemService(Context.ALARM_SERVICE) as AlarmManager 528 val pendingUpdate: PendingIntent = CalendarAppWidgetProvider 529 .getUpdateIntent(mContext) 530 alertManager.cancel(pendingUpdate) 531 alertManager.set(AlarmManager.RTC, triggerTime, pendingUpdate) 532 val time = Time(Utils.getTimeZone(mContext, null)) 533 time.setToNow() 534 if (time.normalize(true) !== sLastUpdateTime) { 535 val time2 = Time(Utils.getTimeZone(mContext, null)) 536 time2.set(sLastUpdateTime) 537 time2.normalize(true) 538 if (time.year !== time2.year || time.yearDay !== time2.yearDay) { 539 val updateIntent = Intent( 540 Utils.getWidgetUpdateAction(mContext as Context) 541 ) 542 mContext?.sendBroadcast(updateIntent) 543 } 544 sLastUpdateTime = time.toMillis(true) 545 } 546 val widgetManager: AppWidgetManager = AppWidgetManager.getInstance(mContext) 547 if (widgetManager == null) { 548 return 549 } 550 if (mAppWidgetId == -1) { 551 val ids: IntArray = widgetManager.getAppWidgetIds( 552 CalendarAppWidgetProvider 553 .getComponentName(mContext) 554 ) 555 widgetManager.notifyAppWidgetViewDataChanged(ids, R.id.events_list) 556 } else { 557 widgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.events_list) 558 } 559 } 560 } 561 562 @Override onReceivenull563 override fun onReceive(context: Context?, intent: Intent) { 564 if (LOGD) Log.d(TAG, "AppWidgetService received an intent. It was " + intent.toString()) 565 mContext = context 566 567 // We cannot do any queries from the UI thread, so push the 'selection' query 568 // to a background thread. However the implementation of the latter query 569 // (cursor loading) uses CursorLoader which must be initiated from the UI thread, 570 // so there is some convoluted handshaking here. 571 // 572 // Note that as currently implemented, this must run in a single threaded executor 573 // or else the loads may be run out of order. 574 // 575 // TODO: Remove use of mHandler and CursorLoader, and do all the work synchronously 576 // in the background thread. All the handshaking going on here between the UI and 577 // background thread with using goAsync, mHandler, and CursorLoader is confusing. 578 val result: PendingResult = goAsync() 579 executor.submit(object : Runnable { 580 @Override 581 override fun run() { 582 // We always complete queryForSelection() even if the load task ends up being 583 // canceled because of a more recent one. Optimizing this to allow 584 // canceling would require keeping track of all the PendingResults 585 // (from goAsync) to abort them. Defer this until it becomes a problem. 586 val selection = queryForSelection() 587 if (mLoader == null) { 588 mAppWidgetId = -1 589 mHandler.post(object : Runnable { 590 @Override 591 override fun run() { 592 initLoader(selection) 593 result.finish() 594 } 595 }) 596 } else { 597 mHandler.post( 598 createUpdateLoaderRunnable( 599 selection, result, 600 currentVersion.incrementAndGet() 601 ) 602 ) 603 } 604 } 605 }) 606 } 607 608 internal companion object { 609 private const val LOGD = false 610 611 // Suppress unnecessary logging about update time. Need to be static as this object is 612 // re-instantiated frequently. 613 // TODO: It seems loadData() is called via onCreate() four times, which should mean 614 // unnecessary CalendarFactory object is created and dropped. It is not efficient. 615 private var sLastUpdateTime = UPDATE_TIME_NO_EVENTS 616 private var mModel: CalendarAppWidgetModel? = null 617 private val mLock: Object = Object() 618 619 @Volatile 620 private var mSerialNum = 0 621 private val currentVersion: AtomicInteger = AtomicInteger(0) 622 623 /* @VisibleForTesting */ buildAppWidgetModelnull624 @JvmStatic protected fun buildAppWidgetModel( 625 context: Context?, 626 cursor: Cursor?, 627 timeZone: String? 628 ): CalendarAppWidgetModel { 629 val model = CalendarAppWidgetModel(context as Context, timeZone) 630 model.buildFromCursor(cursor as Cursor, timeZone) 631 return model 632 } 633 getNextMidnightTimeMillisnull634 @JvmStatic private fun getNextMidnightTimeMillis(timezone: String): Long { 635 val time = Time() 636 time.setToNow() 637 time.monthDay++ 638 time.hour = 0 639 time.minute = 0 640 time.second = 0 641 val midnightDeviceTz: Long = time.normalize(true) 642 time.timezone = timezone 643 time.setToNow() 644 time.monthDay++ 645 time.hour = 0 646 time.minute = 0 647 time.second = 0 648 val midnightHomeTz: Long = time.normalize(true) 649 return Math.min(midnightDeviceTz, midnightHomeTz) 650 } 651 updateTextViewnull652 @JvmStatic fun updateTextView( 653 views: RemoteViews, 654 id: Int, 655 visibility: Int, 656 string: String? 657 ) { 658 views.setViewVisibility(id, visibility) 659 if (visibility == View.VISIBLE) { 660 views.setTextViewText(id, string) 661 } 662 } 663 } 664 } 665 }