-
-
Notifications
You must be signed in to change notification settings - Fork 0
HelpfulUtils
Jacob Rein edited this page May 12, 2020
·
16 revisions
implementation 'com.github.jakepurple13.HelpfulTools:helpfulutils:{version}'
There are lots of utilities here. These are ones that don't fit into the other categories but aren't considered "fun".
requestPermissions(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE) {
println(it.isGranted)
println(it.grantedPermissions)
println(it.deniedPermissions)
}
BiometricBuilder.biometricBuilder(/*FragmentActivity*/) {
authSuccess {
"Success"
}
authError { _, _ ->
"Error"
}
authFailed {
"Failed"
}
error {
"Error"
}
promptInfo {
title = "Testing"
subtitle = "Tester"
description = "Test"
negativeButton = null
confirmationRequired = true
deviceCredentialAllowed = true
}
}
val time: BroadcastReceiver = Context.timeTick { _, _ -> println("Runs every minute") }
val batteryInfo: BroadcastReceiver = Context.battery { info: Battery -> println(info) }
val screenOff: BroadcastReceiver = Context.screenOff { _,_ -> println("Screen turned off") }
val screenOn: BroadcastReceiver = Context.screenOn { _,_ -> println("Screen turned on") }
val screenState: BroadcastReceiver = Context.screenState {
when(it) {
ScreenState.OFF -> {}
ScreenState.ON -> {}
ScreenState.UNKNOWN -> {}
}
}
var Context.key: String? by sharedPrefDelegate()
val Context.sharedPref get() = defaultSharedPref
Context.speechToText(object : SpeechListener {
//The arraylist is all the possibilities. Usually the first index is the closest but just in case, here's all of them
override fun getResult(text: ArrayList<String>?) = println(text)
})
Context.textToSpeech("Hello World")
createNotificationChannel("testChannel")
createNotificationGroup("testGroup")
//NotificationDslBuilder has support for below O and above O
val notification = NotificationDslBuilder.builder(this, channelId = "testChannel", smallIconId = R.mipmap.ic_launcher) {
title = "Title"
message = "Message"
autoCancel = true
resultKey = "result"
label = "label"
actionTitle = "Action Title"
actionIcon = R.mipmap.ic_launcher
pendingActivity(ReplyService::class.java)
}
bigTextStyle {
summaryText = "Summary"
contentTitle = "Content Title"
bigText = "Big Text"
}
//To add a bubble
//Will only work on versions that support it
addBubble {
val target = Intent(context, BubbleActivity::class.java)
val bubbleIntent = PendingIntent.getActivity(context, 0, target, 0 /* flags */)
bubbleIntent(bubbleIntent)
desiredHeight = 600
icon = Icon.createWithResource(context, R.mipmap.ic_launcher)
}
//To add a custom NotificationView
remoteViews {
landscapeCollapsed(this@MainActivity.packageName, R.layout.collapsed_notification_landscape) {
setProgressBar(R.id.progress_bar, 100, 2, false)
}
portraitCollapsed(this@MainActivity.packageName, R.layout.collapsed_notification_portrait)
landscapeHeadsUp(this@MainActivity.packageName, R.layout.heads_up_notification_landscape)
portraitHeadsUp(this@MainActivity.packageName, R.layout.heads_up_notification_portrait)
landscapeExpanded(this@MainActivity.packageName, R.layout.expanded_notification_landscape)
portraitExpanded(this@MainActivity.packageName, R.layout.expanded_notification_portrait)
}
}
notificationManager.notify(/*notification id*/, notification)
You can dynamically add items at anytime
recyclerView.quickAdapter(R.layout.support_simple_spinner_dropdown_item, "Hello", "World") {
//this is to render the view
println(it)
}
recyclerView.quickAdapter(R.layout.support_simple_spinner_dropdown_item, "Jake", "Purple") {
//this is to render the view
println(it)
}
//this will loop around the items given to it
var range = ItemRange(1, 2, 3, 4, 5, loop = true)
range++