-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demo app: activity with fragments (#570)
* refactored packages to make more sense with the fragment activity * added new activity "AboutActicity" which purpose is to display fragment lifecycle instrumentation and 2 fragments within it. Creted buttom nav menu to navigate between these fragments and to return to main activity. Added a "Learn more" button to main activity that launches the About Activity. * added some content to the AppFeaturesFragment * set contentDescription for an image to avoid warnings * added some content for the AboutOpenTelemetryFragment, for now hard written into the layout file. * made unnecessarily global vars local * changed activities' labels * changed button name from OpentStore to Launcher
- Loading branch information
Showing
31 changed files
with
383 additions
and
70 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
50 changes: 50 additions & 0 deletions
50
demo-app/src/main/java/io/opentelemetry/android/demo/about/AboutActivity.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,50 @@ | ||
package io.opentelemetry.android.demo.about | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.google.android.material.bottomnavigation.BottomNavigationView | ||
import io.opentelemetry.android.demo.MainActivity | ||
import io.opentelemetry.android.demo.R | ||
|
||
class AboutActivity : AppCompatActivity() { | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_about) | ||
|
||
val bottomNavigationView: BottomNavigationView = findViewById(R.id.bottom_navigation) | ||
|
||
if (savedInstanceState == null) { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.fragment_container, AppFeaturesFragment()) | ||
.commit() | ||
bottomNavigationView.selectedItemId = R.id.navigation_app_features | ||
} | ||
|
||
bottomNavigationView.setOnItemSelectedListener { item -> | ||
when (item.itemId) { | ||
R.id.navigation_exit -> { | ||
val intent = Intent(this, MainActivity::class.java) | ||
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK | ||
startActivity(intent) | ||
finish() | ||
true | ||
} | ||
R.id.navigation_app_features -> { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.fragment_container, AppFeaturesFragment()) | ||
.commit() | ||
true | ||
} | ||
R.id.navigation_about_opentelemetry -> { | ||
supportFragmentManager.beginTransaction() | ||
.replace(R.id.fragment_container, AboutOpenTelemetryFragment()) | ||
.commit() | ||
true | ||
} | ||
else -> false | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
demo-app/src/main/java/io/opentelemetry/android/demo/about/AboutOpenTelemetryFragment.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,18 @@ | ||
package io.opentelemetry.android.demo.about | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import io.opentelemetry.android.demo.R | ||
|
||
class AboutOpenTelemetryFragment : Fragment() { | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
return inflater.inflate(R.layout.fragment_about_opentelemetry, container, false) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
demo-app/src/main/java/io/opentelemetry/android/demo/about/AppFeaturesFragment.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,29 @@ | ||
package io.opentelemetry.android.demo.about | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import androidx.recyclerview.widget.RecyclerView | ||
import io.opentelemetry.android.demo.R | ||
|
||
class AppFeaturesFragment : Fragment() { | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
val view = inflater.inflate(R.layout.fragment_app_features, container, false) | ||
lateinit var featureAdapter: FeatureAdapter | ||
val features = getFeatureList() | ||
val recyclerView: RecyclerView = view.findViewById(R.id.recyclerView) | ||
|
||
featureAdapter = FeatureAdapter(features) | ||
recyclerView.adapter = featureAdapter | ||
recyclerView.layoutManager = LinearLayoutManager(requireContext()) | ||
|
||
return view | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
demo-app/src/main/java/io/opentelemetry/android/demo/about/Feature.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,45 @@ | ||
package io.opentelemetry.android.demo.about | ||
|
||
data class Feature( | ||
val title: String, | ||
val description: String, | ||
var isExpanded: Boolean = false | ||
) | ||
|
||
fun getFeatureList(): List<Feature> { | ||
return listOf( | ||
Feature( | ||
"Android Activity Lifecycle Monitoring", | ||
""" | ||
- Automatically captures spans for key lifecycle events: | ||
- Created: Includes `onCreate`, `onStart`, `onResume`, | ||
- Paused: Includes `onPause`, | ||
- Stopped: Includes `onStop`, | ||
- Destroyed: Includes `onDestroy`. | ||
- This covers the entire Activity lifecycle, providing detailed insights into each phase. | ||
""".trimIndent() | ||
), | ||
Feature( | ||
"ANR Detection", | ||
""" | ||
- Automatically detects and reports ANRs in the app. | ||
- ANR events are captured as spans with detailed stack traces, providing insights into the exact operations that caused the ANR. | ||
- The span includes key attributes such as `screen.name`, `session.id`, and network information to assist in diagnosing the issue. | ||
""".trimIndent() | ||
), | ||
Feature( | ||
"Slow Render Detection", | ||
""" | ||
- Automatically detects instances of slow rendering within the app. | ||
- Slow render events are captured as spans, providing information on when and where rendering delays occurred. | ||
- The span includes attributes such as `activity.name`, `screen.name`, `count`, and network details to help diagnose performance issues. | ||
""".trimIndent() | ||
), | ||
Feature( | ||
"Manual Instrumentation", | ||
""" | ||
- Provides access to the OpenTelemetry APIs for manual instrumentation, allowing developers to create custom spans and events as needed. | ||
""".trimIndent() | ||
) | ||
) | ||
} |
43 changes: 43 additions & 0 deletions
43
demo-app/src/main/java/io/opentelemetry/android/demo/about/FeatureAdapter.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,43 @@ | ||
package io.opentelemetry.android.demo.about | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ImageView | ||
import android.widget.TextView | ||
import androidx.recyclerview.widget.RecyclerView | ||
import io.opentelemetry.android.demo.R | ||
|
||
class FeatureAdapter(private val features: List<Feature>) : RecyclerView.Adapter<FeatureAdapter.FeatureViewHolder>() { | ||
|
||
inner class FeatureViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { | ||
private val titleTextView: TextView = itemView.findViewById(R.id.titleTextView) | ||
private val descriptionTextView: TextView = itemView.findViewById(R.id.descriptionTextView) | ||
private val arrowImageView: ImageView = itemView.findViewById(R.id.arrowImageView) | ||
|
||
fun bind(feature: Feature) { | ||
titleTextView.text = feature.title | ||
descriptionTextView.text = feature.description | ||
descriptionTextView.visibility = if (feature.isExpanded) View.VISIBLE else View.GONE | ||
arrowImageView.rotation = if (feature.isExpanded) 180f else 0f | ||
|
||
itemView.setOnClickListener { | ||
feature.isExpanded = !feature.isExpanded | ||
notifyItemChanged(adapterPosition) | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FeatureViewHolder { | ||
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_feature, parent, false) | ||
return FeatureViewHolder(view) | ||
} | ||
|
||
override fun onBindViewHolder(holder: FeatureViewHolder, position: Int) { | ||
holder.bind(features[position]) | ||
} | ||
|
||
override fun getItemCount(): Int = features.size | ||
|
||
} | ||
|
2 changes: 1 addition & 1 deletion
2
...metry/android/demo/clients/ImageLoader.kt → .../android/demo/shop/clients/ImageLoader.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
6 changes: 3 additions & 3 deletions
6
...roid/demo/clients/ProductCatalogClient.kt → ...demo/shop/clients/ProductCatalogClient.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
6 changes: 3 additions & 3 deletions
6
...oid/demo/clients/RecommendationService.kt → ...emo/shop/clients/RecommendationService.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
2 changes: 1 addition & 1 deletion
2
...entelemetry/android/demo/model/Product.kt → ...emetry/android/demo/shop/model/Product.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
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
2 changes: 1 addition & 1 deletion
2
...emetry/android/demo/ui/shop/Navigation.kt → ...emetry/android/demo/shop/ui/Navigation.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
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
4 changes: 2 additions & 2 deletions
4
...ndroid/demo/ui/shop/cart/CartViewModel.kt → ...ndroid/demo/shop/ui/cart/CartViewModel.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
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
2 changes: 1 addition & 1 deletion
2
...emo/ui/shop/components/QuantityChooser.kt → ...emo/shop/ui/components/QuantityChooser.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
2 changes: 1 addition & 1 deletion
2
.../demo/ui/shop/components/UpPressButton.kt → .../demo/shop/ui/components/UpPressButton.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
Oops, something went wrong.