-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #314 from openedx/develop
Develop to main v1.5.1
- Loading branch information
Showing
109 changed files
with
4,983 additions
and
3,369 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
@file:Suppress("DEPRECATION") | ||
|
||
package org.openedx.core | ||
|
||
import android.content.Context | ||
import android.graphics.Bitmap | ||
import android.graphics.drawable.Drawable | ||
import android.renderscript.Allocation | ||
import android.renderscript.RenderScript | ||
import android.renderscript.ScriptIntrinsicBlur | ||
import androidx.annotation.DrawableRes | ||
import coil.ImageLoader | ||
import coil.request.ImageRequest | ||
|
||
class ImageProcessor(private val context: Context) { | ||
fun loadImage( | ||
@DrawableRes | ||
defaultImage: Int, | ||
imageUrl: String, | ||
onComplete: (result: Drawable) -> Unit | ||
) { | ||
val loader = ImageLoader(context) | ||
val request = ImageRequest.Builder(context) | ||
.data(imageUrl) | ||
.target { result -> | ||
onComplete(result) | ||
} | ||
.error(defaultImage) | ||
.placeholder(defaultImage) | ||
.allowHardware(false) | ||
.build() | ||
loader.enqueue(request) | ||
} | ||
|
||
fun applyBlur( | ||
bitmap: Bitmap, | ||
blurRadio: Float | ||
): Bitmap { | ||
val renderScript = RenderScript.create(context) | ||
val bitmapAlloc = Allocation.createFromBitmap(renderScript, bitmap) | ||
ScriptIntrinsicBlur.create(renderScript, bitmapAlloc.element).apply { | ||
setRadius(blurRadio) | ||
setInput(bitmapAlloc) | ||
repeat(3) { | ||
forEach(bitmapAlloc) | ||
} | ||
} | ||
val newBitmap: Bitmap = Bitmap.createBitmap( | ||
bitmap.width, | ||
bitmap.height, | ||
Bitmap.Config.ARGB_8888 | ||
) | ||
bitmapAlloc.copyTo(newBitmap) | ||
renderScript.destroy() | ||
return newBitmap | ||
} | ||
} |
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
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
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
Oops, something went wrong.