Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mobile Computing
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ali Senpinar
Mobile Computing
Commits
6fe9c405
Commit
6fe9c405
authored
1 year ago
by
Ali Senpinar
Browse files
Options
Downloads
Patches
Plain Diff
Main
parent
97b86b01
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MainActivity.kt
+83
-0
83 additions, 0 deletions
MainActivity.kt
with
83 additions
and
0 deletions
MainActivity.kt
0 → 100644
+
83
−
0
View file @
6fe9c405
package
com.example.diceroller
import
android.os.Bundle
import
androidx.activity.ComponentActivity
import
androidx.activity.compose.setContent
import
androidx.compose.foundation.layout.Column
import
androidx.compose.foundation.layout.fillMaxSize
import
androidx.compose.foundation.layout.wrapContentSize
import
androidx.compose.material3.Button
import
androidx.compose.material3.MaterialTheme
import
androidx.compose.material3.Surface
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.stringResource
import
androidx.compose.ui.tooling.preview.Preview
import
com.example.diceroller.ui.theme.DiceRollerTheme
import
androidx.compose.foundation.Image
import
androidx.compose.foundation.layout.Spacer
import
androidx.compose.ui.res.painterResource
import
androidx.compose.foundation.layout.height
import
androidx.compose.foundation.layout.Spacer
import
androidx.compose.ui.unit.dp
import
androidx.compose.runtime.getValue
import
androidx.compose.runtime.setValue
import
androidx.compose.runtime.mutableStateOf
import
androidx.compose.runtime.remember
class
MainActivity
:
ComponentActivity
()
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
setContent
{
DiceRollerTheme
{
DiceRollerApp
()
}
}
}
}
@Preview
@Composable
fun
DiceRollerApp
(){
DiceWithButtonAndImage
()
}
@Composable
fun
DiceWithButtonAndImage
(
modifier
:
Modifier
=
Modifier
.
fillMaxSize
()
.
wrapContentSize
(
Alignment
.
Center
)
){
var
result
by
remember
{
mutableStateOf
(
1
)
}
val
imageResource
=
when
(
result
){
1
->
R
.
drawable
.
dice_1
2
->
R
.
drawable
.
dice_2
3
->
R
.
drawable
.
dice_3
4
->
R
.
drawable
.
dice_4
5
->
R
.
drawable
.
dice_5
else
->
R
.
drawable
.
dice_6
}
Column
(
modifier
=
modifier
,
horizontalAlignment
=
Alignment
.
CenterHorizontally
)
{
Image
(
painter
=
painterResource
(
id
=
imageResource
),
contentDescription
=
result
.
toString
()
)
Spacer
(
modifier
=
Modifier
.
height
(
16
.
dp
))
Button
(
onClick
=
{
result
=
(
1
..
6
).
random
()})
{
Text
(
stringResource
(
R
.
string
.
roll
))
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment