Created
August 28, 2018 10:24
-
-
Save mariusz-blaszczak/7bfd351884dafef3759f68304cec7533 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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