Skip to content

Instantly share code, notes, and snippets.

View amsterdatech's full-sized avatar
💭
I may be slow to respond.

William Gouvea amsterdatech

💭
I may be slow to respond.
View GitHub Profile
val showDialogButton = findViewById<Button>(R.id.show_dialog_button)
showDialogButton?.let {
it.setOnClickListener {
dialog {
title = resources.getString(R.string.custom_dialog_title)
contentText = resources.getString(R.string.custom_dialog_body)
negativeText = resources.getString(R.string.custom_dialog_negative_text)
positiveText = resources.getString(R.string.custom_dialog_positive_text)
positiveAction = { toast("Positive Action!!!") }
negativeAction = { toast("Negative Action!!!") }
package com.flyingdutchman.material.components
import android.app.Activity
import android.content.Context
import android.view.LayoutInflater
import android.view.Window
import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.flyingdutchman.material.components.databinding.CustomDialogComponentBinding
/**
* You can report it using trackEvent or do your own logic, but remember, you are running in the Main Thread.
* Besides, you shouldn't rely on heavy libraries like RxJava, but Coroutines or Executors are easy to follow as well
*/
override fun uncaughtException(thread: Thread, throwable: Throwable) {
try {
analytics(context)
.track {
name = EventName.EXCEPTION
EventName.STACK_TRACE to extractStackTraceInfo(throwable)
--------- beginning of crash
2021-01-26 22:25:18.607 8665-8665/com.flyingdutchman.simple_analytics E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.flyingdutchman.simple_analytics, PID: 8665
java.lang.RuntimeException: Simulate Crash: Boom!!
at com.flyingdutchman.simple_analytics.AndroidCrashLogger.simulateCrash(AndroidCrashLogger.kt:35)
at com.flyingdutchman.simple_analytics.AnalyticsImpl.simulateCrash(Analytics.kt:46)
at com.flyingdutchman.simple_analytics.Main2Activity$onCreate$1.onClick(Main2Activity.kt:14)
at android.view.View.performClick(View.java:6256)
at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
at android.view.View$PerformClick.run(View.java:24701)
// Call inside a button on debug drawer or through a kinda of easter egg backdoor inside your app
button.setOnClickListener { analytics(it.context).simulateCrash() }
override fun simulateCrash() {
//Here you can throw a RuntimeException or use a related method of your crash report SDK
throw RuntimeException("Simulate Crash: Boom!!")
}
abstract class BaseActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
log("onCreate()")
super.onCreate(savedInstanceState)
}
override fun onStart() {
log("onStart()")
super.onStart()
private var defaultHandler: Thread.UncaughtExceptionHandler? =
Thread.getDefaultUncaughtExceptionHandler()
package com.flyingdutchman.simple_analytics
import android.content.Context
import android.text.TextUtils
import android.util.Log
import java.io.PrintWriter
import java.io.StringWriter
import java.io.Writer
import java.util.*
/**After create your Tracker classes and initialize your Analytics implementation inside Application you can use this simple library like the examples below*/
//Track PageViews
analytics.track {
name = EVENT.PAGE_VIEWED
put(EVENT.PROPERTY_PAGE_NAME, "SCREEN 1")
}
//Track Events
analytics.track {