Skip to content

Commit

Permalink
chore(android): redesign demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaysood committed Feb 3, 2025
1 parent a8385f4 commit 0cd1db0
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 108 deletions.
3 changes: 2 additions & 1 deletion android/sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
android:theme="@style/Theme.MeasureAndroid" />
<activity
android:name=".ExceptionDemoActivity"
android:exported="true">
android:exported="true"
android:theme="@style/Theme.MeasureAndroid">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package sh.measure.sample

import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.util.Log
import android.widget.Button
import android.widget.ScrollView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.google.android.material.switchmaterial.SwitchMaterial
import com.google.android.material.textview.MaterialTextView
import sh.measure.android.Measure
import sh.measure.android.tracing.SpanStatus
import sh.measure.sample.fragments.AndroidXFragmentNavigationActivity
Expand All @@ -25,58 +30,59 @@ class ExceptionDemoActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
val span = Measure.startSpan("activity.onCreate")
setContentView(R.layout.activity_exception_demo)
findViewById<Button>(R.id.btn_single_exception).setOnClickListener {
handleEdgeToEdgeDisplay()
findViewById<MaterialTextView>(R.id.btn_single_exception).setOnClickListener {
throw IllegalAccessException("This is a new exception")
}
findViewById<Button>(R.id.btn_chained_exception).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_chained_exception).setOnClickListener {
throw IOException("This is a test exception").initCause(
CustomException(message = "This is a nested custom exception")
)
}
findViewById<Button>(R.id.btn_oom_exception).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_oom_exception).setOnClickListener {
val list = mutableListOf<ByteArray>()
while (true) {
val byteArray = ByteArray(1024 * 1024 * 100) // Allocate 100MB of memory
list.add(byteArray)
}
}
findViewById<Button>(R.id.btn_stack_overflow_exception).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_stack_overflow_exception).setOnClickListener {
recursiveFunction()
}
findViewById<Button>(R.id.btn_infinite_loop).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_infinite_loop).setOnClickListener {
infiniteLoop()
}
findViewById<Button>(R.id.btn_deadlock).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_deadlock).setOnClickListener {
deadLock()
}
findViewById<Button>(R.id.btn_okhttp).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_okhttp).setOnClickListener {
startActivity(Intent(this, OkHttpActivity::class.java))
}
findViewById<Button>(R.id.btn_compose).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_compose).setOnClickListener {
startActivity(Intent(this, ComposeActivity::class.java))
}
findViewById<Button>(R.id.btn_compose_navigation).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_compose_navigation).setOnClickListener {
startActivity(Intent(this, ComposeNavigationActivity::class.java))
}
findViewById<Button>(R.id.btn_view_screenshot).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_view_screenshot).setOnClickListener {
startActivity(Intent(this, ViewScreenshotActivity::class.java))
}
findViewById<Button>(R.id.btn_compose_screenshot).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_compose_screenshot).setOnClickListener {
startActivity(Intent(this, ComposeScreenshotActivity::class.java))
}
findViewById<Button>(R.id.btn_nested_fragments).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_nested_fragments).setOnClickListener {
startActivity(Intent(this, NestedFragmentActivity::class.java))
}
findViewById<Button>(R.id.btn_fragment_navigation).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_fragment_navigation).setOnClickListener {
startActivity(Intent(this, FragmentNavigationActivity::class.java))
}
findViewById<Button>(R.id.btn_fragment_androidx_navigation).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_fragment_androidx_navigation).setOnClickListener {
startActivity(Intent(this, AndroidXFragmentNavigationActivity::class.java))
}
findViewById<Button>(R.id.btn_bug_report).setOnClickListener {
findViewById<MaterialTextView>(R.id.btn_bug_report).setOnClickListener {
Measure.launchBugReportActivity(this)
}
val spanButton = findViewById<Button>(R.id.btn_generate_span)
val spanButton = findViewById<MaterialTextView>(R.id.btn_generate_span)
spanButton.setOnClickListener {
spanButton.isEnabled = false
thread {
Expand Down Expand Up @@ -152,6 +158,33 @@ class ExceptionDemoActivity : AppCompatActivity() {
e.printStackTrace()
}
}

private fun handleEdgeToEdgeDisplay() {
val container = findViewById<ScrollView>(R.id.sv_container)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
ViewCompat.setOnApplyWindowInsetsListener(container) { view, windowInsets ->
val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars())
view.updatePadding(
left = insets.left,
top = insets.top,
right = insets.right,
bottom = insets.bottom
)
windowInsets
}
} else {
ViewCompat.setOnApplyWindowInsetsListener(container) { view, windowInsets ->
@Suppress("DEPRECATION") val insets = windowInsets.systemWindowInsets
view.updatePadding(
left = insets.left,
top = insets.top,
right = insets.right,
bottom = insets.bottom
)
windowInsets
}
}
}
}

class CustomException(override val message: String? = null) : Exception()
9 changes: 9 additions & 0 deletions android/sample/src/main/res/drawable/ic_chevron_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/chevron"
android:pathData="M9.29,6.71C8.9,7.1 8.9,7.73 9.29,8.12L13.17,12L9.29,15.88C8.9,16.27 8.9,16.9 9.29,17.29C9.68,17.68 10.31,17.68 10.7,17.29L15.29,12.7C15.68,12.31 15.68,11.68 15.29,11.29L10.7,6.7C10.31,6.31 9.68,6.31 9.29,6.7Z"/>
</vector>
Loading

0 comments on commit 0cd1db0

Please sign in to comment.