-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FileInputStream/FileOutputStream instrumentation (#239)
- Loading branch information
Showing
22 changed files
with
867 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,10 @@ | |
android:name=".ui.EditActivity" | ||
android:theme="@style/Theme.AppCompat.NoActionBar" /> | ||
|
||
<activity | ||
android:name=".ui.LyricsActivity" | ||
android:theme="@style/Theme.AppCompat.NoActionBar" /> | ||
|
||
<meta-data | ||
android:name="io.sentry.dsn" | ||
android:value="https://[email protected]/5428559" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
examples/android-room/src/main/java/io/sentry/android/roomsample/ui/LyricsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.sentry.android.roomsample.ui | ||
|
||
import android.annotation.SuppressLint | ||
import android.os.Bundle | ||
import android.widget.EditText | ||
import androidx.activity.ComponentActivity | ||
import androidx.appcompat.widget.Toolbar | ||
import io.sentry.Sentry | ||
import io.sentry.SpanStatus | ||
import io.sentry.android.roomsample.R | ||
import io.sentry.android.roomsample.data.Track | ||
import java.io.File | ||
|
||
@SuppressLint("SetTextI18n") | ||
class LyricsActivity : ComponentActivity() { | ||
private lateinit var file: File | ||
private lateinit var lyricsInput: EditText | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_lyrics) | ||
|
||
val transaction = Sentry.startTransaction( | ||
"Track Interaction", | ||
"ui.action.lyrics", | ||
true | ||
) | ||
|
||
lyricsInput = findViewById(R.id.lyrics) | ||
val toolbar = findViewById<Toolbar>(R.id.toolbar) | ||
|
||
val track: Track = intent.getSerializableExtra(TRACK_EXTRA_KEY) as Track | ||
toolbar.title = "Lyrics for ${track.name}" | ||
|
||
val dir = File("$filesDir${File.separatorChar}lyrics") | ||
dir.mkdirs() | ||
|
||
file = File(dir, "${track.id}.txt") | ||
if (file.exists()) { | ||
lyricsInput.setText(file.readText()) | ||
} | ||
transaction.finish(SpanStatus.OK) | ||
} | ||
|
||
override fun onBackPressed() { | ||
val transaction = Sentry.getSpan() ?: Sentry.startTransaction( | ||
"Track Interaction", | ||
"ui.action.lyrics_finish", | ||
true | ||
) | ||
if (!file.exists()) { | ||
file.createNewFile() | ||
} | ||
file.writeText(lyricsInput.text.toString()) | ||
transaction.finish(SpanStatus.OK) | ||
super.onBackPressed() | ||
} | ||
|
||
companion object { | ||
const val TRACK_EXTRA_KEY = "LyricsActivity.Track" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
examples/android-room/src/main/java/io/sentry/android/roomsample/ui/list/TrackAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.sentry.android.roomsample.ui.list | ||
|
||
import android.content.Intent | ||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import io.sentry.Sentry | ||
import io.sentry.SpanStatus | ||
import io.sentry.android.roomsample.R | ||
import io.sentry.android.roomsample.SampleApp | ||
import io.sentry.android.roomsample.data.Track | ||
import io.sentry.android.roomsample.ui.EditActivity | ||
import io.sentry.android.roomsample.ui.LyricsActivity | ||
import kotlinx.coroutines.runBlocking | ||
|
||
class TrackAdapter : RecyclerView.Adapter<TrackAdapter.ViewHolder>() { | ||
|
||
private var data: List<Track> = listOf() | ||
|
||
fun populate(data: List<Track>) { | ||
this.data = data | ||
notifyDataSetChanged() | ||
} | ||
|
||
override fun getItemCount() = data.size | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||
return ViewHolder( | ||
LayoutInflater.from(parent.context).inflate( | ||
R.layout.track_row, | ||
parent, | ||
false | ||
) as TrackRow | ||
) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ViewHolder, position: Int) { | ||
holder.row.populate(data[position]) | ||
holder.row.deleteButton.setOnClickListener { | ||
val transaction = Sentry.startTransaction( | ||
"Track Interaction", | ||
"ui.action.delete", | ||
true | ||
) | ||
runBlocking { | ||
SampleApp.database.tracksDao().delete(data[holder.bindingAdapterPosition]) | ||
val deleteCount = SampleApp.analytics.getInt("delete_count", 0) + 1 | ||
SampleApp.analytics.edit().putInt("delete_count", deleteCount).apply() | ||
} | ||
transaction.finish(SpanStatus.OK) | ||
} | ||
holder.row.editButton.setOnClickListener { | ||
val context = holder.row.context | ||
val track = data[holder.bindingAdapterPosition] | ||
context.startActivity( | ||
Intent( | ||
context, | ||
EditActivity::class.java | ||
).putExtra(EditActivity.TRACK_EXTRA_KEY, track) | ||
) | ||
} | ||
holder.row.infoButton.setOnClickListener { | ||
val context = holder.row.context | ||
val track = data[holder.bindingAdapterPosition] | ||
context.startActivity( | ||
Intent( | ||
context, | ||
LyricsActivity::class.java | ||
).putExtra(LyricsActivity.TRACK_EXTRA_KEY, track) | ||
) | ||
} | ||
} | ||
|
||
override fun onViewRecycled(holder: ViewHolder) { | ||
super.onViewRecycled(holder) | ||
holder.row.deleteButton.setOnClickListener(null) | ||
holder.row.editButton.setOnClickListener(null) | ||
} | ||
|
||
inner class ViewHolder(val row: TrackRow) : RecyclerView.ViewHolder(row) | ||
} |
30 changes: 30 additions & 0 deletions
30
examples/android-room/src/main/java/io/sentry/android/roomsample/ui/list/TrackRow.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.sentry.android.roomsample.ui.list | ||
|
||
import android.annotation.SuppressLint | ||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.view.View | ||
import android.widget.LinearLayout | ||
import android.widget.TextView | ||
import io.sentry.android.roomsample.R | ||
import io.sentry.android.roomsample.data.Track | ||
|
||
class TrackRow( | ||
context: Context, | ||
attrs: AttributeSet | ||
) : LinearLayout(context, attrs) { | ||
|
||
val deleteButton: View get() = findViewById(R.id.delete_track) | ||
val editButton: View get() = findViewById(R.id.edit_track) | ||
val infoButton: View get() = findViewById(R.id.track_info) | ||
|
||
@SuppressLint("SetTextI18n") | ||
fun populate(track: Track) { | ||
val mins = (track.millis / 1000) / 60 | ||
val secs = (track.millis / 1000) % 60 | ||
|
||
findViewById<TextView>(R.id.track_name).text = track.name | ||
findViewById<TextView>(R.id.track_duration).text = "${mins}m ${secs}s" | ||
findViewById<TextView>(R.id.band_name).text = track.composer | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
examples/android-room/src/main/java/io/sentry/android/roomsample/util/Lyrics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package io.sentry.android.roomsample.util | ||
|
||
val DEFAULT_LYRICS = | ||
""" | ||
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi dapibus elit vel commodo varius. Suspendisse eget tempus est. Pellentesque egestas mi vitae massa ultrices vulputate. Aenean tempor nec sem eu congue. Phasellus mollis tellus odio, ut tincidunt arcu ullamcorper at. Nunc quis lorem vel risus auctor ultricies. Quisque ornare congue sagittis. Donec sit amet arcu vitae mi sodales porta vitae et mi. Nullam eu viverra urna, quis elementum risus. In at accumsan justo. Nam hendrerit, lorem ac lacinia semper, diam dolor pulvinar turpis, non tincidunt dolor lacus non quam. Etiam tempus, dui ut rutrum ornare, quam eros feugiat nisi, et blandit nisi lacus nec neque. Mauris aliquam id tellus vel molestie. Quisque ultricies ante nec lacus condimentum, at aliquet diam volutpat. | ||
Vivamus fermentum eu ante non aliquam. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum interdum semper orci, et auctor enim pharetra vel. Ut porttitor neque in blandit scelerisque. Cras fermentum urna sit amet metus tincidunt, eu porttitor nisi mattis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Mauris pharetra leo vitae turpis commodo, sit amet cursus nunc varius. Etiam bibendum interdum dolor, a scelerisque massa mattis eu. Suspendisse consequat tortor ac tincidunt vulputate. | ||
Maecenas non lectus sit amet dui porta dapibus. Etiam vitae velit nibh. Morbi purus urna, cursus convallis feugiat vel, vulputate eget turpis. Vivamus et tincidunt lectus. Nullam id risus est. Sed ullamcorper pellentesque massa, dignissim ultricies urna maximus ac. Vivamus maximus eu ex quis ultricies. Donec facilisis diam arcu, id cursus sapien condimentum ac. Aenean suscipit, nibh ac tempus pharetra, ligula augue bibendum arcu, sed fringilla magna nisl vel felis. | ||
Cras lacinia efficitur elit, ac sagittis nulla commodo eu. Aliquam a est at augue imperdiet eleifend. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Maecenas luctus est non vulputate porta. Phasellus eros libero, auctor id justo ac, mollis eleifend enim. Suspendisse pulvinar mi lorem, a maximus massa tincidunt ac. Duis mattis nibh a mauris laoreet laoreet. Donec malesuada quis dui feugiat ultricies. Ut at sem consectetur, tincidunt massa in, bibendum metus. | ||
Sed fermentum eros ac odio venenatis, id varius est mollis. Fusce sollicitudin tellus risus, vel accumsan ante auctor in. Phasellus vel blandit massa. Suspendisse potenti. Donec vitae elementum enim, quis dictum mauris. Nullam consectetur enim at turpis bibendum, consequat facilisis sem ultrices. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam eget nisl id libero tempus fringilla vitae eget urna. Etiam dui neque, vestibulum a mi vulputate, placerat interdum sem. Mauris sit amet aliquam felis. Suspendisse potenti. Nullam odio purus, ultricies in tincidunt sit amet, interdum ac orci. Nulla volutpat auctor velit, sed malesuada urna auctor sed. Suspendisse non sollicitudin tortor. Vivamus vulputate lacinia nisi, pellentesque sagittis sapien. | ||
""".trimIndent() |
Oops, something went wrong.