توابع پرکاربرد اندروید با کتابخانه AndroidUtilCode
پراستفادهترین و مرسومترین توابع اندروید در یک کتابخانه
بدون شک در هنگام توسعهی هر نرمافزار اندرویدی، برخی از کدها یکسان میباشند و ما مجبوریم که در تمامی پروژههای خود، برای انجام این آنها را تکرار کرده و دوباره بنویسیم! اما برای راحتی کار، کتابخانهای با عنان AndroidUtilCode ساخته شده است که شامل مهمترین و پرکاربردیترین توابع مورد استفاده در پروژههای اندرویدی میباشد.
راهاندازی AndroidUtilCode
ابتدا کتابخانه را به فایل Gradle خود اضافه کنید:
1 |
compile 'com.blankj:utilcode:1.11.1' |
اگر کلاس اپلیکیشن ندارید، یک کلاس با نام دلخواهی در مسیر اصلی پکیج اپلیکیشن خود ساخته و آن را از کلاس Application ارث بری کنید، سپس این کلاس را به تگ application منیفست خود اضافه کنید:
1 |
<application android:name=".ClassName" ... > |
دستور زیر را در رویداد onCreate کلاس اپلیکیشن خود بنویسید:
1 |
Utils.init(application); |
و چنانچه پروژهی خود را قرار است Proguard کنید، موارد زیر را به آن اضافه کنید:
1 2 3 |
-keep class com.blankj.utilcode.** { *; } -keepclassmembers class com.blankj.utilcode.** { *; } -dontwarn com.blankj.utilcode.** |
متدهای ActivityUtils
- isActivityExist
- startActivity
- startActivities
- startHomeActivity
- getActivityList
- getLauncherActivity
- getTopActivity
- isActivityExistsInStack
- finishActivity
- finishToActivity
- finishOtherActivities
- finishAllActivities
- finishAllActivitiesExceptNewest
متدهای AppUtils
- isInstallApp
- installApp
- installAppSilent
- uninstallApp
- uninstallAppSilent
- isAppRoot
- launchApp
- exitApp
- getAppPackageName
- getAppDetailsSettings
- getAppName
- getAppIcon
- getAppPath
- getAppVersionName
- getAppVersionCode
- isSystemApp
- isAppDebug
- getAppSignature
- getAppSignatureSHA1
- isAppForeground
- getForegroundApp
- getAppInfo
- getAppsInfo
- cleanAppData
متدهای BarUtils
- getStatusBarHeight
- setStatusBarVisibility
- isStatusBarVisible
- addMarginTopEqualStatusBarHeight
- subtractMarginTopEqualStatusBarHeight
- setStatusBarColor
- setStatusBarAlpha
- setStatusBarColor4Drawer
- setStatusBarAlpha4Drawer
- getActionBarHeight
- setNotificationBarVisibility
- getNavBarHeight
- setNavBarVisibility
- setNavBarImmersive
- isNavBarVisible
متدهای CacheUtils
- getInstance
- put
- getBytes
- getString
- getJSONObject
- getJSONArray
- getBitmap
- getDrawable
- getParcelable
- getSerializable
- getCacheSize
- getCacheCount
- remove
- clear
متدهای CleanUtils
- cleanInternalCache
- cleanInternalFiles
- cleanInternalDbs
- cleanInternalDbByName
- cleanInternalSp
- cleanExternalCache
- cleanCustomCache
متدهای CloseUtils
- closeIO
- closeIOQuietly
متدهای ConvertUtils
- bytes2HexString, hexString2Bytes
- chars2Bytes, bytes2Chars
- memorySize2Byte, byte2MemorySize
- byte2FitMemorySize
- timeSpan2Millis, millis2TimeSpan
- millis2FitTimeSpan
- bytes2Bits, bits2Bytes
- input2OutputStream, output2InputStream
- inputStream2Bytes, bytes2InputStream
- outputStream2Bytes, bytes2OutputStream
- inputStream2String, string2InputStream
- outputStream2String, string2OutputStream
- bitmap2Bytes, bytes2Bitmap
- drawable2Bitmap, bitmap2Drawable
- drawable2Bytes, bytes2Drawable
- view2Bitmap
- dp2px, px2dp
- sp2px, px2sp
متدهای CrashUtils
- init
متدهای DeviceUtils
- isDeviceRooted
- getSDKVersion
- getAndroidID
- getMacAddress
- getManufacturer
- getModel
- shutdown
- reboot
- reboot2Recovery
- reboot2Bootloader
متدهای EncodeUtils
- urlEncode
- urlDecode
- base64Encode
- base64Encode2String
- base64Decode
- base64UrlSafeEncode
- htmlEncode
- htmlDecode
متدهای EncryptUtils
- encryptMD2, encryptMD2ToString
- encryptMD5, encryptMD5ToString
- encryptMD5File, encryptMD5File2String
- encryptSHA1, encryptSHA1ToString
- encryptSHA224, encryptSHA224ToString
- encryptSHA256, encryptSHA256ToString
- encryptSHA384, encryptSHA384ToString
- encryptSHA512, encryptSHA512ToString
- encryptHmacMD5, encryptHmacMD5ToString
- encryptHmacSHA1, encryptHmacSHA1ToString
- encryptHmacSHA224, encryptHmacSHA224ToString
- encryptHmacSHA256, encryptHmacSHA256ToString
- encryptHmacSHA384, encryptHmacSHA384ToString
- encryptHmacSHA512, encryptHmacSHA512ToString
- encryptDES, encryptDES2HexString, encryptDES2Base64
- decryptDES, decryptHexStringDES, decryptBase64DES
- encrypt3DES, encrypt3DES2HexString, encrypt3DES2Base64
- decrypt3DES, decryptHexString3DES, decryptBase64_3DES
- encryptAES, encryptAES2HexString, encryptAES2Base64
- decryptAES, decryptHexStringAES, decryptBase64AES
متدهای FileIOUtils
- writeFileFromIS
- writeFileFromBytesByStream
- writeFileFromBytesByChannel
- writeFileFromBytesByMap
- writeFileFromString
- readFile2List
- readFile2String
- readFile2BytesByStream
- readFile2BytesByChanne
- readFile2BytesByMap
- setBufferSize
متدهای FileUtils
- getFileByPath
- isFileExists
- rename
- isDir
- isFile
- createOrExistsDir
- createOrExistsFile
- createFileByDeleteOldFile
- copyDir
- copyFile
- moveDir
- moveFile
- deleteDir
- deleteFile
- deleteAllInDir
- deleteFilesInDir
- deleteFilesInDirWithFilter
- listFilesInDir
- listFilesInDirWithFilter
- getFileLastModified
- getFileCharsetSimple
- getFileLines
- getDirSize
- getFileSize
- getDirLength
- getFileLength
- getFileMD5
- getFileMD5ToString
- getDirName
- getFileName
- getFileNameNoExtension
- getFileExtension
متدهای FragmentUtils
- add
- show
- hide
- showHide
- replace
- pop
- popTo
- popAll
- remove
- removeTo
- removeAll
- getTop
- getTopInStack
- getTopShow
- getTopShowInStack
- getFragments
- getFragmentsInStack
- getAllFragments
- getAllFragmentsInStack
- findFragment
- dispatchBackPress
- setBackgroundColor
- setBackgroundResource
- setBackground
متدهای ImageUtils
- bitmap2Bytes, bytes2Bitmap
- drawable2Bitmap, bitmap2Drawable
- drawable2Bytes, bytes2Drawable
- view2Bitmap
- getBitmap
- scale
- clip
- skew
- rotate
- getRotateDegree
- toRound
- toRoundCorner
- addCornerBorder
- addCircleBorder
- addReflection
- addTextWatermark
- addImageWatermark
- toAlpha
- toGray
- fastBlur
- renderScriptBlur
- stackBlur
- save
- isImage
- getImageType
- compressByScale
- compressByQuality
- compressBySampleSize
متدهای IntentUtils
- getInstallAppIntent
- getUninstallAppIntent
- getLaunchAppIntent
- getAppDetailsSettingsIntent
- getShareTextIntent
- getShareImageIntent
- getComponentIntent
- getShutdownIntent
- getCaptureIntent
متدهای KeyboardUtils
- showSoftInput
- hideSoftInput
- toggleSoftInput
- isSoftInputVisible
- registerSoftInputChangedListener
- clickBlankArea2HideSoftInput
متدهای LogUtils
- getConfig
- Config.setLogSwitch
- Config.setConsoleSwitch
- Config.setGlobalTag
- Config.setLogHeadSwitch
- Config.setLog2FileSwitch
- Config.setDir
- Config.setFilePrefix
- Config.setBorderSwitch
- Config.setConsoleFilter
- Config.setFileFilter
- Config.setStackDeep
- v
- vTag
- d
- dTag
- i
- iTag
- w
- wTag
- e
- eTag
- a
- aTag
- file
- json
- xml
متدهای NetworkUtils
- openWirelessSettings
- isConnected
- isAvailableByPing
- getMobileDataEnabled
- setMobileDataEnabled
- isMobileData
- is4G
- getWifiEnabled
- setWifiEnabled
- isWifiConnected
- isWifiAvailable
- getNetworkOperatorName
- getNetworkType
- getIPAddress
- getDomainAddress
متدهای ObjectUtils
- isEmpty
- isNotEmpty
- equals
متدهای PermissionUtills
- getPermissions
- isGranted
- openAppSettings
- permission
- rationale
- callback
- theme
- request
متدهای PhoenUtils
- isPhone
- getIME
- getIMSI
- getPhoneType
- isSimCardReady
- getSimOperatorName
- getSimOperatorByMnc
- getPhoneStatus
- dial
- call
- sendSms
- sendSmsSilent
- getAllContactInfo
- getContactNum
- getAllSMS
متدهای ProccessUtils
- getForegroundProcessName
- killAllBackgroundProcesses
- killBackgroundProcesses
متدهای RegexUtils
- isMobileSimple
- isMobileExact
- isTel
- isIDCard15
- isIDCard18
- isEmail
- isURL
- isZh
- isUsername
- isDate
- isIP
- isMatch
- getMatches
- getSplits
- getReplaceFirst
- getReplaceAll
متدهای ScreenUtils
- getScreenWidth
- getScreenHeight
- getScreenDensity
- getScreenDensityDpi
- setFullScreen
- setLandscape
- setPortrait
- isLandscape
- isPortrait
- getScreenRotation
- screenShot
- isScreenLock
- setSleepDuration
- getSleepDuration
- isTablet
متدهای SDCardUtils
- isSDCardEnable
- getSDCardPaths
متدهای ServiceUtils
- getAllRunningService
- startService
- stopService
- bindService
- unbindService
- isServiceRunning
متدهای ShellUtils
- execCmd
متدهای SizeUtils
- dp2px, px2dp
- sp2px, px2sp
- applyDimension
- forceGetViewSize
- measureView
- getMeasuredWidth
- getMeasuredHeight
متدهای SnackbarUtils
- with
- setMessage
- setMessageColor
- setBgColor
- setBgResource
- setDuration
- setAction
- setBottomMargin
- show
- showSuccess
- showWarning
- showError
- dismiss
- getView
- addView
متدهای SpanUtils
- setFlag
- setForegroundColor
- setBackgroundColor
- setLineHeight
- setQuoteColor
- setLeadingMargin
- setBullet
- setIconMargin
- setFontSize
- setFontProportion
- setFontXProportion
- setStrikethrough
- setUnderline
- setSuperscript
- setSubscript
- setBold
- setItalic
- setBoldItalic
- setFontFamily
- setTypeface
- setAlign
- setClickSpan
- setUrl
- setBlur
- setShader
- setShadow
- setSpans
- append
- appendLine
- appendImage
- appendSpace
- create
متدهای SPUtils
- getInstance:
- put
- getString
- getInt
- getLong
- getFloat
- getBoolean
- getAll
- contains
- remove
- clear
متدهایSettingsUtils
- isEmpty
- isTrimEmpty
- isSpace
- equals
- equalsIgnoreCase
- null2Length0
- length
- upperFirstLetter
- lowerFirstLetter
- reverse
- toDBC
- toSBC
متدهای TimeUtils
- millis2String
- string2Millis
- string2Date
- date2String
- date2Millis
- millis2Date
- getTimeSpan
- getFitTimeSpan
- getNowMills
- getNowString
- getNowDate
- getTimeSpanByNow
- getFitTimeSpanByNow
- getFriendlyTimeSpanByNow
- getMillis
- getString
- getDate
- getMillisByNow
- getStringByNow
- getDateByNow
- isToday
- isLeapYear
- getChineseWeek
- getUSWeek
- getWeekIndex
- getWeekOfMonth
- getWeekOfYear
- getChineseZodiac
- getZodiac
متدهای ToastUtils
- setGravity
- setBgColor
- setBgResource
- setMessageColor
- showShort
- showLong
- showCustomShort
- showCustomLong
- cancel
متدهایZipUtils
- zipFile
- unzipFile
- unzipFileByKeyword
- getFilesPath
- getComments
نظرات ثبت شده بدون دیدگاه