Skip to content

Commit 61f8a76

Browse files
committed
Add initial version of compose-based variant
1 parent e592687 commit 61f8a76

39 files changed

+1003
-0
lines changed

android-compose/.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

android-compose/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

android-compose/app/build.gradle.kts

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.jetbrains.kotlin.android)
4+
}
5+
6+
android {
7+
namespace = "dev.danielc.fudgecmp"
8+
compileSdk = 34
9+
10+
defaultConfig {
11+
applicationId = "dev.danielc.fudgecmp"
12+
minSdk = 24
13+
targetSdk = 35
14+
versionCode = 12
15+
versionName = "0.3.0"
16+
17+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
18+
vectorDrawables {
19+
useSupportLibrary = true
20+
}
21+
}
22+
23+
buildTypes {
24+
release {
25+
isMinifyEnabled = false
26+
proguardFiles(
27+
getDefaultProguardFile("proguard-android-optimize.txt"),
28+
"proguard-rules.pro"
29+
)
30+
}
31+
}
32+
compileOptions {
33+
sourceCompatibility = JavaVersion.VERSION_1_8
34+
targetCompatibility = JavaVersion.VERSION_1_8
35+
}
36+
kotlinOptions {
37+
jvmTarget = "1.8"
38+
}
39+
buildFeatures {
40+
compose = true
41+
}
42+
composeOptions {
43+
kotlinCompilerExtensionVersion = "1.5.1"
44+
}
45+
packaging {
46+
resources {
47+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
48+
}
49+
}
50+
}
51+
52+
dependencies {
53+
implementation(libs.androidx.core.ktx)
54+
implementation(libs.androidx.lifecycle.runtime.ktx)
55+
implementation(libs.androidx.activity.compose)
56+
implementation(platform(libs.androidx.compose.bom))
57+
implementation(libs.androidx.ui)
58+
implementation(libs.androidx.ui.graphics)
59+
implementation(libs.androidx.ui.tooling.preview)
60+
implementation(libs.androidx.material3)
61+
testImplementation(libs.junit)
62+
androidTestImplementation(libs.androidx.junit)
63+
androidTestImplementation(libs.androidx.espresso.core)
64+
androidTestImplementation(platform(libs.androidx.compose.bom))
65+
androidTestImplementation(libs.androidx.ui.test.junit4)
66+
debugImplementation(libs.androidx.ui.tooling)
67+
debugImplementation(libs.androidx.ui.test.manifest)
68+
}
+21
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package dev.danielc.fudgecmp
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("dev.danielc.fujiapp", appContext.packageName)
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.Fudge"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true"
18+
android:label="@string/app_name"
19+
android:theme="@style/Theme.Fudge">
20+
<intent-filter>
21+
<action android:name="android.intent.action.MAIN" />
22+
23+
<category android:name="android.intent.category.LAUNCHER" />
24+
</intent-filter>
25+
</activity>
26+
</application>
27+
28+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package dev.danielc.fudgecmp
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.background
8+
import androidx.compose.foundation.layout.Box
9+
import androidx.compose.foundation.layout.Column
10+
import androidx.compose.foundation.layout.fillMaxSize
11+
import androidx.compose.foundation.text.BasicText
12+
import androidx.compose.material3.Button
13+
import androidx.compose.material3.Text
14+
import androidx.compose.runtime.Composable
15+
import androidx.compose.ui.Modifier
16+
import androidx.compose.ui.tooling.preview.Preview
17+
import dev.danielc.fudgecmp.ui.theme.FudgeTheme
18+
import androidx.compose.runtime.*
19+
import androidx.compose.ui.graphics.Color
20+
21+
fun test(x: Int) {
22+
23+
}
24+
25+
@Composable
26+
fun AppButton(
27+
modifier: Modifier = Modifier,
28+
enabled: Boolean = true,
29+
onClick: (Int) -> Unit,
30+
content: @Composable () -> Unit,
31+
ctx: Int
32+
) {
33+
Button(
34+
onClick = {
35+
onClick(ctx)
36+
},
37+
modifier = modifier,
38+
enabled = enabled,
39+
) {
40+
content()
41+
}
42+
}
43+
44+
@Preview(showBackground = true, device = "id:pixel_7")
45+
@Composable
46+
fun MainScreen() {
47+
var isEnabled by remember { mutableStateOf(true) }
48+
return FudgeTheme {
49+
Box(modifier = Modifier.fillMaxSize().background(color = Color.DarkGray)) {
50+
Column {
51+
Widgets.Button(ctx = 1, onClick = {
52+
isEnabled = !isEnabled
53+
}, content = {Text("Disable button below")})
54+
Widgets.Button(ctx = 1, enabled = isEnabled, onClick = {}, content = {Text("Hello")})
55+
56+
BasicText("hello")
57+
}
58+
}
59+
}
60+
}
61+
62+
class MainActivity : ComponentActivity() {
63+
override fun onCreate(savedInstanceState: Bundle?) {
64+
super.onCreate(savedInstanceState)
65+
enableEdgeToEdge()
66+
setContent {
67+
FudgeTheme {
68+
MainScreen()
69+
}
70+
}
71+
}
72+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package dev.danielc.fudgecmp
2+
3+
import androidx.compose.foundation.layout.fillMaxWidth
4+
import androidx.compose.foundation.layout.padding
5+
import androidx.compose.material3.Button
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.graphics.RectangleShape
9+
import androidx.compose.ui.unit.dp
10+
11+
object Widgets {
12+
@Composable
13+
fun Button(
14+
modifier: Modifier = Modifier,
15+
enabled: Boolean = true,
16+
onClick: (Int) -> Unit,
17+
content: @Composable () -> Unit,
18+
ctx: Int
19+
) {
20+
Button(
21+
onClick = {
22+
onClick(ctx)
23+
},
24+
modifier = modifier.padding(10.dp).fillMaxWidth(),
25+
shape = RectangleShape,
26+
enabled = enabled,
27+
) {
28+
content()
29+
}
30+
}
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package dev.danielc.fudgecmp.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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package dev.danielc.fudgecmp.ui.theme
2+
3+
import android.os.Build
4+
import androidx.compose.foundation.isSystemInDarkTheme
5+
import androidx.compose.material3.MaterialTheme
6+
import androidx.compose.material3.darkColorScheme
7+
import androidx.compose.material3.dynamicDarkColorScheme
8+
import androidx.compose.material3.dynamicLightColorScheme
9+
import androidx.compose.material3.lightColorScheme
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.platform.LocalContext
12+
13+
private val DarkColorScheme = darkColorScheme(
14+
primary = Purple80,
15+
secondary = PurpleGrey80,
16+
tertiary = Pink80
17+
)
18+
19+
private val LightColorScheme = lightColorScheme(
20+
primary = Purple40,
21+
secondary = PurpleGrey40,
22+
tertiary = Pink40
23+
24+
/* Other default colors to override
25+
background = Color(0xFFFFFBFE),
26+
surface = Color(0xFFFFFBFE),
27+
onPrimary = Color.White,
28+
onSecondary = Color.White,
29+
onTertiary = Color.White,
30+
onBackground = Color(0xFF1C1B1F),
31+
onSurface = Color(0xFF1C1B1F),
32+
*/
33+
)
34+
35+
@Composable
36+
fun FudgeTheme(
37+
darkTheme: Boolean = isSystemInDarkTheme(),
38+
// Dynamic color is available on Android 12+
39+
dynamicColor: Boolean = true,
40+
content: @Composable () -> Unit
41+
) {
42+
val colorScheme = when {
43+
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
44+
val context = LocalContext.current
45+
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
46+
}
47+
48+
darkTheme -> DarkColorScheme
49+
else -> LightColorScheme
50+
}
51+
52+
MaterialTheme(
53+
colorScheme = colorScheme,
54+
typography = Typography,
55+
content = content
56+
)
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dev.danielc.fudgecmp.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)