Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //BroadcastReceiver fetches, stores and notifies feature handlers of color updates.
- override fun onReceive(context: Context, intent: Intent) {
- Timber.d("Pluvius Broadcast Received, $intent")
- if (isSameWallpaper() && intent.action == Intent.ACTION_WALLPAPER_CHANGED) {
- return
- }
- val wallpaper = wallpaperManager.drawable as BitmapDrawable
- Palette.from(wallpaper.bitmap).maximumColorCount(32).generate {
- saveColorValues(it)
- when (intent.action) {
- Intent.ACTION_WALLPAPER_CHANGED -> {
- OverlayUpdateHandler(APP_FEATURE_ACCENT)
- OverlayUpdateHandler(APP_FEATURE_SYSTEMUI)
- }
- APP_FEATURE_ACCENT -> {
- OverlayUpdateHandler(APP_FEATURE_ACCENT)
- }
- APP_FEATURE_SYSTEMUI -> {
- OverlayUpdateHandler(APP_FEATURE_SYSTEMUI)
- }
- ACTION_TOTAL_WIPEOUT -> {
- OverlayUpdateHandler(APP_FEATURE_ACCENT)
- OverlayUpdateHandler(APP_FEATURE_SYSTEMUI)
- }
- }
- }
- }
- // here's list of color values it saves:
- private fun saveColorValues(it: Palette) {
- val col1 = it.getVibrantColor(Color.BLACK)
- val col2 = it.getDominantColor(Color.BLACK)
- val col3 = it.getMutedColor(Color.BLACK)
- val col4 = it.getDarkVibrantColor(Color.BLACK)
- val col5 = it.getDarkMutedColor(Color.BLACK)
- val col6 = it.getLightMutedColor(Color.BLACK)
- val col7 = it.getLightVibrantColor(Color.BLACK)
- App.sp.edit().putInt(COLOR_VIBRANT, col1)
- .putInt(COLOR_DOMINANT, col2)
- .putInt(COLOR_MUTED, col3)
- .putInt(COLOR_DARK_VIBRANT, col4)
- .putInt(COLOR_DARK_MUTED, col5)
- .putInt(COLOR_LIGHT_MUTED, col6)
- .putInt(COLOR_LIGHT_VIBRANT, col7)
- .apply()
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement