Skip to content

Instantly share code, notes, and snippets.

@mariusz-blaszczak
Created August 28, 2018 10:24
Show Gist options
  • Save mariusz-blaszczak/7bfd351884dafef3759f68304cec7533 to your computer and use it in GitHub Desktop.
Save mariusz-blaszczak/7bfd351884dafef3759f68304cec7533 to your computer and use it in GitHub Desktop.
open class LockWidgetProvider : AppWidgetProvider() {
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
for (id in appWidgetIds) {
appWidgetManager.updateAppWidget(id, createLockRemoteViews(context, AppCache.lockState))
}
}
override fun onReceive(context: Context, intent: Intent) {
super.onReceive(context, intent)
LockWidgetJobService.handleAction(context, intent.action)
}
override fun onEnabled(context: Context) {
super.onEnabled(context)
LockWidgetJobService.handleAction(context, ACTION_REFRESH)
}
companion object {
const val ACTION_TOGGLE = "${BuildConfig.APPLICATION_ID}.ACTION_TOGGLE"
const val ACTION_REFRESH = "${BuildConfig.APPLICATION_ID}.ACTION_REFRESH"
private fun createPendingIntent(context: Context, action: String): PendingIntent {
val intent = Intent(context, LockWidgetProvider::class.java)
intent.action = action
intent.data = Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))
return PendingIntent.getBroadcast(context, 0, intent,
PendingIntent.FLAG_UPDATE_CURRENT)
}
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment