├── .github
├── ISSUE_TEMPLATE
│ └── build_bus_schedule_app.md
├── renovate.json
└── workflows
│ └── build.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── app
├── build.gradle.kts
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── assets
│ └── database
│ │ └── bus_schedule.db
│ ├── java
│ └── com
│ │ └── example
│ │ └── busschedule
│ │ ├── BusScheduleApplication.kt
│ │ ├── MainActivity.kt
│ │ ├── data
│ │ ├── AppDatabase.kt
│ │ ├── BusSchedule.kt
│ │ └── BusScheduleDao.kt
│ │ └── ui
│ │ ├── BusScheduleScreens.kt
│ │ ├── BusScheduleViewModel.kt
│ │ └── theme
│ │ ├── Color.kt
│ │ ├── Theme.kt
│ │ └── Type.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ └── ic_launcher_background.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.xml
│ ├── mipmap-hdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-mdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xhdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xxhdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ ├── mipmap-xxxhdpi
│ ├── ic_launcher.webp
│ └── ic_launcher_round.webp
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── themes.xml
├── build.gradle.kts
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle.kts
/.github/ISSUE_TEMPLATE/build_bus_schedule_app.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Build Bus Schedule App issue template.
3 | about: Issue template for Build Bus Schedule App practice set
4 | title: Build Bus Schedule App
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **URL of codelab:**
11 |
12 |
13 | **Specify the language of the codelab if it is not English:**
14 |
15 |
16 | **In which task and step of the codelab can this issue be found?**
17 |
18 |
19 | **Describe the problem**
20 |
21 |
22 | **Steps to reproduce?**
23 | 1. Go to...
24 | 2. Click on...
25 | 3. See error...
26 |
27 | **Versions**
28 | _Android Studio version:_
29 | _API version of the emulator:_
30 |
31 |
32 | **Additional information**
33 | _Include screenshots if they would be useful in clarifying the problem._
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3 | "extends": [
4 | "local>android/.github:renovate-config"
5 | ],
6 | "baseBranches": [
7 | "main",
8 | "starter"
9 | ]
10 | }
11 |
--------------------------------------------------------------------------------
/.github/workflows/build.yml:
--------------------------------------------------------------------------------
1 | name: Build
2 |
3 | on:
4 | pull_request:
5 | branches:
6 | - main
7 | - starter
8 |
9 | jobs:
10 | build:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v4
14 |
15 | - name: Set Up JDK
16 | uses: actions/setup-java@v4
17 | with:
18 | distribution: 'zulu' # See 'Supported distributions' for available options
19 | java-version: '17'
20 | cache: 'gradle'
21 |
22 | - name: Setup Gradle
23 | uses: gradle/actions/setup-gradle@v4
24 |
25 | - name: Setup Android SDK
26 | uses: android-actions/setup-android@v3
27 |
28 | - name: Build project and run local and device tests
29 | run: ./gradlew :app:assembleDebug
30 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # built application files
2 | *.apk
3 | *.ap_
4 |
5 | # Mac files
6 | .DS_Store
7 |
8 | # files for the dex VM
9 | *.dex
10 |
11 | # Java class files
12 | *.class
13 |
14 | # generated files
15 | bin/
16 | gen/
17 |
18 | # Ignore 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 | proguard-project.txt
28 |
29 | # Eclipse files
30 | .project
31 | .classpath
32 | .settings/
33 |
34 | # Android Studio/IDEA
35 | *.iml
36 | .idea
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement (CLA). You (or your employer) retain the copyright to your
10 | contribution; this simply gives us permission to use and redistribute your
11 | contributions as part of the project. Head over to
12 | to see your current agreements on file or
13 | to sign a new one.
14 |
15 | You generally only need to submit a CLA once, so if you've already submitted one
16 | (even if it was for a different project), you probably don't need to do it
17 | again.
18 |
19 | ## Code reviews
20 |
21 | All submissions, including submissions by project members, require review. We
22 | use GitHub pull requests for this purpose. Consult
23 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
24 | information on using pull requests.
25 |
26 | ## Community Guidelines
27 |
28 | This project follows
29 | [Google's Open Source Community Guidelines](https://opensource.google/conduct/).
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bus Schedule App
2 |
3 | This folder contains the source code for the Bus Schedule app codelab.
4 |
5 | # Introduction
6 | The Bus Schedule app displays a list of bus stops and arrival times. Tapping a bus stop on the first
7 | screen will display a list of all arrival times for that particular stop.
8 |
9 | The bus stops are stored in a Room database. Schedule items are represented by the `Schedule` class
10 | and queries on the data table are made by the `ScheduleDao` class. The app includes a view model to
11 | access the `ScheduleDao` and format data to be display in a list.
12 |
13 | # Pre-requisites
14 | * Experience with Kotlin syntax.
15 | * Experience with Jetpack Compose.
16 | * How to create and run a project in Android Studio.
17 | * Basic knowledge of SQL databases and performing basic queries.
18 |
19 | # Getting Started
20 | 1. Install Android Studio, if you don't already have it.
21 | 2. Download the sample.
22 | 3. Import the sample into Android Studio.
23 | 4. Build and run the sample.
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | plugins {
17 | id("com.android.application")
18 | id("com.google.devtools.ksp") version "2.1.0-1.0.29"
19 | id("org.jetbrains.kotlin.android")
20 | id("org.jetbrains.kotlin.plugin.compose")
21 | }
22 |
23 | android {
24 | namespace = "com.example.busschedule"
25 | compileSdk = 35
26 |
27 | defaultConfig {
28 | applicationId = "com.example.busschedule"
29 | minSdk = 24
30 | targetSdk = 35
31 | versionCode = 1
32 | versionName = "1.0"
33 |
34 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
35 | vectorDrawables {
36 | useSupportLibrary = true
37 | }
38 | }
39 |
40 | buildTypes {
41 | release {
42 | isMinifyEnabled = false
43 | proguardFiles(
44 | getDefaultProguardFile("proguard-android-optimize.txt"),
45 | "proguard-rules.pro"
46 | )
47 | }
48 | }
49 | compileOptions {
50 | sourceCompatibility = JavaVersion.VERSION_17
51 | targetCompatibility = JavaVersion.VERSION_17
52 | }
53 | kotlinOptions {
54 | jvmTarget = "17"
55 | }
56 | buildFeatures {
57 | compose = true
58 | }
59 | packaging {
60 | resources {
61 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
62 | }
63 | }
64 | }
65 |
66 | dependencies {
67 |
68 | implementation(platform("androidx.compose:compose-bom:2024.11.00"))
69 | implementation("androidx.activity:activity-compose:1.9.3")
70 | implementation("androidx.compose.material3:material3")
71 | implementation("androidx.compose.ui:ui")
72 | implementation("androidx.compose.ui:ui-graphics")
73 | implementation("androidx.compose.ui:ui-tooling-preview")
74 | implementation("androidx.core:core-ktx:1.15.0")
75 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7")
76 | implementation("androidx.navigation:navigation-compose:${rootProject.extra["nav_version"]}")
77 | implementation("androidx.room:room-ktx:${rootProject.extra["room_version"]}")
78 | implementation("androidx.room:room-runtime:${rootProject.extra["room_version"]}")
79 | ksp("androidx.room:room-compiler:${rootProject.extra["room_version"]}")
80 |
81 | debugImplementation("androidx.compose.ui:ui-test-manifest")
82 | debugImplementation("androidx.compose.ui:ui-tooling")
83 | }
84 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
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:
--------------------------------------------------------------------------------
1 |
2 |
17 |
19 |
20 |
28 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/assets/database/bus_schedule.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/assets/database/bus_schedule.db
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/BusScheduleApplication.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule
17 |
18 | import android.app.Application
19 | import com.example.busschedule.data.AppDatabase
20 |
21 | class BusScheduleApplication: Application() {
22 | val database: AppDatabase by lazy { AppDatabase.getDatabase(this) }
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/MainActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule
17 |
18 | import android.os.Bundle
19 | import androidx.activity.ComponentActivity
20 | import androidx.activity.compose.setContent
21 | import com.example.busschedule.ui.BusScheduleApp
22 | import com.example.busschedule.ui.theme.BusScheduleTheme
23 |
24 | class MainActivity : ComponentActivity() {
25 | override fun onCreate(savedInstanceState: Bundle?) {
26 | super.onCreate(savedInstanceState)
27 | setContent {
28 | BusScheduleTheme {
29 | BusScheduleApp()
30 | }
31 | }
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/data/AppDatabase.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.data
17 |
18 | import android.content.Context
19 | import androidx.room.Database
20 | import androidx.room.Room
21 | import androidx.room.RoomDatabase
22 |
23 | @Database(entities = arrayOf(BusSchedule::class), version = 1)
24 | abstract class AppDatabase: RoomDatabase() {
25 | abstract fun busScheduleDao(): BusScheduleDao
26 |
27 | companion object {
28 | @Volatile
29 | private var INSTANCE: AppDatabase? = null
30 |
31 | fun getDatabase(context: Context): AppDatabase {
32 | return INSTANCE ?: synchronized(this) {
33 | Room.databaseBuilder(
34 | context,
35 | AppDatabase::class.java,
36 | "app_database"
37 | )
38 | .createFromAsset("database/bus_schedule.db")
39 | // Wipes and rebuilds instead of migrating if no Migration object.
40 | // Migration is not part of this codelab.
41 | .fallbackToDestructiveMigration()
42 | .build()
43 | .also {
44 | INSTANCE = it
45 | }
46 | }
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/data/BusSchedule.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.data
17 |
18 | import androidx.annotation.NonNull
19 | import androidx.room.ColumnInfo
20 | import androidx.room.Entity
21 | import androidx.room.PrimaryKey
22 |
23 | /**
24 | * Represents a single table in the database. Each row is a separate instance of
25 | * the BusSchedule class. Each property corresponds to a column.
26 | * Additionally, an ID is needed as a unique identifier for
27 | * each row in the database.
28 | */
29 | @Entity(tableName = "Schedule")
30 | data class BusSchedule(
31 | @PrimaryKey
32 | val id: Int,
33 | @NonNull
34 | @ColumnInfo(name = "stop_name")
35 | val stopName: String,
36 | @NonNull
37 | @ColumnInfo(name = "arrival_time")
38 | val arrivalTimeInMillis: Int
39 | )
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/data/BusScheduleDao.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.data
17 |
18 | import androidx.room.Dao
19 | import androidx.room.Query
20 | import kotlinx.coroutines.flow.Flow
21 |
22 | /**
23 | * Provides access to read/write operations on the schedule table.
24 | * Used by the view models to format the query results for use in the UI.
25 | */
26 | @Dao
27 | interface BusScheduleDao {
28 | @Query(
29 | """
30 | SELECT * FROM schedule
31 | ORDER BY arrival_time ASC
32 | """
33 | )
34 | fun getAll(): Flow>
35 |
36 | @Query(
37 | """
38 | SELECT * FROM schedule
39 | WHERE stop_name = :stopName
40 | ORDER BY arrival_time ASC
41 | """
42 | )
43 | fun getByStopName(stopName: String): Flow>
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/ui/BusScheduleScreens.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.ui
17 |
18 | import androidx.activity.compose.BackHandler
19 | import androidx.compose.foundation.clickable
20 | import androidx.compose.foundation.layout.Arrangement
21 | import androidx.compose.foundation.layout.Column
22 | import androidx.compose.foundation.layout.PaddingValues
23 | import androidx.compose.foundation.layout.Row
24 | import androidx.compose.foundation.layout.calculateEndPadding
25 | import androidx.compose.foundation.layout.calculateStartPadding
26 | import androidx.compose.foundation.layout.fillMaxWidth
27 | import androidx.compose.foundation.layout.padding
28 | import androidx.compose.foundation.lazy.LazyColumn
29 | import androidx.compose.foundation.lazy.items
30 | import androidx.compose.material.icons.Icons
31 | import androidx.compose.material.icons.filled.ArrowBack
32 | import androidx.compose.material3.Divider
33 | import androidx.compose.material3.ExperimentalMaterial3Api
34 | import androidx.compose.material3.Icon
35 | import androidx.compose.material3.IconButton
36 | import androidx.compose.material3.MaterialTheme
37 | import androidx.compose.material3.Scaffold
38 | import androidx.compose.material3.Text
39 | import androidx.compose.material3.TopAppBar
40 | import androidx.compose.runtime.Composable
41 | import androidx.compose.runtime.collectAsState
42 | import androidx.compose.runtime.getValue
43 | import androidx.compose.runtime.mutableStateOf
44 | import androidx.compose.runtime.remember
45 | import androidx.compose.runtime.setValue
46 | import androidx.compose.ui.Modifier
47 | import androidx.compose.ui.platform.LocalLayoutDirection
48 | import androidx.compose.ui.res.dimensionResource
49 | import androidx.compose.ui.res.stringResource
50 | import androidx.compose.ui.text.font.FontWeight
51 | import androidx.compose.ui.text.style.TextAlign
52 | import androidx.compose.ui.tooling.preview.Preview
53 | import androidx.compose.ui.unit.dp
54 | import androidx.compose.ui.unit.sp
55 | import androidx.lifecycle.viewmodel.compose.viewModel
56 | import androidx.navigation.NavType
57 | import androidx.navigation.compose.NavHost
58 | import androidx.navigation.compose.composable
59 | import androidx.navigation.compose.rememberNavController
60 | import androidx.navigation.navArgument
61 | import com.example.busschedule.R
62 | import com.example.busschedule.data.BusSchedule
63 | import com.example.busschedule.ui.theme.BusScheduleTheme
64 | import java.text.SimpleDateFormat
65 | import java.util.Date
66 | import java.util.Locale
67 |
68 | enum class BusScheduleScreens {
69 | FullSchedule,
70 | RouteSchedule
71 | }
72 |
73 | @Composable
74 | fun BusScheduleApp(
75 | viewModel: BusScheduleViewModel = viewModel(factory = BusScheduleViewModel.factory)
76 | ) {
77 | val navController = rememberNavController()
78 | val fullScheduleTitle = stringResource(R.string.full_schedule)
79 | var topAppBarTitle by remember { mutableStateOf(fullScheduleTitle) }
80 | val fullSchedule by viewModel.getFullSchedule().collectAsState(emptyList())
81 | val onBackHandler = {
82 | topAppBarTitle = fullScheduleTitle
83 | navController.navigateUp()
84 | }
85 |
86 | Scaffold(
87 | topBar = {
88 | BusScheduleTopAppBar(
89 | title = topAppBarTitle,
90 | canNavigateBack = navController.previousBackStackEntry != null,
91 | onBackClick = { onBackHandler() }
92 | )
93 | }
94 | ) { innerPadding ->
95 | NavHost(
96 | navController = navController,
97 | startDestination = BusScheduleScreens.FullSchedule.name
98 | ) {
99 | composable(BusScheduleScreens.FullSchedule.name) {
100 | FullScheduleScreen(
101 | busSchedules = fullSchedule,
102 | contentPadding = innerPadding,
103 | onScheduleClick = { busStopName ->
104 | navController.navigate(
105 | "${BusScheduleScreens.RouteSchedule.name}/$busStopName"
106 | )
107 | topAppBarTitle = busStopName
108 | }
109 | )
110 | }
111 | val busRouteArgument = "busRoute"
112 | composable(
113 | route = BusScheduleScreens.RouteSchedule.name + "/{$busRouteArgument}",
114 | arguments = listOf(navArgument(busRouteArgument) { type = NavType.StringType })
115 | ) { backStackEntry ->
116 | val stopName = backStackEntry.arguments?.getString(busRouteArgument)
117 | ?: error("busRouteArgument cannot be null")
118 | val routeSchedule by viewModel.getScheduleFor(stopName).collectAsState(emptyList())
119 | RouteScheduleScreen(
120 | stopName = stopName,
121 | busSchedules = routeSchedule,
122 | contentPadding = innerPadding,
123 | onBack = { onBackHandler() }
124 | )
125 | }
126 | }
127 | }
128 | }
129 |
130 | @Composable
131 | fun FullScheduleScreen(
132 | busSchedules: List,
133 | onScheduleClick: (String) -> Unit,
134 | modifier: Modifier = Modifier,
135 | contentPadding: PaddingValues = PaddingValues(0.dp),
136 | ) {
137 | BusScheduleScreen(
138 | busSchedules = busSchedules,
139 | onScheduleClick = onScheduleClick,
140 | contentPadding = contentPadding,
141 | modifier = modifier
142 | )
143 | }
144 |
145 | @Composable
146 | fun RouteScheduleScreen(
147 | stopName: String,
148 | busSchedules: List,
149 | modifier: Modifier = Modifier,
150 | contentPadding: PaddingValues = PaddingValues(0.dp),
151 | onBack: () -> Unit = {}
152 | ) {
153 | BackHandler { onBack() }
154 | BusScheduleScreen(
155 | busSchedules = busSchedules,
156 | modifier = modifier,
157 | contentPadding = contentPadding,
158 | stopName = stopName
159 | )
160 | }
161 |
162 | @Composable
163 | fun BusScheduleScreen(
164 | busSchedules: List,
165 | modifier: Modifier = Modifier,
166 | contentPadding: PaddingValues = PaddingValues(0.dp),
167 | stopName: String? = null,
168 | onScheduleClick: ((String) -> Unit)? = null,
169 | ) {
170 | val stopNameText = if (stopName == null) {
171 | stringResource(R.string.stop_name)
172 | } else {
173 | "$stopName ${stringResource(R.string.route_stop_name)}"
174 | }
175 | val layoutDirection = LocalLayoutDirection.current
176 | Column(
177 | modifier = modifier.padding(
178 | start = contentPadding.calculateStartPadding(layoutDirection),
179 | end = contentPadding.calculateEndPadding(layoutDirection),
180 | )
181 | ) {
182 | Row(
183 | modifier = Modifier
184 | .fillMaxWidth()
185 | .padding(
186 | top = contentPadding.calculateTopPadding(),
187 | bottom = dimensionResource(R.dimen.padding_medium),
188 | start = dimensionResource(R.dimen.padding_medium),
189 | end = dimensionResource(R.dimen.padding_medium),
190 | )
191 | ,
192 | horizontalArrangement = Arrangement.SpaceBetween
193 | ) {
194 | Text(stopNameText)
195 | Text(stringResource(R.string.arrival_time))
196 | }
197 | Divider()
198 | BusScheduleDetails(
199 | contentPadding = PaddingValues(
200 | bottom = contentPadding.calculateBottomPadding()
201 | ),
202 | busSchedules = busSchedules,
203 | onScheduleClick = onScheduleClick
204 | )
205 | }
206 | }
207 |
208 | /*
209 | * Composable for BusScheduleDetails which show list of bus schedule
210 | * When [onScheduleClick] is null, [stopName] is replaced with placeholder
211 | * as it is assumed [stopName]s are the same as shown
212 | * in the list heading display in [BusScheduleScreen]
213 | */
214 | @Composable
215 | fun BusScheduleDetails(
216 | busSchedules: List,
217 | modifier: Modifier = Modifier,
218 | contentPadding: PaddingValues = PaddingValues(0.dp),
219 | onScheduleClick: ((String) -> Unit)? = null
220 | ) {
221 | LazyColumn(
222 | modifier = modifier,
223 | contentPadding = contentPadding,
224 | ) {
225 | items(
226 | items = busSchedules,
227 | key = { busSchedule -> busSchedule.id }
228 | ) { schedule ->
229 | Row(
230 | modifier = Modifier
231 | .fillMaxWidth()
232 | .clickable(enabled = onScheduleClick != null) {
233 | onScheduleClick?.invoke(schedule.stopName)
234 | }
235 | .padding(dimensionResource(R.dimen.padding_medium)),
236 | horizontalArrangement = Arrangement.SpaceBetween
237 | ) {
238 | if (onScheduleClick == null) {
239 | Text(
240 | text = "--",
241 | style = MaterialTheme.typography.bodyLarge.copy(
242 | fontSize = dimensionResource(R.dimen.font_large).value.sp,
243 | fontWeight = FontWeight(300)
244 | ),
245 | textAlign = TextAlign.Center,
246 | modifier = Modifier.weight(1f)
247 | )
248 | } else {
249 | Text(
250 | text = schedule.stopName,
251 | style = MaterialTheme.typography.bodyLarge.copy(
252 | fontSize = dimensionResource(R.dimen.font_large).value.sp,
253 | fontWeight = FontWeight(300)
254 | )
255 | )
256 | }
257 | Text(
258 | text = SimpleDateFormat("h:mm a", Locale.getDefault())
259 | .format(Date(schedule.arrivalTimeInMillis.toLong() * 1000)),
260 | style = MaterialTheme.typography.bodyLarge.copy(
261 | fontSize = dimensionResource(R.dimen.font_large).value.sp,
262 | fontWeight = FontWeight(600)
263 | ),
264 | textAlign = TextAlign.End,
265 | modifier = Modifier.weight(2f)
266 | )
267 | }
268 | }
269 | }
270 | }
271 |
272 | @OptIn(ExperimentalMaterial3Api::class)
273 | @Composable
274 | fun BusScheduleTopAppBar(
275 | title: String,
276 | canNavigateBack: Boolean,
277 | onBackClick: () -> Unit,
278 | modifier: Modifier = Modifier
279 | ) {
280 | if (canNavigateBack) {
281 | TopAppBar(
282 | title = { Text(title) },
283 | navigationIcon = {
284 | IconButton(onClick = onBackClick) {
285 | Icon(
286 | imageVector = Icons.Filled.ArrowBack,
287 | contentDescription = stringResource(
288 | R.string.back
289 | )
290 | )
291 | }
292 | },
293 | modifier = modifier
294 | )
295 | } else {
296 | TopAppBar(
297 | title = { Text(title) },
298 | modifier = modifier
299 | )
300 | }
301 | }
302 |
303 | @Preview(showBackground = true)
304 | @Composable
305 | fun FullScheduleScreenPreview() {
306 | BusScheduleTheme {
307 | FullScheduleScreen(
308 | busSchedules = List(3) { index ->
309 | BusSchedule(
310 | index,
311 | "Main Street",
312 | 111111
313 | )
314 | },
315 | onScheduleClick = {}
316 | )
317 | }
318 | }
319 |
320 | @Preview(showBackground = true)
321 | @Composable
322 | fun RouteScheduleScreenPreview() {
323 | BusScheduleTheme {
324 | RouteScheduleScreen(
325 | stopName = "Main Street",
326 | busSchedules = List(3) { index ->
327 | BusSchedule(
328 | index,
329 | "Main Street",
330 | 111111
331 | )
332 | }
333 | )
334 | }
335 | }
336 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/ui/BusScheduleViewModel.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.ui
17 |
18 | import androidx.lifecycle.ViewModel
19 | import androidx.lifecycle.ViewModelProvider
20 | import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY
21 | import androidx.lifecycle.viewmodel.initializer
22 | import androidx.lifecycle.viewmodel.viewModelFactory
23 | import com.example.busschedule.BusScheduleApplication
24 | import com.example.busschedule.data.BusSchedule
25 | import com.example.busschedule.data.BusScheduleDao
26 | import kotlinx.coroutines.flow.Flow
27 |
28 | /*
29 | * View model for Bus Schedule
30 | * contains methods to access Room DB through [busScheduleDao]
31 | */
32 | class BusScheduleViewModel(private val busScheduleDao: BusScheduleDao): ViewModel() {
33 | // Get full bus schedule from Room DB
34 | fun getFullSchedule(): Flow> = busScheduleDao.getAll()
35 | // Get bus schedule based on the stop name from Room DB
36 | fun getScheduleFor(stopName: String): Flow> =
37 | busScheduleDao.getByStopName(stopName)
38 |
39 | companion object {
40 | val factory : ViewModelProvider.Factory = viewModelFactory {
41 | initializer {
42 | val application = (this[APPLICATION_KEY] as BusScheduleApplication)
43 | BusScheduleViewModel(application.database.busScheduleDao())
44 | }
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/ui/theme/Color.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.ui.theme
17 |
18 | import androidx.compose.ui.graphics.Color
19 |
20 | val md_theme_light_primary = Color(0xFF6750A4)
21 | val md_theme_light_onPrimary = Color(0xFFFFFFFF)
22 | val md_theme_light_primaryContainer = Color(0xFFEADDFF)
23 | val md_theme_light_onPrimaryContainer = Color(0xFF21005D)
24 | val md_theme_light_secondary = Color(0xFF625B71)
25 | val md_theme_light_onSecondary = Color(0xFFFFFFFF)
26 | val md_theme_light_secondaryContainer = Color(0xFFE8DEF8)
27 | val md_theme_light_onSecondaryContainer = Color(0xFF1D192B)
28 | val md_theme_light_tertiary = Color(0xFF7D5260)
29 | val md_theme_light_onTertiary = Color(0xFFFFFFFF)
30 | val md_theme_light_tertiaryContainer = Color(0xFFFFD8E4)
31 | val md_theme_light_onTertiaryContainer = Color(0xFF31111D)
32 | val md_theme_light_error = Color(0xFFB3261E)
33 | val md_theme_light_onError = Color(0xFFFFFFFF)
34 | val md_theme_light_errorContainer = Color(0xFFF9DEDC)
35 | val md_theme_light_onErrorContainer = Color(0xFF410E0B)
36 | val md_theme_light_outline = Color(0xFF79747E)
37 | val md_theme_light_background = Color(0xFFFFFBFE)
38 | val md_theme_light_onBackground = Color(0xFF1C1B1F)
39 | val md_theme_light_surface = Color(0xFFFFFBFE)
40 | val md_theme_light_onSurface = Color(0xFF1C1B1F)
41 | val md_theme_light_surfaceVariant = Color(0xFFE7E0EC)
42 | val md_theme_light_onSurfaceVariant = Color(0xFF49454F)
43 | val md_theme_light_inverseSurface = Color(0xFF313033)
44 | val md_theme_light_inverseOnSurface = Color(0xFFF4EFF4)
45 | val md_theme_light_inversePrimary = Color(0xFFD0BCFF)
46 | val md_theme_light_shadow = Color(0xFF000000)
47 | val md_theme_light_surfaceTint = Color(0xFF6750A4)
48 | val md_theme_light_outlineVariant = Color(0xFFCAC4D0)
49 | val md_theme_light_scrim = Color(0xFF000000)
50 |
51 | val md_theme_dark_primary = Color(0xFFD0BCFF)
52 | val md_theme_dark_onPrimary = Color(0xFF381E72)
53 | val md_theme_dark_primaryContainer = Color(0xFF4F378B)
54 | val md_theme_dark_onPrimaryContainer = Color(0xFFEADDFF)
55 | val md_theme_dark_secondary = Color(0xFFCCC2DC)
56 | val md_theme_dark_onSecondary = Color(0xFF332D41)
57 | val md_theme_dark_secondaryContainer = Color(0xFF4A4458)
58 | val md_theme_dark_onSecondaryContainer = Color(0xFFE8DEF8)
59 | val md_theme_dark_tertiary = Color(0xFFEFB8C8)
60 | val md_theme_dark_onTertiary = Color(0xFF492532)
61 | val md_theme_dark_tertiaryContainer = Color(0xFF633B48)
62 | val md_theme_dark_onTertiaryContainer = Color(0xFFFFD8E4)
63 | val md_theme_dark_error = Color(0xFFF2B8B5)
64 | val md_theme_dark_onError = Color(0xFF601410)
65 | val md_theme_dark_errorContainer = Color(0xFF8C1D18)
66 | val md_theme_dark_onErrorContainer = Color(0xFFF9DEDC)
67 | val md_theme_dark_outline = Color(0xFF938F99)
68 | val md_theme_dark_background = Color(0xFF1C1B1F)
69 | val md_theme_dark_onBackground = Color(0xFFE6E1E5)
70 | val md_theme_dark_surface = Color(0xFF1C1B1F)
71 | val md_theme_dark_onSurface = Color(0xFFE6E1E5)
72 | val md_theme_dark_surfaceVariant = Color(0xFF49454F)
73 | val md_theme_dark_onSurfaceVariant = Color(0xFFCAC4D0)
74 | val md_theme_dark_inverseSurface = Color(0xFFE6E1E5)
75 | val md_theme_dark_inverseOnSurface = Color(0xFF313033)
76 | val md_theme_dark_inversePrimary = Color(0xFF6750A4)
77 | val md_theme_dark_shadow = Color(0xFF000000)
78 | val md_theme_dark_surfaceTint = Color(0xFFD0BCFF)
79 | val md_theme_dark_outlineVariant = Color(0xFF49454F)
80 | val md_theme_dark_scrim = Color(0xFF000000)
81 |
82 | val seed = Color(0xFF6750A4)
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.ui.theme
17 |
18 | import android.app.Activity
19 | import android.os.Build
20 | import android.view.View
21 | import androidx.compose.foundation.isSystemInDarkTheme
22 | import androidx.compose.material3.MaterialTheme
23 | import androidx.compose.material3.darkColorScheme
24 | import androidx.compose.material3.dynamicDarkColorScheme
25 | import androidx.compose.material3.dynamicLightColorScheme
26 | import androidx.compose.material3.lightColorScheme
27 | import androidx.compose.runtime.Composable
28 | import androidx.compose.runtime.SideEffect
29 | import androidx.compose.ui.graphics.Color
30 | import androidx.compose.ui.graphics.toArgb
31 | import androidx.compose.ui.platform.LocalContext
32 | import androidx.compose.ui.platform.LocalView
33 | import androidx.core.view.WindowCompat
34 |
35 | private val LightColorScheme = lightColorScheme(
36 | primary = md_theme_light_primary,
37 | onPrimary = md_theme_light_onPrimary,
38 | primaryContainer = md_theme_light_primaryContainer,
39 | onPrimaryContainer = md_theme_light_onPrimaryContainer,
40 | secondary = md_theme_light_secondary,
41 | onSecondary = md_theme_light_onSecondary,
42 | secondaryContainer = md_theme_light_secondaryContainer,
43 | onSecondaryContainer = md_theme_light_onSecondaryContainer,
44 | tertiary = md_theme_light_tertiary,
45 | onTertiary = md_theme_light_onTertiary,
46 | tertiaryContainer = md_theme_light_tertiaryContainer,
47 | onTertiaryContainer = md_theme_light_onTertiaryContainer,
48 | error = md_theme_light_error,
49 | onError = md_theme_light_onError,
50 | errorContainer = md_theme_light_errorContainer,
51 | onErrorContainer = md_theme_light_onErrorContainer,
52 | outline = md_theme_light_outline,
53 | background = md_theme_light_background,
54 | onBackground = md_theme_light_onBackground,
55 | surface = md_theme_light_surface,
56 | onSurface = md_theme_light_onSurface,
57 | surfaceVariant = md_theme_light_surfaceVariant,
58 | onSurfaceVariant = md_theme_light_onSurfaceVariant,
59 | inverseSurface = md_theme_light_inverseSurface,
60 | inverseOnSurface = md_theme_light_inverseOnSurface,
61 | inversePrimary = md_theme_light_inversePrimary,
62 | surfaceTint = md_theme_light_surfaceTint,
63 | outlineVariant = md_theme_light_outlineVariant,
64 | scrim = md_theme_light_scrim,
65 | )
66 |
67 | private val DarkColorScheme = darkColorScheme(
68 | primary = md_theme_dark_primary,
69 | onPrimary = md_theme_dark_onPrimary,
70 | primaryContainer = md_theme_dark_primaryContainer,
71 | onPrimaryContainer = md_theme_dark_onPrimaryContainer,
72 | secondary = md_theme_dark_secondary,
73 | onSecondary = md_theme_dark_onSecondary,
74 | secondaryContainer = md_theme_dark_secondaryContainer,
75 | onSecondaryContainer = md_theme_dark_onSecondaryContainer,
76 | tertiary = md_theme_dark_tertiary,
77 | onTertiary = md_theme_dark_onTertiary,
78 | tertiaryContainer = md_theme_dark_tertiaryContainer,
79 | onTertiaryContainer = md_theme_dark_onTertiaryContainer,
80 | error = md_theme_dark_error,
81 | onError = md_theme_dark_onError,
82 | errorContainer = md_theme_dark_errorContainer,
83 | onErrorContainer = md_theme_dark_onErrorContainer,
84 | outline = md_theme_dark_outline,
85 | background = md_theme_dark_background,
86 | onBackground = md_theme_dark_onBackground,
87 | surface = md_theme_dark_surface,
88 | onSurface = md_theme_dark_onSurface,
89 | surfaceVariant = md_theme_dark_surfaceVariant,
90 | onSurfaceVariant = md_theme_dark_onSurfaceVariant,
91 | inverseSurface = md_theme_dark_inverseSurface,
92 | inverseOnSurface = md_theme_dark_inverseOnSurface,
93 | inversePrimary = md_theme_dark_inversePrimary,
94 | surfaceTint = md_theme_dark_surfaceTint,
95 | outlineVariant = md_theme_dark_outlineVariant,
96 | scrim = md_theme_dark_scrim,
97 | )
98 |
99 | @Composable
100 | fun BusScheduleTheme(
101 | darkTheme: Boolean = isSystemInDarkTheme(),
102 | // Dynamic color is available on Android 12+, turned off for training purposes
103 | dynamicColor: Boolean = false,
104 | content: @Composable () -> Unit
105 | ) {
106 | val colorScheme = when {
107 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
108 | val context = LocalContext.current
109 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
110 | }
111 |
112 | darkTheme -> DarkColorScheme
113 | else -> LightColorScheme
114 | }
115 | val view = LocalView.current
116 | if (!view.isInEditMode) {
117 | SideEffect {
118 | setUpEdgeToEdge(view, darkTheme)
119 | }
120 | }
121 |
122 | MaterialTheme(
123 | colorScheme = colorScheme,
124 | typography = Typography,
125 | content = content
126 | )
127 | }
128 |
129 | /**
130 | * Sets up edge-to-edge for the window of this [view]. The system icon colors are set to either
131 | * light or dark depending on whether the [darkTheme] is enabled or not.
132 | */
133 | private fun setUpEdgeToEdge(view: View, darkTheme: Boolean) {
134 | val window = (view.context as Activity).window
135 | WindowCompat.setDecorFitsSystemWindows(window, false)
136 | window.statusBarColor = Color.Transparent.toArgb()
137 | val navigationBarColor = when {
138 | Build.VERSION.SDK_INT >= 29 -> Color.Transparent.toArgb()
139 | Build.VERSION.SDK_INT >= 26 -> Color(0xFF, 0xFF, 0xFF, 0x63).toArgb()
140 | // Min sdk version for this app is 24, this block is for SDK versions 24 and 25
141 | else -> Color(0x00, 0x00, 0x00, 0x50).toArgb()
142 | }
143 | window.navigationBarColor = navigationBarColor
144 | val controller = WindowCompat.getInsetsController(window, view)
145 | controller.isAppearanceLightStatusBars = !darkTheme
146 | controller.isAppearanceLightNavigationBars = !darkTheme
147 | }
148 |
--------------------------------------------------------------------------------
/app/src/main/java/com/example/busschedule/ui/theme/Type.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package com.example.busschedule.ui.theme
17 |
18 | import androidx.compose.material3.Typography
19 | import androidx.compose.ui.text.TextStyle
20 | import androidx.compose.ui.text.font.FontFamily
21 | import androidx.compose.ui.text.font.FontWeight
22 | import androidx.compose.ui.unit.sp
23 |
24 | // Set of Material typography styles to start with
25 | val Typography = Typography(
26 | bodyLarge = TextStyle(
27 | fontFamily = FontFamily.Default,
28 | fontWeight = FontWeight.Normal,
29 | fontSize = 16.sp,
30 | lineHeight = 24.sp,
31 | letterSpacing = 0.5.sp
32 | )
33 | )
34 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
16 |
22 |
23 |
24 |
30 |
33 |
36 |
37 |
38 |
39 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
22 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
175 |
180 |
185 |
186 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 | 16dp
19 |
20 | 20sp
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
16 |
17 | Bus Schedule
18 | Bus Schedule
19 | Back
20 | Stop Name
21 | Stop
22 | Arrival Time
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
17 | buildscript {
18 | extra.apply {
19 | set("nav_version", "2.8.4")
20 | set("room_version", "2.6.1")
21 | }
22 | }
23 | plugins {
24 | id("com.android.application") version "8.7.3" apply false
25 | id("com.android.library") version "8.7.3" apply false
26 | id("org.jetbrains.kotlin.android") version "2.1.0" apply false
27 | id("org.jetbrains.kotlin.plugin.compose") version "2.1.0" apply false
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google-developer-training/basic-android-kotlin-compose-training-bus-schedule-app/1d6d81885438202187dc5c5109386c3b4ef238b7/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
4 | networkTimeout=10000
5 | validateDistributionUrl=true
6 | zipStoreBase=GRADLE_USER_HOME
7 | zipStorePath=wrapper/dists
8 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | #
4 | # Copyright © 2015-2021 the original authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 | # SPDX-License-Identifier: Apache-2.0
19 | #
20 |
21 | ##############################################################################
22 | #
23 | # Gradle start up script for POSIX generated by Gradle.
24 | #
25 | # Important for running:
26 | #
27 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
28 | # noncompliant, but you have some other compliant shell such as ksh or
29 | # bash, then to run this script, type that shell name before the whole
30 | # command line, like:
31 | #
32 | # ksh Gradle
33 | #
34 | # Busybox and similar reduced shells will NOT work, because this script
35 | # requires all of these POSIX shell features:
36 | # * functions;
37 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
38 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»;
39 | # * compound commands having a testable exit status, especially «case»;
40 | # * various built-in commands including «command», «set», and «ulimit».
41 | #
42 | # Important for patching:
43 | #
44 | # (2) This script targets any POSIX shell, so it avoids extensions provided
45 | # by Bash, Ksh, etc; in particular arrays are avoided.
46 | #
47 | # The "traditional" practice of packing multiple parameters into a
48 | # space-separated string is a well documented source of bugs and security
49 | # problems, so this is (mostly) avoided, by progressively accumulating
50 | # options in "$@", and eventually passing that to Java.
51 | #
52 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
53 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
54 | # see the in-line comments for details.
55 | #
56 | # There are tweaks for specific operating systems such as AIX, CygWin,
57 | # Darwin, MinGW, and NonStop.
58 | #
59 | # (3) This script is generated from the Groovy template
60 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
61 | # within the Gradle project.
62 | #
63 | # You can find Gradle at https://github.com/gradle/gradle/.
64 | #
65 | ##############################################################################
66 |
67 | # Attempt to set APP_HOME
68 |
69 | # Resolve links: $0 may be a link
70 | app_path=$0
71 |
72 | # Need this for daisy-chained symlinks.
73 | while
74 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
75 | [ -h "$app_path" ]
76 | do
77 | ls=$( ls -ld "$app_path" )
78 | link=${ls#*' -> '}
79 | case $link in #(
80 | /*) app_path=$link ;; #(
81 | *) app_path=$APP_HOME$link ;;
82 | esac
83 | done
84 |
85 | # This is normally unused
86 | # shellcheck disable=SC2034
87 | APP_BASE_NAME=${0##*/}
88 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
89 | APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
90 | ' "$PWD" ) || exit
91 |
92 | # Use the maximum available, or set MAX_FD != -1 to use that value.
93 | MAX_FD=maximum
94 |
95 | warn () {
96 | echo "$*"
97 | } >&2
98 |
99 | die () {
100 | echo
101 | echo "$*"
102 | echo
103 | exit 1
104 | } >&2
105 |
106 | # OS specific support (must be 'true' or 'false').
107 | cygwin=false
108 | msys=false
109 | darwin=false
110 | nonstop=false
111 | case "$( uname )" in #(
112 | CYGWIN* ) cygwin=true ;; #(
113 | Darwin* ) darwin=true ;; #(
114 | MSYS* | MINGW* ) msys=true ;; #(
115 | NONSTOP* ) nonstop=true ;;
116 | esac
117 |
118 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
119 |
120 |
121 | # Determine the Java command to use to start the JVM.
122 | if [ -n "$JAVA_HOME" ] ; then
123 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
124 | # IBM's JDK on AIX uses strange locations for the executables
125 | JAVACMD=$JAVA_HOME/jre/sh/java
126 | else
127 | JAVACMD=$JAVA_HOME/bin/java
128 | fi
129 | if [ ! -x "$JAVACMD" ] ; then
130 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
131 |
132 | Please set the JAVA_HOME variable in your environment to match the
133 | location of your Java installation."
134 | fi
135 | else
136 | JAVACMD=java
137 | if ! command -v java >/dev/null 2>&1
138 | then
139 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
140 |
141 | Please set the JAVA_HOME variable in your environment to match the
142 | location of your Java installation."
143 | fi
144 | fi
145 |
146 | # Increase the maximum file descriptors if we can.
147 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
148 | case $MAX_FD in #(
149 | max*)
150 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
151 | # shellcheck disable=SC2039,SC3045
152 | MAX_FD=$( ulimit -H -n ) ||
153 | warn "Could not query maximum file descriptor limit"
154 | esac
155 | case $MAX_FD in #(
156 | '' | soft) :;; #(
157 | *)
158 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
159 | # shellcheck disable=SC2039,SC3045
160 | ulimit -n "$MAX_FD" ||
161 | warn "Could not set maximum file descriptor limit to $MAX_FD"
162 | esac
163 | fi
164 |
165 | # Collect all arguments for the java command, stacking in reverse order:
166 | # * args from the command line
167 | # * the main class name
168 | # * -classpath
169 | # * -D...appname settings
170 | # * --module-path (only if needed)
171 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
172 |
173 | # For Cygwin or MSYS, switch paths to Windows format before running java
174 | if "$cygwin" || "$msys" ; then
175 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
176 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
177 |
178 | JAVACMD=$( cygpath --unix "$JAVACMD" )
179 |
180 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
181 | for arg do
182 | if
183 | case $arg in #(
184 | -*) false ;; # don't mess with options #(
185 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
186 | [ -e "$t" ] ;; #(
187 | *) false ;;
188 | esac
189 | then
190 | arg=$( cygpath --path --ignore --mixed "$arg" )
191 | fi
192 | # Roll the args list around exactly as many times as the number of
193 | # args, so each arg winds up back in the position where it started, but
194 | # possibly modified.
195 | #
196 | # NB: a `for` loop captures its iteration list before it begins, so
197 | # changing the positional parameters here affects neither the number of
198 | # iterations, nor the values presented in `arg`.
199 | shift # remove old arg
200 | set -- "$@" "$arg" # push replacement arg
201 | done
202 | fi
203 |
204 |
205 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
206 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
207 |
208 | # Collect all arguments for the java command:
209 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
210 | # and any embedded shellness will be escaped.
211 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
212 | # treated as '${Hostname}' itself on the command line.
213 |
214 | set -- \
215 | "-Dorg.gradle.appname=$APP_BASE_NAME" \
216 | -classpath "$CLASSPATH" \
217 | org.gradle.wrapper.GradleWrapperMain \
218 | "$@"
219 |
220 | # Stop when "xargs" is not available.
221 | if ! command -v xargs >/dev/null 2>&1
222 | then
223 | die "xargs is not available"
224 | fi
225 |
226 | # Use "xargs" to parse quoted args.
227 | #
228 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed.
229 | #
230 | # In Bash we could simply go:
231 | #
232 | # readarray ARGS < <( xargs -n1 <<<"$var" ) &&
233 | # set -- "${ARGS[@]}" "$@"
234 | #
235 | # but POSIX shell has neither arrays nor command substitution, so instead we
236 | # post-process each arg (as a line of input to sed) to backslash-escape any
237 | # character that might be a shell metacharacter, then use eval to reverse
238 | # that process (while maintaining the separation between arguments), and wrap
239 | # the whole thing up as a single "set" statement.
240 | #
241 | # This will of course break if any of these variables contains a newline or
242 | # an unmatched quote.
243 | #
244 |
245 | eval "set -- $(
246 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
247 | xargs -n1 |
248 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
249 | tr '\n' ' '
250 | )" '"$@"'
251 |
252 | exec "$JAVACMD" "$@"
253 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 | @rem SPDX-License-Identifier: Apache-2.0
17 | @rem
18 |
19 | @if "%DEBUG%"=="" @echo off
20 | @rem ##########################################################################
21 | @rem
22 | @rem Gradle startup script for Windows
23 | @rem
24 | @rem ##########################################################################
25 |
26 | @rem Set local scope for the variables with windows NT shell
27 | if "%OS%"=="Windows_NT" setlocal
28 |
29 | set DIRNAME=%~dp0
30 | if "%DIRNAME%"=="" set DIRNAME=.
31 | @rem This is normally unused
32 | set APP_BASE_NAME=%~n0
33 | set APP_HOME=%DIRNAME%
34 |
35 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
36 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
37 |
38 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
39 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
40 |
41 | @rem Find java.exe
42 | if defined JAVA_HOME goto findJavaFromJavaHome
43 |
44 | set JAVA_EXE=java.exe
45 | %JAVA_EXE% -version >NUL 2>&1
46 | if %ERRORLEVEL% equ 0 goto execute
47 |
48 | echo. 1>&2
49 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
50 | echo. 1>&2
51 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
52 | echo location of your Java installation. 1>&2
53 |
54 | goto fail
55 |
56 | :findJavaFromJavaHome
57 | set JAVA_HOME=%JAVA_HOME:"=%
58 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
59 |
60 | if exist "%JAVA_EXE%" goto execute
61 |
62 | echo. 1>&2
63 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
64 | echo. 1>&2
65 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2
66 | echo location of your Java installation. 1>&2
67 |
68 | goto fail
69 |
70 | :execute
71 | @rem Setup the command line
72 |
73 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
74 |
75 |
76 | @rem Execute Gradle
77 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
78 |
79 | :end
80 | @rem End local scope for the variables with windows NT shell
81 | if %ERRORLEVEL% equ 0 goto mainEnd
82 |
83 | :fail
84 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
85 | rem the _cmd.exe /c_ return code!
86 | set EXIT_CODE=%ERRORLEVEL%
87 | if %EXIT_CODE% equ 0 set EXIT_CODE=1
88 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
89 | exit /b %EXIT_CODE%
90 |
91 | :mainEnd
92 | if "%OS%"=="Windows_NT" endlocal
93 |
94 | :omega
95 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2023 The Android Open Source Project
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * https://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | pluginManagement {
17 | repositories {
18 | google()
19 | mavenCentral()
20 | gradlePluginPortal()
21 | }
22 | }
23 | dependencyResolutionManagement {
24 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
25 | repositories {
26 | google()
27 | mavenCentral()
28 | }
29 | }
30 | rootProject.name = "Bus Schedule"
31 | include(":app")
32 |
--------------------------------------------------------------------------------