Created
January 5, 2020 05:56
-
-
Save crypticminds/3c73d429124fbd1d700b56f4ea957e32 to your computer and use it in GitHub Desktop.
This file contains 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
package com.arcane.coldstoragecache.converter.impl | |
import android.graphics.Bitmap | |
import android.graphics.BitmapFactory | |
import android.util.Base64 | |
import android.util.Log | |
import com.arcane.coldstoragecache.converter.IConverter | |
/** | |
* An example converter that will convert the stored string | |
* into a bitmap. | |
* | |
*/ | |
class StringToBitmapConverter : IConverter<Any?> { | |
/** | |
* The function will convert the string stored in the cache | |
* into the required bitmap. | |
*/ | |
override fun convert(cachedString: String): Bitmap? { | |
return try { | |
val encodeByte: ByteArray = Base64.decode(cachedString, Base64.DEFAULT) | |
BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.size) | |
} catch (e: Exception) { | |
Log.e("ERROR", "Failed to convert cached string to bitmap") | |
return null | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment