Skip to content

Commit 724319c

Browse files
committed
Random Number generator + second activity
1 parent 4998528 commit 724319c

22 files changed

+672
-14
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx

.idea/.name

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/Project.xml

+138
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

+21
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+25
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/src/main/AndroidManifest.xml

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
<category android:name="android.intent.category.LAUNCHER" />
1717
</intent-filter>
1818
</activity>
19+
<activity android:name=".CurseActivity">
20+
21+
</activity>
1922
</application>
2023

2124
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.example.myapplication
2+
3+
import android.content.Intent
4+
import android.os.Bundle
5+
import android.view.MenuItem
6+
import android.widget.Toast
7+
import androidx.appcompat.app.ActionBarDrawerToggle
8+
import androidx.appcompat.app.AppCompatActivity
9+
import kotlinx.android.synthetic.main.activity_main.*
10+
11+
class CurseActivity : AppCompatActivity(){
12+
13+
lateinit var toggle: ActionBarDrawerToggle
14+
15+
override fun onCreate(savedInstanceState: Bundle?) {
16+
super.onCreate(savedInstanceState)
17+
setContentView(R.layout.activity_main)
18+
19+
20+
toggle = ActionBarDrawerToggle(this,drawerLayout, R.string.open, R.string.close)
21+
drawerLayout.addDrawerListener(toggle)
22+
toggle.syncState()
23+
24+
supportActionBar?.setDisplayHomeAsUpEnabled(true)
25+
26+
navView.setNavigationItemSelectedListener {
27+
when(it.itemId){
28+
R.id.miItem1 -> {
29+
val intent = Intent(this,MainActivity::class.java)
30+
startActivity(intent)
31+
}
32+
R.id.miItem3 -> Toast.makeText(applicationContext,
33+
"Clicked Item 3", Toast.LENGTH_SHORT).show()
34+
}
35+
true
36+
}
37+
38+
}
39+
40+
override fun onOptionsItemSelected(item: MenuItem): Boolean {
41+
if(toggle.onOptionsItemSelected(item)){
42+
return true
43+
}
44+
return super.onOptionsItemSelected(item)
45+
}
46+
47+
}

app/src/main/java/com/example/myapplication/MainActivity.kt

+22-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.example.myapplication
22

3+
import android.content.Intent
34
import androidx.appcompat.app.AppCompatActivity
45
import android.os.Bundle
56
import android.view.MenuItem
6-
import android.widget.Toast
7+
import android.widget.*
78
import androidx.appcompat.app.ActionBarDrawerToggle
89
import kotlinx.android.synthetic.main.activity_main.*
10+
import java.util.*
11+
912

1013
class MainActivity : AppCompatActivity() {
1114

@@ -15,6 +18,19 @@ class MainActivity : AppCompatActivity() {
1518
super.onCreate(savedInstanceState)
1619
setContentView(R.layout.activity_main)
1720

21+
val rollButton = findViewById<Button>(R.id.rollButton)
22+
val resultTextView = findViewById<TextView>(R.id.resultView)
23+
val input = findViewById<EditText>(R.id.inputView)
24+
25+
26+
27+
rollButton.setOnClickListener {
28+
if (Integer.parseInt(input.text.toString()) <= 1000000){
29+
val rand = 1 + Random().nextInt(Integer.parseInt(input.text.toString()))
30+
resultTextView.text = rand.toString()
31+
}
32+
}
33+
1834
toggle = ActionBarDrawerToggle(this,drawerLayout, R.string.open, R.string.close)
1935
drawerLayout.addDrawerListener(toggle)
2036
toggle.syncState()
@@ -23,12 +39,12 @@ class MainActivity : AppCompatActivity() {
2339

2440
navView.setNavigationItemSelectedListener {
2541
when(it.itemId){
26-
R.id.miItem1 -> Toast.makeText(applicationContext,
27-
"Clicked Item 1", Toast.LENGTH_SHORT).show()
28-
R.id.miItem2 -> Toast.makeText(applicationContext,
29-
"Clicked Item 2", Toast.LENGTH_SHORT).show()
42+
R.id.miItem2 -> {
43+
val intent = Intent(this,CurseActivity::class.java)
44+
startActivity(intent)
45+
}
3046
R.id.miItem3 -> Toast.makeText(applicationContext,
31-
"Clicked Item 3", Toast.LENGTH_SHORT).show()
47+
"Coming Soon", Toast.LENGTH_SHORT).show()
3248
}
3349
true
3450
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout
3+
xmlns:android="http://schemas.android.com/apk/res/android"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
xmlns:tools="http://schemas.android.com/tools"
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent">
8+
9+
<TextView
10+
android:id="@+id/textView"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:text="Coming Soon"
14+
android:textSize="40sp"
15+
app:layout_constraintBottom_toBottomOf="parent"
16+
app:layout_constraintEnd_toEndOf="parent"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent" />
19+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)