Skip to content

Commit 0655c15

Browse files
authored
Add spotless (#23)
* Add spotless * Using init script. * Add spotless * Remove editorconfig.
1 parent 85ab926 commit 0655c15

File tree

22 files changed

+740
-437
lines changed

22 files changed

+740
-437
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,8 @@ jobs:
4040
with:
4141
java-version: 11
4242

43+
- name: Check formatting
44+
run: ./gradlew :compose:spotlessCheck --init-script gradle/init.gradle.kts --no-configuration-cache --stacktrace
45+
4346
- name: Build Compose
4447
run: ./gradlew :compose:build

compose/recomposehighlighter/src/main/java/com/example/android/compose/recomposehighlighter/MainActivity.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
/*
2-
* Copyright 2022 Google Inc.
2+
* Copyright 2022 The Android Open Source Project
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5-
* except in compliance with the License. You may obtain a copy of the License at
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
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the
10-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11-
* KIND, either express or implied. See the License for the specific language governing
12-
* permissions and limitations under the License.
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.
1315
*/
1416

1517
package com.example.android.compose.recomposehighlighter
1618

17-
import android.content.Context
1819
import android.os.Bundle
1920
import androidx.activity.ComponentActivity
2021
import androidx.activity.compose.setContent
@@ -46,7 +47,8 @@ private fun Content() {
4647
Column(
4748
Modifier
4849
.fillMaxSize()
49-
.padding(16.dp)) {
50+
.padding(16.dp)
51+
) {
5052
Button(
5153
onClick = { counter++ },
5254
Modifier.padding(bottom = 12.dp)

compose/recomposehighlighter/src/main/java/com/example/android/compose/recomposehighlighter/RecomposeHighlighter.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/*
2-
* Copyright 2022 Google Inc.
2+
* Copyright 2022 The Android Open Source Project
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5-
* except in compliance with the License. You may obtain a copy of the License at
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
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the
10-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11-
* KIND, either express or implied. See the License for the specific language governing
12-
* permissions and limitations under the License.
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.
1315
*/
1416

1517
package com.example.android.compose.recomposehighlighter
@@ -78,7 +80,7 @@ private val recomposeModifier =
7880

7981
val (color, strokeWidthPx) =
8082
when (numCompositionsSinceTimeout) {
81-
// We need at least one composition to draw, so draw the smallest border
83+
// We need at least one composition to draw, so draw the smallest border
8284
// color in blue.
8385
1L -> Color.Blue to 1f
8486
// 2 compositions is _probably_ okay.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2022 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+
117
package com.example.compose.snippets.interop
218

319
import androidx.compose.ui.test.assertIsDisplayed
@@ -11,16 +27,16 @@ import org.junit.Test
1127

1228
// [START android_compose_interop_add_compose_test_mixed]
1329
class MyActivityTest {
14-
@Rule
15-
@JvmField
16-
val composeTestRule = createAndroidComposeRule<MyActivity>()
30+
@Rule
31+
@JvmField
32+
val composeTestRule = createAndroidComposeRule<MyActivity>()
1733

18-
@Test
19-
fun testGreeting() {
20-
val greeting = InstrumentationRegistry.getInstrumentation()
21-
.targetContext.resources.getString(R.string.greeting)
34+
@Test
35+
fun testGreeting() {
36+
val greeting = InstrumentationRegistry.getInstrumentation()
37+
.targetContext.resources.getString(R.string.greeting)
2238

23-
composeTestRule.onNodeWithText(greeting).assertIsDisplayed()
24-
}
39+
composeTestRule.onNodeWithText(greeting).assertIsDisplayed()
40+
}
2541
}
2642
// [END android_compose_interop_add_compose_test_mixed]
Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2022 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+
117
package com.example.compose.snippets
218

319
import android.os.Bundle
@@ -7,10 +23,10 @@ import androidx.compose.material3.Text
723
import androidx.compose.ui.res.stringResource
824

925
class MyActivity : ComponentActivity() {
10-
override fun onCreate(savedInstanceState: Bundle?) {
11-
super.onCreate(savedInstanceState)
12-
setContent {
13-
Text(text = stringResource(id = R.string.greeting))
26+
override fun onCreate(savedInstanceState: Bundle?) {
27+
super.onCreate(savedInstanceState)
28+
setContent {
29+
Text(text = stringResource(id = R.string.greeting))
30+
}
1431
}
15-
}
16-
}
32+
}
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/*
2-
* Copyright 2022 Google LLC
2+
* Copyright 2022 The Android Open Source Project
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5-
* except in compliance with the License. You may obtain a copy of the License at
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
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the
10-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11-
* KIND, either express or implied. See the License for the specific language governing
12-
* permissions and limitations under the License.
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.
1315
*/
16+
1417
package com.example.compose.snippets
1518

1619
import android.os.Bundle
1720
import androidx.activity.ComponentActivity
1821
import androidx.activity.compose.setContent
1922
import androidx.compose.foundation.layout.Column
2023
import androidx.compose.foundation.layout.fillMaxSize
21-
import androidx.compose.foundation.rememberScrollState
22-
import androidx.compose.foundation.verticalScroll
2324
import androidx.compose.material3.MaterialTheme
2425
import androidx.compose.material3.Surface
2526
import androidx.compose.ui.Modifier
26-
import com.example.compose.snippets.graphics.BrushExamplesScreen
2727
import com.example.compose.snippets.images.ImageExamplesScreen
2828
import com.example.compose.snippets.ui.theme.SnippetsTheme
2929

@@ -38,13 +38,15 @@ class SnippetsActivity : ComponentActivity() {
3838
color = MaterialTheme.colorScheme.background
3939
) {
4040
// TODO - We should put these in different navigation destinations
41-
Column(modifier = Modifier
42-
.fillMaxSize()) {
43-
// BrushExamplesScreen()
41+
Column(
42+
modifier = Modifier
43+
.fillMaxSize()
44+
) {
45+
// BrushExamplesScreen()
4446
ImageExamplesScreen()
4547
}
4648
}
4749
}
4850
}
4951
}
50-
}
52+
}

compose/snippets/src/main/java/com/example/compose/snippets/graphics/BrushExampleSnippets.kt

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
/*
2-
* Copyright 2022 Google LLC
2+
* Copyright 2022 The Android Open Source Project
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
5-
* except in compliance with the License. You may obtain a copy of the License at
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
67
*
7-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* https://www.apache.org/licenses/LICENSE-2.0
89
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the
10-
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11-
* KIND, either express or implied. See the License for the specific language governing
12-
* permissions and limitations under the License.
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.
1315
*/
16+
1417
package com.example.compose.snippets.graphics
1518

1619
import android.graphics.RuntimeShader
@@ -91,7 +94,6 @@ fun BrushExamplesScreen() {
9194
}
9295
}
9396

94-
9597
@Preview
9698
@Composable
9799
fun GraphicsBrushCanvasUsage() {
@@ -160,7 +162,6 @@ fun GraphicsBrushSize() {
160162
tileMode = TileMode.Mirror
161163
)
162164
}
163-
164165
}
165166
}
166167
Box(
@@ -201,7 +202,6 @@ fun GraphicsBrushSizeRadialGradientAfter() {
201202
colorStops = listOf(0f, 0.95f)
202203
)
203204
}
204-
205205
}
206206

207207
Box(
@@ -228,14 +228,14 @@ fun GraphicsBrushSizeRecreationExample() {
228228
.drawBehind {
229229
drawRect(brush = brush) // will allocate a shader to occupy the 200 x 200 dp drawing area
230230
inset(10f) {
231-
/* Will allocate a shader to occupy the 180 x 180 dp drawing area as the
232-
inset scope reduces the drawing area by 10 pixels on the left, top, right,
233-
bottom sides */
231+
/* Will allocate a shader to occupy the 180 x 180 dp drawing area as the
232+
inset scope reduces the drawing area by 10 pixels on the left, top, right,
233+
bottom sides */
234234
drawRect(brush = brush)
235235
inset(5f) {
236-
/* will allocate a shader to occupy the 170 x 170 dp drawing area as the
237-
inset scope reduces the drawing area by 5 pixels on the left, top,
238-
right, bottom sides */
236+
/* will allocate a shader to occupy the 170 x 170 dp drawing area as the
237+
inset scope reduces the drawing area by 5 pixels on the left, top,
238+
right, bottom sides */
239239
drawRect(brush = brush)
240240
}
241241
}
@@ -249,7 +249,8 @@ fun GraphicsBrushSizeRecreationExample() {
249249
@Composable
250250
fun GraphicsImageBrush() {
251251
// [START android_compose_graphics_brush_image]
252-
val imageBrush = ShaderBrush(ImageShader(ImageBitmap.imageResource(id = R.drawable.dog)))
252+
val imageBrush =
253+
ShaderBrush(ImageShader(ImageBitmap.imageResource(id = R.drawable.dog)))
253254

254255
// Use ImageShader Brush with background
255256
Box(
@@ -262,7 +263,17 @@ fun GraphicsImageBrush() {
262263
Text(
263264
text = "Hello Android!",
264265
style = TextStyle(
265-
brush = imageBrush,
266+
brush = imageBrush,
267+
fontWeight = FontWeight.ExtraBold,
268+
fontSize = 36.sp
269+
)
270+
)
271+
272+
// Use ImageShader Brush with TextStyle
273+
Text(
274+
text = "Hello Android!",
275+
style = TextStyle(
276+
brush = imageBrush,
266277
fontWeight = FontWeight.ExtraBold,
267278
fontSize = 36.sp
268279
)
@@ -299,28 +310,36 @@ val LightYellow = Color(0xFFF8EE94)
299310
@Composable
300311
@Preview
301312
fun ShaderBrushExample() {
302-
Box(modifier = Modifier
303-
.drawWithCache {
304-
val shader = RuntimeShader(CUSTOM_SHADER)
305-
val shaderBrush = ShaderBrush(shader)
306-
shader.setFloatUniform("resolution", size.width, size.height)
307-
onDrawBehind {
308-
shader.setColorUniform(
309-
"color",
310-
android.graphics.Color.valueOf(
311-
LightYellow.red, LightYellow.green, LightYellow
312-
.blue, LightYellow.alpha
313+
Box(
314+
modifier = Modifier
315+
.drawWithCache {
316+
val shader = RuntimeShader(CUSTOM_SHADER)
317+
val shaderBrush = ShaderBrush(shader)
318+
shader.setFloatUniform("resolution", size.width, size.height)
319+
onDrawBehind {
320+
shader.setColorUniform(
321+
"color",
322+
android.graphics.Color.valueOf(
323+
LightYellow.red, LightYellow.green,
324+
LightYellow
325+
.blue,
326+
LightYellow.alpha
327+
)
313328
)
314-
)
315-
shader.setColorUniform(
316-
"color2",
317-
android.graphics.Color.valueOf(Coral.red, Coral.green, Coral.blue, Coral.alpha)
318-
)
319-
drawRect(shaderBrush)
329+
shader.setColorUniform(
330+
"color2",
331+
android.graphics.Color.valueOf(
332+
Coral.red,
333+
Coral.green,
334+
Coral.blue,
335+
Coral.alpha
336+
)
337+
)
338+
drawRect(shaderBrush)
339+
}
320340
}
321-
}
322-
.fillMaxWidth()
323-
.height(200.dp)
341+
.fillMaxWidth()
342+
.height(200.dp)
324343
)
325344
}
326345
// [END android_compose_brush_custom_shader_usage]

0 commit comments

Comments
 (0)