madshellnpm 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/cli.js +44 -0
  2. package/generator.js +30 -0
  3. package/index.js +5 -0
  4. package/menu/context menu/MainActivity.kt +50 -0
  5. package/menu/context menu/activity_main.xml +18 -0
  6. package/menu/context menu/menu_main.xml +34 -0
  7. package/menu/options menu/MainActivity.kt +52 -0
  8. package/menu/options menu/activity_main.xml +9 -0
  9. package/menu/options menu/menu_main.xml +81 -0
  10. package/menu/popup menu/MainActivity.kt +58 -0
  11. package/menu/popup menu/activity_main.xml +20 -0
  12. package/menu/popup menu/menu_main.xml +39 -0
  13. package/package.json +27 -0
  14. package/templates/alertdialog/MainActivity.kt +47 -0
  15. package/templates/alertdialog/activity_main.xml +39 -0
  16. package/templates/animations/MainActivity.kt +70 -0
  17. package/templates/animations/activity_main.xml +125 -0
  18. package/templates/animations/bounce.xml +24 -0
  19. package/templates/animations/fade_in.xml +11 -0
  20. package/templates/animations/fade_out.xml +12 -0
  21. package/templates/animations/slide_down.xml +9 -0
  22. package/templates/animations/slide_up.xml +9 -0
  23. package/templates/animations/zoom_in.xml +15 -0
  24. package/templates/animations/zoom_out.xml +15 -0
  25. package/templates/autocomplete_textview/MainActivity.kt +40 -0
  26. package/templates/autocomplete_textview/activity_main.xml +34 -0
  27. package/templates/canvas/MainActivity.kt +54 -0
  28. package/templates/canvas/activity_main.xml +19 -0
  29. package/templates/canvas/example2.kt +13 -0
  30. package/templates/checkbox/MainActivity.kt +56 -0
  31. package/templates/checkbox/activity_main.xml +67 -0
  32. package/templates/custom_checkbox/MainActivity.kt +32 -0
  33. package/templates/custom_checkbox/activity_main.xml +43 -0
  34. package/templates/custom_toast/MainActivity.kt +23 -0
  35. package/templates/custom_toast/activity_main.xml +22 -0
  36. package/templates/custom_toast/customtoast.xml +20 -0
  37. package/templates/database/MainActivity.kt +64 -0
  38. package/templates/database/activity_main.xml +77 -0
  39. package/templates/database/dbController.kt +56 -0
  40. package/templates/datepicker_and_timepicker/datepicker/MainActivity.kt +34 -0
  41. package/templates/datepicker_and_timepicker/datepicker/activity_main.xml +24 -0
  42. package/templates/datepicker_and_timepicker/timepicker/MainActivity.kt +37 -0
  43. package/templates/datepicker_and_timepicker/timepicker/activity_main.xml +15 -0
  44. package/templates/explicit_and_implicit_intents/example 1/MainActivity.kt +36 -0
  45. package/templates/explicit_and_implicit_intents/example 1/SecondActivity.kt +12 -0
  46. package/templates/explicit_and_implicit_intents/example 1/activity_main.xml +33 -0
  47. package/templates/explicit_and_implicit_intents/example 1/activity_second.xml +20 -0
  48. package/templates/explicit_and_implicit_intents/example 2/MainActivity.kt +37 -0
  49. package/templates/explicit_and_implicit_intents/example 2/MainActivity2.kt +23 -0
  50. package/templates/explicit_and_implicit_intents/example 2/activity_main.xml +38 -0
  51. package/templates/explicit_and_implicit_intents/example 2/activity_second.xml +18 -0
  52. package/templates/image_view_listener/MainActivity.kt +38 -0
  53. package/templates/image_view_listener/activity_main.xml +89 -0
  54. package/templates/menu/context menu/MainActivity.kt +50 -0
  55. package/templates/menu/context menu/activity_main.xml +18 -0
  56. package/templates/menu/context menu/menu_main.xml +34 -0
  57. package/templates/menu/options menu/MainActivity.kt +52 -0
  58. package/templates/menu/options menu/activity_main.xml +9 -0
  59. package/templates/menu/options menu/menu_main.xml +81 -0
  60. package/templates/menu/popup menu/MainActivity.kt +58 -0
  61. package/templates/menu/popup menu/activity_main.xml +20 -0
  62. package/templates/menu/popup menu/menu_main.xml +39 -0
  63. package/templates/progressbar/MainActivity.kt +60 -0
  64. package/templates/progressbar/activity_main.xml +47 -0
  65. package/templates/radio_button/MainActivity.kt +46 -0
  66. package/templates/radio_button/activity_main.xml +86 -0
  67. package/templates/sharedpreferences/example1/MainActivity.kt +54 -0
  68. package/templates/sharedpreferences/example1/activity_main.xml +69 -0
  69. package/templates/sharedpreferences/example2/MainActivity.kt +45 -0
  70. package/templates/sharedpreferences/example2/activity_main.xml +48 -0
  71. package/templates/spinner/MainActivity.kt +54 -0
  72. package/templates/spinner/activity_main.xml +37 -0
  73. package/templates/spinner/strings.xml +13 -0
  74. package/templates/toggle_button/MainActivity.kt +39 -0
  75. package/templates/toggle_button/activity_main.xml +50 -0
@@ -0,0 +1,50 @@
1
+ package com.example.contextmenu
2
+
3
+ import android.support.v7.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.view.ContextMenu
6
+ import android.view.MenuItem
7
+ import android.view.View
8
+ import android.widget.Button
9
+ import android.widget.Toast
10
+
11
+ class MainActivity : AppCompatActivity() {
12
+
13
+ override fun onCreate(savedInstanceState: Bundle?) {
14
+ super.onCreate(savedInstanceState)
15
+ setContentView(R.layout.activity_main)
16
+
17
+ val B1 = findViewById<Button>(R.id.B1)
18
+
19
+ registerForContextMenu(B1)
20
+
21
+ B1.setOnClickListener { v ->
22
+ openContextMenu(v)
23
+ }
24
+ }
25
+
26
+ override fun onCreateContextMenu(
27
+ menu: ContextMenu?,
28
+ v: View?,
29
+ menuInfo: ContextMenu.ContextMenuInfo?
30
+ ) {
31
+ super.onCreateContextMenu(menu, v, menuInfo)
32
+ menuInflater.inflate(R.menu.menu, menu)
33
+ }
34
+
35
+ override fun onContextItemSelected(item: MenuItem): Boolean {
36
+ when (item.itemId) {
37
+
38
+ R.id.item1 ->
39
+ Toast.makeText(this, "Open Selected", Toast.LENGTH_SHORT).show()
40
+
41
+ R.id.item2 ->
42
+ Toast.makeText(this, "Search Selected", Toast.LENGTH_SHORT).show()
43
+
44
+ R.id.item3 ->
45
+ Toast.makeText(this, "Exit Selected", Toast.LENGTH_SHORT).show()
46
+ }
47
+
48
+ return super.onContextItemSelected(item)
49
+ }
50
+ }
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <android.support.constraint.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
+ tools:context=".MainActivity">
9
+ <Button
10
+ android:id="@+id/B1"
11
+ android:layout_width="wrap_content"
12
+ android:layout_height="wrap_content"
13
+ android:text="Context Menu"
14
+ app:layout_constraintBottom_toBottomOf="parent"
15
+ app:layout_constraintEnd_toEndOf="parent"
16
+ app:layout_constraintStart_toStartOf="parent"
17
+ app:layout_constraintTop_toTopOf="parent" />
18
+ </android.support.constraint.ConstraintLayout>
@@ -0,0 +1,34 @@
1
+ <!--
2
+ Create a Menu XML File
3
+
4
+ 1. In Android Studio, go to:
5
+ res > menu
6
+
7
+ 2. If the menu folder doesn't exist:
8
+ Right-click res → New → Android Resource Directory
9
+ → Select Resource type = menu
10
+
11
+ 3. Create menu file:
12
+ Right-click menu → New → Menu Resource File
13
+ → Name it menu_main.xml
14
+
15
+ 4. Add menu items inside <menu> tag
16
+
17
+ -->
18
+
19
+ <?xml version="1.0" encoding="utf-8"?>
20
+ <menu xmlns:android="http://schemas.android.com/apk/res/android"
21
+ xmlns:app="http://schemas.android.com/apk/res-auto">
22
+ <item android:id="@+id/item1"
23
+ android:title="Open"
24
+ app:showAsAction="never"
25
+ />
26
+ <item android:id="@+id/item2"
27
+ android:title="Search"
28
+ app:showAsAction="never"
29
+ />
30
+ <item android:id="@+id/item3"
31
+ android:title="Exit"
32
+ app:showAsAction="never"
33
+ />
34
+ </menu>
@@ -0,0 +1,52 @@
1
+ package com.example.menu
2
+
3
+ import android.support.v7.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.view.Menu
6
+ import android.view.MenuItem
7
+ import android.widget.Toast
8
+
9
+ class MainActivity : AppCompatActivity() {
10
+
11
+ override fun onCreate(savedInstanceState: Bundle?) {
12
+
13
+ super.onCreate(savedInstanceState)
14
+ setContentView(R.layout.activity_main)
15
+ }
16
+
17
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
18
+
19
+ menuInflater.inflate(R.menu.option_menu, menu)
20
+
21
+ return super.onCreateOptionsMenu(menu)
22
+ }
23
+
24
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
25
+
26
+ when (item.itemId) {
27
+
28
+ R.id.about ->
29
+ Toast.makeText(
30
+ this,
31
+ "About Selected",
32
+ Toast.LENGTH_SHORT
33
+ ).show()
34
+
35
+ R.id.settings ->
36
+ Toast.makeText(
37
+ this,
38
+ "Settings Selected",
39
+ Toast.LENGTH_SHORT
40
+ ).show()
41
+
42
+ R.id.exit ->
43
+ Toast.makeText(
44
+ this,
45
+ "Exit Selected",
46
+ Toast.LENGTH_SHORT
47
+ ).show()
48
+ }
49
+
50
+ return super.onOptionsItemSelected(item)
51
+ }
52
+ }
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <android.support.constraint.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
+ tools:context=".MainActivity">
9
+ </android.support.constraint.ConstraintLayout>
@@ -0,0 +1,81 @@
1
+ <!--
2
+ Create a Menu XML File
3
+
4
+ 1. In Android Studio, go to:
5
+ res > menu
6
+
7
+ 2. If the menu folder doesn't exist:
8
+ Right-click res → New → Android Resource Directory
9
+ → Select Resource type = menu
10
+
11
+ 3. Create menu file:
12
+ Right-click menu → New → Menu Resource File
13
+ → Name it menu_main.xml
14
+
15
+ 4. Add menu items inside <menu> tag
16
+
17
+
18
+ Create Drawable Icons (Vector Assets)
19
+
20
+ 1. Go to:
21
+ res → drawable
22
+
23
+ 2. Right-click → New → Vector Asset
24
+
25
+ 3. Click "Clip Art" and search:
26
+ - settings
27
+ - label
28
+ - exit_to_app
29
+
30
+ 4. Select icon → Next
31
+
32
+ 5. Set file names EXACTLY:
33
+ - ic_baseline_settings_24
34
+ - ic_baseline_label_24
35
+ - ic_baseline_exit_to_app_24
36
+
37
+ 6. Click Finish
38
+
39
+ These will create XML vector drawable files inside res/drawable.
40
+
41
+ NOTE:
42
+ These drawable files are required because menu items use icons:
43
+ android:icon="@drawable/..."
44
+ -->
45
+
46
+ <?xml version="1.0" encoding="utf-8"?>
47
+ <menu
48
+ xmlns:android="http://schemas.android.com/apk/res/android"
49
+ xmlns:app="http://schemas.android.com/apk/res-auto">
50
+
51
+ <item
52
+ android:id="@+id/overflowMenu"
53
+ android:icon="@drawable/ic_baseline_unfold_less_double_24"
54
+ android:title=""
55
+ app:showAsAction="always">
56
+
57
+ <menu>
58
+
59
+ <item
60
+ android:id="@+id/settings"
61
+ android:icon="@drawable/ic_baseline_settings_24"
62
+ android:title="SETTINGS"
63
+ app:showAsAction="never" />
64
+
65
+ <item
66
+ android:id="@+id/about"
67
+ android:icon="@drawable/ic_baseline_label_24"
68
+ android:title="ABOUT"
69
+ app:showAsAction="never" />
70
+
71
+ <item
72
+ android:id="@+id/exit"
73
+ android:icon="@drawable/ic_baseline_exit_to_app_24"
74
+ android:title="EXIT"
75
+ app:showAsAction="never" />
76
+
77
+ </menu>
78
+
79
+ </item>
80
+
81
+ </menu>
@@ -0,0 +1,58 @@
1
+ package com.example.popmenu
2
+
3
+ import android.support.v7.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.widget.Button
6
+ import android.widget.PopupMenu
7
+ import android.widget.Toast
8
+
9
+ class MainActivity : AppCompatActivity() {
10
+
11
+ override fun onCreate(savedInstanceState: Bundle?) {
12
+ super.onCreate(savedInstanceState)
13
+ setContentView(R.layout.activity_main)
14
+
15
+ val B1 = findViewById<Button>(R.id.B1)
16
+
17
+ B1.setOnClickListener {
18
+
19
+ val popupMenu: PopupMenu = PopupMenu(this, B1)
20
+
21
+ popupMenu.menuInflater.inflate(
22
+ R.menu.menu,
23
+ popupMenu.menu
24
+ )
25
+
26
+ popupMenu.setOnMenuItemClickListener { item ->
27
+
28
+ when (item.itemId) {
29
+
30
+ R.id.item1 ->
31
+ Toast.makeText(
32
+ this@MainActivity,
33
+ "You Clicked : " + item.title,
34
+ Toast.LENGTH_SHORT
35
+ ).show()
36
+
37
+ R.id.item2 ->
38
+ Toast.makeText(
39
+ this@MainActivity,
40
+ "You Clicked : " + item.title,
41
+ Toast.LENGTH_SHORT
42
+ ).show()
43
+
44
+ R.id.item3 ->
45
+ Toast.makeText(
46
+ this@MainActivity,
47
+ "You Clicked : " + item.title,
48
+ Toast.LENGTH_SHORT
49
+ ).show()
50
+ }
51
+
52
+ true
53
+ }
54
+
55
+ popupMenu.show()
56
+ }
57
+ }
58
+ }
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <android.support.constraint.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
+ tools:context=".MainActivity">
9
+
10
+ <Button
11
+ android:id="@+id/B1"
12
+ android:layout_width="wrap_content"
13
+ android:layout_height="wrap_content"
14
+ android:text="Popup menu"
15
+ app:layout_constraintTop_toTopOf="parent"
16
+ app:layout_constraintBottom_toBottomOf="parent"
17
+ app:layout_constraintStart_toStartOf="parent"
18
+ app:layout_constraintEnd_toEndOf="parent" />
19
+
20
+ </android.support.constraint.ConstraintLayout>
@@ -0,0 +1,39 @@
1
+ <!--
2
+ Create a Menu XML File
3
+
4
+ 1. In Android Studio, go to:
5
+ res > menu
6
+
7
+ 2. If the menu folder doesn't exist:
8
+ Right-click res → New → Android Resource Directory
9
+ → Select Resource type = menu
10
+
11
+ 3. Create menu file:
12
+ Right-click menu → New → Menu Resource File
13
+ → Name it menu_main.xml
14
+
15
+ 4. Add menu items inside <menu> tag
16
+
17
+ -->
18
+
19
+ <?xml version="1.0" encoding="utf-8"?>
20
+ <menu
21
+ xmlns:android="http://schemas.android.com/apk/res/android"
22
+ xmlns:app="http://schemas.android.com/apk/res-auto">
23
+
24
+ <item
25
+ android:id="@+id/item1"
26
+ android:title="Open"
27
+ app:showAsAction="never" />
28
+
29
+ <item
30
+ android:id="@+id/item2"
31
+ android:title="Search"
32
+ app:showAsAction="never" />
33
+
34
+ <item
35
+ android:id="@+id/item3"
36
+ android:title="Exit"
37
+ app:showAsAction="never" />
38
+
39
+ </menu>
@@ -0,0 +1,60 @@
1
+ package com.example.progressbar1
2
+
3
+ import android.support.v7.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.os.Handler
6
+ import android.view.View
7
+ import android.widget.Button
8
+ import android.widget.ProgressBar
9
+ import android.widget.TextView
10
+
11
+ class MainActivity : AppCompatActivity() {
12
+
13
+ private var progressBar: ProgressBar? = null
14
+ private var i = 0
15
+ private var txtView: TextView? = null
16
+ private val handler = Handler()
17
+
18
+ override fun onCreate(savedInstanceState: Bundle?) {
19
+ super.onCreate(savedInstanceState)
20
+ setContentView(R.layout.activity_main)
21
+
22
+ // finding progressbar by its id
23
+ progressBar = findViewById<ProgressBar>(R.id.progress_Bar) as ProgressBar
24
+
25
+ // finding textview by its id
26
+ txtView = findViewById<TextView>(R.id.text_view)
27
+
28
+ // finding button by its id
29
+ val btn = findViewById<Button>(R.id.show_button)
30
+
31
+ // handling click on button
32
+ btn.setOnClickListener {
33
+
34
+ // making progress bar visible
35
+ progressBar!!.visibility = View.VISIBLE
36
+ i = progressBar!!.progress
37
+
38
+ Thread(Runnable {
39
+
40
+ while (i < 100) {
41
+ i += 1
42
+
43
+ handler.post(Runnable {
44
+ progressBar!!.progress = i
45
+ txtView!!.text = i.toString() + "/" + progressBar!!.max
46
+ })
47
+
48
+ try {
49
+ Thread.sleep(100)
50
+ } catch (e: InterruptedException) {
51
+ e.printStackTrace()
52
+ }
53
+ }
54
+
55
+ progressBar!!.visibility = View.INVISIBLE
56
+
57
+ }).start()
58
+ }
59
+ }
60
+ }
@@ -0,0 +1,47 @@
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
+ tools:context=".MainActivity">
9
+
10
+ <!-- Progress Bar -->
11
+ <ProgressBar
12
+ android:id="@+id/progress_Bar"
13
+ style="?android:attr/progressBarStyle"
14
+ android:layout_width="200dp"
15
+ android:layout_height="wrap_content"
16
+ android:indeterminate="true"
17
+ android:max="100"
18
+ android:minWidth="200dp"
19
+ android:minHeight="50dp"
20
+ android:visibility="invisible"
21
+ android:progress="0"
22
+ app:layout_constraintTop_toTopOf="parent"
23
+ app:layout_constraintBottom_toTopOf="@id/text_view"
24
+ app:layout_constraintStart_toStartOf="parent"
25
+ app:layout_constraintEnd_toEndOf="parent" />
26
+
27
+ <!-- TextView -->
28
+ <TextView
29
+ android:id="@+id/text_view"
30
+ android:layout_width="wrap_content"
31
+ android:layout_height="wrap_content"
32
+ app:layout_constraintTop_toBottomOf="@id/progress_Bar"
33
+ app:layout_constraintStart_toStartOf="parent"
34
+ app:layout_constraintEnd_toEndOf="parent" />
35
+
36
+ <!-- Button -->
37
+ <Button
38
+ android:id="@+id/show_button"
39
+ android:layout_width="191dp"
40
+ android:layout_height="wrap_content"
41
+ android:layout_marginTop="20dp"
42
+ android:text="Progress Bar"
43
+ app:layout_constraintTop_toBottomOf="@id/text_view"
44
+ app:layout_constraintStart_toStartOf="parent"
45
+ app:layout_constraintEnd_toEndOf="parent" />
46
+
47
+ </androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1,46 @@
1
+ package com.example.radiobutton
2
+
3
+ import androidx.appcompat.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.widget.Button
6
+ import android.widget.RadioButton
7
+ import android.widget.RadioGroup
8
+ import android.widget.Toast
9
+
10
+ class MainActivity : AppCompatActivity() {
11
+
12
+ var radioGroup: RadioGroup? = null
13
+ private lateinit var radioButton: RadioButton
14
+ private lateinit var button: Button
15
+
16
+ override fun onCreate(savedInstanceState: Bundle?) {
17
+ super.onCreate(savedInstanceState)
18
+ setContentView(R.layout.activity_main)
19
+
20
+ // Display name of the application
21
+ title = "RadioGroup in Kotlin"
22
+
23
+ // Assigning id of RadioGroup
24
+ radioGroup = findViewById(R.id.radioGroup1)
25
+
26
+ // Assigning id of Submit button
27
+ button = findViewById(R.id.submitButton)
28
+
29
+ // Actions to be performed when Submit button is clicked
30
+ button.setOnClickListener {
31
+
32
+ // Getting the checked radio button id from the radio group
33
+ val selectedOption: Int = radioGroup!!.checkedRadioButtonId
34
+
35
+ // Assigning id of the checked radio button
36
+ radioButton = findViewById(selectedOption)
37
+
38
+ // Displaying text of the checked radio button in the form of toast
39
+ Toast.makeText(
40
+ baseContext,
41
+ radioButton.text,
42
+ Toast.LENGTH_SHORT
43
+ ).show()
44
+ }
45
+ }
46
+ }
@@ -0,0 +1,86 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+
3
+ <androidx.constraintlayout.widget.ConstraintLayout
4
+ xmlns:android="http://schemas.android.com/apk/res/android"
5
+ xmlns:app="http://schemas.android.com/apk/res-auto"
6
+ xmlns:tools="http://schemas.android.com/tools"
7
+ android:layout_width="match_parent"
8
+ android:layout_height="match_parent"
9
+ tools:context=".MainActivity">
10
+
11
+ <TextView
12
+ android:id="@+id/textView"
13
+ android:layout_width="wrap_content"
14
+ android:layout_height="wrap_content"
15
+ android:text="Choose a course"
16
+ android:textAlignment="center"
17
+ android:textColor="@android:color/holo_green_dark"
18
+ android:textSize="36sp"
19
+ android:textStyle="bold"
20
+ app:layout_constraintBottom_toBottomOf="parent"
21
+ app:layout_constraintEnd_toEndOf="parent"
22
+ app:layout_constraintStart_toStartOf="parent"
23
+ app:layout_constraintTop_toTopOf="parent"
24
+ app:layout_constraintVertical_bias="0.19" />
25
+
26
+ <RadioGroup
27
+ android:id="@+id/radioGroup1"
28
+ android:layout_width="0dp"
29
+ android:layout_height="wrap_content"
30
+ android:background="#024CAF50"
31
+ app:layout_constraintBottom_toBottomOf="parent"
32
+ app:layout_constraintEnd_toEndOf="parent"
33
+ app:layout_constraintStart_toStartOf="parent"
34
+ app:layout_constraintTop_toBottomOf="@id/textView"
35
+ app:layout_constraintVertical_bias="0.24000001">
36
+
37
+ <RadioButton
38
+ android:id="@+id/radioButton1"
39
+ android:layout_width="match_parent"
40
+ android:layout_height="wrap_content"
41
+ android:text="Data Mining"
42
+ android:textSize="24sp" />
43
+
44
+ <RadioButton
45
+ android:id="@+id/radioButton2"
46
+ android:layout_width="match_parent"
47
+ android:layout_height="wrap_content"
48
+ android:text="Cloud Computing"
49
+ android:textSize="24sp" />
50
+
51
+ <RadioButton
52
+ android:id="@+id/radioButton3"
53
+ android:layout_width="match_parent"
54
+ android:layout_height="wrap_content"
55
+ android:text="Computer Networks - 1"
56
+ android:textSize="24sp" />
57
+
58
+ <RadioButton
59
+ android:id="@+id/radioButton4"
60
+ android:layout_width="match_parent"
61
+ android:layout_height="wrap_content"
62
+ android:text="Software Engineering Object-Oriented Modelling Designs"
63
+ android:textSize="24sp" />
64
+
65
+ <RadioButton
66
+ android:id="@+id/radioButton5"
67
+ android:layout_width="match_parent"
68
+ android:layout_height="wrap_content"
69
+ android:text="Mobile Application Development"
70
+ android:textSize="24sp" />
71
+
72
+ </RadioGroup>
73
+
74
+ <Button
75
+ android:id="@+id/submitButton"
76
+ android:layout_width="wrap_content"
77
+ android:layout_height="wrap_content"
78
+ android:background="#AB4CAF50"
79
+ android:text="Submit"
80
+ app:layout_constraintBottom_toBottomOf="parent"
81
+ app:layout_constraintEnd_toEndOf="parent"
82
+ app:layout_constraintStart_toStartOf="parent"
83
+ app:layout_constraintTop_toBottomOf="@id/radioGroup1"
84
+ app:layout_constraintVertical_bias="0.17000002" />
85
+
86
+ </androidx.constraintlayout.widget.ConstraintLayout>
@@ -0,0 +1,54 @@
1
+ package com.example.shared_preferences
2
+
3
+ import android.content.Context
4
+ import android.support.v7.app.AppCompatActivity
5
+ import android.os.Bundle
6
+ import android.widget.Button
7
+ import android.widget.EditText
8
+ import android.widget.Toast
9
+
10
+ class MainActivity : AppCompatActivity() {
11
+
12
+ override fun onCreate(savedInstanceState: Bundle?) {
13
+ super.onCreate(savedInstanceState)
14
+ setContentView(R.layout.activity_main)
15
+
16
+ val name = findViewById<EditText>(R.id.ed1)
17
+ val password = findViewById<EditText>(R.id.ed2)
18
+
19
+ val save = findViewById<Button>(R.id.b1)
20
+ val load = findViewById<Button>(R.id.b2)
21
+ val del = findViewById<Button>(R.id.b4)
22
+
23
+ val sharedPref = getSharedPreferences(
24
+ "addName",
25
+ Context.MODE_PRIVATE
26
+ ) // instantiate shared preferences
27
+
28
+ val edit = sharedPref.edit()
29
+
30
+ save.setOnClickListener {
31
+ edit.putString("name", name.text.toString())
32
+ edit.putString("password", password.text.toString())
33
+ edit.commit()
34
+
35
+ Toast.makeText(this, "Data Saved", Toast.LENGTH_LONG).show()
36
+ }
37
+
38
+ load.setOnClickListener {
39
+ val getname = sharedPref.getString("name", "default value")
40
+ val getpass = sharedPref.getString("password", "default value")
41
+
42
+ Toast.makeText(
43
+ this,
44
+ getname + " " + getpass,
45
+ Toast.LENGTH_LONG
46
+ ).show()
47
+ }
48
+
49
+ del.setOnClickListener {
50
+ edit.clear()
51
+ edit.commit()
52
+ }
53
+ }
54
+ }