Skip to content

Instantly share code, notes, and snippets.

/* PHONE REGEX REGION */
# PHONE_REGEX_1 = "^((\\(\\d{3}\\))|\\d{3})[- .]?\\d{3}[- .]?\\d{4}$"
--> validation: (202) 555-0125
# PHONE_REGEX_2 = "^(\\+\\d{1,2}( )?)?((\\(\\d{3}\\))|\\d{3})[- .]?\\d{3}[- .]?\\d{4}$"
--> validation: +90 (202) 555-0125
@tfaki
tfaki / gist:c41ebca8f5072aaa401b42d070f215ef
Last active April 21, 2022 12:38
CustomThreeItemsToolbar
@Composable
fun ScreenContent() {
Scaffold(
backgouroundColor = // yourcolor,
topBar = {
CustomToolbar()
},
content = {
// your content
}
private fun pictureInPictureMode(){
//Requires Android O and higher
Log.d(TAG, "pictureInPictureMode: Try to enter in PIP mode")
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){
Log.d(TAG, "pictureInPictureMode: Supports PIP")
//setup PIP height width
val aspectRatio = Rational(videoView.width, videoView.height)
pictureInPictureParamsBuilder!!.setAspectRatio(aspectRatio).build()
enterPictureInPictureMode(pictureInPictureParamsBuilder!!.build())
}
override fun onUserLeaveHint() {
super.onUserLeaveHint()
//when user presses home button, if not in PIP mode, enter in PIP, requires Android N and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N){
Log.d(TAG, "onUserLeaveHint: was not in PIP")
pictureInPictureMode()
}
else{
Log.d(TAG, "onUserLeaveHint: Already in PIP")
}
override fun onPictureInPictureModeChanged(
isInPictureInPictureMode: Boolean,
newConfig: Configuration?
) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (isInPictureInPictureMode){
Log.d(TAG, "onPictureInPictureModeChanged: Entered PIP")
pipButton.visibility = View.GONE
}
else{
@Composable
fun YourTheme(darkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
val dynamicColor = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val colors = if (dynamicColor) {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
} else {
if (darkTheme) DarkColorPalette else LightColorPalette
}
@Composable
fun CardItem() {
Card(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.padding(horizontal = 16.dp, vertical = 8.dp),
colors = CardDefaults.cardColors(containerColor = MaterialTheme.colorScheme.primary)
) {
@tfaki
tfaki / WithRunBlock
Created March 30, 2023 20:48
Modifier Run Block
@Composable
fun WithRunBlock() {
var isExpanded by remember {
mutableStateOf(true)
}
Box(
modifier = Modifier
.height(50.dp)
.run {
@tfaki
tfaki / WithThenBlock
Created March 30, 2023 20:49
Modifier Then Block
@Composable
fun WithThenBlock() {
var isExpanded by remember {
mutableStateOf(true)
}
Box(
modifier = Modifier
.height(50.dp)
.then(
task("sayDone") {
doLast {
exec {
commandLine("say", "Ilk Turda Bitirelim")
}
}
}