Browse Source

added image resize

yattoz 4 years ago
parent
commit
53614b3c86

+ 6 - 7
app/src/main/java/fr/forum_thalie/tsumugi/ui/news/NewsAdapter.kt View File

45
             try {
45
             try {
46
                 k = URL(source).content as InputStream
46
                 k = URL(source).content as InputStream
47
                 val options = BitmapFactory.Options()
47
                 val options = BitmapFactory.Options()
48
-                options.inSampleSize = 1/4
49
-                // this makes 1/2 of origin image size from width and height.
50
-                // it alleviates the memory for API16-API19 especially
48
+                options.inSampleSize = 1
49
+                // Putting 2 makes 1/2 of origin image size from width and height.
50
+                // it alleviates the memory and CPU too for weak devices.
51
                 pic = BitmapFactory.decodeStream(k, null, options)
51
                 pic = BitmapFactory.decodeStream(k, null, options)
52
                 k.close()
52
                 k.close()
53
             } catch (e: IOException) {
53
             } catch (e: IOException) {
67
             val size = Point()
67
             val size = Point()
68
             (context as Activity).windowManager.defaultDisplay.getSize(size)
68
             (context as Activity).windowManager.defaultDisplay.getSize(size)
69
             // Lets calculate the ratio according to the screen width in px
69
             // Lets calculate the ratio according to the screen width in px
70
-            val multiplier: Int = size.x / bitmap!!.width
71
-            //Log.d(LOG_CAT, "multiplier: $multiplier")
70
+            val multiplier: Double = (size.x).toDouble() / (bitmap!!.width.toDouble())
72
             levelListDrawable.addLevel(1, 1, d)
71
             levelListDrawable.addLevel(1, 1, d)
73
             // Set bounds width  and height according to the bitmap resized size
72
             // Set bounds width  and height according to the bitmap resized size
74
             levelListDrawable.setBounds(
73
             levelListDrawable.setBounds(
75
                 0,
74
                 0,
76
                 0,
75
                 0,
77
-                bitmap.width * multiplier,
78
-                bitmap.height * multiplier
76
+                (bitmap.width.toDouble() * multiplier).toInt(),
77
+                (bitmap.height.toDouble() * multiplier).toInt()
79
             )
78
             )
80
             levelListDrawable.level = 1
79
             levelListDrawable.level = 1
81
             t!!.text = t!!.text // invalidate() doesn't work correctly...
80
             t!!.text = t!!.text // invalidate() doesn't work correctly...