项目作者: Aryan-mor

项目描述 :
Android Utils Functions | Android amazing helper function library
高级语言: Kotlin
项目地址: git://github.com/Aryan-mor/Utils-Library.git
创建时间: 2019-03-20T20:34:15Z
项目社区:https://github.com/Aryan-mor/Utils-Library

开源协议:

下载


Utils-Library

Android amazing helper function library

Works better on kotlin

Usage

Include the library in your build.gradle

  1. //Project
  2. allprojects {
  3. repositories {
  4. google()
  5. jcenter()
  6. maven { url 'https://jitpack.io' }
  7. }
  8. }
  9. //Module:App
  10. dependencies {
  11. implementation 'com.github.Aryan-mor:Utils-Library:1.3.12'
  12. }

Index

Example

Some examples of library functions

UtilsFunctions

You can convert all classes to json like this and hydrate

  1. val json = Any().toJson()
  2. //json type is String
  3. val myObject = json.hydrate(Any::class.java)
  4. //myObject type is Any

Another functions

  1. //You can close application like this
  2. activity.closeApp()
  3. //You can restart application like this
  4. activity.restartApp()
  5. //you can delay application like this
  6. actvity.delayOnUiThread(200) // 200 is duration milisecound
  7. //or run funtion by delay like this
  8. actvity.delayOnUiThread(200){
  9. //your code
  10. }
  11. ***************************************
  12. //Hidden keyboard
  13. actvity.showSoftKeyboard()
  14. //or
  15. actvity.showSoftKeyboard(EditText)
  16. //Show keyboard
  17. actvity.showSoftKeyboard()
  18. //or
  19. actvity.showSoftKeyboard(AnyView)
  20. ***************************************
  21. //You can understand user device size | fucntions return Boolean
  22. context.isTablet()
  23. context.isLargeScreen()
  24. context.isNormalScreen()
  25. context.isSmallScreen()
  26. ***************************************
  27. //You can understand device is portrait or landscape | fucntions return Boolean
  28. context.isPortrait()
  29. context.isLandscape()
  30. ***************************************
  31. //Random number
  32. getRandomNumber()
  33. //or
  34. //getRandomNumber(0,100)
  35. ***************************************
  36. //RandomString
  37. randomString(5) // example return XsREs
  38. randomStringWithNumber(5) // example return F5A8F
  39. ***************************************
  40. //You can vibrate phone if use vibrate permision on your manifest | fucntions return Vibrator?
  41. activity.vibrate(VibrationEffect)
  42. //Or
  43. activity.vibrate(milliseconds: Long, amplitude: Int)

IntentFunctions

  1. class MainActivity : AppCompatActivity(){
  2. override fun onCreate(savedInstanceState: Bundle?) {
  3. super.onCreate(savedInstanceState)
  4. setContentView(R.layout.activity_main)
  5. //Basic usage
  6. intentTo(AnotherActivity::class)
  7. //Or
  8. var intent = makeIntent(AnotherActivity::class)
  9. //You can send any params to another activity
  10. intentTo(AnotherActivity::class,"myParamKey", anyObject)
  11. //On another activity you can recive object like this
  12. val myParam = getExtra("myParamKey",AnyObject::class.java)
  13. }
  14. }

You can intent to your app package setting like this

  1. context.intentToPackageSetting()

You can open link like this

  1. context.openLink("http://...")

LogFunctions

AnyWhere can use log funtion :relaxed:

  1. //Basic usage
  2. log(Any) // log any object
  3. //or
  4. Any().logThis()
  5. //or
  6. log("log this message")
  7. //AdvanceTools
  8. log(Any(),"MyLogFlag",LOG_ERROR_MODE)
  9. //or
  10. log(logMessage = Any(),logFlag = "MyLogFlag",logType = LOG_ERROR_MODE)
  11. //LogType ->
  12. //LOG_DEBUG_MODE
  13. //LOG_ERROR_MODE
  14. //LOG_INFO_MODE
  15. //LOG_VERBOSE_MODE
  16. //LOG_WARN_MODE
  17. //LOG_WTF_MODE

You can use 6 type log type :metal:

  1. logD("Log Type Debug")
  2. logE("Log Type Error")
  3. logI("Log Type Info")
  4. logV("Log Type Verbose")
  5. logW("Log Type Warn")
  6. logWTF("Log Type WTF")

You can log ArrayList or Map item

  1. val map = hashMapOf<String,Any>()
  2. map["aa"] = "safa"
  3. map.logThis()
  4. //or
  5. map.logThisE()
  6. //or ....
  7. //The array is the same

SharedPreferencesFunctions

Source code for Shared Preferences
All items will be first encrypted and then saved into shared preferences,
items will be decrypted upon retrieving

  1. context.addPref("key", any)
  2. context.getPref("key", Any:class.java)
  3. //Or
  4. context.getPrefBoolean("key", defultValue)
  5. context.getPrefString("key", defultValue)
  6. context.getPrefInt("key", defultValue)
  7. context.getPrefFloat("key", defultValue)
  8. context.getPrefLong("key", defultValue)

ToastFunctions

Toast fuction by context

  1. //ToastFucntion | return Toast
  2. context.toast("myToastMessage").show()
  3. context.toast(R.string.myString).show()
  4. context.longToast("myToastMessage").show()
  5. context.longToast(R.string.myString).show()

HashFunctions

You can make hash of your string using 6 algoritm

  1. val s = "MyString"
  2. logI("toMD5 -> " + s.toMd5())
  3. logI("toSHA-1 -> " + s.toSHA_1())
  4. logI("toSHA-224 -> " + s.toSHA_224())
  5. logI("toSHA-256 -> " + s.toSHA_256())
  6. logI("toSHA-384 -> " + s.toSHA_384())
  7. logI("toSHA-512 -> " + s.toSHA_512())