Skip to content

Commit

Permalink
Merge pull request #2151 from DataDog/yl/add-sample-fragments
Browse files Browse the repository at this point in the history
RUM-5550: Add session replay benchmark fragments
  • Loading branch information
ambushwork authored Jul 31, 2024
2 parents e6a94df + 45e7822 commit ca6fabe
Show file tree
Hide file tree
Showing 16 changed files with 714 additions and 12 deletions.
2 changes: 2 additions & 0 deletions sample/benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ dependencies {
implementation(libs.bundles.androidXNavigation)
implementation(libs.androidXAppCompat)
implementation(libs.androidXConstraintLayout)
implementation(libs.googleMaterial)
implementation(libs.glideCore)
}

kotlinConfig()
Expand Down
2 changes: 2 additions & 0 deletions sample/benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,24 @@
package com.datadog.benchmark.sample

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavController
import androidx.navigation.Navigation
import com.datadog.sample.benchmark.R

/**
* MainActivity of benchmark sample application.
*/
class MainActivity : ComponentActivity() {
class MainActivity : AppCompatActivity() {

private lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}

override fun onResume() {
super.onResume()
navController = Navigation.findNavController(this, R.id.nav_host_fragment)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.benchmark.sample.fragment

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.CheckedTextView
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.Spinner
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.datadog.sample.benchmark.R
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.timepicker.MaterialTimePicker
import java.util.Locale

internal class SessionReplayAppcompatFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_session_replay_compat, container, false).apply {
findViewById<CheckedTextView>(R.id.checked_text_view).apply {
setOnClickListener { this.toggle() }
}

findViewById<Spinner>(R.id.default_spinner)?.let { spinner ->
ArrayAdapter.createFromResource(
requireContext(),
R.array.planets_array,
android.R.layout.simple_spinner_item
).also { adapter ->
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// Apply the adapter to the spinner
spinner.adapter = adapter
}
}

val defaultNumberPicker: NumberPicker = findViewById(R.id.default_number_picker)
val defaultPickerMinIndex = NUMBER_PICKER_INDEX_MIN
val defaultPickerMaxIndex = NUMBER_PICKER_INDEX_MAX
defaultNumberPicker.minValue = defaultPickerMinIndex
defaultNumberPicker.maxValue = defaultPickerMaxIndex
initTimePicker(this)
findViewById<ImageView>(R.id.imageView_remote).apply {
loadImage(this)
}

findViewById<Button>(R.id.button_navigation).apply {
setOnClickListener {
findNavController(this@SessionReplayAppcompatFragment)
.navigate(R.id.fragment_session_replay_material)
}
}
}
}

private fun initTimePicker(rootView: View) {
val setTimeTextView = rootView.findViewById<EditText>(R.id.set_time_text_view)
val setDateTextView = rootView.findViewById<EditText>(R.id.set_date_text_view)

rootView.findViewById<ImageButton>(R.id.set_time_button).setOnClickListener {
activity?.supportFragmentManager?.let {
MaterialTimePicker.Builder().build().apply {
addOnPositiveButtonClickListener {
val hour = this.hour
val minute = this.minute
setTimeTextView.setText(
String.format(
Locale.US,
"%s : %s",
hour,
minute
)
)
}
}.show(it, null)
}
}
rootView.findViewById<ImageButton>(R.id.set_date_button).setOnClickListener {
activity?.supportFragmentManager?.let {
MaterialDatePicker.Builder.datePicker().build().apply {
addOnPositiveButtonClickListener {
setDateTextView.setText(this.headerText)
}
}.show(it, null)
}
}
}

private fun loadImage(imageView: ImageView) {
Glide.with(imageView)
.load("https://picsum.photos/800/450")
.placeholder(R.drawable.ic_dd_icon_rgb)
.fitCenter()
.into(object : CustomTarget<Drawable>() {
override fun onLoadCleared(placeholder: Drawable?) {}
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
imageView.setImageDrawable(resource)
}
})
}

companion object {
private const val NUMBER_PICKER_INDEX_MIN = 0
private const val NUMBER_PICKER_INDEX_MAX = 10
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
/*
* Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
* This product includes software developed at Datadog (https://www.datadoghq.com/).
* Copyright 2016-Present Datadog, Inc.
*/

package com.datadog.benchmark.sample.fragment

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.Button
import android.widget.CheckedTextView
import android.widget.EditText
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.NumberPicker
import android.widget.Spinner
import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment.findNavController
import com.bumptech.glide.Glide
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.transition.Transition
import com.datadog.sample.benchmark.R
import com.google.android.material.datepicker.MaterialDatePicker
import com.google.android.material.timepicker.MaterialTimePicker
import java.util.Locale

internal class SessionReplayMaterialFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.fragment_session_replay_material, container, false).apply {
findViewById<CheckedTextView>(R.id.checked_text_view).apply {
setOnClickListener { this.toggle() }
}

findViewById<Spinner>(R.id.default_spinner)?.let { spinner ->
ArrayAdapter.createFromResource(
requireContext(),
R.array.planets_array,
android.R.layout.simple_spinner_item
).also { adapter ->
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
// Apply the adapter to the spinner
spinner.adapter = adapter
}
}
val defaultNumberPicker: NumberPicker = findViewById(R.id.default_number_picker)
val defaultPickerMinIndex = NUMBER_PICKER_INDEX_MIN
val defaultPickerMaxIndex = NUMBER_PICKER_INDEX_MAX
defaultNumberPicker.minValue = defaultPickerMinIndex
defaultNumberPicker.maxValue = defaultPickerMaxIndex
initTimePicker(this)
findViewById<ImageView>(R.id.imageView_remote).apply {
loadImage(this)
}
findViewById<Button>(R.id.button_navigation).apply {
setOnClickListener {
findNavController(this@SessionReplayMaterialFragment)
.navigate(R.id.fragment_session_replay_appcompat)
}
}
}
}

private fun initTimePicker(rootView: View) {
val setTimeTextView = rootView.findViewById<EditText>(R.id.set_time_text_view)
val setDateTextView = rootView.findViewById<EditText>(R.id.set_date_text_view)
rootView.findViewById<ImageButton>(R.id.set_time_button).setOnClickListener {
activity?.supportFragmentManager?.let {
MaterialTimePicker.Builder().build().apply {
addOnPositiveButtonClickListener {
val hour = this.hour
val minute = this.minute
setTimeTextView.setText(
String.format(
Locale.US,
"%s : %s",
hour,
minute
)
)
}
}.show(it, null)
}
}
rootView.findViewById<ImageButton>(R.id.set_date_button).setOnClickListener {
activity?.supportFragmentManager?.let {
MaterialDatePicker.Builder.datePicker().build().apply {
addOnPositiveButtonClickListener {
setDateTextView.setText(this.headerText)
}
}.show(it, null)
}
}
}

private fun loadImage(imageView: ImageView) {
Glide.with(imageView)
.load("https://picsum.photos/800/450")
.placeholder(R.drawable.ic_dd_icon_rgb)
.fitCenter()
.into(object : CustomTarget<Drawable>() {
override fun onLoadCleared(placeholder: Drawable?) {}
override fun onResourceReady(
resource: Drawable,
transition: Transition<in Drawable>?
) {
imageView.setImageDrawable(resource)
}
})
}

companion object {
private const val NUMBER_PICKER_INDEX_MIN = 0
private const val NUMBER_PICKER_INDEX_MAX = 10
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
~ Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
~ This product includes software developed at Datadog (https://www.datadoghq.com/).
~ Copyright 2016-Present Datadog, Inc.
-->

<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M12,22H5c-1.11,0 -2,-0.9 -2,-2L3.01,6c0,-1.1 0.88,-2 1.99,-2h1V2h2v2h8V2h2v2h1c1.1,0 2,0.9 2,2v6h-2v-2H5v10h7V22zM22.13,16.99l0.71,-0.71c0.39,-0.39 0.39,-1.02 0,-1.41l-0.71,-0.71c-0.39,-0.39 -1.02,-0.39 -1.41,0l-0.71,0.71L22.13,16.99zM21.42,17.7l-5.3,5.3H14v-2.12l5.3,-5.3L21.42,17.7z"/>
</vector>
13 changes: 13 additions & 0 deletions sample/benchmark/src/main/res/drawable/baseline_more_time_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--
~ Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
~ This product includes software developed at Datadog (https://www.datadoghq.com/).
~ Copyright 2016-Present Datadog, Inc.
-->

<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M10,8l0,6l4.7,2.9l0.8,-1.2l-4,-2.4l0,-5.3z"/>
<path android:fillColor="@android:color/white" android:pathData="M17.92,12c0.05,0.33 0.08,0.66 0.08,1c0,3.9 -3.1,7 -7,7s-7,-3.1 -7,-7c0,-3.9 3.1,-7 7,-7c0.7,0 1.37,0.1 2,0.29V4.23C12.36,4.08 11.69,4 11,4c-5,0 -9,4 -9,9s4,9 9,9s9,-4 9,-9c0,-0.34 -0.02,-0.67 -0.06,-1H17.92z"/>
<path android:fillColor="@android:color/white" android:pathData="M20,5l0,-3l-2,0l0,3l-3,0l0,2l3,0l0,3l2,0l0,-3l3,0l0,-2z"/>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 8 additions & 9 deletions sample/benchmark/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello world"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="32dp"
app:defaultNavHost="true"
app:navGraph="@navigation/nav_graph" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading

0 comments on commit ca6fabe

Please sign in to comment.