Skip to content

Commit 7d4ca4d

Browse files
committed
Initial Kotin/Jetpack compose project
0 parents  commit 7d4ca4d

36 files changed

Lines changed: 1659 additions & 0 deletions

.gitignore

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Built application files
2+
*.apk
3+
*.aar
4+
*.ap_
5+
*.aab
6+
7+
# Files for the ART/Dalvik VM
8+
*.dex
9+
10+
# Java class files
11+
*.class
12+
13+
# Generated files
14+
/bin/
15+
/gen/
16+
/out/
17+
# Uncomment the following line in case you need and you don't have the release build type files in your app
18+
# Gradle files
19+
.gradle/
20+
/build/
21+
22+
# Local configuration file (sdk path, etc)
23+
local.properties
24+
25+
# Proguard folder generated by Eclipse
26+
proguard/
27+
28+
# Log Files
29+
*.log
30+
31+
# Android Studio Navigation editor temp files
32+
.navigation/
33+
34+
# Android Studio captures folder
35+
captures/
36+
37+
# IntelliJ
38+
*.iml
39+
.idea/workspace.xml
40+
.idea/tasks.xml
41+
.idea/gradle.xml
42+
.idea/assetWizardSettings.xml
43+
.idea/dictionaries
44+
.idea/libraries
45+
# Android Studio 3 in .gitignore file.
46+
.idea/caches
47+
.idea/modules.xml
48+
# Comment next line if keeping position of elements in Navigation Editor is relevant for you
49+
.idea/navEditor.xml
50+
51+
# Keystore files
52+
# Uncomment the following lines if you do not want to check your keystore files in.
53+
#*.jks
54+
#*.keystore
55+
56+
# External native build folder generated in Android Studio 2.2 and later
57+
.externalNativeBuild
58+
.cxx/
59+
60+
# Google Services (e.g. APIs or Firebase)
61+
# google-services.json
62+
63+
# Freeline
64+
freeline.py
65+
freeline/
66+
freeline_project_description.json
67+
68+
# fastlane
69+
fastlane/report.xml
70+
fastlane/Preview.html
71+
fastlane/screenshots
72+
fastlane/test_output
73+
fastlane/readme.md
74+
75+
# Version control
76+
vcs.xml
77+
78+
# lint
79+
lint/intermediates/
80+
lint/generated/
81+
lint/outputs/
82+
lint/tmp/
83+
# lint/reports/

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# TestAppKtx

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle.kts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
plugins {
3+
id("com.android.application")
4+
id("kotlin-android")
5+
}
6+
7+
android {
8+
namespace = "io.sohil876.testappktx"
9+
compileSdk = 33
10+
11+
defaultConfig {
12+
applicationId = "io.sohil876.testappktx"
13+
minSdk = 26
14+
targetSdk = 33
15+
versionCode = 1
16+
versionName = "1.0"
17+
18+
vectorDrawables {
19+
useSupportLibrary = true
20+
}
21+
}
22+
23+
compileOptions {
24+
sourceCompatibility = JavaVersion.VERSION_11
25+
targetCompatibility = JavaVersion.VERSION_11
26+
}
27+
28+
buildTypes {
29+
release {
30+
isMinifyEnabled = true
31+
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
32+
}
33+
}
34+
35+
buildFeatures {
36+
37+
compose = true
38+
}
39+
composeOptions {
40+
kotlinCompilerExtensionVersion = "1.3.2"
41+
}
42+
packagingOptions {
43+
resources {
44+
excludes += "/META-INF/{AL2.0,LGPL2.1}"
45+
}
46+
}
47+
}
48+
49+
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
50+
kotlinOptions.jvmTarget = "11"
51+
}
52+
53+
dependencies {
54+
55+
implementation(platform("androidx.compose:compose-bom:2022.10.00"))
56+
57+
implementation("androidx.compose.ui:ui-graphics")
58+
implementation("androidx.core:core-ktx:1.8.0")
59+
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
60+
implementation("androidx.compose.material3:material3")
61+
debugImplementation("androidx.compose.ui:ui-test-manifest")
62+
implementation("androidx.compose.ui:ui-tooling-preview")
63+
implementation("androidx.compose.ui:ui")
64+
implementation("androidx.activity:activity-compose:1.5.1")
65+
debugImplementation("androidx.compose.ui:ui-tooling")
66+
}

app/proguard-rules.pro

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

app/src/main/AndroidManifest.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<manifest
4+
xmlns:android="http://schemas.android.com/apk/res/android">
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:roundIcon="@mipmap/ic_launcher"
9+
android:label="@string/app_name"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity
13+
android:name="MainActivity"
14+
android:exported="true">
15+
<intent-filter>
16+
<action
17+
android:name="android.intent.action.MAIN" />
18+
<category
19+
android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
</manifest>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.sohil876.testappktx
2+
3+
import android.os.Bundle
4+
import androidx.activity.ComponentActivity
5+
import androidx.activity.compose.setContent
6+
import androidx.compose.foundation.layout.fillMaxSize
7+
import androidx.compose.material3.MaterialTheme
8+
import androidx.compose.material3.Surface
9+
import androidx.compose.material3.Text
10+
import androidx.compose.runtime.Composable
11+
import androidx.compose.ui.Modifier
12+
import androidx.compose.ui.tooling.preview.Preview
13+
import io.sohil876.testappktx.ui.theme.MyComposeApplicationTheme
14+
15+
class MainActivity : ComponentActivity() {
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setContent {
20+
MyComposeApplicationTheme {
21+
// A surface container using the 'background' color from the theme
22+
Surface(modifier = Modifier.fillMaxSize(),
23+
color = MaterialTheme.colorScheme.background) {
24+
Greeting("Android")
25+
}
26+
}
27+
}
28+
}
29+
}
30+
31+
@Composable
32+
fun Greeting(name: String, modifier: Modifier = Modifier) {
33+
Text(text = "Hello $name!", modifier = modifier)
34+
}
35+
36+
@Preview(showBackground = true)
37+
@Composable
38+
fun GreetingPreview() {
39+
MyComposeApplicationTheme {
40+
Greeting("Android")
41+
}
42+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package io.sohil876.testappktx.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: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package io.sohil876.testappktx.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.runtime.SideEffect
13+
import androidx.compose.ui.graphics.toArgb
14+
import androidx.compose.ui.platform.LocalContext
15+
import androidx.compose.ui.platform.LocalView
16+
import androidx.core.view.WindowCompat
17+
18+
private val DarkColorScheme =
19+
darkColorScheme(primary = Purple80, secondary = PurpleGrey80,
20+
tertiary = Pink80)
21+
22+
private val LightColorScheme =
23+
lightColorScheme(primary = Purple40, secondary = PurpleGrey40,
24+
tertiary = Pink40
25+
26+
/* Other default colors to override
27+
background = Color(0xFFFFFBFE),
28+
surface = Color(0xFFFFFBFE),
29+
onPrimary = Color.White,
30+
onSecondary = Color.White,
31+
onTertiary = Color.White,
32+
onBackground = Color(0xFF1C1B1F),
33+
onSurface = Color(0xFF1C1B1F),
34+
*/)
35+
36+
@Composable
37+
fun MyComposeApplicationTheme(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(
46+
context) else dynamicLightColorScheme(context)
47+
}
48+
49+
darkTheme -> DarkColorScheme
50+
else -> LightColorScheme
51+
}
52+
val view = LocalView.current
53+
if (!view.isInEditMode) {
54+
SideEffect {
55+
val window = (view.context as Activity).window
56+
window.statusBarColor = colorScheme.primary.toArgb()
57+
WindowCompat.getInsetsController(window,
58+
view).isAppearanceLightStatusBars = darkTheme
59+
}
60+
}
61+
62+
MaterialTheme(colorScheme = colorScheme, typography = Typography,
63+
content = content)
64+
}

0 commit comments

Comments
 (0)