aboutsummaryrefslogtreecommitdiff
path: root/palette
diff options
context:
space:
mode:
authorJake Wharton <jakew@google.com>2018-03-15 16:54:55 -0400
committerJake Wharton <jakew@google.com>2018-03-21 11:04:38 -0400
commitb9b8af241d3be7d0d26a04cb2ec331db28c295c8 (patch)
tree5a22687b6ddab6a5565dd430d120205043a57505 /palette
parentac87449fd926c959d786f2b3df13d2c1e6516695 (diff)
downloadsupport-b9b8af241d3be7d0d26a04cb2ec331db28c295c8.tar.gz
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
Diffstat (limited to 'palette')
-rw-r--r--palette/ktx/OWNERS1
-rw-r--r--palette/ktx/build.gradle48
-rw-r--r--palette/ktx/src/androidTest/java/androidx/palette/graphics/PaletteTest.kt42
-rw-r--r--palette/ktx/src/main/AndroidManifest.xml17
-rw-r--r--palette/ktx/src/main/java/androidx/palette/graphics/Palette.kt36
5 files changed, 144 insertions, 0 deletions
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+<manifest package="androidx.palette.ktx"/>
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)