-
Notifications
You must be signed in to change notification settings - Fork 8
Create first sample for WSC L and XL #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tiwiz
wants to merge
5
commits into
main
Choose a base branch
from
wsclxl
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
67e77a6
Create first sample for WSC L and XL
tiwiz 45378ed
Merge remote-tracking branch 'origin/main' into wsclxl
tiwiz 2792dd8
Update WindowSizeClassSample/app/src/main/java/com/google/sample/wsc/…
tiwiz b0c923c
Update code based on Gemini's suggestions
tiwiz 78a86e4
Update code based on Gemini's suggestions
tiwiz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,17 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties | ||
/.idea/ | ||
/.kotlin/ |
This file contains hidden or 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 hidden or 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,60 @@ | ||
plugins { | ||
alias(libs.plugins.android.application) | ||
alias(libs.plugins.kotlin.android) | ||
alias(libs.plugins.kotlin.compose) | ||
} | ||
|
||
android { | ||
namespace = "com.google.sample.wsc.lxl" | ||
compileSdk = 36 | ||
|
||
defaultConfig { | ||
applicationId = "com.google.sample.wsc.lxl" | ||
minSdk = 24 | ||
targetSdk = 36 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_21 | ||
targetCompatibility = JavaVersion.VERSION_21 | ||
} | ||
buildFeatures { | ||
compose = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.androidx.core.ktx) | ||
implementation(libs.androidx.lifecycle.runtime.ktx) | ||
implementation(libs.androidx.activity.compose) | ||
implementation(platform(libs.androidx.compose.bom)) | ||
implementation(libs.androidx.ui) | ||
implementation(libs.androidx.ui.graphics) | ||
implementation(libs.androidx.ui.tooling.preview) | ||
implementation(libs.androidx.material3) | ||
implementation(libs.androidx.material3.adaptive) | ||
implementation(libs.androidx.material3.wsc) | ||
implementation(libs.androidx.window) | ||
implementation(libs.androidx.window.core) | ||
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
debugImplementation(libs.androidx.ui.tooling) | ||
debugImplementation(libs.androidx.ui.test.manifest) | ||
} |
This file contains hidden or 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 |
24 changes: 24 additions & 0 deletions
24
...ClassSample/app/src/androidTest/java/com/google/sample/wsc/lxl/ExampleInstrumentedTest.kt
This file contains hidden or 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,24 @@ | ||
package com.google.sample.wsc.lxl | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.google.sample.wsc.lxl", appContext.packageName) | ||
} | ||
} |
This file contains hidden or 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,23 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.WindowSizeClassSample"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true" | ||
android:theme="@style/Theme.WindowSizeClassSample"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
28 changes: 28 additions & 0 deletions
28
WindowSizeClassSample/app/src/main/java/com/google/sample/wsc/lxl/MainActivity.kt
This file contains hidden or 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,28 @@ | ||
package com.google.sample.wsc.lxl | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.compose.setContent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material3.Scaffold | ||
import androidx.compose.ui.Modifier | ||
import com.google.sample.wsc.lxl.ui.Content | ||
import com.google.sample.wsc.lxl.ui.theme.WindowSizeClassSampleTheme | ||
|
||
class MainActivity : ComponentActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
setContent { | ||
WindowSizeClassSampleTheme { | ||
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> | ||
Content( | ||
modifier = Modifier.padding(innerPadding) | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
197 changes: 197 additions & 0 deletions
197
WindowSizeClassSample/app/src/main/java/com/google/sample/wsc/lxl/ui/Content.kt
This file contains hidden or 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,197 @@ | ||
package com.google.sample.wsc.lxl.ui | ||
|
||
import androidx.activity.compose.LocalActivity | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.RowScope | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.GridItemSpan | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi | ||
import androidx.compose.material3.HorizontalDivider | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.tooling.preview.PreviewScreenSizes | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import com.google.sample.wsc.lxl.utils.Height | ||
import com.google.sample.wsc.lxl.utils.Width | ||
import com.google.sample.wsc.lxl.utils.calculateColumns | ||
import com.google.sample.wsc.lxl.utils.calculateColumnsForTitles | ||
import com.google.sample.wsc.lxl.utils.material | ||
import com.google.sample.wsc.lxl.utils.windowManager | ||
|
||
@PreviewScreenSizes | ||
@Composable | ||
fun Content(modifier: Modifier = Modifier) { | ||
|
||
val wm = LocalActivity.current!!.windowManager() | ||
val material = material() | ||
val numberOfColumns = calculateColumns(wm.first) | ||
val numberOfColumnsForTitles = calculateColumnsForTitles(wm.first) | ||
|
||
LazyVerticalGrid( | ||
columns = GridCells.Fixed(numberOfColumns), modifier = modifier.fillMaxSize() | ||
) { | ||
item(span = { GridItemSpan(numberOfColumnsForTitles) }) { | ||
Title() | ||
} | ||
item(span = { GridItemSpan(numberOfColumnsForTitles) }) { | ||
Subtitle("WindowManager") | ||
} | ||
item { | ||
WidthComposable(width = wm.first) | ||
} | ||
item { | ||
HeightComposable(height = wm.second) | ||
} | ||
|
||
if (numberOfColumns < 3) { | ||
item(span = { GridItemSpan(numberOfColumnsForTitles) }) { | ||
HorizontalDivider( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(vertical = 8.dp, horizontal = 24.dp), | ||
thickness = 4.dp, | ||
color = MaterialTheme.colorScheme.onPrimaryFixedVariant | ||
) | ||
} | ||
} | ||
|
||
item(span = { GridItemSpan(numberOfColumnsForTitles) }) { | ||
Subtitle("Material") | ||
} | ||
item { | ||
WidthComposable(material.first) | ||
} | ||
item { | ||
HeightComposable(material.second) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
private fun Title() { | ||
Text( | ||
text = "WindowSizeClass Sample", | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(color = MaterialTheme.colorScheme.inverseOnSurface) | ||
.padding(vertical = 16.dp), | ||
style = MaterialTheme.typography.headlineLarge, | ||
textAlign = TextAlign.Center | ||
) | ||
} | ||
|
||
@Composable | ||
private fun Subtitle(text: String) { | ||
Text( | ||
text = text, | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.background(color = MaterialTheme.colorScheme.onPrimaryContainer) | ||
.padding(vertical = 16.dp), | ||
color = MaterialTheme.colorScheme.onPrimary, | ||
style = MaterialTheme.typography.headlineSmall, | ||
textAlign = TextAlign.Center | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalMaterial3ExpressiveApi::class) | ||
@Composable | ||
private fun WidthComposable(width: Width) { | ||
Column { | ||
DimensionTitle(title = "Width") | ||
Row( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(top = 4.dp), | ||
horizontalArrangement = Arrangement.SpaceEvenly | ||
) { | ||
for (w in Width.entries) { | ||
Indicator(label = w.label, isSelected = w == width) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@OptIn(ExperimentalMaterial3ExpressiveApi::class) | ||
private fun DimensionTitle(title: String) { | ||
Text( | ||
text = title, modifier = Modifier | ||
.fillMaxSize() | ||
.background(color = MaterialTheme.colorScheme.tertiaryContainer) | ||
.padding(vertical = 8.dp), | ||
color = MaterialTheme.colorScheme.onTertiaryContainer, | ||
style = MaterialTheme.typography.bodyMediumEmphasized, | ||
textAlign = TextAlign.Center | ||
) | ||
} | ||
|
||
@Composable | ||
private fun RowScope.Indicator(label: String, isSelected: Boolean) { | ||
val backgroundColor = if (isSelected) { | ||
MaterialTheme.colorScheme.primaryContainer | ||
} else { | ||
MaterialTheme.colorScheme.secondaryContainer | ||
} | ||
val borderWidth = if (isSelected) { | ||
2.dp | ||
} else { | ||
0.dp | ||
} | ||
val textColor = if (isSelected) { | ||
MaterialTheme.colorScheme.onPrimaryContainer | ||
} else { | ||
MaterialTheme.colorScheme.onSecondaryContainer | ||
} | ||
Box( | ||
modifier = Modifier | ||
.padding(horizontal = 2.dp) | ||
.weight(1f) | ||
.height(200.dp) | ||
.background(color = backgroundColor, shape = MaterialTheme.shapes.medium) | ||
.border( | ||
width = borderWidth, | ||
color = MaterialTheme.colorScheme.onPrimaryContainer, | ||
shape = MaterialTheme.shapes.medium | ||
), | ||
contentAlignment = Alignment.BottomCenter | ||
) { | ||
Text( | ||
text = label, | ||
color = textColor, | ||
modifier = Modifier.padding(all = 4.dp), | ||
fontSize = 12.sp | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun HeightComposable(height: Height) { | ||
Column { | ||
DimensionTitle(title = "Height") | ||
Row( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(top = 4.dp), | ||
horizontalArrangement = Arrangement.SpaceEvenly | ||
) { | ||
for (h in Height.entries) { | ||
Indicator(label = h.label, isSelected = h == height) | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
WindowSizeClassSample/app/src/main/java/com/google/sample/wsc/lxl/ui/theme/Color.kt
This file contains hidden or 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,11 @@ | ||
package com.google.sample.wsc.lxl.ui.theme | ||
|
||
import androidx.compose.ui.graphics.Color | ||
|
||
val Purple80 = Color(0xFFD0BCFF) | ||
val PurpleGrey80 = Color(0xFFCCC2DC) | ||
val Pink80 = Color(0xFFEFB8C8) | ||
|
||
val Purple40 = Color(0xFF6650a4) | ||
val PurpleGrey40 = Color(0xFF625b71) | ||
val Pink40 = Color(0xFF7D5260) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.