Skip to content

Commit a5419df

Browse files
create navigation tutorial
1 parent ce0aa5c commit a5419df

File tree

29 files changed

+527
-54
lines changed

29 files changed

+527
-54
lines changed

Tutorial3-1Navigation/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
plugins {
2+
alias(libs.plugins.android.application)
3+
alias(libs.plugins.kotlin.android)
4+
alias(libs.plugins.compose)
5+
}
6+
7+
android {
8+
namespace = "com.smarttoolfactory.tutorial3_1navigation"
9+
compileSdk = libs.versions.compileSdk.get().toInt()
10+
11+
defaultConfig {
12+
applicationId = "com.smarttoolfactory.tutorial3_1navigation"
13+
minSdk = libs.versions.minSdk.get().toInt()
14+
targetSdk = libs.versions.targetSdk.get().toInt()
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(
25+
getDefaultProguardFile("proguard-android-optimize.txt"),
26+
"proguard-rules.pro"
27+
)
28+
}
29+
}
30+
compileOptions {
31+
sourceCompatibility = JavaVersion.VERSION_17
32+
targetCompatibility = JavaVersion.VERSION_17
33+
}
34+
35+
kotlinOptions { jvmTarget = "17" }
36+
37+
buildFeatures {
38+
compose = true
39+
}
40+
}
41+
42+
dependencies {
43+
implementation(libs.androidx.core.ktx)
44+
implementation(libs.androidx.lifecycle.runtime)
45+
implementation(libs.androidx.activity.compose)
46+
implementation(platform(libs.androidx.compose.bom))
47+
implementation(libs.androidx.compose.ui)
48+
implementation(libs.androidx.compose.ui.graphics)
49+
implementation(libs.androidx.compose.ui.tooling.preview)
50+
implementation(libs.androidx.compose.material3)
51+
testImplementation(libs.junit)
52+
androidTestImplementation(libs.androidx.junit.v121)
53+
androidTestImplementation(libs.androidx.espresso.core.v361)
54+
androidTestImplementation(platform(libs.androidx.compose.bom))
55+
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
56+
debugImplementation(libs.androidx.compose.ui.tooling)
57+
debugImplementation(libs.androidx.compose.ui.test.manifest)
58+
}
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
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.smarttoolfactory.tutorial3_1navigation
2+
3+
import androidx.test.ext.junit.runners.AndroidJUnit4
4+
import androidx.test.platform.app.InstrumentationRegistry
5+
import org.junit.Assert.*
6+
import org.junit.Test
7+
import org.junit.runner.RunWith
8+
9+
/**
10+
* Instrumented test, which will execute on an Android device.
11+
*
12+
* See [testing documentation](http://d.android.com/tools/testing).
13+
*/
14+
@RunWith(AndroidJUnit4::class)
15+
class ExampleInstrumentedTest {
16+
@Test
17+
fun useAppContext() {
18+
// Context of the app under test.
19+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20+
assertEquals("com.smarttoolfactory.tutorial3_1navigation", appContext.packageName)
21+
}
22+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application
5+
android:allowBackup="true"
6+
android:icon="@mipmap/ic_launcher"
7+
android:label="@string/app_name"
8+
android:roundIcon="@mipmap/ic_launcher_round"
9+
android:supportsRtl="true"
10+
android:theme="@style/Theme.ComposeTutorials">
11+
<activity
12+
android:name=".MainActivity"
13+
android:exported="true"
14+
android:label="@string/app_name"
15+
android:theme="@style/Theme.ComposeTutorials">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
</application>
23+
24+
</manifest>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.smarttoolfactory.tutorial3_1navigation
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.fillMaxSize
8+
import androidx.compose.foundation.layout.padding
9+
import androidx.compose.material3.Scaffold
10+
import androidx.compose.material3.Text
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Modifier
13+
import androidx.compose.ui.tooling.preview.Preview
14+
import com.smarttoolfactory.tutorial3_1navigation.ui.theme.ComposeTutorialsTheme
15+
16+
class MainActivity : ComponentActivity() {
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
enableEdgeToEdge()
20+
setContent {
21+
ComposeTutorialsTheme {
22+
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
23+
Greeting(
24+
name = "Android",
25+
modifier = Modifier.padding(innerPadding)
26+
)
27+
}
28+
}
29+
}
30+
}
31+
}
32+
33+
@Composable
34+
fun Greeting(name: String, modifier: Modifier = Modifier) {
35+
Text(
36+
text = "Hello $name!",
37+
modifier = modifier
38+
)
39+
}
40+
41+
@Preview(showBackground = true)
42+
@Composable
43+
fun GreetingPreview() {
44+
ComposeTutorialsTheme {
45+
Greeting("Android")
46+
}
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.smarttoolfactory.tutorial3_1navigation.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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.smarttoolfactory.tutorial3_1navigation.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 ComposeTutorialsTheme(
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.smarttoolfactory.tutorial3_1navigation.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)