Update to kotlin 1.3

Update anko
Fix bug KT-19489 : https://youtrack.jetbrains.com/issue/KT-19489
This commit is contained in:
oupson 2018-11-09 21:34:21 +01:00
parent 2cf1095fdf
commit 208625b35e
11 changed files with 51 additions and 18 deletions

View File

@ -1,6 +0,0 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="UnusedSymbol" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@ -5,22 +5,26 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="5">
<list size="7">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="4">
<list size="6">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
</list>
</value>
</option>

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -32,7 +32,7 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.anko:anko:0.10.7"
implementation "org.jetbrains.anko:anko:0.10.8"
}
repositories {
mavenCentral()

View File

@ -3,6 +3,7 @@ package oupson.apng
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Canvas
import android.util.Log
import oupson.apng.Utils.Companion.isApng
import oupson.apng.Utils.Companion.pngSignature
import oupson.apng.Utils.Companion.to4Bytes
@ -25,6 +26,8 @@ class APNGDisassembler(val byteArray: ByteArray) {
var blend_op : Utils.Companion.blend_op = Utils.Companion.blend_op.APNG_BLEND_OP_SOURCE
var dispose_op : Utils.Companion.dispose_op= Utils.Companion.dispose_op.APNG_DISPOSE_OP_NONE
var apng : Apng
init {
if (isApng(byteArray)) {
val ihdr = IHDR()
@ -33,7 +36,7 @@ class APNGDisassembler(val byteArray: ByteArray) {
maxHeight = ihdr.pngHeight
for(i in 0 until byteArray.size) {
// find new Frame with fcTL
if (byteArray[i] == 0x66.toByte() && byteArray[i + 1] == 0x63.toByte() && byteArray[ i + 2 ] == 0x54.toByte() && byteArray[ i + 3 ] == 0x4C.toByte() || i == byteArray.size - 1) {
if (byteArray[i] == 0x66.toByte() && byteArray[i + 1] == 0x63.toByte() && byteArray[ i + 2 ] == 0x54.toByte() && byteArray[ i + 3 ] == 0x4C.toByte()) {
if (png == null) {
if (cover != null) {
cover!!.addAll(to4Bytes(0).toList())
@ -78,7 +81,15 @@ class APNGDisassembler(val byteArray: ByteArray) {
png = ArrayList()
val fcTL = fcTL(byteArray.copyOfRange(i - 4, i + 36))
val bodySize = {
var lengthString = ""
byteArray.copyOfRange(i - 4, i).forEach {
lengthString += String.format("%02x", it)
}
lengthString.toLong(16).toInt()
}()
val newBytes = byteArray.copyOfRange(i - 4, i + 4 + bodySize)
val fcTL = fcTL(newBytes)
delay = fcTL.delay
yOffset = fcTL.y_offset
@ -99,6 +110,17 @@ class APNGDisassembler(val byteArray: ByteArray) {
}
}
}
else if (i == byteArray.size - 1) {
png!!.addAll(to4Bytes(0).toList())
// Add IEND
val iend = byteArrayOf(0x49, 0x45, 0x4E, 0x44)
// Generate crc for IEND
val crC32 = CRC32()
crC32.update(iend, 0, iend.size)
png!!.addAll(iend.toList())
png!!.addAll(to4Bytes(crC32.value.toInt()).toList())
pngList.add(Frame(png!!.toByteArray(), delay, xOffset, yOffset, maxWidth, maxHeight, blend_op, dispose_op))
}
// Check if is IDAT
else if (byteArray[i] == 0x49.toByte() && byteArray[i + 1] == 0x44.toByte() && byteArray[ i + 2 ] == 0x41.toByte() && byteArray[ i + 3 ] == 0x54.toByte()) {
if (png == null) {
@ -183,6 +205,10 @@ class APNGDisassembler(val byteArray: ByteArray) {
tnrs = byteArray.copyOfRange( i -4, i + 8 + bodySize)
}
}
apng = Apng()
apng.frames = pngList
} else {
throw NotApngException()
}

View File

@ -29,7 +29,7 @@ class Apng {
*/
var cover : Bitmap? = null
set(value) {
field = convertImage(value!!)
field = value!!
}
var frames : ArrayList<Frame> = ArrayList()
@ -121,6 +121,14 @@ class Apng {
fun addFrames(index: Int, bitmap: Bitmap, delay: Float, xOffset : Int, yOffset : Int, dispose_op: Utils.Companion.dispose_op, blend_op: Utils.Companion.blend_op) {
frames.add(index, Frame(toByteArray(bitmap), delay, xOffset, yOffset, blend_op, dispose_op))
}
fun addFrames(frame : Frame) {
frames.add(frame)
}
fun addFrames(index: Int,frame : Frame) {
frames.add(index, frame)
}
//endregion
/**

View File

@ -91,7 +91,7 @@ class Utils {
*/
fun toByteArray(bitmap: Bitmap) : ByteArray {
val bos = ByteArrayOutputStream();
convertImage(bitmap).compress(Bitmap.CompressFormat.PNG, 0 /*ignored for PNG*/, bos);
convertImage(bitmap).compress(Bitmap.CompressFormat.PNG, 100 /*ignored for PNG*/, bos);
return bos.toByteArray();
}
@ -102,6 +102,7 @@ class Utils {
*/
fun convertImage(bitmap: Bitmap) : Bitmap{
val btm = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
btm.setHasAlpha(true)
val canvas = Canvas(btm)
canvas.drawBitmap(bitmap, 0f, 0f, null)
return btm

View File

@ -7,7 +7,7 @@ import oupson.apng.Utils.Companion.getDispose_op
class fcTL(byteArray: ByteArray) {
private var corpsSize = -1
var fcTLBody = byteArrayOf()
lateinit var fcTLBody : ByteArray
// Height and width of frame
var pngWidth = -1
@ -92,7 +92,7 @@ class fcTL(byteArray: ByteArray) {
y_offset = yOffset.toLong(16).toInt()
val _fcTLBody = ArrayList<Byte>()
byteArray.copyOfRange(i + 4, i + corpsSize + 4).forEach {
byteArray.copyOfRange(i + 4, i + corpsSize + 3 ).forEach {
_fcTLBody.add(it)
}
fcTLBody= _fcTLBody.toByteArray()

View File

@ -30,7 +30,7 @@ android {
productFlavors {
}
}
ext.anko_version = '0.10.7'
ext.anko_version = '0.10.8'
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

View File

@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.71'
ext.kotlin_version = '1.3.0'
repositories {
google()
jcenter()