Skip to content

Commit

Permalink
v1.0.5 using Universal image loader for load image
Browse files Browse the repository at this point in the history
  • Loading branch information
hantrungkien committed Jul 20, 2018
1 parent 7e3fd78 commit bdd8f3d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bubblepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ dependencies {

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.github.bumptech.glide:glide:3.8.0'

implementation files('libs/jbox2d-library-2.1.2.2.jar')
implementation files('libs/slf4j-api-1.7.22.jar')
implementation files('libs/universal-image-loader-1.9.5.jar')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.kienht.bubblepicker.rendering

import android.content.Context
import android.content.res.Resources
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.opengl.GLES20.*
Expand All @@ -10,7 +9,6 @@ import android.text.Layout
import android.text.StaticLayout
import android.text.TextPaint
import android.text.TextUtils
import com.bumptech.glide.Glide
import com.kienht.bubblepicker.model.BubbleGradient
import com.kienht.bubblepicker.model.PickerItem
import com.kienht.bubblepicker.physics.CircleBody
Expand All @@ -19,8 +17,14 @@ import com.kienht.bubblepicker.toTexture
import org.jbox2d.common.Vec2
import java.lang.ref.WeakReference
import android.graphics.Bitmap
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.kienht.bubblepicker.resizeBitmap
import com.nostra13.universalimageloader.core.ImageLoader
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration
import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer
import com.nostra13.universalimageloader.core.assist.ImageScaleType
import com.nostra13.universalimageloader.core.DisplayImageOptions
import com.nostra13.universalimageloader.core.assist.ImageSize


/**
Expand Down Expand Up @@ -84,14 +88,25 @@ data class Item(val context: WeakReference<Context>,

private fun createBitmap(isSelected: Boolean): Bitmap {
var bitmap = if (!TextUtils.isEmpty(pickerItem.imgUrl) && pickerItem.isUseImgUrl) {
val bmLoaded = Glide.with(context.get())
.load(pickerItem.imgUrl)
.asBitmap()
.skipMemoryCache(true)
.into(bitmapSize.toInt() / 2, bitmapSize.toInt() / 2)
.get()

bmLoaded.resizeBitmap(bitmapSize.toInt(), bitmapSize.toInt())

val imageLoader = ImageLoader.getInstance()

val defaultOptions = DisplayImageOptions.Builder()
.cacheInMemory(true)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.build()

val config = ImageLoaderConfiguration.Builder(context.get())
.defaultDisplayImageOptions(defaultOptions)
.memoryCache(WeakMemoryCache())
.build()

imageLoader.init(config)

val bmp = imageLoader.loadImageSync(pickerItem.imgUrl, ImageSize(bitmapSize.toInt() / 2, bitmapSize.toInt() /2))

bmp.resizeBitmap(bitmapSize.toInt(), bitmapSize.toInt())
} else {
Bitmap.createBitmap(bitmapSize.toInt(), bitmapSize.toInt(), Bitmap.Config.ARGB_4444)
}
Expand All @@ -108,6 +123,7 @@ data class Item(val context: WeakReference<Context>,
drawBackground(canvas, isSelected)
drawIcon(canvas)
drawText(canvas)

return bitmap
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import android.opengl.GLES20.*
import android.opengl.GLSurfaceView
import android.util.Log
import android.view.View
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.kienht.bubblepicker.*
import com.kienht.bubblepicker.model.Color
import com.kienht.bubblepicker.model.PickerItem
Expand Down
Binary file removed bubblepicker/src/main/res/drawable/test.jpg
Binary file not shown.

0 comments on commit bdd8f3d

Please sign in to comment.