当前位置:网站首页>Realize an air conditioner with compose to bring you cool in summer
Realize an air conditioner with compose to bring you cool in summer
2022-06-28 10:15:00 【Zhujiang】
heat
Summer is coming , Experience is like the word in the subtitle , So , Just want to draw an air conditioner , It will be cooler if you look at it ...
Let's take a look at the finished product style first .

Ha ha ha , It looks cool .
Air conditioning
Let's review the functions that need to be implemented :
1、 First there must be a switch , It is used to control the switch state of the air conditioner ;
2、 Then you can set the cold air and warm air , It can be used in winter and summer ;
3、 Finally, increase and decrease the temperature ;
OK, Demand is almost like this , Then it's time to code .
Write the title
Let's write down the title of the air conditioner first :
Column(
modifier = Modifier
.fillMaxSize()
.statusBarsPadding()
.navigationBarsPadding(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally,
) {
Spacer(modifier = Modifier.height(50.dp))
Text(text = " Portable small air conditioner ", fontSize = 25.sp)
Text(
text = "Tip: Bring coolness to your summer !",
fontSize = 15.sp,
modifier = Modifier.padding(bottom = 20.dp)
)
}
The code above is nothing , Just a linear layout with two Text, There's nothing to say .
Draw air conditioning style
Let's draw the style of the air conditioner :
@Composable
private fun Conditioner() {
Card(
modifier = Modifier
.fillMaxWidth()
.height(100.dp)
.padding(horizontal = 20.dp),
shape = RoundedCornerShape(
topStart = 18f,
topEnd = 18f,
bottomStart = 36f,
bottomEnd = 36f
)
) {
Column {
Divider(
modifier = Modifier.padding(top = 6.dp),
thickness = 0.4.dp,
)
Row(
modifier = Modifier
.fillMaxSize()
.background(color = Color.White)
.padding(6.dp)
) {
Image(
painter = painterResource(id = R.mipmap.logo),
contentDescription = "",
)
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.End,
) {
Image(
painter = painterResource(id = R.drawable.ic_snow),
contentDescription = "",
modifier = Modifier.size(25.dp)
)
Spacer(modifier = Modifier.height(5.dp))
Text(
text = "23°C",
fontSize = 20.sp,
fontFamily = FontFamily(Font(R.font.lcd, FontWeight.SemiBold))
)
}
}
}
}
}
Let's put it simply , The style of the air conditioner will have rounded corners , Use here Card To achieve , Then there is a picture of energy efficiency , On the right is the sign and temperature of cold air or warm air .
Control the air conditioning
The air conditioning style has been painted , The only thing left is to control the air conditioner :
// Air conditioning switch
val airSwitch = rememberSaveable { mutableStateOf(false) }
// temperature
val temperature = rememberSaveable { mutableStateOf(23) }
// type , Cooling or heating
val airType = rememberSaveable { mutableStateOf(true) }
Row(modifier = Modifier.padding(10.dp)) {
Button(onClick = { airType.value = true }, shape = RoundedCornerShape(15.dp)) {
Text(text = " cold wind ")
}
Switch(checked = airSwitch.value, onCheckedChange = {
airSwitch.value = !airSwitch.value
})
Button(onClick = { airType.value = false }, shape = RoundedCornerShape(15.dp)) {
Text(text = " Hot air ")
}
}
Button(onClick = {
if (temperature.value >= 31) {
showToast(context, " The temperature can't be any higher !!!")
Log.e(TAG, "AirConditioner: It's too hot ")
[email protected]
}
temperature.value = temperature.value + 1
}, shape = RoundedCornerShape(15.dp)) {
Text(text = "+")
}
Button(onClick = {
if (temperature.value <= 16) {
showToast(context, " The temperature can't be any lower !!!")
Log.e(TAG, "AirConditioner: It's too cold ")
[email protected]
}
temperature.value = temperature.value - 1
}, shape = RoundedCornerShape(15.dp)) {
Text(text = "-")
}
To control the air conditioner, you need State To control , The code is also simple , Only the status value is modified .
Blow the air conditioner
The whole application code is very simple , Plus all kinds of blank lines and imports Less than twohundred lines . You can write a small air conditioner in less than 200 lines , Although there is no actual temperature experience .... however , Peace of mind is naturally cool
You can copy the code , And then blow it on your mobile phone to try the effect , Ha ha ha
Give me this Demo Upload to Github 了 , You can get your own code and pictures :https://github.com/zhujiang521/AirConditioner
Postscript
The code is very simple , But I hope everyone can keep a calm heart in the hot summer , The future can also calmly face all kinds of things in life , Strive , Mutual encouragement .
边栏推荐
- Read PDF image and identify content
- Django database operation and problem solving
- Chapter 5 trees and binary trees
- 适配器模式(Adapter)
- Unity 从服务器加载AssetBundle资源写入本地内存,并将下载保存的AB资源从本地内存加载至场景
- Crawler small operation
- Interface automation framework scaffold - use reflection mechanism to realize the unified initiator of the interface
- Installing redis under Linux and windows (ultra detailed graphic tutorial)
- Explain final, finally, and finalize
- Instant messaging and BS architecture simulation of TCP practical cases
猜你喜欢

丢弃 Tkinter!简单配置快速生成超酷炫 GUI!

PMP examination key summary VIII - monitoring process group (2)

To enhance the function of jupyter notebook, here are four tips
![[NLP] this year's college entrance examination English AI score is 134. The research of Fudan Wuda alumni is interesting](/img/a8/51b95432a9c8f25d8440cfd80926ce.png)
[NLP] this year's college entrance examination English AI score is 134. The research of Fudan Wuda alumni is interesting

How to use dataant to monitor Apache apisex

Composite pattern

Decorator

Solve the problem that the value of the action attribute of the form is null when transferring parameters

第六天 脚本与动画系统
![[unity][ecs] learning notes (II)](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[unity][ecs] learning notes (II)
随机推荐
MySQL cannot be opened. Flash back
The R language uses the avplots function in the car package to create added variable plots. In image interaction, manually identify (add) strong influence points that have a great impact on each predi
物联网5种无线传输协议特点大汇总
理想中的接口自动化项目
I'm almost addicted to it. I can't sleep! Let a bug fuck me twice!
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
Fabric.js 笔刷到底怎么用?
关于FTP的协议了解
MySQL的开发环境和测试环境有什么区别??
Thread lifecycle
2022吴恩达机器学习specialization Week 2 practice lab: Linear regression
[Unity][ECS]学习笔记(一)
dotnet 使用 Crossgen2 对 DLL 进行 ReadyToRun 提升启动性能
接口自动化框架脚手架-利用反射机制实现接口统一发起端
Ideal interface automation project
HDI blind hole design, have you noticed this detail?
Starting from full power to accelerate brand renewal, Chang'an electric and electrification products sound the "assembly number"
Unity AssetBundle asset packaging and asset loading
Dbeaver installation and use tutorial (super detailed installation and use tutorial)
错过金三银四,找工作4个月,面试15家,终于拿到3个offer,定级P7+