androidd 0.0.1__py3-none-any.whl → 0.0.2__py3-none-any.whl

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 (97) hide show
  1. androidd/__init__.py +1 -0
  2. androidd/cie1/activityCycle/MainActivity.kt +44 -0
  3. androidd/cie1/activityCycle/activity_main.xml +15 -0
  4. androidd/cie1/alert/MainActivity.kt +28 -0
  5. androidd/cie1/alert/activity_main.xml +14 -0
  6. androidd/cie1/autoCompleteText/MainActivity.kt +19 -0
  7. androidd/cie1/autoCompleteText/activity_main.xml +14 -0
  8. androidd/cie1/checkbox/MainActivity.kt +28 -0
  9. androidd/cie1/checkbox/activity_main.xml +32 -0
  10. androidd/cie1/customCheckbox/MainActivity.kt +20 -0
  11. androidd/cie1/customCheckbox/activity_main.xml +22 -0
  12. androidd/cie1/customCheckbox/custom_checkbox.xml +9 -0
  13. androidd/cie1/customRadio/MainActivity.kt +22 -0
  14. androidd/cie1/customRadio/activity_main.xml +28 -0
  15. androidd/cie1/customRadio/custom_checkbox.xml +9 -0
  16. androidd/cie1/customToast/MainActivity.kt +35 -0
  17. androidd/cie1/customToast/activity_main.xml +14 -0
  18. androidd/cie1/customToast/custom_toast.xml +23 -0
  19. androidd/cie1/datepicker/MainActivity.kt +31 -0
  20. androidd/cie1/datepicker/activity_main.xml +20 -0
  21. androidd/cie1/progressbar/MainActivity.kt +26 -0
  22. androidd/cie1/progressbar/activity_main.xml +21 -0
  23. androidd/cie1/radiobutton/MainActivity.kt +25 -0
  24. androidd/cie1/radiobutton/activity_main.xml +38 -0
  25. androidd/cie1/timePicker/MainActivity.kt +30 -0
  26. androidd/cie1/timePicker/activity_main.xml +20 -0
  27. androidd/cie1/toast/MainActivity.kt +18 -0
  28. androidd/cie1/toast/activity_main.xml +14 -0
  29. androidd/cie1/toggle/MainActivity.kt +20 -0
  30. androidd/cie1/toggle/activity_main.xml +23 -0
  31. androidd/madbmsj/IMPLICIT and EXPLICIT/Main Activity.kt +31 -0
  32. androidd/madbmsj/IMPLICIT and EXPLICIT/activity_main.xml +33 -0
  33. androidd/madbmsj/IMPLICIT and EXPLICIT/second.xml +16 -0
  34. androidd/madbmsj/IMPLICIT and EXPLICIT/secondactivity.kt +15 -0
  35. androidd/madbmsj/animation/MainActivity.kt +60 -0
  36. androidd/madbmsj/animation/activity_main.xml +122 -0
  37. androidd/madbmsj/animation/bounce.xml +17 -0
  38. androidd/madbmsj/animation/fad_in.xml +7 -0
  39. androidd/madbmsj/animation/fade_out.xml +8 -0
  40. androidd/madbmsj/animation/info.txt +2 -0
  41. androidd/madbmsj/animation/slide_down.xml +7 -0
  42. androidd/madbmsj/animation/slide_up.xml +7 -0
  43. androidd/madbmsj/animation/zoom_in.xml +11 -0
  44. androidd/madbmsj/animation/zoom_out.xml +11 -0
  45. androidd/madbmsj/canvas/MainActivity.kt +51 -0
  46. androidd/madbmsj/canvas/activity_main.xml +18 -0
  47. androidd/madbmsj/cie1/code.txt +719 -0
  48. androidd/madbmsj/cie1/sampleQuestion.txt +280 -0
  49. androidd/madbmsj/cie2/code.txt +1255 -0
  50. androidd/madbmsj/cie2/ques1/AndroidManifest.xml +2 -0
  51. androidd/madbmsj/cie2/ques1/MainActivity.kt +45 -0
  52. androidd/madbmsj/cie2/ques1/SecondActivity.kt +21 -0
  53. androidd/madbmsj/cie2/ques1/activity_main.xml +19 -0
  54. androidd/madbmsj/cie2/ques1/activity_second.xml +15 -0
  55. androidd/madbmsj/cie2/ques1/department_menu.xml +11 -0
  56. androidd/madbmsj/contextMenu/MainActivity.kt +37 -0
  57. androidd/madbmsj/contextMenu/activity_main.xml +19 -0
  58. androidd/madbmsj/contextMenu/info.txt +1 -0
  59. androidd/madbmsj/contextMenu/menu_main.xml +16 -0
  60. androidd/madbmsj/database/DatabaseHelper.kt +108 -0
  61. androidd/madbmsj/database/MainActivity.kt +151 -0
  62. androidd/madbmsj/database/activity_main.xml +55 -0
  63. androidd/madbmsj/database/dialog_update_student.xml +22 -0
  64. androidd/madbmsj/database/info.txt +4 -0
  65. androidd/madbmsj/datePicker/MainActivity.kt +23 -0
  66. androidd/madbmsj/datePicker/activity_main.xml +20 -0
  67. androidd/madbmsj/explicit/activity_main.xml +39 -0
  68. androidd/madbmsj/explicit/activity_second.xml +15 -0
  69. androidd/madbmsj/explicit/info.txt +6 -0
  70. androidd/madbmsj/explicit/mainactivity.kt +32 -0
  71. androidd/madbmsj/explicit/secondactivity.kt +27 -0
  72. androidd/madbmsj/fragment/MainActivity.kt +35 -0
  73. androidd/madbmsj/fragment/activity_main.xml +41 -0
  74. androidd/madbmsj/fragment/fragment_1.kt +24 -0
  75. androidd/madbmsj/fragment/fragment_1.xml +16 -0
  76. androidd/madbmsj/fragment/fragment_2.kt +17 -0
  77. androidd/madbmsj/fragment/fragnent_2.xml +16 -0
  78. androidd/madbmsj/fragment/info.txt +1 -0
  79. androidd/madbmsj/optionsMenu/MainActivity.kt +26 -0
  80. androidd/madbmsj/optionsMenu/activity_main.xml +18 -0
  81. androidd/madbmsj/optionsMenu/info.txt +1 -0
  82. androidd/madbmsj/optionsMenu/menu_main.xml +27 -0
  83. androidd/madbmsj/package.json +13 -0
  84. androidd/madbmsj/popMenu/MainActivity.kt +49 -0
  85. androidd/madbmsj/popMenu/activity_main.xml +19 -0
  86. androidd/madbmsj/popMenu/info.txt +1 -0
  87. androidd/madbmsj/popMenu/menu_main.xml +16 -0
  88. androidd/madbmsj/sharedpref/shared1/activity_main.xml +64 -0
  89. androidd/madbmsj/sharedpref/shared1/mainactivity.kt +47 -0
  90. androidd/madbmsj/sharedpref/shared2/activity_main.xml +44 -0
  91. androidd/madbmsj/sharedpref/shared2/mainactivity.kt +57 -0
  92. {androidd-0.0.1.dist-info → androidd-0.0.2.dist-info}/METADATA +1 -1
  93. androidd-0.0.2.dist-info/RECORD +95 -0
  94. androidd-0.0.2.dist-info/top_level.txt +1 -0
  95. androidd-0.0.1.dist-info/RECORD +0 -4
  96. androidd-0.0.1.dist-info/top_level.txt +0 -1
  97. {androidd-0.0.1.dist-info → androidd-0.0.2.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1255 @@
1
+ package com.example.a8_datepicker_timepicker
2
+
3
+ import android.support.v7.app.AppCompatActivity
4
+ import android.os.Bundle
5
+ import android.app.DatePickerDialog
6
+ import android.app.TimePickerDialog
7
+ import android.widget.*
8
+ import java.util.*
9
+
10
+ class MainActivity : AppCompatActivity() {
11
+ private lateinit var tvDate: TextView
12
+ private lateinit var tvTime: TextView
13
+ override fun onCreate(savedInstanceState: Bundle?) {
14
+ super.onCreate(savedInstanceState)
15
+ setContentView(R.layout.activity_main)
16
+ val btnDatePicker: Button = findViewById(R.id.btnDatePicker)
17
+ val btnTimePicker: Button = findViewById(R.id.btnTimePicker)
18
+ tvDate = findViewById(R.id.tvDate)
19
+ tvTime = findViewById(R.id.tvTime)
20
+
21
+ btnDatePicker.setOnClickListener {
22
+ showDatePicker()
23
+ }
24
+
25
+ btnTimePicker.setOnClickListener {
26
+ showTimePicker()
27
+ }
28
+ }
29
+
30
+ private fun showDatePicker() {
31
+ val calendar = Calendar.getInstance()
32
+ val year = calendar.get(Calendar.YEAR)
33
+ val month = calendar.get(Calendar.MONTH)
34
+ val day = calendar.get(Calendar.DAY_OF_MONTH)
35
+
36
+ val datePickerDialog = DatePickerDialog(this,
37
+ { _, selectedYear, selectedMonth, selectedDay ->
38
+ tvDate.text = "Selected Date: $selectedDay/${selectedMonth + 1}/$selectedYear"
39
+ }, year, month, day)
40
+
41
+ datePickerDialog.show()
42
+ }
43
+
44
+ private fun showTimePicker() {
45
+ val calendar = Calendar.getInstance()
46
+ val hour = calendar.get(Calendar.HOUR_OF_DAY)
47
+ val minute = calendar.get(Calendar.MINUTE)
48
+
49
+ val timePickerDialog = TimePickerDialog(this,
50
+ { _, selectedHour, selectedMinute ->
51
+ tvTime.text = "Selected Time: %02d:%02d".format(selectedHour, selectedMinute)
52
+ }, hour, minute, true)
53
+
54
+ timePickerDialog.show()
55
+ }
56
+ }
57
+
58
+
59
+
60
+ <?xml version="1.0" encoding="utf-8"?>
61
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
62
+ android:layout_width="match_parent"
63
+ android:layout_height="match_parent"
64
+ android:orientation="vertical"
65
+ android:padding="24dp"
66
+ android:gravity="center">
67
+
68
+ <Button
69
+ android:id="@+id/btnDatePicker"
70
+ android:layout_width="match_parent"
71
+ android:layout_height="wrap_content"
72
+ android:text="Pick Date" />
73
+
74
+ <TextView
75
+ android:id="@+id/tvDate"
76
+ android:layout_width="wrap_content"
77
+ android:layout_height="wrap_content"
78
+ android:text="Selected Date"
79
+ android:textSize="18sp"
80
+ android:padding="10dp" />
81
+
82
+ <Button
83
+ android:id="@+id/btnTimePicker"
84
+ android:layout_width="match_parent"
85
+ android:layout_height="wrap_content"
86
+ android:text="Pick Time"
87
+ android:layout_marginTop="20dp" />
88
+
89
+ <TextView
90
+ android:id="@+id/tvTime"
91
+ android:layout_width="wrap_content"
92
+ android:layout_height="wrap_content"
93
+ android:text="Selected Time"
94
+ android:textSize="18sp"
95
+ android:padding="10dp" />
96
+ </LinearLayout>
97
+
98
+ package com.example.a9_togglebutton
99
+
100
+ import android.support.v7.app.AppCompatActivity
101
+ import android.os.Bundle
102
+ import android.widget.*
103
+
104
+ class MainActivity : AppCompatActivity() {
105
+
106
+ private lateinit var toggleButton: ToggleButton
107
+ private lateinit var tvToggleStatus: TextView
108
+
109
+ override fun onCreate(savedInstanceState: Bundle?) {
110
+ super.onCreate(savedInstanceState)
111
+ setContentView(R.layout.activity_main)
112
+
113
+ toggleButton = findViewById(R.id.toggleButton)
114
+ tvToggleStatus = findViewById(R.id.tvToggleStatus)
115
+
116
+ toggleButton.setOnCheckedChangeListener { _, isChecked ->
117
+ if (isChecked) {
118
+ tvToggleStatus.text = "Toggle is ON"
119
+ } else {
120
+ tvToggleStatus.text = "Toggle is OFF"
121
+ }
122
+ }
123
+ }
124
+ }
125
+
126
+
127
+
128
+
129
+ <?xml version="1.0" encoding="utf-8"?>
130
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
131
+ android:layout_width="match_parent"
132
+ android:layout_height="match_parent"
133
+ android:orientation="vertical"
134
+ android:padding="24dp"
135
+ android:gravity="center">
136
+
137
+ <ToggleButton
138
+ android:id="@+id/toggleButton"
139
+ android:layout_width="wrap_content"
140
+ android:layout_height="wrap_content"
141
+ android:textOn="Toggle ON"
142
+ android:textOff="Toggle OFF" />
143
+
144
+ <TextView
145
+ android:id="@+id/tvToggleStatus"
146
+ android:layout_width="wrap_content"
147
+ android:layout_height="wrap_content"
148
+ android:text="Toggle is OFF"
149
+ android:textSize="18sp"
150
+ android:padding="16dp" />
151
+ </LinearLayout>
152
+
153
+ package com.example.a10_custom_toast
154
+
155
+ import android.support.v7.app.AppCompatActivity
156
+ import android.os.Bundle
157
+ import android.view.*
158
+ import android.widget.*
159
+
160
+ class MainActivity : AppCompatActivity() {
161
+ override fun onCreate(savedInstanceState: Bundle?) {
162
+ super.onCreate(savedInstanceState)
163
+ setContentView(R.layout.activity_main)
164
+
165
+ val btnShowToast: Button = findViewById(R.id.btnShowToast)
166
+
167
+ btnShowToast.setOnClickListener {
168
+ showCustomToast("Custom Toast Example!")
169
+ }
170
+ }
171
+
172
+ private fun showCustomToast(message: String) {
173
+ val inflater: LayoutInflater = layoutInflater
174
+ val layout: View = inflater.inflate(R.layout.custom_toast, null)
175
+
176
+ val toastText: TextView = layout.findViewById(R.id.toastText)
177
+ toastText.text = message
178
+
179
+ val toast = Toast(applicationContext)
180
+ toast.duration = Toast.LENGTH_SHORT
181
+ toast.view = layout
182
+ toast.show()
183
+ }
184
+ }
185
+
186
+
187
+
188
+
189
+ <?xml version="1.0" encoding="utf-8"?>
190
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
191
+ android:layout_width="match_parent"
192
+ android:layout_height="match_parent"
193
+ android:orientation="vertical"
194
+ android:padding="24dp"
195
+ android:gravity="center">
196
+
197
+ <Button
198
+ android:id="@+id/btnShowToast"
199
+ android:layout_width="wrap_content"
200
+ android:layout_height="wrap_content"
201
+ android:text="Show Custom Toast" />
202
+ </LinearLayout>
203
+
204
+
205
+
206
+
207
+
208
+ custom_toast.xml
209
+
210
+ <?xml version="1.0" encoding="utf-8"?>
211
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
212
+ android:layout_width="wrap_content"
213
+ android:layout_height="wrap_content"
214
+ android:background="@drawable/toast_background"
215
+ android:orientation="horizontal"
216
+ android:padding="12dp">
217
+
218
+ <ImageView
219
+ android:layout_width="40dp"
220
+ android:layout_height="40dp"
221
+ android:src="@android:drawable/alert_dark_frame"
222
+ android:layout_marginEnd="8dp" />
223
+
224
+ <TextView
225
+ android:id="@+id/toastText"
226
+ android:layout_width="wrap_content"
227
+ android:layout_height="wrap_content"
228
+ android:text="Hello from Custom Toast!"
229
+ android:textColor="#FFFFFF"
230
+ android:textSize="16sp" />
231
+ </LinearLayout>
232
+
233
+
234
+
235
+
236
+
237
+
238
+
239
+
240
+ toast_background.xml
241
+
242
+ <shape xmlns:android="http://schemas.android.com/apk/res/android"
243
+ android:shape="rectangle">
244
+ <solid android:color="#444" />
245
+ <corners android:radius="12dp" />
246
+ <padding android:left="10dp" android:top="10dp"
247
+ android:right="10dp" android:bottom="10dp"/>
248
+ </shape>
249
+
250
+
251
+
252
+ package com.example.a25_drawing_custom_shapes_on_canvas
253
+
254
+ import android.support.v7.app.AppCompatActivity
255
+ import android.os.Bundle
256
+
257
+ class MainActivity : AppCompatActivity() {
258
+ override fun onCreate(savedInstanceState: Bundle?) {
259
+ super.onCreate(savedInstanceState)
260
+ setContentView(R.layout.activity_main)
261
+ }
262
+ }
263
+
264
+
265
+
266
+
267
+
268
+ <?xml version="1.0" encoding="utf-8"?>
269
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
270
+ xmlns:tools="http://schemas.android.com/tools"
271
+ android:layout_width="match_parent"
272
+ android:layout_height="match_parent"
273
+ android:orientation="vertical"
274
+ tools:context=".MainActivity">
275
+
276
+ <com.example.a25_drawing_custom_shapes_on_canvas.MyCanvasView
277
+ android:layout_width="match_parent"
278
+ android:layout_height="match_parent" />
279
+ </LinearLayout>
280
+
281
+
282
+
283
+
284
+
285
+
286
+ MyCanvasView.kt
287
+
288
+
289
+ package com.example.a25_drawing_custom_shapes_on_canvas
290
+
291
+ import android.content.Context
292
+ import android.graphics.Canvas
293
+ import android.graphics.Color
294
+ import android.graphics.Paint
295
+ import android.util.AttributeSet
296
+ import android.view.View
297
+
298
+ class MyCanvasView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
299
+ private val paint = Paint()
300
+
301
+ override fun onDraw(canvas: Canvas?) {
302
+ super.onDraw(canvas)
303
+
304
+ canvas?.let {
305
+ // Set paint color and style
306
+ paint.color = Color.BLUE
307
+ paint.style = Paint.Style.FILL
308
+
309
+ // Draw a circle
310
+ it.drawCircle(300f, 300f, 150f, paint)
311
+
312
+ // Draw a red rectangle
313
+ paint.color = Color.RED
314
+ it.drawRect(100f, 600f, 500f, 800f, paint)
315
+
316
+ // Draw a line
317
+ paint.color = Color.GREEN
318
+ paint.strokeWidth = 10f
319
+ it.drawLine(100f, 900f, 500f, 1000f, paint)
320
+ }
321
+ }
322
+ }
323
+
324
+ package com.example.a26_intents
325
+
326
+ import android.support.v7.app.AppCompatActivity
327
+ import android.os.Bundle
328
+ import android.content.Intent
329
+ import android.net.Uri
330
+ import android.widget.Button
331
+
332
+ class MainActivity : AppCompatActivity() {
333
+ override fun onCreate(savedInstanceState: Bundle?) {
334
+ super.onCreate(savedInstanceState)
335
+ setContentView(R.layout.activity_main)
336
+
337
+ val btnExplicit = findViewById<Button>(R.id.btnExplicit)
338
+ val btnImplicit = findViewById<Button>(R.id.btnImplicit)
339
+
340
+ // Explicit Intent to go to SecondActivity
341
+ btnExplicit.setOnClickListener {
342
+ val intent = Intent(this, SecondActivity::class.java)
343
+ startActivity(intent)
344
+ }
345
+
346
+ // Implicit Intent to open a website
347
+ btnImplicit.setOnClickListener {
348
+ val webpage: Uri = Uri.parse("https://www.google.com")
349
+ val intent = Intent(Intent.ACTION_VIEW, webpage)
350
+ startActivity(intent)
351
+ }
352
+ }
353
+ }
354
+
355
+
356
+
357
+ <?xml version="1.0" encoding="utf-8"?>
358
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
359
+ android:layout_width="match_parent"
360
+ android:layout_height="match_parent"
361
+ android:orientation="vertical"
362
+ android:gravity="center"
363
+ android:padding="16dp">
364
+
365
+ <Button
366
+ android:id="@+id/btnExplicit"
367
+ android:layout_width="wrap_content"
368
+ android:layout_height="wrap_content"
369
+ android:text="Go to Second Activity" />
370
+
371
+ <Button
372
+ android:id="@+id/btnImplicit"
373
+ android:layout_width="wrap_content"
374
+ android:layout_height="wrap_content"
375
+ android:text="Open Website"
376
+ android:layout_marginTop="16dp" />
377
+ </LinearLayout>
378
+
379
+
380
+
381
+
382
+
383
+ SecondActivity.kt
384
+
385
+ package com.example.a26_intents
386
+
387
+ import android.support.v7.app.AppCompatActivity
388
+ import android.os.Bundle
389
+
390
+ class SecondActivity : AppCompatActivity() {
391
+ override fun onCreate(savedInstanceState: Bundle?) {
392
+ super.onCreate(savedInstanceState)
393
+ setContentView(R.layout.activity_second)
394
+ }
395
+ }
396
+
397
+
398
+
399
+ Activity_second.xml
400
+
401
+
402
+ <?xml version="1.0" encoding="utf-8"?>
403
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
404
+ android:layout_width="match_parent"
405
+ android:layout_height="match_parent"
406
+ android:gravity="center"
407
+ android:orientation="vertical">
408
+
409
+ <TextView
410
+ android:text="Welcome to Second Activity!"
411
+ android:layout_width="wrap_content"
412
+ android:layout_height="wrap_content"
413
+ android:textSize="24sp"
414
+ android:textStyle="bold" />
415
+ </LinearLayout>
416
+
417
+ package com.example.a27_listview
418
+
419
+ import android.support.v7.app.AppCompatActivity
420
+ import android.os.Bundle
421
+ import android.widget.*
422
+
423
+ class MainActivity : AppCompatActivity() {
424
+ override fun onCreate(savedInstanceState: Bundle?) {
425
+ super.onCreate(savedInstanceState)
426
+ setContentView(R.layout.activity_main)
427
+
428
+ val listView = findViewById<ListView>(R.id.listView)
429
+
430
+ val fruits = arrayOf("Apple", "Banana", "Mango", "Grapes", "Orange", "Pineapple")
431
+
432
+ val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, fruits)
433
+ listView.adapter = adapter
434
+
435
+ listView.setOnItemClickListener { _, _, position, _ ->
436
+ val selectedItem = fruits[position]
437
+ Toast.makeText(this, "You clicked: $selectedItem", Toast.LENGTH_SHORT).show()
438
+ }
439
+ }
440
+ }
441
+
442
+
443
+
444
+ <?xml version="1.0" encoding="utf-8"?>
445
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
446
+ android:layout_width="match_parent"
447
+ android:layout_height="match_parent"
448
+ android:orientation="vertical"
449
+ android:padding="16dp">
450
+
451
+ <ListView
452
+ android:id="@+id/listView"
453
+ android:layout_width="match_parent"
454
+ android:layout_height="match_parent" />
455
+ </LinearLayout>
456
+
457
+ package com.example.a31_spinner_and_customshapes
458
+
459
+ import android.support.v7.app.AppCompatActivity
460
+ import android.os.Bundle
461
+ import android.view.View
462
+ import android.widget.*
463
+
464
+ class MainActivity : AppCompatActivity() {
465
+ override fun onCreate(savedInstanceState: Bundle?) {
466
+ super.onCreate(savedInstanceState)
467
+ setContentView(R.layout.activity_main)
468
+
469
+ val spinner = findViewById<Spinner>(R.id.spinner)
470
+
471
+ val adapter = ArrayAdapter.createFromResource(
472
+ this,
473
+ R.array.languages,
474
+ android.R.layout.simple_spinner_item
475
+ )
476
+ adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
477
+ spinner.adapter = adapter
478
+
479
+ spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
480
+ override fun onItemSelected(
481
+ parent: AdapterView<*>, view: View?, position: Int, id: Long
482
+ ) {
483
+ val selected = parent.getItemAtPosition(position).toString()
484
+ Toast.makeText(this@MainActivity, "Selected: $selected", Toast.LENGTH_SHORT).show()
485
+ }
486
+
487
+ override fun onNothingSelected(parent: AdapterView<*>) {}
488
+ }
489
+ }
490
+ }
491
+
492
+
493
+
494
+ <?xml version="1.0" encoding="utf-8"?>
495
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
496
+ android:layout_width="match_parent"
497
+ android:layout_height="match_parent"
498
+ android:orientation="vertical"
499
+ android:gravity="center"
500
+ android:padding="16dp">
501
+
502
+ <Spinner
503
+ android:id="@+id/spinner"
504
+ android:layout_width="wrap_content"
505
+ android:layout_height="wrap_content"
506
+ android:background="@drawable/spinner_background"
507
+ android:padding="12dp"
508
+ android:spinnerMode="dropdown" />
509
+ </LinearLayout>
510
+
511
+
512
+
513
+ Spinner_background.xml in drawable
514
+
515
+ <?xml version="1.0" encoding="utf-8"?>
516
+ <shape xmlns:android="http://schemas.android.com/apk/res/android"
517
+ android:shape="rectangle">
518
+
519
+ <solid android:color="#FFBB86FC"/>
520
+ <corners android:radius="12dp"/>
521
+ <padding
522
+ android:left="10dp"
523
+ android:top="10dp"
524
+ android:right="10dp"
525
+ android:bottom="10dp" />
526
+ </shape>
527
+
528
+
529
+
530
+
531
+ Added this in string.xml
532
+
533
+ <resources>
534
+ <string name="app_name">31_Spinner_and_customshapes</string>
535
+ <string-array name="languages">
536
+ <item>Java</item>
537
+ <item>Kotlin</item>
538
+ <item>Python</item>
539
+ <item>C++</item>
540
+ <item>JavaScript</item>
541
+ </string-array>
542
+
543
+ </resources>
544
+
545
+ package com.example.a33_android_animation
546
+
547
+ import android.support.v7.app.AppCompatActivity
548
+ import android.os.Bundle
549
+ import android.animation.*
550
+ import android.view.animation.BounceInterpolator
551
+ import android.widget.*
552
+
553
+ class MainActivity : AppCompatActivity() {
554
+ override fun onCreate(savedInstanceState: Bundle?) {
555
+ super.onCreate(savedInstanceState)
556
+ setContentView(R.layout.activity_main)
557
+
558
+ val imageView = findViewById<ImageView>(R.id.imageView)
559
+ val btnAnimate = findViewById<Button>(R.id.btnAnimate)
560
+
561
+ btnAnimate.setOnClickListener {
562
+ // Animate Y position
563
+ val animator = ObjectAnimator.ofFloat(imageView, "translationY", 0f, -400f, 0f)
564
+ animator.duration = 1000
565
+ animator.interpolator = BounceInterpolator()
566
+ animator.start()
567
+ }
568
+ }
569
+ }
570
+
571
+
572
+
573
+ <?xml version="1.0" encoding="utf-8"?>
574
+ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
575
+ android:layout_width="match_parent"
576
+ android:layout_height="match_parent"
577
+ android:padding="16dp">
578
+
579
+ <ImageView
580
+ android:id="@+id/imageView"
581
+ android:layout_width="100dp"
582
+ android:layout_height="100dp"
583
+ android:src="@android:drawable/btn_star_big_on"
584
+ android:layout_centerInParent="true" />
585
+
586
+ <Button
587
+ android:id="@+id/btnAnimate"
588
+ android:layout_width="wrap_content"
589
+ android:layout_height="wrap_content"
590
+ android:text="Animate Star"
591
+ android:layout_alignParentBottom="true"
592
+ android:layout_centerHorizontal="true"
593
+ android:layout_marginBottom="32dp" />
594
+ </RelativeLayout>
595
+
596
+ package com.example.a34_android_options_menu
597
+
598
+ import android.os.Bundle
599
+ import android.support.v7.app.AppCompatActivity
600
+ import android.view.*
601
+ import android.widget.*
602
+
603
+ class MainActivity : AppCompatActivity() {
604
+ override fun onCreate(savedInstanceState: Bundle?) {
605
+ super.onCreate(savedInstanceState)
606
+ setContentView(R.layout.activity_main)
607
+
608
+ }
609
+
610
+ override fun onCreateOptionsMenu(menu: Menu?): Boolean {
611
+ menuInflater.inflate(R.menu.menu_main, menu)
612
+ return true
613
+ }
614
+
615
+ override fun onOptionsItemSelected(item: MenuItem): Boolean {
616
+ return when (item.itemId) {
617
+ R.id.menu_settings -> {
618
+ Toast.makeText(this, "Settings clicked", Toast.LENGTH_SHORT).show()
619
+ true
620
+ }
621
+ R.id.menu_help -> {
622
+ Toast.makeText(this, "Help clicked", Toast.LENGTH_SHORT).show()
623
+ true
624
+ }
625
+ else -> super.onOptionsItemSelected(item)
626
+ }
627
+ }
628
+ }
629
+
630
+
631
+
632
+
633
+ <?xml version="1.0" encoding="utf-8"?>
634
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
635
+ android:layout_width="match_parent"
636
+ android:layout_height="match_parent"
637
+ android:orientation="vertical">
638
+
639
+ <!-- No Toolbar used here since native ActionBar is used -->
640
+
641
+ <TextView
642
+ android:layout_width="match_parent"
643
+ android:layout_height="wrap_content"
644
+ android:text="Options Menu Demo"
645
+ android:gravity="center"
646
+ android:textSize="18sp"
647
+ android:layout_marginTop="30dp"/>
648
+ </LinearLayout>
649
+
650
+
651
+
652
+
653
+
654
+ Menu_main.xml
655
+
656
+ Location: res > menu
657
+ 📄 File Name: menu_main.xml
658
+ (If menu folder doesn’t exist, right-click res > New > Android Resource Directory, select menu as Resource type.)
659
+
660
+
661
+ <?xml version="1.0" encoding="utf-8"?>
662
+ <menu xmlns:app="http://schemas.android.com/apk/res-auto"
663
+ xmlns:android="http://schemas.android.com/apk/res/android">
664
+
665
+ <item
666
+ android:id="@+id/menu_settings"
667
+ android:title="Settings"
668
+ android:icon="@android:drawable/ic_menu_preferences"
669
+ app:showAsAction="ifRoom" />
670
+
671
+ <item
672
+ android:id="@+id/menu_help"
673
+ android:title="Help"
674
+ android:icon="@android:drawable/ic_menu_help"
675
+ app:showAsAction="ifRoom" />
676
+
677
+ </menu>
678
+
679
+ package com.example.a35_context_menu
680
+
681
+ import android.support.v7.app.AppCompatActivity
682
+ import android.os.Bundle
683
+ import android.view.*
684
+ import android.widget.*
685
+
686
+ class MainActivity : AppCompatActivity() {
687
+
688
+ lateinit var textView: TextView
689
+
690
+ override fun onCreate(savedInstanceState: Bundle?) {
691
+ super.onCreate(savedInstanceState)
692
+ setContentView(R.layout.activity_main)
693
+
694
+ textView = findViewById(R.id.myTextView)
695
+
696
+ // Register the TextView for context menu
697
+ registerForContextMenu(textView)
698
+
699
+ }
700
+
701
+ override fun onCreateContextMenu(
702
+ menu: ContextMenu?,
703
+ v: View?,
704
+ menuInfo: ContextMenu.ContextMenuInfo?
705
+ ) {
706
+ super.onCreateContextMenu(menu, v, menuInfo)
707
+ menuInflater.inflate(R.menu.context_menu, menu)
708
+ menu?.setHeaderTitle("Choose an action")
709
+ }
710
+
711
+ override fun onContextItemSelected(item: MenuItem): Boolean {
712
+ return when (item.itemId) {
713
+ R.id.menu_edit -> {
714
+ Toast.makeText(this, "Edit selected", Toast.LENGTH_SHORT).show()
715
+ true
716
+ }
717
+ R.id.menu_delete -> {
718
+ Toast.makeText(this, "Delete selected", Toast.LENGTH_SHORT).show()
719
+ true
720
+ }
721
+ else -> super.onContextItemSelected(item)
722
+ }
723
+ }
724
+ }
725
+
726
+
727
+ <?xml version="1.0" encoding="utf-8"?>
728
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
729
+ android:layout_width="match_parent"
730
+ android:layout_height="match_parent"
731
+ android:orientation="vertical"
732
+ android:gravity="center"
733
+ android:padding="16dp">
734
+
735
+ <TextView
736
+ android:id="@+id/myTextView"
737
+ android:layout_width="wrap_content"
738
+ android:layout_height="wrap_content"
739
+ android:text="Long press me!"
740
+ android:textSize="24sp"
741
+ android:padding="20dp"
742
+ android:background="#DDDDDD" />
743
+ </LinearLayout>
744
+
745
+
746
+
747
+
748
+ Context_menu.xml
749
+
750
+
751
+ <?xml version="1.0" encoding="utf-8"?>
752
+ <menu xmlns:android="http://schemas.android.com/apk/res/android">
753
+
754
+ <item
755
+ android:id="@+id/menu_edit"
756
+ android:title="Edit" />
757
+
758
+ <item
759
+ android:id="@+id/menu_delete"
760
+ android:title="Delete" />
761
+
762
+ </menu>
763
+
764
+ package com.example.a36_popup_menu
765
+
766
+ import android.support.v7.app.AppCompatActivity
767
+ import android.os.Bundle
768
+ import android.view.*
769
+ import android.widget.*
770
+
771
+ class MainActivity : AppCompatActivity() {
772
+ override fun onCreate(savedInstanceState: Bundle?) {
773
+ super.onCreate(savedInstanceState)
774
+ setContentView(R.layout.activity_main)
775
+
776
+ val btnShowMenu = findViewById<Button>(R.id.btnShowMenu)
777
+
778
+ btnShowMenu.setOnClickListener {
779
+ // Create the PopupMenu
780
+ val popup = PopupMenu(this@MainActivity, btnShowMenu)
781
+ popup.menuInflater.inflate(R.menu.popup_menu, popup.menu)
782
+
783
+ // Handle menu item clicks
784
+ popup.setOnMenuItemClickListener { item: MenuItem ->
785
+ when (item.itemId) {
786
+ R.id.menu_refresh -> {
787
+ Toast.makeText(this, "Refresh clicked", Toast.LENGTH_SHORT).show()
788
+ true
789
+ }
790
+ R.id.menu_about -> {
791
+ Toast.makeText(this, "About clicked", Toast.LENGTH_SHORT).show()
792
+ true
793
+ }
794
+ else -> false
795
+ }
796
+ }
797
+
798
+ // Show the popup menu
799
+ popup.show()
800
+ }
801
+ }
802
+ }
803
+
804
+
805
+
806
+
807
+
808
+ <?xml version="1.0" encoding="utf-8"?>
809
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
810
+ android:layout_width="match_parent"
811
+ android:layout_height="match_parent"
812
+ android:orientation="vertical"
813
+ android:gravity="center"
814
+ android:padding="16dp">
815
+
816
+ <Button
817
+ android:id="@+id/btnShowMenu"
818
+ android:layout_width="wrap_content"
819
+ android:layout_height="wrap_content"
820
+ android:text="Show Pop-up Menu" />
821
+ </LinearLayout>
822
+
823
+
824
+
825
+
826
+ Popup_menu.xml
827
+
828
+
829
+ <?xml version="1.0" encoding="utf-8"?>
830
+ <menu xmlns:android="http://schemas.android.com/apk/res/android">
831
+
832
+ <item
833
+ android:id="@+id/menu_refresh"
834
+ android:title="Refresh" />
835
+
836
+ <item
837
+ android:id="@+id/menu_about"
838
+ android:title="About" />
839
+
840
+ </menu>
841
+
842
+ package com.example.a37_android_fragments
843
+
844
+ import android.support.v7.app.AppCompatActivity
845
+ import android.os.Bundle
846
+ import android.support.v4.app.Fragment
847
+ import android.widget.*
848
+
849
+ class MainActivity : AppCompatActivity() {
850
+
851
+ lateinit var btn1: Button
852
+ lateinit var btn2: Button
853
+
854
+ override fun onCreate(savedInstanceState: Bundle?) {
855
+ super.onCreate(savedInstanceState)
856
+ setContentView(R.layout.activity_main)
857
+
858
+ btn1 = findViewById(R.id.btnFragment1)
859
+ btn2 = findViewById(R.id.btnFragment2)
860
+
861
+ btn1.setOnClickListener {
862
+ loadFragment(FragmentOne())
863
+ }
864
+
865
+ btn2.setOnClickListener {
866
+ loadFragment(FragmentTwo())
867
+ }
868
+
869
+ // Load default fragment
870
+ loadFragment(FragmentOne())
871
+ }
872
+
873
+ private fun loadFragment(fragment: Fragment) {
874
+ supportFragmentManager.beginTransaction()
875
+ .replace(R.id.fragment_container, fragment)
876
+ .commit()
877
+ }
878
+ }
879
+
880
+
881
+
882
+
883
+
884
+ <?xml version="1.0" encoding="utf-8"?>
885
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
886
+ android:layout_width="match_parent"
887
+ android:layout_height="match_parent"
888
+ android:orientation="vertical"
889
+ android:padding="16dp">
890
+
891
+ <Button
892
+ android:id="@+id/btnFragment1"
893
+ android:layout_width="match_parent"
894
+ android:layout_height="wrap_content"
895
+ android:text="Load Fragment 1" />
896
+
897
+ <Button
898
+ android:id="@+id/btnFragment2"
899
+ android:layout_width="match_parent"
900
+ android:layout_height="wrap_content"
901
+ android:text="Load Fragment 2"
902
+ android:layout_marginTop="10dp"/>
903
+
904
+ <FrameLayout
905
+ android:id="@+id/fragment_container"
906
+ android:layout_width="match_parent"
907
+ android:layout_height="0dp"
908
+ android:layout_weight="1"
909
+ android:layout_marginTop="20dp"
910
+ android:background="#EEEEEE"/>
911
+ </LinearLayout>
912
+
913
+
914
+
915
+
916
+ Now fragments.
917
+ fragment1
918
+
919
+
920
+
921
+
922
+
923
+
924
+
925
+
926
+ package com.example.a37_android_fragments
927
+
928
+ import android.os.Bundle
929
+ import android.support.v4.app.Fragment
930
+ import android.view.*
931
+
932
+ class FragmentOne : Fragment() {
933
+ override fun onCreateView(
934
+ inflater: LayoutInflater,
935
+ container: ViewGroup?,
936
+ savedInstanceState: Bundle?
937
+ ): View? {
938
+ return inflater.inflate(R.layout.fragment_one, container, false)
939
+ }
940
+ }
941
+
942
+
943
+
944
+
945
+
946
+ <?xml version="1.0" encoding="utf-8"?>
947
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
948
+ android:layout_width="match_parent"
949
+ android:layout_height="match_parent"
950
+ android:background="#FFCDD2">
951
+
952
+ <TextView
953
+ android:layout_width="wrap_content"
954
+ android:layout_height="wrap_content"
955
+ android:text="This is Fragment One"
956
+ android:textSize="20sp"
957
+ android:layout_gravity="center"/>
958
+ </FrameLayout>
959
+
960
+
961
+
962
+
963
+
964
+ Fragment2
965
+
966
+
967
+
968
+
969
+
970
+ package com.example.a37_android_fragments
971
+
972
+
973
+ import android.os.Bundle
974
+ import android.support.v4.app.Fragment
975
+ import android.view.*
976
+
977
+ class FragmentTwo : Fragment() {
978
+ override fun onCreateView(
979
+ inflater: LayoutInflater,
980
+ container: ViewGroup?,
981
+ savedInstanceState: Bundle?
982
+ ): View? {
983
+ return inflater.inflate(R.layout.fragment_two, container, false)
984
+ }
985
+ }
986
+
987
+
988
+
989
+
990
+
991
+
992
+ <?xml version="1.0" encoding="utf-8"?>
993
+ <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
994
+ android:layout_width="match_parent"
995
+ android:layout_height="match_parent"
996
+ android:background="#BBDEFB">
997
+
998
+ <TextView
999
+ android:layout_width="wrap_content"
1000
+ android:layout_height="wrap_content"
1001
+ android:text="This is Fragment Two"
1002
+ android:textSize="20sp"
1003
+ android:layout_gravity="center"/>
1004
+ </FrameLayout>
1005
+
1006
+ package com.example.a41_shared_preference_primitives
1007
+
1008
+ import android.content.SharedPreferences
1009
+ import android.os.Bundle
1010
+ import android.support.v7.app.AppCompatActivity
1011
+ import android.widget.*
1012
+
1013
+ class MainActivity : AppCompatActivity() {
1014
+
1015
+ lateinit var etName: EditText
1016
+ lateinit var etAge: EditText
1017
+ lateinit var btnSave: Button
1018
+ lateinit var btnLoad: Button
1019
+ lateinit var tvResult: TextView
1020
+ lateinit var sharedPref: SharedPreferences
1021
+
1022
+
1023
+ override fun onCreate(savedInstanceState: Bundle?) {
1024
+ super.onCreate(savedInstanceState)
1025
+ setContentView(R.layout.activity_main)
1026
+
1027
+ etName = findViewById(R.id.etName)
1028
+ etAge = findViewById(R.id.etAge)
1029
+ btnSave = findViewById(R.id.btnSave)
1030
+ btnLoad = findViewById(R.id.btnLoad)
1031
+ tvResult = findViewById(R.id.tvResult)
1032
+
1033
+ // Create shared preference with private mode
1034
+ sharedPref = getSharedPreferences("MyPrefs", MODE_PRIVATE)
1035
+
1036
+ btnSave.setOnClickListener {
1037
+ val name = etName.text.toString()
1038
+ val age = etAge.text.toString().toIntOrNull() ?: 0
1039
+
1040
+ val editor = sharedPref.edit()
1041
+ editor.putString("name", name)
1042
+ editor.putInt("age", age)
1043
+ editor.apply()
1044
+
1045
+ Toast.makeText(this, "Data Saved", Toast.LENGTH_SHORT).show()
1046
+ }
1047
+
1048
+ btnLoad.setOnClickListener {
1049
+ val name = sharedPref.getString("name", "No Name Found")
1050
+ val age = sharedPref.getInt("age", 0)
1051
+
1052
+ tvResult.text = "Name: $name\nAge: $age"
1053
+ }
1054
+ }
1055
+ }
1056
+
1057
+
1058
+
1059
+
1060
+
1061
+
1062
+ <?xml version="1.0" encoding="utf-8"?>
1063
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1064
+ android:layout_width="match_parent"
1065
+ android:layout_height="match_parent"
1066
+ android:orientation="vertical"
1067
+ android:padding="20dp">
1068
+
1069
+ <EditText
1070
+ android:id="@+id/etName"
1071
+ android:layout_width="match_parent"
1072
+ android:layout_height="wrap_content"
1073
+ android:hint="Enter your name" />
1074
+
1075
+ <EditText
1076
+ android:id="@+id/etAge"
1077
+ android:layout_width="match_parent"
1078
+ android:layout_height="wrap_content"
1079
+ android:hint="Enter your age"
1080
+ android:inputType="number"
1081
+ android:layout_marginTop="10dp"/>
1082
+
1083
+ <Button
1084
+ android:id="@+id/btnSave"
1085
+ android:layout_width="match_parent"
1086
+ android:layout_height="wrap_content"
1087
+ android:text="Save Data"
1088
+ android:layout_marginTop="10dp"/>
1089
+
1090
+ <Button
1091
+ android:id="@+id/btnLoad"
1092
+ android:layout_width="match_parent"
1093
+ android:layout_height="wrap_content"
1094
+ android:text="Load Data"
1095
+ android:layout_marginTop="10dp"/>
1096
+
1097
+ <TextView
1098
+ android:id="@+id/tvResult"
1099
+ android:layout_width="match_parent"
1100
+ android:layout_height="wrap_content"
1101
+ android:text="Stored data will appear here"
1102
+ android:textSize="18sp"
1103
+ android:layout_marginTop="20dp"/>
1104
+ </LinearLayout>
1105
+
1106
+ package com.example.a43_sqlite
1107
+
1108
+ import android.support.v7.app.AppCompatActivity
1109
+ import android.os.Bundle
1110
+ import android.widget.*
1111
+
1112
+ class MainActivity : AppCompatActivity() {
1113
+
1114
+ lateinit var etName: EditText
1115
+ lateinit var etEmail: EditText
1116
+ lateinit var btnInsert: Button
1117
+ lateinit var btnFetch: Button
1118
+ lateinit var tvResult: TextView
1119
+ lateinit var dbHelper: DatabaseHelper
1120
+
1121
+ override fun onCreate(savedInstanceState: Bundle?) {
1122
+ super.onCreate(savedInstanceState)
1123
+ setContentView(R.layout.activity_main)
1124
+
1125
+ etName = findViewById(R.id.etName)
1126
+ etEmail = findViewById(R.id.etEmail)
1127
+ btnInsert = findViewById(R.id.btnInsert)
1128
+ btnFetch = findViewById(R.id.btnFetch)
1129
+ tvResult = findViewById(R.id.tvResult)
1130
+
1131
+ dbHelper = DatabaseHelper(this)
1132
+
1133
+ btnInsert.setOnClickListener {
1134
+ val name = etName.text.toString()
1135
+ val email = etEmail.text.toString()
1136
+
1137
+ val success = dbHelper.insertUser(name, email)
1138
+ if (success)
1139
+ Toast.makeText(this, "Data Inserted", Toast.LENGTH_SHORT).show()
1140
+ else
1141
+ Toast.makeText(this, "Insert Failed", Toast.LENGTH_SHORT).show()
1142
+
1143
+ etName.text.clear()
1144
+ etEmail.text.clear()
1145
+ }
1146
+
1147
+ btnFetch.setOnClickListener {
1148
+ val data = dbHelper.fetchAllUsers()
1149
+ tvResult.text = data
1150
+ }
1151
+ }
1152
+ }
1153
+
1154
+ <?xml version="1.0" encoding="utf-8"?>
1155
+ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
1156
+ android:layout_width="match_parent"
1157
+ android:layout_height="match_parent"
1158
+ android:orientation="vertical"
1159
+ android:padding="20dp">
1160
+
1161
+ <EditText
1162
+ android:id="@+id/etName"
1163
+ android:layout_width="match_parent"
1164
+ android:layout_height="wrap_content"
1165
+ android:hint="Enter Name" />
1166
+
1167
+ <EditText
1168
+ android:id="@+id/etEmail"
1169
+ android:layout_width="match_parent"
1170
+ android:layout_height="wrap_content"
1171
+ android:hint="Enter Email"
1172
+ android:layout_marginTop="10dp"/>
1173
+
1174
+ <Button
1175
+ android:id="@+id/btnInsert"
1176
+ android:layout_width="match_parent"
1177
+ android:layout_height="wrap_content"
1178
+ android:text="Insert Data"
1179
+ android:layout_marginTop="10dp"/>
1180
+
1181
+ <Button
1182
+ android:id="@+id/btnFetch"
1183
+ android:layout_width="match_parent"
1184
+ android:layout_height="wrap_content"
1185
+ android:text="Fetch Data"
1186
+ android:layout_marginTop="10dp"/>
1187
+
1188
+ <TextView
1189
+ android:id="@+id/tvResult"
1190
+ android:layout_width="match_parent"
1191
+ android:layout_height="wrap_content"
1192
+ android:text="Fetched data will show here"
1193
+ android:layout_marginTop="20dp"
1194
+ android:textSize="16sp"/>
1195
+ </LinearLayout>
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+ DatabaseHelper.kt
1203
+
1204
+
1205
+
1206
+ package com.example.a43_sqlite
1207
+
1208
+ import android.content.*
1209
+ import android.database.sqlite.*
1210
+
1211
+ class DatabaseHelper(context: Context) :
1212
+ SQLiteOpenHelper(context, "UserDB", null, 1) {
1213
+
1214
+ override fun onCreate(db: SQLiteDatabase) {
1215
+ db.execSQL("CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, email TEXT)")
1216
+ }
1217
+
1218
+ override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
1219
+ db.execSQL("DROP TABLE IF EXISTS users")
1220
+ onCreate(db)
1221
+ }
1222
+
1223
+ fun insertUser(name: String, email: String): Boolean {
1224
+ val db = this.writableDatabase
1225
+ val values = ContentValues()
1226
+ values.put("name", name)
1227
+ values.put("email", email)
1228
+
1229
+ val result = db.insert("users", null, values)
1230
+ db.close()
1231
+ return result != -1L
1232
+ }
1233
+
1234
+ fun fetchAllUsers(): String {
1235
+ val db = this.readableDatabase
1236
+ val cursor = db.rawQuery("SELECT * FROM users", null)
1237
+ val sb = StringBuilder()
1238
+
1239
+ if (cursor.moveToFirst()) {
1240
+ do {
1241
+ val name = cursor.getString(cursor.getColumnIndexOrThrow("name"))
1242
+ val email = cursor.getString(cursor.getColumnIndexOrThrow("email"))
1243
+ sb.append("Name: $name\nEmail: $email\n\n")
1244
+ } while (cursor.moveToNext())
1245
+ } else {
1246
+ sb.append("No data found.")
1247
+ }
1248
+
1249
+ cursor.close()
1250
+ db.close()
1251
+ return sb.toString()
1252
+ }
1253
+ }
1254
+
1255
+