Kotlin(10)
-
LinearSmoothScroller&scrollToPositionWithOffset
1. RecyclerView 안에 있는 item(position)의 top까지 스크롤 layoutManager.scrollToPositionWithOffset(position, 0) 2. RecyclerView 안에 있는 item(position)의 top까지 스크롤 및 set scroll speed val smoothScroller: SmoothScroller = object : LinearSmoothScroller(recyclerview?.context) { override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics?): Float { return 50f / displayMetrics?.densityDpi!! } override fun ge..
2020.11.23 -
파일 열기(createChooser)
/** * 다운로드 후 파일 열기 */ private fun openFile(dirPath: String, name: String) { try { var file = File(dirPath.plus(File.separator).plus(name)) if (file.exists()) { var mimeType = when { name.endsWith("txt") -> "text/*" name.endsWith("jpg") or name.endsWith("jpeg") or name.endsWith("JPG") or name.endsWith("gif") or name.endsWith("png") or name.endsWith("bmp") -> "image/*" name.endsWith("doc") or name..
2020.03.27 -
file.copyTo
val file = File(path) if(file.path.startsWith("file:/") or file.path.startsWith("file:///")){ FileOutputStream(File(file.absolutePath, file.name)).use { out -> assets.open(file.name).use { it.copyTo(out) } } }else{ file.copyTo(File(file.absolutePath, file.name), true) }
2019.12.20 -
Bitmap to File
fun bitmapToFile(bitmap: Bitmap, path: String): File{ var file = File(path) var out: OutputStream? = null try{ file.createNewFile() out = FileOutputStream(file) bitmap.compress(Bitmap.CompressFormat.JPEG, 80, out) }finally{ out?.close() } return file } https://smartstore.naver.com/byrollin? 바이롤린 : 네이버쇼핑 스마트스토어 언제나 함께해요 smartstore.naver.com
2019.12.20 -
zip, unzip
fun unZip(zipFile: File, targetPath: String) { val zip = ZipFile(zipFile, "euc-kr") // UTF-8 zip.entries.forEach { if (!it.isDirectory) BufferedInputStream(zip.getInputStream(it)).use { bis -> File(targetPath, it.name).outputStream().buffered(1024).use { bis.copyTo(it) } } } } fun zip(path: String){ val folderToZip = File(path) var out: ZipOutputStream? = null try { out = ZipOutputStream( Buffer..
2019.12.20 -
Bitmap in putExtra
// putExtra Activity val bimap = BitmapFactory.decodeFile(path) // example val stream = ByteArrayOutputStream() bitmap.compress(Bitmap.CompressFormat.JPEG, 80, stream) val byteArray = stream.toByteArray() startActivityForResult(Intent(this, TestActivity::class.java).apply { putExtra("bitmap", byteArray) }, 100) // TestActivity private var mBitmap: Bitmap? = null onCreate(){ intent.let { it.getBy..
2019.12.20