Upgrade to Pro — share decks privately, control downloads, hide ads and more …

kotlin season 1 - Part 15 Image Load Library

TaeHwan
November 18, 2016

kotlin season 1 - Part 15 Image Load Library

2016년 유데미 Kotlin 강의를 공개합니다.

동영상 : https://www.youtube.com/watch?v=dROp2e7jNyk

2회 분은 유데미에서 확인 가능합니다.
http://bit.ly/2UpaJUR

TaeHwan

November 18, 2016
Tweet

More Decks by TaeHwan

Other Decks in Education

Transcript

  1. Part 15 Kotlin Image Load Library Taehwan ରࣁ؀ উ٘۽੉٘ ѐߊ

    ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 1
  2. ࢠ೒ ௏٘ח!!! 4 Sample Code GitHub ࠳۠஖ : 10-Image-Library 4

    https://github.com/taehwandev/Kotlin-Udemy- Sample/tree/10-Image-Library ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 2
  3. য়ט ೡ ࠗ࠙ 4 AsyncTaskܳ ੉ਊೠ ੉޷૑ ۽٘ೞח ߑߨ 4

    Threadܳ ੉ਊೠ ੉޷૑ ۽٘ೞח ߑߨ 4 ੉޷૑ ۽٘ ۄ੉࠳۞ܻ ࣗѐ ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 3
  4. AsyncTask private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { protected

    Long doInBackground(URL... urls) { return totalSize; } protected void onProgressUpdate(Integer... progress) { setProgressPercent(progress[0]); } protected void onPostExecute(Long result) { showDialog("Downloaded " + result + " bytes"); } } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 6
  5. AsyncTask 4 SERIAL_EXECUTOR 4 THREADPOOLEXECUTOR new DownloadFilesTask().execute(url1, url2, url3); new

    DownloadFilesTask().executeOnExecutor(THREAD_POOL_EXECUTOR, url1, url2, url3); ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 7
  6. AsyncTask۽ ੘ࢿೠ ઱ਃ ௏٘ private class ImageAsync(imageView: ImageView) : AsyncTask<String,

    String, String>() { override fun doInBackground(vararg strings: String): String? { try { val urlString = strings[0] connection = URL(urlString).openConnection() connection?.connect() inputStream = connection?.inputStream bufferedInputStream = BufferedInputStream(inputStream) cache.put(urlString, WeakReference(BitmapFactory.decodeStream(bufferedInputStream))) return urlString } catch (e: IOException) { } return null } } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 8
  7. ചݶী Ӓܻח ࠗ࠙ override fun onPostExecute(url: String) { super.onPostExecute(url) if

    (isCancelled) { return } val imageView = weakReferenceImageView.get() // ࢤۚ... imageView.setImageBitmap(cache.get(url).get()) } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 9
  8. Threadܳ ੉ਊೠ ੉޷૑ ۽٘ೞח ߑߨ 4 Thread৬ Runnableਸ ੉ਊೞৈ ੉޷૑ܳ

    ۽٘ೞҊ, Ӓܽ׮. ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 12
  9. Threadਸ ੉ਊೠ ࠗ࠙੄ ઱ਃ ௏٘ private class DownloadThread(imageView: ImageView, private

    val resourceUrl: String) : Runnable { override fun run() { try { val url = URL(resourceUrl) connection = url.openConnection() connection?.connect() inputStream = connection?.inputStream bufferedInputStream = BufferedInputStream(inputStream) cache.put(resourceUrl, WeakReference(BitmapFactory.decodeStream(bufferedInputStream))) draw(resourceUrl) } catch (e: IOException) { } } } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 13
  10. Threadਸ ੉ਊೞৈ ੉޷૑ Ӓܻח ࠗ࠙ private fun draw(resourceUrl: String) {

    Handler(Looper.getMainLooper()).post { val imageView = weakReferenceImageView.get() if (!TextUtils.isEmpty(resourceUrl) && imageView.tag != null && imageView.tag == resourceUrl && cache.get(resourceUrl) != null && cache.get(resourceUrl).get() != null) { imageView.setImageBitmap(cache.get(resourceUrl).get()) } } } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 14
  11. ૒੽ ҳഅೞݶ? - ࢤп೧ঠ ೡ ࠗ࠙ 4 ݒߣ ੋఠ֔ਸ ా೧ࢲ

    ࠛ۞ৢ Ѫੋо? 4 நएח যڃ धਵ۽ ೡ Ѫੋо? 4 ݫݽܻח? ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 16
  12. ੉޷૑ ۽٘ ۄ੉࠳۞ܻ ࣗѐ 4 Universal Image Loader 4 Picasso

    4 Glide 4 Fresco ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 18
  13. Fresco 4 Fresco द੘ೞӝ 4 ੉޷૑ ׮਍۽٘ ߂ ୊ܻܳ ਤೠ

    Library 4 ׮নೠ Format ૑ਗ(JPEG, GIF, WebP ١) 4 ۽ஸ நए ࢎਊ 4 Android NDK ӝ߈੄ ੉޷૑ ۄ੉࠳۞ܻ ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 20
  14. Fresco ௏٘ Uri uri = Uri.parse("http://frescolib.org/static/fresco-logo.png"); SimpleDraweeView draweeView = (SimpleDraweeView)

    findViewById(R.id.my_image_view); draweeView.setImageURI(uri); ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 24
  15. Fresco 4 ׮ܲ ۄ੉࠳۞ܻী ࠺೧ࢲ ޖѢ਑(ਊ۝੉ ௼Ҋ, ݫࣗ٘ ஠਍౟ب ௼

    ׮) 4 Ҋ೧࢚ب੄ ੉޷૑ܳ ೙ਃ۽ ೞ૑ ঋਵݶ Ҷ੉ ೙ਃ஖ ঋ਺.(GIF ನ ೣ) 4 ߹ب੄ ImageViewܳ ࢎਊ೧ঠ ೣ ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 25
  16. Glide ࣗѐ 4 ੉޷૑ ׮਍۽٘ ߂ Loadܳ ਤೠ Library 4

    ׮নೠ Format ૑ਗ(JPEG, GIF, PNG ١) 4 ۽ஸ நए ࢎਊ ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 27
  17. Glide ࢎਊೞӝ // For a simple view: @Override public void

    onCreate(Bundle savedInstanceState) { // ... ImageView imageView = (ImageView) findViewById(R.id.my_image_view); Glide.with(this).load("http://goo.gl/gEgYUd").into(imageView); } ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 29
  18. ଵҊ ੗ܐ 4 Glide 4 Fresco 4 উ٘۽੉٘ ѐߊ੗ܳ ਤೠ)

    য়೑ࣗझ ۄ੉࠳۞ܻ ࢎਊ о੉٘ - kunny 4 Glide vs Fresco of GIF Performance - SeongUg Steve Jung ରࣁ؀ উ٘۽੉٘ ѐߊ ঱য ௏ౣܽ, द੘ೞӝ thdev.tech, 2016 31