瀏覽代碼

Fix Int.hexValue extension to use 00 as the prefix when alpha is 0

Aidan Follestad 6 年之前
父節點
當前提交
3a6adb499d

+ 10 - 1
color/src/main/java/com/afollestad/materialdialogs/color/utils/ColorExt.kt

@@ -20,7 +20,16 @@ import android.graphics.Color
 internal fun Int.hexValue(includeAlpha: Boolean) = if (this == 0) {
   if (includeAlpha) "00000000" else "000000"
 } else {
-  if (includeAlpha) Integer.toHexString(this) else String.format("%06X", 0xFFFFFF and this)
+  if (includeAlpha) {
+    val result = Integer.toHexString(this)
+    if (result.length == 6) {
+      "00$result"
+    } else {
+      result
+    }
+  } else {
+    String.format("%06X", 0xFFFFFF and this)
+  }
 }
 
 internal fun String.toColor(): Int? {

+ 3 - 3
color/src/main/java/com/afollestad/materialdialogs/color/view/PreviewFrameView.kt

@@ -47,9 +47,9 @@ internal class PreviewFrameView(
     const val HEX_VALUE_ALPHA_THRESHOLD = 50
   }
 
-  lateinit var argbView: View
-  lateinit var hexPrefixView: TextView
-  lateinit var hexValueView: ObservableEditText
+  private lateinit var argbView: View
+  private lateinit var hexPrefixView: TextView
+  private lateinit var hexValueView: ObservableEditText
 
   var supportCustomAlpha: Boolean = true
   var onHexChanged: HexColorChanged = { true }