forked from android/compose-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change-Id: I3a88e591b739487ed19b237b6897f998485df5a2
- Loading branch information
Manuel Vivo
committed
Jun 15, 2020
1 parent
0fbf067
commit 0ac9f7f
Showing
72 changed files
with
3,976 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
/studio/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Steps to run this sample in go/compose-samples-howto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
apply plugin: 'com.android.application' | ||
apply plugin: 'kotlin-android' | ||
|
||
// Reads the Google maps key that is used in the AndroidManifest | ||
Properties properties = new Properties() | ||
properties.load(project.rootProject.file("local.properties").newDataInputStream()) | ||
|
||
android { | ||
compileSdkVersion 29 | ||
defaultConfig { | ||
applicationId "androidx.compose.samples.crane" | ||
minSdkVersion 21 | ||
targetSdkVersion 29 | ||
versionCode 1 | ||
versionName "1.0" | ||
vectorDrawables.useSupportLibrary = true | ||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" | ||
|
||
manifestPlaceholders = [ googleMapsKey : properties.getProperty("google.maps.key", "") ] | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility JavaVersion.VERSION_1_8 | ||
targetCompatibility JavaVersion.VERSION_1_8 | ||
} | ||
|
||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
|
||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerVersion "1.3.70-dev-withExperimentalGoogleExtensions-20200424" | ||
kotlinCompilerExtensionVersion "0.1.0-SNAPSHOT" | ||
} | ||
} | ||
|
||
configurations { | ||
ktlint | ||
} | ||
|
||
dependencies { | ||
// Actual dependencies of the application | ||
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.61' | ||
implementation 'com.google.android.gms:play-services-maps:17.0.0' | ||
|
||
def composeVersion = "0.1.0-SNAPSHOT" | ||
implementation ("androidx.compose:compose-runtime:$composeVersion") | ||
implementation ("androidx.ui:ui-core:$composeVersion") | ||
implementation ("androidx.ui:ui-foundation:$composeVersion") | ||
implementation ("androidx.ui:ui-layout:$composeVersion") | ||
implementation ("androidx.ui:ui-material:$composeVersion") | ||
implementation ("androidx.ui:ui-android-view:$composeVersion") | ||
implementation ("androidx.ui:ui-tooling:$composeVersion") | ||
implementation ("androidx.ui:ui-android-view:$composeVersion") | ||
|
||
implementation ('androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0') | ||
implementation ('androidx.appcompat:appcompat:1.1.0') | ||
implementation ('androidx.activity:activity-ktx:1.1.0') | ||
implementation ('androidx.lifecycle:lifecycle-extensions:2.2.0') | ||
|
||
implementation ('com.squareup.picasso:picasso:2.71828') | ||
|
||
ktlint "com.pinterest:ktlint:0.36.0" | ||
} | ||
|
||
task ktlint(type: JavaExec, group: "verification") { | ||
description = "Check Kotlin code style." | ||
main = "com.pinterest.ktlint.Main" | ||
classpath = configurations.ktlint | ||
// Ignoring paren-spacing as it flags a composable type param as an error | ||
args "-F", "src/**/*.kt", "--disabled_rules", "paren-spacing" | ||
} | ||
|
||
check.dependsOn ktlint | ||
|
||
task ktlintFormat(type: JavaExec, group: "formatting") { | ||
description = "Fix Kotlin code style deviations." | ||
main = "com.pinterest.ktlint.Main" | ||
classpath = configurations.ktlint | ||
// Ignoring paren-spacing as it flags a composable type param as an error | ||
args "-F", "src/**/*.kt", "--disabled_rules", "paren-spacing" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2019 Google LLC | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
~ | ||
--> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="androidx.compose.samples.crane"> | ||
|
||
<uses-permission android:name="android.permission.INTERNET" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
|
||
<meta-data android:name="com.google.android.geo.API_KEY" | ||
android:value="${googleMapsKey}"/> | ||
|
||
<activity android:name=".home.MainActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
<activity android:name=".details.DetailsActivity" /> | ||
<activity android:name=".calendar.CalendarActivity" /> | ||
</application> | ||
|
||
</manifest> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions
151
Crane/app/src/main/java/androidx/compose/samples/crane/base/BaseUserInput.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/* | ||
* Copyright 2019 Google, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package androidx.compose.samples.crane.base | ||
|
||
import androidx.annotation.DrawableRes | ||
import androidx.compose.Composable | ||
import androidx.compose.getValue | ||
import androidx.compose.mutableStateOf | ||
import androidx.compose.samples.crane.R | ||
import androidx.compose.samples.crane.ui.captionTextStyle | ||
import androidx.compose.setValue | ||
import androidx.ui.core.Alignment | ||
import androidx.ui.core.Modifier | ||
import androidx.ui.foundation.Icon | ||
import androidx.ui.foundation.Text | ||
import androidx.ui.foundation.TextField | ||
import androidx.ui.foundation.TextFieldValue | ||
import androidx.ui.foundation.contentColor | ||
import androidx.ui.graphics.Color | ||
import androidx.ui.layout.Row | ||
import androidx.ui.layout.Spacer | ||
import androidx.ui.layout.padding | ||
import androidx.ui.layout.preferredSize | ||
import androidx.ui.layout.preferredWidth | ||
import androidx.ui.material.MaterialTheme | ||
import androidx.ui.material.Surface | ||
import androidx.ui.res.vectorResource | ||
import androidx.ui.tooling.preview.Preview | ||
import androidx.ui.unit.dp | ||
|
||
@Composable | ||
fun SimpleUserInput( | ||
text: String? = null, | ||
caption: String? = null, | ||
@DrawableRes vectorImageId: Int? = null | ||
) { | ||
CraneUserInput( | ||
caption = if (text == null) caption else null, | ||
text = text ?: "", | ||
vectorImageId = vectorImageId | ||
) | ||
} | ||
|
||
@Composable | ||
fun CraneUserInput( | ||
modifier: Modifier = Modifier, | ||
text: String, | ||
caption: String? = null, | ||
@DrawableRes vectorImageId: Int? = null, | ||
tint: Color = contentColor() | ||
) { | ||
CraneBaseUserInput( | ||
modifier = modifier, | ||
caption = caption, | ||
vectorImageId = vectorImageId, | ||
tintIcon = { text.isNotEmpty() }, | ||
tint = tint | ||
) { | ||
Text(text = text, style = MaterialTheme.typography.body1.copy(color = tint)) | ||
} | ||
} | ||
|
||
@Composable | ||
fun CraneEditableUserInput( | ||
hint: String, | ||
caption: String? = null, | ||
@DrawableRes vectorImageId: Int? = null, | ||
onInputChanged: (String) -> Unit | ||
) { | ||
var textFieldState by mutableStateOf(TextFieldValue(text = hint)) | ||
val isHint = { textFieldState.text == hint } | ||
|
||
CraneBaseUserInput( | ||
caption = caption, | ||
tintIcon = { !isHint() }, | ||
showCaption = { !isHint() }, | ||
vectorImageId = vectorImageId | ||
) { | ||
TextField( | ||
value = textFieldState, | ||
onValueChange = { | ||
textFieldState = it | ||
if (!isHint()) onInputChanged(textFieldState.text) | ||
}, | ||
textStyle = if (isHint()) captionTextStyle else MaterialTheme.typography.body1 | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun CraneBaseUserInput( | ||
modifier: Modifier = Modifier, | ||
caption: String? = null, | ||
@DrawableRes vectorImageId: Int? = null, | ||
showCaption: () -> Boolean = { true }, | ||
tintIcon: () -> Boolean, | ||
tint: Color = MaterialTheme.colors.onSurface, | ||
children: @Composable () -> Unit | ||
) { | ||
Surface(modifier = modifier, color = MaterialTheme.colors.primaryVariant) { | ||
Row(Modifier.padding(all = 12.dp)) { | ||
if (vectorImageId != null) { | ||
Icon( | ||
modifier = Modifier.preferredSize(24.dp, 24.dp), | ||
asset = vectorResource(id = vectorImageId), | ||
tint = if (tintIcon()) tint else Color(0x80FFFFFF) | ||
) | ||
Spacer(Modifier.preferredWidth(8.dp)) | ||
} | ||
if (caption != null && showCaption()) { | ||
Text( | ||
modifier = Modifier.gravity(Alignment.CenterVertically), | ||
text = caption, | ||
style = (captionTextStyle).copy(color = tint) | ||
) | ||
Spacer(Modifier.preferredWidth(8.dp)) | ||
} | ||
Row(Modifier.weight(1f).gravity(Alignment.CenterVertically)) { | ||
children() | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun previewInput() { | ||
CraneScaffold { | ||
CraneBaseUserInput( | ||
tintIcon = { true }, | ||
vectorImageId = R.drawable.ic_plane, | ||
caption = "Caption", | ||
showCaption = { true }) { | ||
Text(text = "text", style = MaterialTheme.typography.body1) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Crane/app/src/main/java/androidx/compose/samples/crane/base/CraneDrawer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package androidx.compose.samples.crane.base | ||
|
||
import androidx.compose.Composable | ||
import androidx.compose.samples.crane.R | ||
import androidx.compose.samples.crane.ui.CraneTheme | ||
import androidx.ui.core.Modifier | ||
import androidx.ui.foundation.Image | ||
import androidx.ui.foundation.Text | ||
import androidx.ui.layout.Column | ||
import androidx.ui.layout.Spacer | ||
import androidx.ui.layout.fillMaxSize | ||
import androidx.ui.layout.padding | ||
import androidx.ui.layout.preferredHeight | ||
import androidx.ui.material.MaterialTheme | ||
import androidx.ui.res.vectorResource | ||
import androidx.ui.tooling.preview.Preview | ||
import androidx.ui.unit.dp | ||
|
||
private val screens = listOf("Find Trips", "My Trips", "Saved Trips", "Price Alerts", "My Account") | ||
|
||
@Composable | ||
fun CraneDrawer(modifier: Modifier = Modifier) { | ||
Column(modifier.fillMaxSize().padding(start = 24.dp, top = 48.dp)) { | ||
Image(asset = vectorResource(id = R.drawable.ic_crane_drawer)) | ||
for (screen in screens) { | ||
Spacer(Modifier.preferredHeight(24.dp)) | ||
Text(text = screen, style = MaterialTheme.typography.h4) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun CraneDrawerPreview() { | ||
CraneTheme { | ||
CraneDrawer() | ||
} | ||
} |
Oops, something went wrong.