Skip to content

Commit 19b76e7

Browse files
committed
Add sample app
1 parent 21f456b commit 19b76e7

File tree

20 files changed

+441
-0
lines changed

20 files changed

+441
-0
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ on:
66
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]
77
paths-ignore:
88
- '**.md'
9+
- 'samples/**'
910
pull_request:
1011
branches: [ main ]
1112
paths-ignore:
1213
- '**.md'
14+
- 'samples/**'
1315

1416
workflow_dispatch:
1517

samples/android/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
plugins {
2+
id("com.android.application")
3+
id("org.jetbrains.kotlin.android")
4+
id("org.jetbrains.kotlin.plugin.compose")
5+
}
6+
7+
android {
8+
namespace = "com.example.configcat_openfeature_sample"
9+
compileSdk = 35
10+
11+
defaultConfig {
12+
applicationId = "com.example.configcat_openfeature_sample"
13+
minSdk = 24
14+
targetSdk = 35
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19+
}
20+
21+
buildTypes {
22+
release {
23+
isMinifyEnabled = false
24+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
25+
}
26+
}
27+
compileOptions {
28+
sourceCompatibility = JavaVersion.VERSION_11
29+
targetCompatibility = JavaVersion.VERSION_11
30+
}
31+
kotlinOptions {
32+
jvmTarget = "11"
33+
}
34+
buildFeatures {
35+
compose = true
36+
}
37+
}
38+
39+
dependencies {
40+
41+
implementation("androidx.core:core-ktx:1.10.1")
42+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1")
43+
implementation("androidx.activity:activity-compose:1.8.0")
44+
implementation(platform("androidx.compose:compose-bom:2024.09.00"))
45+
implementation("androidx.compose.ui:ui")
46+
implementation("androidx.compose.ui:ui-graphics")
47+
implementation("androidx.compose.ui:ui-tooling-preview")
48+
implementation("androidx.compose.material3:material3")
49+
implementation("com.configcat:configcat-openfeature-provider:0.1.0")
50+
testImplementation("junit:junit:4.13.2")
51+
androidTestImplementation("androidx.test.ext:junit:1.1.5")
52+
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
53+
androidTestImplementation(platform("androidx.compose:compose-bom:2024.09.00"))
54+
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
55+
debugImplementation("androidx.compose.ui:ui-tooling")
56+
debugImplementation("androidx.compose.ui:ui-test-manifest")
57+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.example.configcat_openfeature_sample
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
import org.junit.Assert.*
10+
11+
/**
12+
* Instrumented test, which will execute on an Android device.
13+
*
14+
* See [testing documentation](http://d.android.com/tools/testing).
15+
*/
16+
@RunWith(AndroidJUnit4::class)
17+
class ExampleInstrumentedTest {
18+
@Test
19+
fun useAppContext() {
20+
// Context of the app under test.
21+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22+
assertEquals("com.example.configcat_openfeature_sample", appContext.packageName)
23+
}
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true"
11+
android:theme="@style/Theme.Configcatopenfeaturesample"
12+
tools:targetApi="31">
13+
<activity
14+
android:name=".MainActivity"
15+
android:exported="true"
16+
android:label="@string/app_name"
17+
android:theme="@style/Theme.Configcatopenfeaturesample">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN"/>
20+
21+
<category android:name="android.intent.category.LAUNCHER"/>
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.example.configcat_openfeature_sample.ui.theme
2+
3+
import androidx.compose.ui.graphics.Color
4+
5+
val Purple80 = Color(0xFFD0BCFF)
6+
val PurpleGrey80 = Color(0xFFCCC2DC)
7+
val Pink80 = Color(0xFFEFB8C8)
8+
9+
val Purple40 = Color(0xFF6650a4)
10+
val PurpleGrey40 = Color(0xFF625b71)
11+
val Pink40 = Color(0xFF7D5260)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.example.configcat_openfeature_sample.ui.theme
2+
3+
import android.app.Activity
4+
import android.os.Build
5+
import androidx.compose.foundation.isSystemInDarkTheme
6+
import androidx.compose.material3.MaterialTheme
7+
import androidx.compose.material3.darkColorScheme
8+
import androidx.compose.material3.dynamicDarkColorScheme
9+
import androidx.compose.material3.dynamicLightColorScheme
10+
import androidx.compose.material3.lightColorScheme
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.platform.LocalContext
13+
14+
private val DarkColorScheme = darkColorScheme(
15+
primary = Purple80,
16+
secondary = PurpleGrey80,
17+
tertiary = Pink80
18+
)
19+
20+
private val LightColorScheme = lightColorScheme(
21+
primary = Purple40,
22+
secondary = PurpleGrey40,
23+
tertiary = Pink40
24+
25+
/* Other default colors to override
26+
background = Color(0xFFFFFBFE),
27+
surface = Color(0xFFFFFBFE),
28+
onPrimary = Color.White,
29+
onSecondary = Color.White,
30+
onTertiary = Color.White,
31+
onBackground = Color(0xFF1C1B1F),
32+
onSurface = Color(0xFF1C1B1F),
33+
*/
34+
)
35+
36+
@Composable
37+
fun ConfigcatopenfeaturesampleTheme(
38+
darkTheme: Boolean = isSystemInDarkTheme(),
39+
// Dynamic color is available on Android 12+
40+
dynamicColor: Boolean = true,
41+
content: @Composable () -> Unit
42+
) {
43+
val colorScheme = when {
44+
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
45+
val context = LocalContext.current
46+
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
47+
}
48+
49+
darkTheme -> DarkColorScheme
50+
else -> LightColorScheme
51+
}
52+
53+
MaterialTheme(
54+
colorScheme = colorScheme,
55+
typography = Typography,
56+
content = content
57+
)
58+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.example.configcat_openfeature_sample.ui.theme
2+
3+
import androidx.compose.material3.Typography
4+
import androidx.compose.ui.text.TextStyle
5+
import androidx.compose.ui.text.font.FontFamily
6+
import androidx.compose.ui.text.font.FontWeight
7+
import androidx.compose.ui.unit.sp
8+
9+
// Set of Material typography styles to start with
10+
val Typography = Typography(
11+
bodyLarge = TextStyle(
12+
fontFamily = FontFamily.Default,
13+
fontWeight = FontWeight.Normal,
14+
fontSize = 16.sp,
15+
lineHeight = 24.sp,
16+
letterSpacing = 0.5.sp
17+
)
18+
/* Other default text styles to override
19+
titleLarge = TextStyle(
20+
fontFamily = FontFamily.Default,
21+
fontWeight = FontWeight.Normal,
22+
fontSize = 22.sp,
23+
lineHeight = 28.sp,
24+
letterSpacing = 0.sp
25+
),
26+
labelSmall = TextStyle(
27+
fontFamily = FontFamily.Default,
28+
fontWeight = FontWeight.Medium,
29+
fontSize = 11.sp,
30+
lineHeight = 16.sp,
31+
letterSpacing = 0.5.sp
32+
)
33+
*/
34+
)

0 commit comments

Comments
 (0)