diff --git a/README.md b/README.md
index 63f9892..a9da7b0 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,18 @@ new ChromaDialog.Builder()
.show(getSupportFragmentManager(), "ChromaDialog");
```
+Don't want a dialog? Use `ChromaView` directly:
+```
+
+
+ChromaView chromaView = ...;
+chromaView.getCurrentColor();
+```
+
Check out the [sample project](chroma-sample) for more details.
License
diff --git a/chroma/src/main/kotlin/me/priyesh/chroma/ChromaDialog.kt b/chroma/src/main/kotlin/me/priyesh/chroma/ChromaDialog.kt
index bf0c9f0..b9e3400 100644
--- a/chroma/src/main/kotlin/me/priyesh/chroma/ChromaDialog.kt
+++ b/chroma/src/main/kotlin/me/priyesh/chroma/ChromaDialog.kt
@@ -23,10 +23,9 @@ import android.os.Bundle
import android.support.annotation.ColorInt
import android.support.v4.app.DialogFragment
import android.view.WindowManager
-import me.priyesh.chroma.internal.ChromaView
import kotlin.properties.Delegates
-class ChromaDialog constructor() : DialogFragment() {
+class ChromaDialog : DialogFragment() {
companion object {
private val ArgInitialColor = "arg_initial_color"
@@ -76,20 +75,20 @@ class ChromaDialog constructor() : DialogFragment() {
}
private var listener: ColorSelectListener? = null
- private var chromaView: ChromaView by Delegates.notNull()
+ private var chromaView: ChromaView by Delegates.notNull()
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
chromaView = if (savedInstanceState == null) {
- ChromaView(
- arguments.getInt(ArgInitialColor),
- ColorMode.fromName(arguments.getString(ArgColorModeName)),
- context)
+ ChromaView(
+ arguments!!.getInt(ArgInitialColor),
+ ColorMode.fromName(arguments!!.getString(ArgColorModeName)),
+ context!!)
} else {
- ChromaView(
- savedInstanceState.getInt(ArgInitialColor, ChromaView.DefaultColor),
- ColorMode.fromName(savedInstanceState.getString(ArgColorModeName)),
- context
- )
+ ChromaView(
+ savedInstanceState.getInt(ArgInitialColor, ChromaView.DefaultColor),
+ ColorMode.fromName(savedInstanceState.getString(ArgColorModeName)),
+ context!!
+ )
}
chromaView.enableButtonBar(object : ChromaView.ButtonBarListener {
@@ -115,8 +114,8 @@ class ChromaDialog constructor() : DialogFragment() {
}
}
- override fun onSaveInstanceState(outState: Bundle?) {
- outState?.putAll(makeArgs(chromaView.currentColor, chromaView.colorMode))
+ override fun onSaveInstanceState(outState: Bundle) {
+ outState.putAll(makeArgs(chromaView.currentColor, chromaView.colorMode))
super.onSaveInstanceState(outState)
}
diff --git a/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChromaView.kt b/chroma/src/main/kotlin/me/priyesh/chroma/ChromaView.kt
similarity index 80%
rename from chroma/src/main/kotlin/me/priyesh/chroma/internal/ChromaView.kt
rename to chroma/src/main/kotlin/me/priyesh/chroma/ChromaView.kt
index 710f05e..7c2a58a 100644
--- a/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChromaView.kt
+++ b/chroma/src/main/kotlin/me/priyesh/chroma/ChromaView.kt
@@ -14,19 +14,18 @@
* limitations under the License.
*/
-package me.priyesh.chroma.internal
+package me.priyesh.chroma
import android.content.Context
import android.graphics.Color
import android.support.annotation.ColorInt
-import android.util.AttributeSet
+import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.RelativeLayout
-import me.priyesh.chroma.ColorMode
-import me.priyesh.chroma.R
+import me.priyesh.chroma.internal.ChannelView
-internal class ChromaView : RelativeLayout {
+class ChromaView : RelativeLayout {
companion object {
val DefaultColor = Color.GRAY
@@ -45,11 +44,11 @@ internal class ChromaView : RelativeLayout {
init()
}
- private fun init(): Unit {
+ private fun init() {
inflate(context, R.layout.chroma_view, this)
clipToPadding = false
- val colorView = findViewById(R.id.color_view)
+ val colorView = findViewById(R.id.color_view)
colorView.setBackgroundColor(currentColor)
val channelViews = colorMode.channels.map { ChannelView(it, currentColor, context) }
@@ -59,7 +58,7 @@ internal class ChromaView : RelativeLayout {
colorView.setBackgroundColor(currentColor)
}
- val channelContainer = findViewById(R.id.channel_container) as ViewGroup
+ val channelContainer = findViewById(R.id.channel_container)
channelViews.forEach { it ->
channelContainer.addView(it)
@@ -71,15 +70,15 @@ internal class ChromaView : RelativeLayout {
}
}
- internal interface ButtonBarListener {
+ interface ButtonBarListener {
fun onPositiveButtonClick(color: Int)
fun onNegativeButtonClick()
}
- internal fun enableButtonBar(listener: ButtonBarListener?): Unit {
- with(findViewById(R.id.button_bar)) {
- val positiveButton = findViewById(R.id.positive_button)
- val negativeButton = findViewById(R.id.negative_button)
+ fun enableButtonBar(listener: ButtonBarListener?) {
+ with(findViewById(R.id.button_bar)) {
+ val positiveButton = findViewById(R.id.positive_button)
+ val negativeButton = findViewById(R.id.negative_button)
if (listener != null) {
visibility = VISIBLE
diff --git a/chroma/src/main/kotlin/me/priyesh/chroma/chroma.kt b/chroma/src/main/kotlin/me/priyesh/chroma/chroma.kt
index 32ae211..47f56f5 100644
--- a/chroma/src/main/kotlin/me/priyesh/chroma/chroma.kt
+++ b/chroma/src/main/kotlin/me/priyesh/chroma/chroma.kt
@@ -5,16 +5,16 @@ import android.graphics.Color
import android.util.DisplayMetrics
import android.view.WindowManager
-internal fun screenDimensions(context: Context): DisplayMetrics {
+fun screenDimensions(context: Context): DisplayMetrics {
val manager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val metrics = DisplayMetrics()
manager.defaultDisplay.getMetrics(metrics)
return metrics
}
-internal fun orientation(context: Context) = context.resources.configuration.orientation
+fun orientation(context: Context) = context.resources.configuration.orientation
-internal infix fun Int.percentOf(n: Int): Int = (n * (this / 100.0)).toInt()
+infix fun Int.percentOf(n: Int): Int = (n * (this / 100.0)).toInt()
fun hue(color: Int): Int = hsv(color, 0)
fun saturation(color: Int): Int = hsv(color, 1, 100)
diff --git a/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChannelView.kt b/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChannelView.kt
index 5c3bebb..f5ac3a3 100644
--- a/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChannelView.kt
+++ b/chroma/src/main/kotlin/me/priyesh/chroma/internal/ChannelView.kt
@@ -44,7 +44,7 @@ internal class ChannelView(
bindViews(rootView)
}
- private fun bindViews(root: View): Unit {
+ private fun bindViews(root: View) {
(root.findViewById(R.id.label) as TextView).text = context.getString(channel.nameResourceId)
val progressView = root.findViewById(R.id.progress_text) as TextView
@@ -66,7 +66,7 @@ internal class ChannelView(
})
}
- fun registerListener(listener: () -> Unit): Unit {
+ fun registerListener(listener: () -> Unit) {
this.listener = listener
}