Slf4j loggers in 3 ways
If you use SLF4J (and possibly Logback) for logging, you are probably familiar with the following code:
val logger = LoggerFactory.getLogger(MyClass::class.java)
About 2 min
If you use SLF4J (and possibly Logback) for logging, you are probably familiar with the following code:
val logger = LoggerFactory.getLogger(MyClass::class.java)
MainActivity.kt
class MainActivity: ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ColorPicker()
}
}
}
@Composable
fun ColorPicker() {
val colors = listOf(
Color(0xfff9a825),
COlor(0xffff3d00),
Color(0xff4caf50),
Color(0xff9c27b0),
Color(0xff2196f3))
val currentColor = remember { mutableStateOf(colors[0]) }
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arragement.Center,
modifier = Modifier.fillMaxSize()
) {
Row {
colors.forEach { color ->
val isSelected = currentColor.value == color
Box (
modifier = Modifier.padding(4.dp)
.size(50.dp)
.clip(CircleShape)
.background(color)
.selectable(
selected = isSelected,
onClick = { currentColor.value = color }
)
) {
if (currentColor.value == color) {
Icon(imageVector = Icons.Filled.Done,
contentDescription = "Done",
tint = Color.White
modifier = Modifier.align(Alignment.Center))
}
}
}
}
Text (
text = "TEXT",
color = currentColor.value,
fontSize = 27.sp
)
}
}
import android.util.Patterns
/**
* [String.isValidEmail()]
* Check for a Valid Email address
*
* @return whether the input is valid for email address
*/
fun String.isValidEmail(): Boolean {
val pattern = Patterns.EMAIL_ADDRESS
val isEmail = pattern.matcher(this).matches()
return this.isNotEmpty() && isEmail
}