From b9b8af241d3be7d0d26a04cb2ec331db28c295c8 Mon Sep 17 00:00:00 2001 From: Jake Wharton Date: Thu, 15 Mar 2018 16:54:55 -0400 Subject: Nest existing ktx projects into their target artifact. This allows for OWNERS to inherit from the parent directory without requiring duplication. Bug: 69247886 Test: ./gradlew buildOnServer Change-Id: I2dd10657202cfed1d083117ef6b9b39132b2a37f --- palette/ktx/OWNERS | 1 + palette/ktx/build.gradle | 48 ++++++++++++++++++++++ .../java/androidx/palette/graphics/PaletteTest.kt | 42 +++++++++++++++++++ palette/ktx/src/main/AndroidManifest.xml | 17 ++++++++ .../main/java/androidx/palette/graphics/Palette.kt | 36 ++++++++++++++++ 5 files changed, 144 insertions(+) create mode 100644 palette/ktx/OWNERS create mode 100644 palette/ktx/build.gradle create mode 100644 palette/ktx/src/androidTest/java/androidx/palette/graphics/PaletteTest.kt create mode 100644 palette/ktx/src/main/AndroidManifest.xml create mode 100644 palette/ktx/src/main/java/androidx/palette/graphics/Palette.kt (limited to 'palette') diff --git a/palette/ktx/OWNERS b/palette/ktx/OWNERS new file mode 100644 index 00000000000..e450f4c5cff --- /dev/null +++ b/palette/ktx/OWNERS @@ -0,0 +1 @@ +jakew@google.com diff --git a/palette/ktx/build.gradle b/palette/ktx/build.gradle new file mode 100644 index 00000000000..e5d5d4338bc --- /dev/null +++ b/palette/ktx/build.gradle @@ -0,0 +1,48 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * 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. + */ + +import static androidx.build.dependencies.DependenciesKt.* +import androidx.build.LibraryGroups +import androidx.build.LibraryVersions + +plugins { + id("SupportAndroidLibraryPlugin") + id("org.jetbrains.kotlin.android") +} + +android { + buildTypes { + debug { + testCoverageEnabled = false // Breaks Kotlin compiler. + } + } +} + +dependencies { + api(project(":palette")) + api(KOTLIN_STDLIB) + androidTestImplementation(JUNIT) + androidTestImplementation(TEST_RUNNER_TMP, libs.exclude_for_espresso) +} + +supportLibrary { + name = "Palette Kotlin Extensions" + publish = true + mavenVersion = LibraryVersions.SUPPORT_LIBRARY + mavenGroup = LibraryGroups.PALETTE + inceptionYear = "2018" + description = "Kotlin extensions for 'palette' artifact" +} diff --git a/palette/ktx/src/androidTest/java/androidx/palette/graphics/PaletteTest.kt b/palette/ktx/src/androidTest/java/androidx/palette/graphics/PaletteTest.kt new file mode 100644 index 00000000000..c10849303d4 --- /dev/null +++ b/palette/ktx/src/androidTest/java/androidx/palette/graphics/PaletteTest.kt @@ -0,0 +1,42 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * 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.palette.graphics + +import android.graphics.Bitmap +import android.graphics.Bitmap.Config.ARGB_8888 +import android.graphics.Canvas +import android.graphics.Color.RED +import androidx.palette.graphics.Target.VIBRANT +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertSame +import org.junit.Test + +class PaletteTest { + @Test fun bitmapBuild() { + val bitmap = Bitmap.createBitmap(10, 10, ARGB_8888) + // There's no easy way to test that the palette was created from our Bitmap. + assertNotNull(bitmap.buildPalette()) + } + + @Test fun operatorGet() { + val bitmap = Bitmap.createBitmap(10, 10, ARGB_8888).apply { + Canvas(this).drawColor(RED) + } + val palette = Palette.from(bitmap).generate() + assertSame(palette.getSwatchForTarget(VIBRANT), palette[VIBRANT]) + } +} diff --git a/palette/ktx/src/main/AndroidManifest.xml b/palette/ktx/src/main/AndroidManifest.xml new file mode 100644 index 00000000000..f25fda57ffb --- /dev/null +++ b/palette/ktx/src/main/AndroidManifest.xml @@ -0,0 +1,17 @@ + + + diff --git a/palette/ktx/src/main/java/androidx/palette/graphics/Palette.kt b/palette/ktx/src/main/java/androidx/palette/graphics/Palette.kt new file mode 100644 index 00000000000..58da09ae16f --- /dev/null +++ b/palette/ktx/src/main/java/androidx/palette/graphics/Palette.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2018 The Android Open Source Project + * + * 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. + */ + +@file:Suppress("NOTHING_TO_INLINE") // Aliases to public API. + +package androidx.palette.graphics + +import android.graphics.Bitmap + +/** + * Create a [Palette.Builder] from this bitmap. + * + * @see Palette.from + */ +inline fun Bitmap.buildPalette() = Palette.Builder(this) + +/** + * Returns the selected swatch for the given target from the palette, or `null` if one + * could not be found. + * + * @see Palette.getSwatchForTarget + */ +inline operator fun Palette.get(target: Target): Palette.Swatch? = getSwatchForTarget(target) -- cgit v1.2.3