|
@@ -1,6 +1,12 @@
|
|
|
package com.swago
|
|
|
|
|
|
+import android.app.Activity
|
|
|
import android.content.Context
|
|
|
+import android.graphics.Bitmap
|
|
|
+import android.graphics.BitmapFactory
|
|
|
+import android.graphics.NinePatch
|
|
|
+import android.graphics.drawable.Drawable
|
|
|
+import android.graphics.drawable.NinePatchDrawable
|
|
|
import android.os.Build
|
|
|
import android.text.BidiFormatter
|
|
|
import android.text.TextDirectionHeuristics
|
|
@@ -9,8 +15,14 @@ import androidx.annotation.DrawableRes
|
|
|
import androidx.annotation.RequiresApi
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.bumptech.glide.request.RequestOptions
|
|
|
+import com.bumptech.glide.request.target.CustomTarget
|
|
|
+import com.bumptech.glide.request.transition.Transition
|
|
|
import com.swago.baseswago.R
|
|
|
import jp.wasabeef.glide.transformations.BlurTransformation
|
|
|
+import java.io.File
|
|
|
+import java.io.FileInputStream
|
|
|
+import java.io.FileNotFoundException
|
|
|
+import java.io.IOException
|
|
|
import java.util.*
|
|
|
|
|
|
/**
|
|
@@ -72,4 +84,39 @@ fun CharSequence.formatAr(): CharSequence {
|
|
|
this,
|
|
|
TextDirectionHeuristics.LOCALE
|
|
|
)
|
|
|
+}
|
|
|
+
|
|
|
+fun loadDian9Tu(context: Context, imageView: ImageView, url: String){
|
|
|
+ if (context is Activity){
|
|
|
+ if (context.isDestroyed)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Glide.with(context)
|
|
|
+ .asFile()
|
|
|
+ .load(url)
|
|
|
+ .into(object : CustomTarget<File>() {
|
|
|
+ override fun onResourceReady(resource: File, transition: Transition<in File>?) {
|
|
|
+ try {
|
|
|
+ FileInputStream(resource).use { inputStream ->
|
|
|
+ val bitmap = BitmapFactory.decodeStream(inputStream)
|
|
|
+ imageView.setNinePatchImage(context , bitmap)
|
|
|
+ }
|
|
|
+ } catch (e: FileNotFoundException) {
|
|
|
+ e.printStackTrace()
|
|
|
+ } catch (e: IOException) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onLoadCleared(placeholder: Drawable?) {
|
|
|
+
|
|
|
+ }
|
|
|
+ })
|
|
|
+}
|
|
|
+
|
|
|
+fun ImageView.setNinePatchImage(context: Context, bitmap: Bitmap) {
|
|
|
+ val chunk = bitmap.ninePatchChunk
|
|
|
+ val ninePatch = NinePatch(bitmap, chunk, null)
|
|
|
+ val ninePatchDrawable = NinePatchDrawable(context.resources, ninePatch)
|
|
|
+ this.setImageDrawable(ninePatchDrawable)
|
|
|
}
|