Skip to content

Emilio467/CodeLab

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

CodeLab

Introduction to programming in Kotlin:

.Seu primeiro programa em kotlin ------------------------------------------------------------------------------------------------

. partes de uma função

image

fun main () { println("Hello, android!") }

.modificar o programa

image

fun main () { println("Hello, android!") println("Hello, android!") }

image

fun main () { println("Hello, android!") }

.Corrigir erros do codigo-----------------------

image

fun main() { println("Today is sunny!") }

.Exercicios--------------------------------------

image

fun main() { println("I'm") println("learning") println("Kotlin!") }

image

fun main() { println("Tuesday") println("Thursday") println("Wednesday") println("Friday") println("Monday")

}

image

fun main() { println("Tomorrow is rainy") }

image

fun main() { println("There is a chance of snow") }

image

fun main() { println("Cloudy") println("Partly Cloudy") println("Windy") } image

fun main () { println("How's the weather today?") }

.Criar variaveis em kotlin ------------------------

variaveis e tipos de dados:

image

Nome do canal = string inscrições = int likes = int deslikes = int foto do canal = bollean

Definir e usar variaveis

image

fun main() { val count: Int = 2 println(count) }

image

fun main() { val count: Int = 2 println("You have $count unread messages.") }

image

fun main() { val count: Int = 20 println("You have $count unread messages.") }

image

fun main() { val unreadCount = 10 val readCount = 200 println("You have ${unreadCount + readCount} total messages in your inbox.")

}

image

fun main() { val numberOfPhotos = 400 val photosDeleted = 30 println("$numberOfPhotos photos") println("$photosDeleted photos deleted") println("${numberOfPhotos - photosDeleted} photos left") }

Atualizar variaveis

image

fun main() { var cartTotal = 3 cartTotal = 20 println("Total: $cartTotal") }

image

fun main() { var cartTotal = 1000 println("Total antes: $cartTotal") cartTotal = 20 println("Total depois: $cartTotal") }

image

fun main() { var count = 10 println("You have $count unread messages.") count = count + 90 println("You have $count unread messages.") }

image

fun main() { var count = 90 println("You have $count unread messages.") count++ println("You have now $count unread messages.") }

image

fun main() { var count = 109 println("You have $count unread messages.") count-- println("You have now $count unread messages.") }

Outros tipos de dados

image

fun main() { val trip1 = 32.20 val trip2 = 400.10 val trip3 = 10.72 val totalTripLength = trip1 + trip2 + trip3 println("$totalTripLength miles left to destination") }

image

fun main() { val nextMeeting = "Next meeting: " val date = "august 5" val reminder = nextMeeting + date println(reminder) }

image

fun main() { val nextMeeting = "Next meeting: " val date = "august 5" val reminder = nextMeeting + date + " at work" println(reminder) }

image

fun main() { println("Say "Bom dia"") }

image

fun main() { val notificacao: Boolean = true println(notificacao) }

image

fun main() { val notificacao2: Boolean = false println(notificacao2) }

image

fun main() { val notificacao: Boolean = false println("As notificacoes tão ativadas? " + notificacao) }

Criar e usar funções

image

fun birthdayGreeting(): String { val nameGreeting = "Feliz aniversario, Rover!" val ageGreeting = "agora voce tem 5 anos!" return "$nameGreeting\n$ageGreeting" }

fun main() { val greeting = birthdayGreeting() println(greeting)

println() 
println(birthdayGreeting())

}

adicionar parametros a funcao

image

fun main() { println(aniversario("Rover")) println(aniversario("Rex")) } fun aniversario(nome: String): String { val mensagemParabens = "Feliz aniversário, $nome!" val mensagemIdade = "Você completou 5 anos!" return "$mensagemParabens\n$mensagemIdade" }

image

fun main() { println(aniversario("Rover", 5)) println(aniversario(nome = "Rex", idade = 2)) } fun aniversario(nome: String, idade: Int): String { val mensagemParabens = "Feliz aniversário, $nome!" val mensagemIdade = "Você completou $idade anos!" return "$mensagemParabens\n$mensagemIdade" }

image

fun main() { println(aniversario(idade = 5)) println(aniversario(nome = "Rex", idade = 2)) println(aniversario(idade = 2)) } fun aniversario(nome: String = "Rover", idade: Int): String { return "Feliz aniversário, $nome! Você completou $idade anos!" }

Noções basicas de kotlin

image

fun main() { val programa = "Curso de Kotlin" var mensagem = "olá" println(mensagem)

mensagem = "oi"
println(mensagem)

mensagem = "tchau"
println(mensagem)

mensagem = "Bem vindo"
println(mensagem)

}

image

fun main() { println("New chat message from a friend") }

image

fun main() { var discountPercentage: Int = 0 var offer: String = "" val item = "Google Chromecast" discountPercentage = 20 offer = "Sale - Up to $discountPercentage% discount on $item! Hurry up!" println(offer) }

image

fun main() { val numberOfAdults = 20 val numberOfKids = 30 val total = numberOfAdults + numberOfKids println("The total party size is: $total") }

image

fun main() { val baseSalary = 5000 val bonusAmount = 1000 val totalSalary = baseSalary + bonusAmount println("Congratulations for your bonus! You will receive a total of $totalSalary (additional bonus).") }

image

fun main() { val firstNumber = 10 val secondNumber = 5 val thirdNumber = 8 val result = add(firstNumber, secondNumber) val anotherResult = add(firstNumber, thirdNumber) val subResult = subtract(firstNumber, secondNumber) val subAnotherResult = subtract(firstNumber, thirdNumber)

println("$firstNumber + $secondNumber = $result")
println("$firstNumber + $thirdNumber = $anotherResult")
println("$firstNumber - $secondNumber = $subResult")
println("$firstNumber - $thirdNumber = $subAnotherResult")

} fun add(a: Int, b: Int): Int { return a + b } fun subtract(a: Int, b: Int): Int { return a - b }

image

fun main() { val operatingSystem = "Chrome OS" val emailId = "sample@gmail.com"

println(displayAlertMessage(operatingSystem, emailId))

} fun displayAlertMessage(operatingSystem: String, emailId: String): String { return "There's a new sign-in request on $operatingSystem for your Google Account $emailId." }

image

fun main() { val firstUserEmailId = "user_one@gmail.com" println(displayAlertMessage(emailId = firstUserEmailId)) println() val secondUserOperatingSystem = "Windows" val secondUserEmailId = "user_two@gmail.com" println(displayAlertMessage(emailId = secondUserEmailId, operatingSystem = secondUserOperatingSystem)) println() val thirdUserOperatingSystem = "Mac OS" val thirdUserEmailId = "user_three@gmail.com" println(displayAlertMessage(emailId = thirdUserEmailId, operatingSystem = thirdUserOperatingSystem)) println() } fun displayAlertMessage(emailId: String, operatingSystem: String = "Unknown OS"): String { return "There's a new sign-in request on $operatingSystem for your Google Account $emailId." }

image

fun main() { val passosDados = 4000 val caloriasQueimadas = calcularCaloriasPorPassos(passosDados) println("Caminhar $passosDados passos queima $caloriasQueimadas calorias") }

fun calcularCaloriasPorPassos(numeroDePassos: Int): Double { val caloriasPorPasso = 0.04 val totalCalorias = numeroDePassos * caloriasPorPasso return totalCalorias }

image

fun main() { val tempoHoje = 300 val tempoOntem = 250 val passouMaisTempo = compararTempoSmartphone(tempoHoje, tempoOntem) println(passouMaisTempo) } fun compararTempoSmartphone(tempoHoje: Int, tempoOntem: Int): Boolean { return tempoHoje > tempoOntem }

image

fun main() { mostrarClima("Ankara", 27, 31, 82) mostrarClima("Tokyo", 32, 36, 10) mostrarClima("Cape Town", 59, 64, 2) mostrarClima("Guatemala City", 50, 55, 7) } fun mostrarClima(cidade: String, temperaturaMin: Int, temperaturaMax: Int, chanceChuva: Int) { println("City: $cidade") println("Low temperature: $temperaturaMin, High temperature: $temperaturaMax") println("Chance of rain: $chanceChuva%") println() }

image

fun main() { println("Use the val keyword when the value doesn't change.") println("Use the var keyword when the value can change.") println("When you define a function, you define the parameters that can be passed to it.") println("When you call a function, you pass arguments for the parameters.") }

image

fun main() { val discountPercentage = 20 val item = "Google Chromecast" val offer = "Sale - Up to $discountPercentage% discount off $item! Hurry Up!"

println(offer)

}

image

fun main() { val numberOfAdults = 20 val numberOfKids = 30 val total = numberOfAdults + numberOfKids println("The total party size is: $total") }

image

fun main() { val firstNumber = 10 val secondNumber = 5 val thirdNumber = 8 val result = add(firstNumber, secondNumber) println("$firstNumber + $secondNumber = $result") val anotherResult = subtract(firstNumber, thirdNumber) println("$firstNumber - $thirdNumber = $anotherResult") } fun add(firstNumber: Int, secondNumber: Int): Int { return firstNumber + secondNumber } fun subtract(firstNumber: Int, secondNumber: Int): Int { return firstNumber - secondNumber }

image

fun main() { val message1 = displayAlertMessage(emailId = "user@example.com") println(message1) val message2 = displayAlertMessage("MacOS", "user@example.com") println(message2) } fun displayAlertMessage( operatingSystem: String = "Unknown OS", emailId: String ): String { return "There is a new sign-in request on $operatingSystem for your Google Account $emailId." }

image

fun main() { val passos = 7000 val caloriasQueimadas = passosParaCalorias(passos) println("Caminhando $passos passos você queima $caloriasQueimadas calorias") } fun passosParaCalorias(numeroDePassos: Int): Double { val caloriasPorPasso = 0.02 val totalDeCalorias = numeroDePassos * caloriasPorPasso return totalDeCalorias }

image

fun compararTempo(tempoHoje: Int, tempoOntem: Int): Boolean { return tempoHoje > tempoOntem } fun main() { println("Passei mais tempo no celular hoje: ${compararTempo(300, 250)}") println("Passei mais tempo no celular hoje: ${compararTempo(300, 300)}") println("Passei mais tempo no celular hoje: ${compararTempo(200, 220)}") }

image

fun mostrarClimaCidade(nomeCidade: String, tempMin: Int, tempMax: Int, chanceChuva: Int) { println("Cidade: $nomeCidade") println("Temperatura mínima: $tempMin, Temperatura máxima: $tempMax") println("Chance de chuva: $chanceChuva%") println() }

fun main() { mostrarClimaCidade("Ancara", 27, 31, 82) mostrarClimaCidade("Tóquio", 32, 36, 10) mostrarClimaCidade("Cidade do Cabo", 59, 64, 2) mostrarClimaCidade("Cidade da Guatemala", 50, 55, 7) }

.Android studio

image image

Imagem do WhatsApp de 2025-10-05 à(s) 16 45 34_33e820d1

image

Imagem do WhatsApp de 2025-10-05 à(s) 17 43 52_32bd54b9

package com.example.happybirthday

import android.os.Bundle import androidx.compose.ui.res.stringResource import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.material3.* import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.happybirthday.ui.theme.HappyBirthdayTheme import androidx.compose.ui.Alignment import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.stringResource

class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { HappyBirthdayTheme { Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { GreetingImage( message = stringResource(R.string.happy_birthday_text), from = stringResource(R.string.signature_text) ) } } } } }

@Composable fun GreetingText(message: String, from: String, modifier: Modifier = Modifier) { Column( verticalArrangement = Arrangement.Center, modifier = modifier.padding(8.dp) ) { Text( text = message, fontSize = 100.sp, lineHeight = 116.sp, textAlign = TextAlign.Center, modifier = Modifier.fillMaxWidth() ) Text( text = from, fontSize = 36.sp, modifier = Modifier .padding(16.dp) .align(alignment = Alignment.End) ) } }

@Composable fun GreetingImage(message: String, from: String, modifier: Modifier = Modifier) { val image = painterResource(R.drawable.androidparty) Box(modifier) { Image( painter = image, contentDescription = null, contentScale = ContentScale.Crop, alpha = 0.5F, modifier = Modifier.fillMaxSize() ) GreetingText( message = message, from = from, modifier = Modifier .fillMaxSize() .padding(8.dp) ) } }

@Preview(showBackground = true) @Composable fun GreetingPreview() { HappyBirthdayTheme { GreetingImage( message = stringResource(R.string.happy_birthday_text), from = stringResource(R.string.signature_text) ) } }

image

package com.example.compose

import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.background import androidx.compose.foundation.layout.* import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.tooling.preview.Preview import com.example.compose.ui.theme.ComposeTheme

class MainActivity2 : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { ComposeTheme { ComposablesQuadrantsScreen() } } } }

@Composable fun ComposablesQuadrantsScreen() { Column(modifier = Modifier.fillMaxSize()) { Row(modifier = Modifier.weight(1f)) { Quadrant( title = "Text composable", description = "Displays text and follows the recommended Material Design guidelines.", backgroundColor = Color(0xFFEADDFF), modifier = Modifier.weight(1f) ) Quadrant( title = "Image composable", description = "Creates a composable that lays out and draws a given Painter class object.", backgroundColor = Color(0xFFD0BCFF), modifier = Modifier.weight(1f) ) } Row(modifier = Modifier.weight(1f)) { Quadrant( title = "Row composable", description = "A layout composable that places its children in a horizontal sequence.", backgroundColor = Color(0xFFB69DF8), modifier = Modifier.weight(1f) ) Quadrant( title = "Column composable", description = "A layout composable that places its children in a vertical sequence.", backgroundColor = Color(0xFFF6EDFF), modifier = Modifier.weight(1f) ) } } }

@Composable fun Quadrant(title: String, description: String, backgroundColor: Color, modifier: Modifier = Modifier) { Column( modifier = modifier .fillMaxSize() .background(backgroundColor) .padding(16.dp), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { Text( text = title, fontWeight = FontWeight.Bold, modifier = Modifier.padding(bottom = 16.dp) ) Text( text = description ) } }

@Preview(showBackground = true) @Composable fun ComposablesQuadrantsPreview() { ComposeTheme { ComposablesQuadrantsScreen() } }

image

package com.example.compose import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import com.example.compose.ui.theme.ComposeTheme

@Composable fun CompletedTasksScreen() { Column( modifier = Modifier .fillMaxSize(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { val image = painterResource(id = R.drawable.ic_task_completed) Image( painter = image, contentDescription = "All tasks completed" ) Text( text = "All tasks completed", fontWeight = FontWeight.Bold, modifier = Modifier.padding(top = 24.dp, bottom = 8.dp) ) Text( text = "Nice work!", fontSize = 16.sp ) } }

@Preview(showBackground = true) @Composable fun CompletedTasksPreview() { ComposeTheme { CompletedTasksScreen() } }

image

package com.example.compose

import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.compose.foundation.Image import androidx.compose.foundation.layout.* import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Email import androidx.compose.material.icons.filled.Phone import androidx.compose.material3.Icon import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.compose.ui.tooling.preview.Preview import com.example.compose.ui.theme.ComposeTheme

class MainActivity3 : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() setContent { ComposeTheme { BusinessCardScreen() } } } }

@Composable fun BusinessCardScreen() { Column( modifier = Modifier .fillMaxSize() .padding(16.dp), horizontalAlignment = Alignment.CenterHorizontally ) { Column( horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.padding(bottom = 24.dp) ) {

        Text("Seu Nome", fontWeight = FontWeight.Bold, fontSize = 24.sp)
        Text("Cargo", fontSize = 16.sp)
    }

    Column(
        modifier = Modifier.fillMaxWidth(),
        horizontalAlignment = Alignment.Start
    ) {
        Row(verticalAlignment = Alignment.CenterVertically) {
            Icon(Icons.Default.Phone, contentDescription = "Telefone")
            Text(" (11) 99999-9999", fontSize = 16.sp)
        }
        Row(verticalAlignment = Alignment.CenterVertically) {
            Icon(Icons.Default.Email, contentDescription = "E-mail")
            Text(" email@exemplo.com", fontSize = 16.sp)
        }
    }
}

}

@Preview(showBackground = true) @Composable fun BusinessCardPreview() { ComposeTheme { BusinessCardScreen() } }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages