Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
likorn
/
quick_max
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
df14831a
authored
Sep 25, 2019
by
likorn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Selected values are saved in SharedPreferences
parent
f00fff82
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
app/src/main/java/com/example/quickmax/MainActivity.kt
app/src/main/java/com/example/quickmax/MainActivity.kt
View file @
df14831a
package
com.example.quickmax
package
com.example.quickmax
import
android.content.Context
import
android.content.Intent
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.view.View
import
android.view.View
...
@@ -10,14 +11,18 @@ import kotlinx.android.synthetic.main.activity_main.*
...
@@ -10,14 +11,18 @@ import kotlinx.android.synthetic.main.activity_main.*
class
MainActivity
:
AppCompatActivity
()
{
class
MainActivity
:
AppCompatActivity
()
{
private
var
secToSolve
:
Int
=
4
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
setContentView
(
R
.
layout
.
activity_main
)
setContentView
(
R
.
layout
.
activity_main
)
secToSolve
=
retrieveSecondsToSolve
()
seek_bar
.
setMinStartValue
(
secToSolve
.
toFloat
()).
apply
()
seek_bar
.
setOnSeekbarChangeListener
{
seek_bar
.
setOnSeekbarChangeListener
{
n
->
seek_bar_value
.
text
=
resources
.
getString
(
R
.
string
.
time_to_solve
,
n
.
toString
())
n
->
seek_bar_value
.
text
=
resources
.
getString
(
R
.
string
.
time_to_solve
,
n
.
toString
())
secToSolve
=
n
.
toInt
()
}
}
seek_bar
.
setMinStartValue
(
4f
).
apply
()
card_2_digits
.
setOnClickListener
(
cardOnClickListener
)
card_2_digits
.
setOnClickListener
(
cardOnClickListener
)
card_3_digits
.
setOnClickListener
(
cardOnClickListener
)
card_3_digits
.
setOnClickListener
(
cardOnClickListener
)
...
@@ -26,7 +31,8 @@ class MainActivity: AppCompatActivity() {
...
@@ -26,7 +31,8 @@ class MainActivity: AppCompatActivity() {
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
private
val
cardOnClickListener
=
View
.
OnClickListener
{
card
->
val
numDigits
=
((
card
as
CardView
).
getChildAt
(
0
)
as
TextView
).
text
.
toString
().
toInt
()
val
numDigits
=
((
card
as
CardView
).
getChildAt
(
0
)
as
TextView
).
text
.
toString
().
toInt
()
val
secToSolve
=
seek_bar
.
selectedMinValue
.
toInt
()
saveSelectedValues
()
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
).
also
{
i
->
val
intent
=
Intent
(
this
,
TaskActivity
::
class
.
java
).
also
{
i
->
i
.
putExtra
(
"num_digits"
,
numDigits
)
i
.
putExtra
(
"num_digits"
,
numDigits
)
...
@@ -34,4 +40,15 @@ class MainActivity: AppCompatActivity() {
...
@@ -34,4 +40,15 @@ class MainActivity: AppCompatActivity() {
}
}
startActivity
(
intent
)
startActivity
(
intent
)
}
}
private
fun
saveSelectedValues
()
{
val
editor
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
).
edit
()
editor
.
putInt
(
"sec_to_solve"
,
secToSolve
)
editor
.
apply
()
}
private
fun
retrieveSecondsToSolve
():
Int
{
val
prefs
=
getSharedPreferences
(
"my_prefs"
,
Context
.
MODE_PRIVATE
)
return
prefs
.
getInt
(
"sec_to_solve"
,
4
)
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment