### Get Weighted Performance Level for Multiple Parameters Source: https://github.com/grofers/droid-dex/blob/master/README.md This code provides a way to get a composite performance level based on multiple parameters, each assigned a specific weight. This allows for more nuanced performance assessments. You can either get the current value or observe changes using LiveData. 'params' should be a comma-separated list of `PerformanceClass` and their corresponding `Weights`. ```Kotlin DroidDex.getWeightedPerformanceLevel(params) DroidDex.getWeightedPerformanceLevelLd(params).observe(this) { } ``` ```Kotlin DroidDex.getWeightedPerformanceLevelLd(PerformanceClass.CPU to 2F, PerformanceClass.MEMORY to 1F).observe(this) { } ``` -------------------------------- ### Optimize Image Quality Based on Network and Memory Performance Source: https://github.com/grofers/droid-dex/blob/master/README.md This code snippet shows how to get a weighted performance level considering both Network and Memory parameters. This is useful for dynamically adjusting image quality based on network conditions and available memory, ensuring a better user experience without compromising app performance. ```Kotlin DroidDex.getWeightedPerformanceLevelLd(PerformanceClass.NETWORK to 2F, PerformanceClass.MEMORY to 1F).observe(this) { // Implement image quality optimization } ``` -------------------------------- ### Get Performance Level for Single/Multiple Parameters Source: https://github.com/grofers/droid-dex/blob/master/README.md This snippet demonstrates how to retrieve the current performance level for one or more specified parameters. You can either get the immediate value or observe changes over time using LiveData. 'params' should be replaced with a comma-separated list of `PerformanceClass` values. ```Kotlin DroidDex.getPerformanceLevel(params) DroidDex.getPerformanceLevelLd(params).observe(this) { } ``` ```Kotlin DroidDex.getPerformanceLevel(PerformanceClass.CPU, PerformanceClass.MEMORY) ``` -------------------------------- ### Get Weighted Performance Level (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Calculates a weighted average of performance metrics, useful when certain metrics are more critical than others for specific features. It accepts pairs of PerformanceClass and their corresponding weight (Float). The output is a PerformanceLevel. ```kotlin import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass // Network is twice as important as memory for image quality decision val weightedLevel = DroidDex.getWeightedPerformanceLevel( PerformanceClass.NETWORK to 2F, // Higher weight for network PerformanceClass.MEMORY to 1F // Lower weight for memory ) // Use weighted result for image quality selection val imageResolution = when (weightedLevel) { PerformanceLevel.EXCELLENT -> "4K" PerformanceLevel.HIGH -> "1080p" PerformanceLevel.AVERAGE -> "720p" PerformanceLevel.LOW -> "480p" PerformanceLevel.UNKNOWN -> "360p" } // CPU weight is 2x, Battery weight is 3x for background tasks val backgroundTaskLevel = DroidDex.getWeightedPerformanceLevel( PerformanceClass.CPU to 2F, PerformanceClass.BATTERY to 3F ) ``` -------------------------------- ### Get Average Performance Level for Multiple Parameters (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Calculates the average performance level for a specified set of device metrics. This is useful for a holistic performance assessment. It takes a variable number of PerformanceClass enums as input and returns a PerformanceLevel object. ```kotlin import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass // Get average performance level for CPU and Memory val averageLevel = DroidDex.getPerformanceLevel( PerformanceClass.CPU, PerformanceClass.MEMORY ) // Use for feature gating if (averageLevel.level >= PerformanceLevel.HIGH.level) { enableAdvancedAnimations() } else { useSimpleTransitions() } // Get average performance for CPU, Memory, and Network val overallPerformance = DroidDex.getPerformanceLevel( PerformanceClass.CPU, PerformanceClass.MEMORY, PerformanceClass.NETWORK ) ``` -------------------------------- ### Get Single Performance Level (CPU, Memory) Source: https://context7.com/grofers/droid-dex/llms.txt Retrieves the current performance level for a specific performance metric such as CPU or Memory. The function returns a PerformanceLevel enum (EXCELLENT, HIGH, AVERAGE, LOW, UNKNOWN). This allows for immediate checks and conditional logic based on device performance. ```kotlin import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass import com.blinkit.droiddex.constants.PerformanceLevel // Get current CPU performance level val cpuLevel: PerformanceLevel = DroidDex.getPerformanceLevel(PerformanceClass.CPU) // Check the performance level when (cpuLevel) { PerformanceLevel.EXCELLENT -> { // Enable all advanced features enableHighQualityRendering() } PerformanceLevel.HIGH -> { // Enable most features with slight optimizations enableStandardRendering() } PerformanceLevel.AVERAGE -> { // Disable some resource-intensive features enableOptimizedRendering() } PerformanceLevel.LOW -> { // Minimize resource usage enableLowQualityRendering() } PerformanceLevel.UNKNOWN -> { // Fallback behavior enableSafeMode() } } // Get memory performance level val memoryLevel = DroidDex.getPerformanceLevel(PerformanceClass.MEMORY) ``` -------------------------------- ### Initialize Droid Dex Library Source: https://github.com/grofers/droid-dex/blob/master/README.md This is the essential initialization step for the Droid Dex library. It should be called within your Application class to set up the performance monitoring. The function requires the Application Context as a parameter. ```Kotlin DroidDex.init(this) // Parameter: Application Context ``` -------------------------------- ### Configure GitHub Repository for Droid-Dex 2.x (Kotlin) Source: https://github.com/grofers/droid-dex/blob/master/README.md This snippet configures your `settings.gradle[.kts]` file to include a GitHub Maven repository for older versions of Droid-Dex (2.x and before). It requires a GitHub Personal Access Token for authentication. ```kotlin dependencyResolutionManagement { repositories { maven { url = uri("https://maven.pkg.github.com/grofers/*") credentials { username = "Blinkit" password = GITHUB_PERSONAL_ACCESS_TOKEN } } } } ``` -------------------------------- ### Initialize Droid Dex in Application Source: https://context7.com/grofers/droid-dex/llms.txt Initializes the Droid Dex library with the application context. This should be done in your Application class's onCreate() method to enable performance monitoring across the application. No external dependencies are required beyond the Droid Dex library itself. ```kotlin import android.app.Application import com.blinkit.droiddex.DroidDex class MyApplication : Application() { override fun onCreate() { super.onCreate( ) // Initialize Droid Dex with application context DroidDex.init(this) } } ``` -------------------------------- ### Dynamic Content Loading Strategy with Droid-Dex Source: https://context7.com/grofers/droid-dex/llms.txt Implements a dynamic content loading strategy that adjusts prefetch count, image quality, animation enablement, and cache size based on weighted CPU, memory, and network performance levels monitored by Droid-Dex. It utilizes ViewModel and coroutines for reactive updates. Dependencies include androidx.lifecycle and com.blinkit.droiddex. ```kotlin import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.launch class ContentViewModel : ViewModel() { private val _loadingStrategy = MutableStateFlow(LoadingStrategy.CONSERVATIVE) val loadingStrategy: StateFlow = _loadingStrategy init { setupPerformanceMonitoring() } private fun setupPerformanceMonitoring() { // Monitor CPU, Memory, and Network with different weights DroidDex.getWeightedPerformanceLevelLd( PerformanceClass.CPU to 1F, PerformanceClass.MEMORY to 2F, PerformanceClass.NETWORK to 2F ).observeForever { level -> viewModelScope.launch { _loadingStrategy.value = when (level) { PerformanceLevel.EXCELLENT -> LoadingStrategy.AGGRESSIVE PerformanceLevel.HIGH -> LoadingStrategy.BALANCED PerformanceLevel.AVERAGE -> LoadingStrategy.CONSERVATIVE PerformanceLevel.LOW -> LoadingStrategy.MINIMAL PerformanceLevel.UNKNOWN -> LoadingStrategy.MINIMAL } } } } } sealed class LoadingStrategy( val prefetchCount: Int, val imageQuality: Int, val enableAnimations: Boolean, val cacheSize: Int ) { object AGGRESSIVE : LoadingStrategy( prefetchCount = 20, imageQuality = 100, enableAnimations = true, cacheSize = 50 * 1024 * 1024 // 50 MB ) object BALANCED : LoadingStrategy( prefetchCount = 10, imageQuality = 80, enableAnimations = true, cacheSize = 25 * 1024 * 1024 // 25 MB ) object CONSERVATIVE : LoadingStrategy( prefetchCount = 5, imageQuality = 60, enableAnimations = false, cacheSize = 10 * 1024 * 1024 // 10 MB ) object MINIMAL : LoadingStrategy( prefetchCount = 1, imageQuality = 40, enableAnimations = false, cacheSize = 5 * 1024 * 1024 // 5 MB ) } ``` -------------------------------- ### Adaptive Background Sync with Droid-Dex Source: https://context7.com/grofers/droid-dex/llms.txt Sets up a background synchronization task that dynamically adjusts its frequency and requirements (charging, Wi-Fi) based on weighted battery and network performance levels monitored by Droid-Dex. It uses WorkManager for scheduling and execution. Dependencies include androidx.work and com.blinkit.droiddex. ```kotlin import androidx.work.* import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass import java.util.concurrent.TimeUnit class SyncManager(private val context: Context) { fun setupAdaptiveSync() { // Monitor battery and network with battery being more important DroidDex.getWeightedPerformanceLevelLd( PerformanceClass.BATTERY to 2F, PerformanceClass.NETWORK to 1F ).observeForever { level -> scheduleSyncWork(level) } } private fun scheduleSyncWork(performanceLevel: PerformanceLevel) { val (interval, requiresCharging, requiresWifi) = when (performanceLevel) { PerformanceLevel.EXCELLENT -> Triple(15L, false, false) PerformanceLevel.HIGH -> Triple(30L, false, false) PerformanceLevel.AVERAGE -> Triple(60L, false, true) PerformanceLevel.LOW -> Triple(180L, true, true) PerformanceLevel.UNKNOWN -> Triple(360L, true, true) } val constraints = Constraints.Builder() .setRequiredNetworkType(if (requiresWifi) NetworkType.UNMETERED else NetworkType.CONNECTED) .setRequiresCharging(requiresCharging) .build() val syncRequest = PeriodicWorkRequestBuilder(interval, TimeUnit.MINUTES) .setConstraints(constraints) .build() WorkManager.getInstance(context) .enqueueUniquePeriodicWork( "adaptive_sync", ExistingPeriodicWorkPolicy.UPDATE, syncRequest ) } } class SyncWorker(context: Context, params: WorkerParameters) : Worker(context, params) { override fun doWork(): Result { // Perform sync operation return Result.success() } } ``` -------------------------------- ### Understand and Work with Performance Levels (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Understand and work with the five performance level classifications (UNKNOWN, LOW, AVERAGE, HIGH, EXCELLENT). This includes comparing levels, enabling/disabling features based on performance, and retrieving levels from numeric values. ```kotlin import com.blinkit.droiddex.constants.PerformanceLevel import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass // All performance levels with their numeric values val unknown = PerformanceLevel.UNKNOWN // level = 0 val low = PerformanceLevel.LOW // level = 1 val average = PerformanceLevel.AVERAGE // level = 2 val high = PerformanceLevel.HIGH // level = 3 val excellent = PerformanceLevel.EXCELLENT // level = 4 // Compare performance levels fun shouldEnableFeature(currentLevel: PerformanceLevel, minimumRequired: PerformanceLevel): Boolean { return currentLevel.level >= minimumRequired.level } // Usage example val memoryLevel = DroidDex.getPerformanceLevel(PerformanceClass.MEMORY) if (shouldEnableFeature(memoryLevel, PerformanceLevel.HIGH)) { // Enable memory-intensive feature enableLargeImageCache() } else if (shouldEnableFeature(memoryLevel, PerformanceLevel.AVERAGE)) { // Enable with limitations enableSmallImageCache() } else { // Disable or use minimal configuration disableImageCache() } // Get level from numeric value val levelFromInt = PerformanceLevel.getPerformanceLevel(3) // Returns HIGH val unknownFromInvalid = PerformanceLevel.getPerformanceLevel(99) // Returns UNKNOWN // Placeholder functions for example usage fun enableLargeImageCache() {} fun enableSmallImageCache() {} fun disableImageCache() {} ``` -------------------------------- ### Add Droid-Dex 2.x Dependency (Kotlin) Source: https://github.com/grofers/droid-dex/blob/master/README.md This snippet shows how to add older versions of the Droid-Dex library (2.x and before) to your project using Kotlin and Gradle after configuring the GitHub repository. ```kotlin implementation("com.blinkit.kits:droid-dex:<>") ``` -------------------------------- ### Access Performance Classes and Names (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Retrieve all available performance monitoring categories and their human-readable names. This allows for dynamic logging or UI display of performance metrics. ```kotlin import com.blinkit.droiddex.constants.PerformanceClass import com.blinkit.droiddex.constants.PerformanceClass.Companion.name import com.blinkit.droiddex.constants.PerformanceLevel import android.util.Log // Available performance classes val cpuClass = PerformanceClass.CPU // 0 val memoryClass = PerformanceClass.MEMORY // 1 val storageClass = PerformanceClass.STORAGE // 2 val networkClass = PerformanceClass.NETWORK // 3 val batteryClass = PerformanceClass.BATTERY // 4 // Get human-readable name for each class val cpuName = PerformanceClass.CPU.name() // "CPU" val memoryName = PerformanceClass.MEMORY.name() // "MEMORY" val storageName = PerformanceClass.STORAGE.name() // "STORAGE" val networkName = PerformanceClass.NETWORK.name() // "NETWORK" val batteryName = PerformanceClass.BATTERY.name() // "BATTERY" // Use in logging or UI display fun logPerformanceMetric(@PerformanceClass metric: Int, level: PerformanceLevel) { Log.d("Performance", "${metric.name()}: ${level.name} (level ${level.level})") } ``` -------------------------------- ### Add Droid-Dex 3+ Dependency (Kotlin) Source: https://github.com/grofers/droid-dex/blob/master/README.md This snippet shows how to add the Droid-Dex library version 3 and above to your Android project using Kotlin and Gradle. It requires the latest version to be available on Maven Central. ```kotlin implementation("com.eternal.kits:droid-dex:<>") ``` -------------------------------- ### Observe Weighted Performance with LiveData (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Monitor weighted performance metrics for real-time adaptive behavior with custom importance ratios for network, memory, and CPU. This code snippet demonstrates how to observe LiveData from DroidDex and adjust video streaming quality based on the detected performance level. ```kotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass import com.blinkit.droiddex.constants.PerformanceLevel class VideoStreamingActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_streaming) // Network is most important (weight=3), Memory secondary (weight=2), CPU tertiary (weight=1) DroidDex.getWeightedPerformanceLevelLd( PerformanceClass.NETWORK to 3F, PerformanceClass.MEMORY to 2F, PerformanceClass.CPU to 1F ).observe(this) { level -> // Adjust video streaming quality dynamically val videoQuality = when (level) { PerformanceLevel.EXCELLENT -> { setVideoBitrate(8000) // 8 Mbps setBufferSize(30) // 30 seconds "4K UHD" } PerformanceLevel.HIGH -> { setVideoBitrate(4000) // 4 Mbps setBufferSize(20) // 20 seconds "1080p HD" } PerformanceLevel.AVERAGE -> { setVideoBitrate(1500) // 1.5 Mbps setBufferSize(15) // 15 seconds "720p" } PerformanceLevel.LOW -> { setVideoBitrate(500) // 500 Kbps setBufferSize(10) // 10 seconds "480p" } PerformanceLevel.UNKNOWN -> { setVideoBitrate(250) // 250 Kbps setBufferSize(5) // 5 seconds "360p" } } updateVideoPlayer(videoQuality) } } private fun setVideoBitrate(kbps: Int) { /* Player config */ } private fun setBufferSize(seconds: Int) { /* Buffer config */ } private fun updateVideoPlayer(quality: String) { /* Update UI */ } } ``` -------------------------------- ### Observe Multiple Parameters with LiveData (Kotlin) Source: https://context7.com/grofers/droid-dex/llms.txt Monitors combined performance metrics reactively using LiveData, allowing for dynamic application behavior adjustments. This is particularly useful in activities or fragments where UI elements need to respond to performance changes. It observes a combination of PerformanceClass enums. ```kotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass class ImageGalleryActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_gallery) // Monitor memory and network together DroidDex.getPerformanceLevelLd( PerformanceClass.MEMORY, PerformanceClass.NETWORK ).observe(this) { level -> // Adjust image loading strategy val imageQuality = when (level) { PerformanceLevel.EXCELLENT -> ImageQuality.HIGH PerformanceLevel.HIGH -> ImageQuality.MEDIUM_HIGH PerformanceLevel.AVERAGE -> ImageQuality.MEDIUM PerformanceLevel.LOW -> ImageQuality.LOW PerformanceLevel.UNKNOWN -> ImageQuality.LOW } updateImageLoader(imageQuality) } } private fun updateImageLoader(quality: ImageQuality) { // Configure image loading library (Glide, Coil, etc.) } } enum class ImageQuality { HIGH, MEDIUM_HIGH, MEDIUM, LOW } ``` -------------------------------- ### Observe Battery Performance Level with Droid Dex Source: https://github.com/grofers/droid-dex/blob/master/README.md This snippet demonstrates how to observe the battery performance level using Droid Dex. It's useful for optimizing background tasks, such as API polling, to prevent excessive battery drain. The `getPerformanceLevelLd` function returns a LiveData object that emits the current performance level. ```Kotlin DroidDex.getPerformanceLevelLd(PerformanceClass.BATTERY).observe(this) { // Adjust the polling time interval } ``` -------------------------------- ### Observe Battery Performance Level with LiveData Source: https://context7.com/grofers/droid-dex/llms.txt Monitors changes in the battery performance level reactively using LiveData. This is useful for adjusting application behavior, such as polling intervals, based on real-time battery conditions. It requires an AppCompatActivity context to observe the LiveData. The function returns a PerformanceLevel enum. ```kotlin import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.blinkit.droiddex.DroidDex import com.blinkit.droiddex.constants.PerformanceClass import com.blinkit.droiddex.constants.PerformanceLevel class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Observe battery performance level DroidDex.getPerformanceLevelLd(PerformanceClass.BATTERY).observe(this) { level -> // Adjust background polling interval based on battery level when (level) { PerformanceLevel.EXCELLENT -> startPolling(intervalSeconds = 10) PerformanceLevel.HIGH -> startPolling(intervalSeconds = 30) PerformanceLevel.AVERAGE -> startPolling(intervalSeconds = 60) PerformanceLevel.LOW -> startPolling(intervalSeconds = 300) PerformanceLevel.UNKNOWN -> stopPolling() } } } private fun startPolling(intervalSeconds: Int) { // Implementation for API polling } private fun stopPolling() { // Stop polling to save battery } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.