1+ package com.example.configcat_openfeature_sample
2+
3+ import android.os.Bundle
4+ import androidx.activity.ComponentActivity
5+ import androidx.activity.compose.setContent
6+ import androidx.activity.enableEdgeToEdge
7+ import androidx.compose.foundation.layout.Column
8+ import androidx.compose.foundation.layout.Row
9+ import androidx.compose.foundation.layout.fillMaxSize
10+ import androidx.compose.foundation.layout.padding
11+ import androidx.compose.material3.Scaffold
12+ import androidx.compose.material3.Text
13+ import androidx.compose.runtime.Composable
14+ import androidx.compose.ui.Modifier
15+ import androidx.compose.ui.tooling.preview.Preview
16+ import androidx.lifecycle.lifecycleScope
17+ import com.configcat.ConfigCatProvider
18+ import com.configcat.SharedPreferencesCache
19+ import com.configcat.log.LogLevel
20+ import com.example.configcat_openfeature_sample.ui.theme.ConfigcatopenfeaturesampleTheme
21+ import dev.openfeature.sdk.ImmutableContext
22+ import dev.openfeature.sdk.OpenFeatureAPI
23+ import dev.openfeature.sdk.Value
24+ import kotlinx.coroutines.launch
25+
26+ class MainActivity : ComponentActivity () {
27+ override fun onCreate (savedInstanceState : Bundle ? ) {
28+ super .onCreate(savedInstanceState)
29+
30+ lifecycleScope.launch {
31+ OpenFeatureAPI .setProviderAndWait(ConfigCatProvider (" PKDVCLf-Hq-h-kCzMp-L7Q/HhOWfwVtZ0mb30i9wi17GQ" ) {
32+ // Use ConfigCat's shared preferences cache.
33+ configCache = SharedPreferencesCache (this @MainActivity)
34+
35+ // Info level logging helps to inspect the feature flag evaluation process.
36+ // Use the default Warning level to avoid too detailed logging in your application.
37+ logLevel = LogLevel .INFO
38+ }, initialContext
= ImmutableContext (targetingKey
= " [email protected] " , attributes
= mapOf (
39+ " Email" to
Value .
String (
" [email protected] " ),
40+ )))
41+
42+ }
43+
44+ enableEdgeToEdge()
45+ setContent {
46+ ConfigcatopenfeaturesampleTheme {
47+ Scaffold (modifier = Modifier .fillMaxSize()) { innerPadding ->
48+ Greeting (
49+ name = " ConfigCat / OpenFeature" ,
50+ modifier = Modifier .padding(innerPadding)
51+ )
52+ }
53+ }
54+ }
55+ }
56+ }
57+
58+ @Composable
59+ fun Greeting (name : String , modifier : Modifier = Modifier ) {
60+ Column {
61+ Row {
62+ Text (
63+ text = " Welcome to $name !" ,
64+ modifier = modifier
65+ )
66+ }
67+ Row {
68+ Text (
69+ text = " isPOCFeatureEnabled: ${OpenFeatureAPI .getClient().getBooleanValue(" isPOCFeatureEnabled" , false )} " ,
70+ modifier = modifier
71+ )
72+ }
73+ }
74+ }
75+
76+ @Preview(showBackground = true )
77+ @Composable
78+ fun GreetingPreview () {
79+ ConfigcatopenfeaturesampleTheme {
80+ Greeting (" ConfigCat / OpenFeature" )
81+ }
82+ }
0 commit comments