-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2151 from DataDog/yl/add-sample-fragments
RUM-5550: Add session replay benchmark fragments
- Loading branch information
Showing
16 changed files
with
714 additions
and
12 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
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
129 changes: 129 additions & 0 deletions
129
...ark/src/main/java/com/datadog/benchmark/sample/fragment/SessionReplayAppcompatFragment.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,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 | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
...mark/src/main/java/com/datadog/benchmark/sample/fragment/SessionReplayMaterialFragment.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,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 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
sample/benchmark/src/main/res/drawable/baseline_edit_calendar_24.xml
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,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
13
sample/benchmark/src/main/res/drawable/baseline_more_time_24.xml
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,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.
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
Oops, something went wrong.