Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import android.graphics.*
- import android.text.TextPaint
- import android.text.style.TypefaceSpan
- import java.util.*
- import java.util.regex.Pattern
- import java.io.*
- import java.math.BigInteger
- import java.security.MessageDigest
- import java.security.NoSuchAlgorithmException
- import kotlin.experimental.and
- import android.text.TextUtils
- import android.util.Log
- import com.amazonaws.util.Md5Utils
- /**
- * Created by armshare on 22/2/2018 AD.
- */
- fun String.isValidEmail(): Boolean {
- val expression = "^[\\w\\.]+@([\\w]+\\.)+[A-Z]{2,7}$"
- val inputString = this
- val pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE)
- val matcher = pattern.matcher(inputString)
- return matcher.matches()
- }
- fun LinkedHashMap<String,String>.getKeyByIndex(index:Int):String{
- return keys.toTypedArray()[index]
- }
- fun LinkedHashMap<String,String>.getValueByIndex(index:Int):String{
- return values.toTypedArray()[index]
- }
- fun File.lengthInMegaByte():Long {
- return (Math.ceil(((length() / (1024 * 1024) * 10).toDouble())) / 10).toLong()
- }
- fun Long.convertToMegaByte():Long{
- return (Math.ceil(((this / (1024 * 1024) * 10).toDouble())) / 10).toLong()
- }
- fun File.getAllChild(): List<File>{
- val inFiles = ArrayList<File>()
- val files = LinkedList<File>()
- if (listFiles() != null && listFiles().isNotEmpty()){
- files.addAll(listFiles())
- while (!files.isEmpty()) {
- val file = files.remove()
- if (file.isDirectory) {
- files.addAll(file.listFiles())
- }
- else
- inFiles.add(file)
- }
- }
- return inFiles
- }
- fun Long.suffixScaleNumber(): String {
- if (this < 1000) return "" + this
- val exp = (Math.log(this.toDouble()) / Math.log(1000.0)).toInt()
- var string = String.format("%.1f",
- this / Math.pow(1000.0, exp.toDouble()))
- if(string.endsWith(".0"))
- string = string.replace(".0" , "")
- return string+"KMB"[exp - 1]
- }
- fun File.md5Hex():String{
- val result = StringBuffer()
- val HEX_CHARS = "0123456789ABCDEF".toCharArray()
- Md5Utils.computeMD5Hash(this)
- .forEach {
- val octet = it.toInt()
- val firstIndex = (octet and 0xF0).ushr(4)
- val secondIndex = octet and 0x0F
- result.append(HEX_CHARS[firstIndex])
- result.append(HEX_CHARS[secondIndex])
- }
- return result.toString()
- }
Add Comment
Please, Sign In to add comment