|
|
@ -336,7 +336,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
* @param value 保存的bitmap数据 |
|
|
|
* @param value 保存的bitmap数据 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun put(key: String, value: Bitmap) { |
|
|
|
fun put(key: String, value: Bitmap) { |
|
|
|
put(key, Utils.Bitmap2Bytes(value)) |
|
|
|
put(key, Utils.bitmap2Bytes(value)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -347,7 +347,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
* @param saveTime 保存的时间,单位:秒 |
|
|
|
* @param saveTime 保存的时间,单位:秒 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun put(key: String, value: Bitmap, saveTime: Int) { |
|
|
|
fun put(key: String, value: Bitmap, saveTime: Int) { |
|
|
|
put(key, Utils.Bitmap2Bytes(value), saveTime) |
|
|
|
put(key, Utils.bitmap2Bytes(value), saveTime) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -358,7 +358,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
fun getAsBitmap(key: String): Bitmap? { |
|
|
|
fun getAsBitmap(key: String): Bitmap? { |
|
|
|
return if (getAsBinary(key) == null) { |
|
|
|
return if (getAsBinary(key) == null) { |
|
|
|
null |
|
|
|
null |
|
|
|
} else Utils.Bytes2Bimap(getAsBinary(key)!!) |
|
|
|
} else Utils.bytes2Bitmap(getAsBinary(key)!!) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ======================================= |
|
|
|
// ======================================= |
|
|
@ -395,7 +395,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
return if (getAsBinary(key) == null) { |
|
|
|
return if (getAsBinary(key) == null) { |
|
|
|
null |
|
|
|
null |
|
|
|
} else Utils.bitmap2Drawable( |
|
|
|
} else Utils.bitmap2Drawable( |
|
|
|
Utils.Bytes2Bimap( |
|
|
|
Utils.bytes2Bitmap( |
|
|
|
getAsBinary(key)!! |
|
|
|
getAsBinary(key)!! |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
@ -486,16 +486,17 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
|
|
|
|
|
|
|
|
fun newByteArrayWithDateInfo(second: Int, data2: ByteArray): ByteArray { |
|
|
|
fun newByteArrayWithDateInfo(second: Int, data2: ByteArray): ByteArray { |
|
|
|
val data1 = createDateInfo(second).toByteArray() |
|
|
|
val data1 = createDateInfo(second).toByteArray() |
|
|
|
val retdata = ByteArray(data1.size + data2.size) |
|
|
|
val retData = ByteArray(data1.size + data2.size) |
|
|
|
System.arraycopy(data1, 0, retdata, 0, data1.size) |
|
|
|
System.arraycopy(data1, 0, retData, 0, data1.size) |
|
|
|
System.arraycopy(data2, 0, retdata, data1.size, data2.size) |
|
|
|
System.arraycopy(data2, 0, retData, data1.size, data2.size) |
|
|
|
return retdata |
|
|
|
return retData |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun clearDateInfo(strInfo: String?): String? { |
|
|
|
fun clearDateInfo(strInfo: String?): String? { |
|
|
|
var strInfo = strInfo |
|
|
|
strInfo?.let { |
|
|
|
if (strInfo != null && hasDateInfo(strInfo.toByteArray())) { |
|
|
|
if (hasDateInfo(strInfo.toByteArray())) { |
|
|
|
strInfo = strInfo.substring(strInfo.indexOf(mSeparator) + 1) |
|
|
|
return strInfo.substring(strInfo.indexOf(mSeparator) + 1) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return strInfo |
|
|
|
return strInfo |
|
|
|
} |
|
|
|
} |
|
|
@ -559,7 +560,7 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Bitmap → byte[] |
|
|
|
* Bitmap → byte[] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun Bitmap2Bytes(bm: Bitmap): ByteArray { |
|
|
|
fun bitmap2Bytes(bm: Bitmap): ByteArray { |
|
|
|
val baos = ByteArrayOutputStream() |
|
|
|
val baos = ByteArrayOutputStream() |
|
|
|
bm.compress(Bitmap.CompressFormat.PNG, 100, baos) |
|
|
|
bm.compress(Bitmap.CompressFormat.PNG, 100, baos) |
|
|
|
return baos.toByteArray() |
|
|
|
return baos.toByteArray() |
|
|
@ -568,8 +569,8 @@ class ACache private constructor(cacheDir: File, max_size: Long, max_count: Int) |
|
|
|
/* |
|
|
|
/* |
|
|
|
* byte[] → Bitmap |
|
|
|
* byte[] → Bitmap |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun Bytes2Bimap(b: ByteArray): Bitmap? { |
|
|
|
fun bytes2Bitmap(b: ByteArray): Bitmap? { |
|
|
|
return if (b.size == 0) { |
|
|
|
return if (b.isEmpty()) { |
|
|
|
null |
|
|
|
null |
|
|
|
} else BitmapFactory.decodeByteArray(b, 0, b.size) |
|
|
|
} else BitmapFactory.decodeByteArray(b, 0, b.size) |
|
|
|
} |
|
|
|
} |
|
|
|