Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Latest commit

 

History

109 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maven Central Version

anhance

An Android library to make life easier.

This library offers many useful functions to solve problems more efficiently and quickly.

Keep in mind that by using Anhance, you will have less control over your code. For example, when using showToast(message) to display a toast, you cannot set the duration to Toast.LENGTH_LONG as it uses Toast.LENGTH_SHORT instead.

However, Anhance makes it easier to build apps faster and more efficiently. For instance, you can simply use the hideKeyboard() function to hide the keyboard whenever you need to, without even having to remember the code to do so programmatically.

Remember, never let anyone tell you that you are ugly. Enjoy coding! :D

Features

SpeechListener

SpeechListener is a speech recognizer extension

SpeechListener.observe(context = context) { state ->
    when (state) {
        is SpeechToTextResult.Error -> text = state.message
        is SpeechToTextResult.Partial -> text =state.text
        SpeechToTextResult.Ready -> text = "Listening"
        is SpeechToTextResult.Result -> text = state.text
        else -> {}
    }
}
SpeechListener.startListening(context)
SpeechListener.stopListening()

TextReader

TextReader is a text-to-speech extension

//onCreate (Application)
TextReader.initialize(this)
initializeReader(this)

//Read text
TextReader.read("hello"){ //on error 
}
readText("hello"){ //on error 
}

Extensions for Assets

context.readStringAsset("filename.txt"){ result ->
    result.onSuccess {}
    result.onFailure {}
} //read string from assets

Extensions for Audio

context.playAudio(R.raw.music) //play audio from resource
context.playAudio("music.mp3") //play audio from assets

Extensions for Date and time

val duration = 3.seconds  // 3000L
val three = duration.toSecond // 3L
val currentMillis = millisOfNow //Current millisecond
val date = millisOfNow.formatWith("dd/MM/yyyy") //format date
val formatted = threeSeconds.formatDuration() //3s
val timer = duration.formatTimer() //00:03

Context extensions

context.showToast("hi mom!")
context.isInternetAvailable //check connection

Extensions for dimensions

val padding = 16.toPx() //convert 16dp to px
val margin = 24.toDp() //convert 24px to dp

AnRandom

  • Kotlin Random(without seed) will generate the same random sequence of result
  • this is a feature, I guess.
//If you want to generate different sets of result, use millis as seed
val random = Random(millisOfNow).nextInt(0 , 10)
//But anhance is shorter
val random2 = randomOf(0,  10)
val randomFloat = randomFloat()

Extensions for files

//getting file extension from a Uri
val fileExtension = uri.fileExtension(context)

String extensions

val a = "100".toSafeInt() //100 safely convert string into int
val b = "abc".toSafeInt() //0
"hello mom".copy(context) //copy the string to clipboard
"<font color=#ff0000>red</font>".toHtml() //string into html
"12bdae".generateMore() //generate more random combination
"fnck you".censor() //censor a string //**** you

Implementation

Gradle

add a dependency

Maven Central Version

dependencies {
    implementation("com.naulian:anhance:latest_version")
}

About

Android extensions library to make life easier

Topics

Resources

Stars

4 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages