androidd 0.0.1__py3-none-any.whl → 0.0.3__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.
- androidd/__init__.py +1 -0
- androidd/cie1/activityCycle/MainActivity.kt +44 -0
- androidd/cie1/activityCycle/activity_main.xml +15 -0
- androidd/cie1/alert/MainActivity.kt +28 -0
- androidd/cie1/alert/activity_main.xml +14 -0
- androidd/cie1/autoCompleteText/MainActivity.kt +19 -0
- androidd/cie1/autoCompleteText/activity_main.xml +14 -0
- androidd/cie1/checkbox/MainActivity.kt +28 -0
- androidd/cie1/checkbox/activity_main.xml +32 -0
- androidd/cie1/customCheckbox/MainActivity.kt +20 -0
- androidd/cie1/customCheckbox/activity_main.xml +22 -0
- androidd/cie1/customCheckbox/custom_checkbox.xml +9 -0
- androidd/cie1/customRadio/MainActivity.kt +22 -0
- androidd/cie1/customRadio/activity_main.xml +28 -0
- androidd/cie1/customRadio/custom_checkbox.xml +9 -0
- androidd/cie1/customToast/MainActivity.kt +35 -0
- androidd/cie1/customToast/activity_main.xml +14 -0
- androidd/cie1/customToast/custom_toast.xml +23 -0
- androidd/cie1/datepicker/MainActivity.kt +31 -0
- androidd/cie1/datepicker/activity_main.xml +20 -0
- androidd/cie1/progressbar/MainActivity.kt +26 -0
- androidd/cie1/progressbar/activity_main.xml +21 -0
- androidd/cie1/ques1/MainActivity.kt +37 -0
- androidd/cie1/ques1/activity_main.xml +41 -0
- androidd/cie1/ques2/MainActivity.kt +41 -0
- androidd/cie1/ques2/activity_main.xml +66 -0
- androidd/cie1/ques3/AndroidManifest.xml +3 -0
- androidd/cie1/ques3/MainActivity.kt +29 -0
- androidd/cie1/ques3/activity_main.xml +30 -0
- androidd/cie1/radiobutton/MainActivity.kt +25 -0
- androidd/cie1/radiobutton/activity_main.xml +38 -0
- androidd/cie1/timePicker/MainActivity.kt +30 -0
- androidd/cie1/timePicker/activity_main.xml +20 -0
- androidd/cie1/toast/MainActivity.kt +18 -0
- androidd/cie1/toast/activity_main.xml +14 -0
- androidd/cie1/toggle/MainActivity.kt +20 -0
- androidd/cie1/toggle/activity_main.xml +23 -0
- androidd/madbmsj/IMPLICIT and EXPLICIT/Main Activity.kt +31 -0
- androidd/madbmsj/IMPLICIT and EXPLICIT/activity_main.xml +33 -0
- androidd/madbmsj/IMPLICIT and EXPLICIT/second.xml +16 -0
- androidd/madbmsj/IMPLICIT and EXPLICIT/secondactivity.kt +15 -0
- androidd/madbmsj/animation/MainActivity.kt +60 -0
- androidd/madbmsj/animation/activity_main.xml +122 -0
- androidd/madbmsj/animation/bounce.xml +17 -0
- androidd/madbmsj/animation/fad_in.xml +7 -0
- androidd/madbmsj/animation/fade_out.xml +8 -0
- androidd/madbmsj/animation/info.txt +2 -0
- androidd/madbmsj/animation/slide_down.xml +7 -0
- androidd/madbmsj/animation/slide_up.xml +7 -0
- androidd/madbmsj/animation/zoom_in.xml +11 -0
- androidd/madbmsj/animation/zoom_out.xml +11 -0
- androidd/madbmsj/canvas/MainActivity.kt +51 -0
- androidd/madbmsj/canvas/activity_main.xml +18 -0
- androidd/madbmsj/cie1/code.txt +719 -0
- androidd/madbmsj/cie1/sampleQuestion.txt +280 -0
- androidd/madbmsj/cie2/code.txt +1255 -0
- androidd/madbmsj/cie2/ques1/AndroidManifest.xml +2 -0
- androidd/madbmsj/cie2/ques1/MainActivity.kt +45 -0
- androidd/madbmsj/cie2/ques1/SecondActivity.kt +21 -0
- androidd/madbmsj/cie2/ques1/activity_main.xml +19 -0
- androidd/madbmsj/cie2/ques1/activity_second.xml +15 -0
- androidd/madbmsj/cie2/ques1/department_menu.xml +11 -0
- androidd/madbmsj/contextMenu/MainActivity.kt +37 -0
- androidd/madbmsj/contextMenu/activity_main.xml +19 -0
- androidd/madbmsj/contextMenu/info.txt +1 -0
- androidd/madbmsj/contextMenu/menu_main.xml +16 -0
- androidd/madbmsj/database/DatabaseHelper.kt +108 -0
- androidd/madbmsj/database/MainActivity.kt +151 -0
- androidd/madbmsj/database/activity_main.xml +55 -0
- androidd/madbmsj/database/dialog_update_student.xml +22 -0
- androidd/madbmsj/database/info.txt +4 -0
- androidd/madbmsj/datePicker/MainActivity.kt +23 -0
- androidd/madbmsj/datePicker/activity_main.xml +20 -0
- androidd/madbmsj/explicit/activity_main.xml +39 -0
- androidd/madbmsj/explicit/activity_second.xml +15 -0
- androidd/madbmsj/explicit/info.txt +6 -0
- androidd/madbmsj/explicit/mainactivity.kt +32 -0
- androidd/madbmsj/explicit/secondactivity.kt +27 -0
- androidd/madbmsj/fragment/MainActivity.kt +35 -0
- androidd/madbmsj/fragment/activity_main.xml +41 -0
- androidd/madbmsj/fragment/fragment_1.kt +24 -0
- androidd/madbmsj/fragment/fragment_1.xml +16 -0
- androidd/madbmsj/fragment/fragment_2.kt +17 -0
- androidd/madbmsj/fragment/fragnent_2.xml +16 -0
- androidd/madbmsj/fragment/info.txt +1 -0
- androidd/madbmsj/optionsMenu/MainActivity.kt +26 -0
- androidd/madbmsj/optionsMenu/activity_main.xml +18 -0
- androidd/madbmsj/optionsMenu/info.txt +1 -0
- androidd/madbmsj/optionsMenu/menu_main.xml +27 -0
- androidd/madbmsj/package.json +13 -0
- androidd/madbmsj/popMenu/MainActivity.kt +49 -0
- androidd/madbmsj/popMenu/activity_main.xml +19 -0
- androidd/madbmsj/popMenu/info.txt +1 -0
- androidd/madbmsj/popMenu/menu_main.xml +16 -0
- androidd/madbmsj/sharedpref/byJ/MainActivity.kt +34 -0
- androidd/madbmsj/sharedpref/byJ/activity_main.xml +28 -0
- androidd/madbmsj/sharedpref/shared1/activity_main.xml +64 -0
- androidd/madbmsj/sharedpref/shared1/mainactivity.kt +47 -0
- androidd/madbmsj/sharedpref/shared2/activity_main.xml +44 -0
- androidd/madbmsj/sharedpref/shared2/mainactivity.kt +57 -0
- androidd/madbmsj/spinner/MainActivity.kt +30 -0
- androidd/madbmsj/spinner/activity_main.xml +13 -0
- {androidd-0.0.1.dist-info → androidd-0.0.3.dist-info}/METADATA +1 -1
- androidd-0.0.3.dist-info/RECORD +106 -0
- androidd-0.0.3.dist-info/top_level.txt +1 -0
- androidd-0.0.1.dist-info/RECORD +0 -4
- androidd-0.0.1.dist-info/top_level.txt +0 -1
- {androidd-0.0.1.dist-info → androidd-0.0.3.dist-info}/WHEEL +0 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
package com.example.cie_que1
|
2
|
+
|
3
|
+
import android.content.Intent
|
4
|
+
import android.support.v7.app.AppCompatActivity
|
5
|
+
import android.os.Bundle
|
6
|
+
import android.view.MenuInflater
|
7
|
+
import android.view.View
|
8
|
+
import android.widget.*
|
9
|
+
|
10
|
+
class MainActivity : AppCompatActivity() {
|
11
|
+
|
12
|
+
val books = listOf("Data Structures", "Operating Systems", "Machine Learning", "Thermodynamics", "Digital Logic")
|
13
|
+
|
14
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
15
|
+
super.onCreate(savedInstanceState)
|
16
|
+
setContentView(R.layout.activity_main)
|
17
|
+
|
18
|
+
val bookListView = findViewById<ListView>(R.id.bookListView)
|
19
|
+
val btnMenu = findViewById<Button>(R.id.btnMenu)
|
20
|
+
|
21
|
+
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, books)
|
22
|
+
bookListView.adapter = adapter
|
23
|
+
|
24
|
+
bookListView.setOnItemClickListener { _, _, position, _ ->
|
25
|
+
val intent = Intent(this, SecondActivity::class.java)
|
26
|
+
intent.putExtra("book_name", books[position])
|
27
|
+
startActivity(intent)
|
28
|
+
}
|
29
|
+
|
30
|
+
btnMenu.setOnClickListener { v ->
|
31
|
+
showPopupMenu(v)
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
private fun showPopupMenu(view: View) {
|
36
|
+
val popup = PopupMenu(this, view)
|
37
|
+
val inflater: MenuInflater = popup.menuInflater
|
38
|
+
inflater.inflate(R.menu.department_menu, popup.menu)
|
39
|
+
popup.setOnMenuItemClickListener { item ->
|
40
|
+
Toast.makeText(this, "Department: ${item.title}", Toast.LENGTH_SHORT).show()
|
41
|
+
true
|
42
|
+
}
|
43
|
+
popup.show()
|
44
|
+
}
|
45
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
package com.example.cie_que1
|
2
|
+
|
3
|
+
import android.support.v7.app.AppCompatActivity
|
4
|
+
import android.os.Bundle
|
5
|
+
import android.widget.TextView
|
6
|
+
|
7
|
+
class SecondActivity : AppCompatActivity() {
|
8
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
9
|
+
super.onCreate(savedInstanceState)
|
10
|
+
setContentView(R.layout.activity_second)
|
11
|
+
|
12
|
+
// Get the book name passed from MainActivity
|
13
|
+
val bookName = intent.getStringExtra("book_name")
|
14
|
+
|
15
|
+
// Find the TextView in the layout
|
16
|
+
val bookText = findViewById<TextView>(R.id.selectedBookText)
|
17
|
+
|
18
|
+
// Set the book name to the TextView
|
19
|
+
bookText.text = "Selected Book:\n$bookName"
|
20
|
+
}
|
21
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
android:orientation="vertical"
|
4
|
+
android:layout_width="match_parent"
|
5
|
+
android:layout_height="match_parent"
|
6
|
+
android:padding="16dp">
|
7
|
+
|
8
|
+
<Button
|
9
|
+
android:id="@+id/btnMenu"
|
10
|
+
android:layout_width="wrap_content"
|
11
|
+
android:layout_height="wrap_content"
|
12
|
+
android:text="Show Departments" />
|
13
|
+
|
14
|
+
<ListView
|
15
|
+
android:id="@+id/bookListView"
|
16
|
+
android:layout_width="match_parent"
|
17
|
+
android:layout_height="wrap_content"
|
18
|
+
android:layout_marginTop="20dp"/>
|
19
|
+
</LinearLayout>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
android:orientation="vertical"
|
4
|
+
android:layout_width="match_parent"
|
5
|
+
android:layout_height="match_parent"
|
6
|
+
android:gravity="center"
|
7
|
+
android:padding="16dp">
|
8
|
+
|
9
|
+
<TextView
|
10
|
+
android:id="@+id/selectedBookText"
|
11
|
+
android:layout_width="wrap_content"
|
12
|
+
android:layout_height="wrap_content"
|
13
|
+
android:textSize="24sp"
|
14
|
+
android:text="Selected Book" />
|
15
|
+
</LinearLayout>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
3
|
+
<item android:title="CSE"/>
|
4
|
+
<item android:title="ISE"/>
|
5
|
+
<item android:title="ECE"/>
|
6
|
+
<item android:title="EEE"/>
|
7
|
+
<item android:title="ME"/>
|
8
|
+
<item android:title="CV"/>
|
9
|
+
<item android:title="AIML"/>
|
10
|
+
</menu>
|
11
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
package com.example.menu
|
2
|
+
|
3
|
+
import android.support.v7.app.AppCompatActivity
|
4
|
+
import android.os.Bundle
|
5
|
+
import android.support.v7.widget.PopupMenu
|
6
|
+
import android.view.ContextMenu
|
7
|
+
import android.view.Menu
|
8
|
+
import android.view.MenuItem
|
9
|
+
import android.view.View
|
10
|
+
import android.widget.Button
|
11
|
+
import android.widget.Toast
|
12
|
+
|
13
|
+
class MainActivity : AppCompatActivity() {
|
14
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
15
|
+
super.onCreate(savedInstanceState)
|
16
|
+
setContentView(R.layout.activity_main)
|
17
|
+
val B1 = findViewById<Button>(R.id.B1)
|
18
|
+
registerForContextMenu(B1)
|
19
|
+
B1.setOnClickListener { v -> openContextMenu(v)}
|
20
|
+
}
|
21
|
+
override fun onCreateContextMenu(
|
22
|
+
menu: ContextMenu?,
|
23
|
+
v: View?,
|
24
|
+
menuInfo: ContextMenu.ContextMenuInfo?
|
25
|
+
) {
|
26
|
+
super.onCreateContextMenu(menu, v, menuInfo)
|
27
|
+
menuInflater.inflate(R.menu.menu_main,menu)
|
28
|
+
}
|
29
|
+
override fun onContextItemSelected(item: MenuItem): Boolean {
|
30
|
+
when (item.itemId){
|
31
|
+
R.id.item1 -> Toast.makeText(this,"Open Selected",Toast.LENGTH_SHORT).show()
|
32
|
+
R.id.item2 -> Toast.makeText(this,"Search Selected",Toast.LENGTH_SHORT).show()
|
33
|
+
R.id.item3 -> Toast.makeText(this,"Exit Selected",Toast.LENGTH_SHORT).show()
|
34
|
+
}
|
35
|
+
return super.onContextItemSelected(item)
|
36
|
+
}
|
37
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
4
|
+
xmlns:tools="http://schemas.android.com/tools"
|
5
|
+
android:layout_width="match_parent"
|
6
|
+
android:layout_height="match_parent"
|
7
|
+
tools:context=".MainActivity">
|
8
|
+
|
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
|
+
|
19
|
+
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1 @@
|
|
1
|
+
java>new menu directory>new menu resource file named "menu_main.xml"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto">
|
4
|
+
<item android:id="@+id/item1"
|
5
|
+
android:title="Open"
|
6
|
+
app:showAsAction="never"
|
7
|
+
/>
|
8
|
+
<item android:id="@+id/item2"
|
9
|
+
android:title="Search"
|
10
|
+
app:showAsAction="never"
|
11
|
+
/>
|
12
|
+
<item android:id="@+id/item3"
|
13
|
+
android:title="Exit"
|
14
|
+
app:showAsAction="never"
|
15
|
+
/>
|
16
|
+
</menu>
|
@@ -0,0 +1,108 @@
|
|
1
|
+
package com.example.database
|
2
|
+
|
3
|
+
import android.content.ContentValues
|
4
|
+
import android.content.Context
|
5
|
+
import android.database.Cursor
|
6
|
+
import android.database.sqlite.SQLiteDatabase
|
7
|
+
import android.database.sqlite.SQLiteOpenHelper
|
8
|
+
import android.util.Log
|
9
|
+
|
10
|
+
class DatabaseHelper(context: Context) :
|
11
|
+
SQLiteOpenHelper(context, DATABASE_NAME, null, DATABASE_VERSION) {
|
12
|
+
|
13
|
+
companion object {
|
14
|
+
private const val DATABASE_NAME = "StudentDB.db"
|
15
|
+
private const val DATABASE_VERSION = 1
|
16
|
+
|
17
|
+
const val TABLE_STUDENTS = "students"
|
18
|
+
const val COL_ID = "id"
|
19
|
+
const val COL_FIRST_NAME = "first_name"
|
20
|
+
const val COL_LAST_NAME = "last_name"
|
21
|
+
|
22
|
+
// SQL query to create the table
|
23
|
+
private const val CREATE_TABLE_STUDENTS =
|
24
|
+
"CREATE TABLE $TABLE_STUDENTS (" +
|
25
|
+
"$COL_ID INTEGER PRIMARY KEY AUTOINCREMENT," +
|
26
|
+
"$COL_FIRST_NAME TEXT," +
|
27
|
+
"$COL_LAST_NAME TEXT" +
|
28
|
+
")"
|
29
|
+
}
|
30
|
+
|
31
|
+
override fun onCreate(db: SQLiteDatabase) {
|
32
|
+
db.execSQL(CREATE_TABLE_STUDENTS)
|
33
|
+
}
|
34
|
+
|
35
|
+
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
36
|
+
// Drop older table if existed
|
37
|
+
db.execSQL("DROP TABLE IF EXISTS $TABLE_STUDENTS")
|
38
|
+
// Create tables again
|
39
|
+
onCreate(db)
|
40
|
+
}
|
41
|
+
|
42
|
+
// --- CRUD Operations ---
|
43
|
+
|
44
|
+
// Add a new student
|
45
|
+
fun addStudent(firstName: String, lastName: String): Boolean {
|
46
|
+
val db = this.writableDatabase
|
47
|
+
val values = ContentValues().apply {
|
48
|
+
put(COL_FIRST_NAME, firstName)
|
49
|
+
put(COL_LAST_NAME, lastName)
|
50
|
+
}
|
51
|
+
|
52
|
+
val result = db.insert(TABLE_STUDENTS, null, values)
|
53
|
+
db.close()
|
54
|
+
return result != -1L // Returns true if data inserted successfully, false otherwise
|
55
|
+
}
|
56
|
+
|
57
|
+
// Delete a student by first name
|
58
|
+
fun deleteStudent(firstName: String): Boolean {
|
59
|
+
val db = this.writableDatabase
|
60
|
+
val result = db.delete(
|
61
|
+
TABLE_STUDENTS,
|
62
|
+
"$COL_FIRST_NAME = ?",
|
63
|
+
arrayOf(firstName)
|
64
|
+
)
|
65
|
+
db.close()
|
66
|
+
return result > 0 // Returns true if one or more rows were deleted
|
67
|
+
}
|
68
|
+
|
69
|
+
// Update a student's name
|
70
|
+
fun updateStudent(oldFirstName: String, newFirstName: String, newLastName: String): Boolean {
|
71
|
+
val db = this.writableDatabase
|
72
|
+
val values = ContentValues().apply {
|
73
|
+
put(COL_FIRST_NAME, newFirstName)
|
74
|
+
put(COL_LAST_NAME, newLastName)
|
75
|
+
}
|
76
|
+
|
77
|
+
val result = db.update(
|
78
|
+
TABLE_STUDENTS,
|
79
|
+
values,
|
80
|
+
"$COL_FIRST_NAME = ?",
|
81
|
+
arrayOf(oldFirstName)
|
82
|
+
)
|
83
|
+
db.close()
|
84
|
+
return result > 0 // Returns true if one or more rows were updated
|
85
|
+
}
|
86
|
+
|
87
|
+
// Get all students
|
88
|
+
fun getAllStudents(): Cursor? {
|
89
|
+
val db = this.readableDatabase
|
90
|
+
return db.rawQuery("SELECT * FROM $TABLE_STUDENTS", null)
|
91
|
+
}
|
92
|
+
|
93
|
+
// Check if a student exists by first name
|
94
|
+
fun studentExists(firstName: String): Boolean {
|
95
|
+
val db = this.readableDatabase
|
96
|
+
val cursor = db.query(
|
97
|
+
TABLE_STUDENTS,
|
98
|
+
arrayOf(COL_ID),
|
99
|
+
"$COL_FIRST_NAME = ?",
|
100
|
+
arrayOf(firstName),
|
101
|
+
null, null, null
|
102
|
+
)
|
103
|
+
val exists = cursor.count > 0
|
104
|
+
cursor.close()
|
105
|
+
db.close()
|
106
|
+
return exists
|
107
|
+
}
|
108
|
+
}
|
@@ -0,0 +1,151 @@
|
|
1
|
+
package com.example.database
|
2
|
+
|
3
|
+
import android.content.DialogInterface
|
4
|
+
import android.database.Cursor
|
5
|
+
import android.support.v7.app.AppCompatActivity
|
6
|
+
import android.os.Bundle
|
7
|
+
import android.support.v7.app.AlertDialog
|
8
|
+
import android.view.LayoutInflater
|
9
|
+
import android.widget.Button
|
10
|
+
import android.widget.EditText
|
11
|
+
import android.widget.Toast
|
12
|
+
|
13
|
+
class MainActivity : AppCompatActivity() {
|
14
|
+
|
15
|
+
private lateinit var etFirstName: EditText
|
16
|
+
private lateinit var etLastName: EditText
|
17
|
+
private lateinit var btnAddStudent: Button
|
18
|
+
private lateinit var btnDeleteStudent: Button
|
19
|
+
private lateinit var btnUpdateStudent: Button
|
20
|
+
private lateinit var btnListStudents: Button
|
21
|
+
private lateinit var databaseHelper: DatabaseHelper
|
22
|
+
|
23
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
24
|
+
super.onCreate(savedInstanceState)
|
25
|
+
setContentView(R.layout.activity_main)
|
26
|
+
|
27
|
+
etFirstName = findViewById(R.id.et_firstName)
|
28
|
+
etLastName = findViewById(R.id.et_lastName)
|
29
|
+
btnAddStudent = findViewById(R.id.btn_addStudent)
|
30
|
+
btnDeleteStudent = findViewById(R.id.btn_deleteStudent)
|
31
|
+
btnUpdateStudent = findViewById(R.id.btn_updateStudent)
|
32
|
+
btnListStudents = findViewById(R.id.btn_listStudents)
|
33
|
+
|
34
|
+
databaseHelper = DatabaseHelper(this)
|
35
|
+
|
36
|
+
// Add Student
|
37
|
+
btnAddStudent.setOnClickListener {
|
38
|
+
val firstName = etFirstName.text.toString().trim()
|
39
|
+
val lastName = etLastName.text.toString().trim()
|
40
|
+
|
41
|
+
if (firstName.isEmpty() || lastName.isEmpty()) {
|
42
|
+
Toast.makeText(this, "Please enter both First Name and Last Name", Toast.LENGTH_SHORT).show()
|
43
|
+
return@setOnClickListener
|
44
|
+
}
|
45
|
+
|
46
|
+
if (databaseHelper.addStudent(firstName, lastName)) {
|
47
|
+
Toast.makeText(this, "Student added successfully!", Toast.LENGTH_SHORT).show()
|
48
|
+
etFirstName.text.clear()
|
49
|
+
etLastName.text.clear()
|
50
|
+
} else {
|
51
|
+
Toast.makeText(this, "Failed to add student. Maybe student already exists or an error occurred.", Toast.LENGTH_SHORT).show()
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
// Delete Student
|
56
|
+
btnDeleteStudent.setOnClickListener {
|
57
|
+
val firstName = etFirstName.text.toString().trim()
|
58
|
+
|
59
|
+
if (firstName.isEmpty()) {
|
60
|
+
Toast.makeText(this, "Please enter the First Name to delete", Toast.LENGTH_SHORT).show()
|
61
|
+
return@setOnClickListener
|
62
|
+
}
|
63
|
+
|
64
|
+
if (databaseHelper.deleteStudent(firstName)) {
|
65
|
+
Toast.makeText(this, "Student deleted successfully!", Toast.LENGTH_SHORT).show()
|
66
|
+
etFirstName.text.clear()
|
67
|
+
etLastName.text.clear()
|
68
|
+
} else {
|
69
|
+
Toast.makeText(this, "Failed to delete student. Student not found or an error occurred.", Toast.LENGTH_SHORT).show()
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
// Update Student
|
74
|
+
btnUpdateStudent.setOnClickListener {
|
75
|
+
val oldFirstName = etFirstName.text.toString().trim()
|
76
|
+
|
77
|
+
if (oldFirstName.isEmpty()) {
|
78
|
+
Toast.makeText(this, "Please enter the First Name of the student to update", Toast.LENGTH_SHORT).show()
|
79
|
+
return@setOnClickListener
|
80
|
+
}
|
81
|
+
|
82
|
+
if (!databaseHelper.studentExists(oldFirstName)) {
|
83
|
+
Toast.makeText(this, "Student with this First Name does not exist.", Toast.LENGTH_SHORT).show()
|
84
|
+
return@setOnClickListener
|
85
|
+
}
|
86
|
+
|
87
|
+
// Show an alert dialog to get the new name
|
88
|
+
val builder = AlertDialog.Builder(this)
|
89
|
+
builder.setTitle("Update Student Name")
|
90
|
+
|
91
|
+
// Set up the input fields
|
92
|
+
val dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_update_student, null)
|
93
|
+
val newFirstNameEt = dialogView.findViewById<EditText>(R.id.et_newFirstName)
|
94
|
+
val newLastNameEt = dialogView.findViewById<EditText>(R.id.et_newLastName)
|
95
|
+
builder.setView(dialogView)
|
96
|
+
|
97
|
+
// Set up the buttons
|
98
|
+
builder.setPositiveButton("Update") { dialog: DialogInterface, _: Int ->
|
99
|
+
val newFirstName = newFirstNameEt.text.toString().trim()
|
100
|
+
val newLastName = newLastNameEt.text.toString().trim()
|
101
|
+
|
102
|
+
if (newFirstName.isEmpty() || newLastName.isEmpty()) {
|
103
|
+
Toast.makeText(this, "New First Name and Last Name cannot be empty.", Toast.LENGTH_SHORT).show()
|
104
|
+
return@setPositiveButton
|
105
|
+
}
|
106
|
+
|
107
|
+
if (databaseHelper.updateStudent(oldFirstName, newFirstName, newLastName)) {
|
108
|
+
Toast.makeText(this, "Student updated successfully!", Toast.LENGTH_SHORT).show()
|
109
|
+
etFirstName.text.clear()
|
110
|
+
etLastName.text.clear()
|
111
|
+
} else {
|
112
|
+
Toast.makeText(this, "Failed to update student. An error occurred.", Toast.LENGTH_SHORT).show()
|
113
|
+
}
|
114
|
+
}
|
115
|
+
builder.setNegativeButton("Cancel") { dialog: DialogInterface, _: Int ->
|
116
|
+
dialog.cancel()
|
117
|
+
}
|
118
|
+
|
119
|
+
builder.show()
|
120
|
+
}
|
121
|
+
|
122
|
+
// List Students
|
123
|
+
btnListStudents.setOnClickListener {
|
124
|
+
val res = databaseHelper.getAllStudents()
|
125
|
+
if (res == null || res.count == 0) {
|
126
|
+
// Show message
|
127
|
+
showMessage("Error", "No students found")
|
128
|
+
return@setOnClickListener
|
129
|
+
}
|
130
|
+
|
131
|
+
val buffer = StringBuffer()
|
132
|
+
while (res.moveToNext()) {
|
133
|
+
buffer.append("ID: ${res.getString(0)}\n")
|
134
|
+
buffer.append("First Name: ${res.getString(1)}\n")
|
135
|
+
buffer.append("Last Name: ${res.getString(2)}\n\n")
|
136
|
+
}
|
137
|
+
|
138
|
+
// Show all data
|
139
|
+
showMessage("Student Data", buffer.toString())
|
140
|
+
res.close() // Close the cursor
|
141
|
+
}
|
142
|
+
}
|
143
|
+
|
144
|
+
private fun showMessage(title: String, message: String) {
|
145
|
+
val builder = AlertDialog.Builder(this)
|
146
|
+
builder.setCancelable(true)
|
147
|
+
builder.setTitle(title)
|
148
|
+
builder.setMessage(message)
|
149
|
+
builder.show()
|
150
|
+
}
|
151
|
+
}
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
4
|
+
xmlns:tools="http://schemas.android.com/tools"
|
5
|
+
android:layout_width="match_parent"
|
6
|
+
android:layout_height="match_parent"
|
7
|
+
android:orientation="vertical"
|
8
|
+
tools:context=".MainActivity">
|
9
|
+
|
10
|
+
<EditText
|
11
|
+
android:id="@+id/et_firstName"
|
12
|
+
android:layout_width="match_parent"
|
13
|
+
android:layout_height="wrap_content"
|
14
|
+
android:hint="First Name"
|
15
|
+
android:inputType="textPersonName"
|
16
|
+
android:layout_marginBottom="8dp"/>
|
17
|
+
|
18
|
+
<EditText
|
19
|
+
android:id="@+id/et_lastName"
|
20
|
+
android:layout_width="match_parent"
|
21
|
+
android:layout_height="wrap_content"
|
22
|
+
android:hint="Last Name"
|
23
|
+
android:inputType="textPersonName"
|
24
|
+
android:layout_marginBottom="16dp"/>
|
25
|
+
|
26
|
+
<Button
|
27
|
+
android:id="@+id/btn_addStudent"
|
28
|
+
android:layout_width="match_parent"
|
29
|
+
android:layout_height="wrap_content"
|
30
|
+
android:text="ADD STUDENT"
|
31
|
+
android:layout_marginBottom="8dp"/>
|
32
|
+
|
33
|
+
<Button
|
34
|
+
android:id="@+id/btn_deleteStudent"
|
35
|
+
android:layout_width="match_parent"
|
36
|
+
android:layout_height="wrap_content"
|
37
|
+
android:text="DELETE STUDENT"
|
38
|
+
android:layout_marginBottom="8dp"/>
|
39
|
+
|
40
|
+
<Button
|
41
|
+
android:id="@+id/btn_updateStudent"
|
42
|
+
android:layout_width="match_parent"
|
43
|
+
android:layout_height="wrap_content"
|
44
|
+
android:text="UPDATE STUDENT"
|
45
|
+
android:layout_marginBottom="8dp"/>
|
46
|
+
|
47
|
+
<Button
|
48
|
+
android:id="@+id/btn_listStudents"
|
49
|
+
android:layout_width="match_parent"
|
50
|
+
android:layout_height="wrap_content"
|
51
|
+
android:text="LIST STUDENTS"/>
|
52
|
+
|
53
|
+
|
54
|
+
</LinearLayout>
|
55
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
android:layout_width="match_parent"
|
4
|
+
android:layout_height="match_parent"
|
5
|
+
android:orientation="vertical">
|
6
|
+
|
7
|
+
<EditText
|
8
|
+
android:id="@+id/et_newFirstName"
|
9
|
+
android:layout_width="match_parent"
|
10
|
+
android:layout_height="wrap_content"
|
11
|
+
android:hint="New First Name"
|
12
|
+
android:inputType="textPersonName"
|
13
|
+
android:layout_marginBottom="8dp"/>
|
14
|
+
|
15
|
+
<EditText
|
16
|
+
android:id="@+id/et_newLastName"
|
17
|
+
android:layout_width="match_parent"
|
18
|
+
android:layout_height="wrap_content"
|
19
|
+
android:hint="New Last Name"
|
20
|
+
android:inputType="textPersonName"/>
|
21
|
+
|
22
|
+
</LinearLayout>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
package com.example.calendar
|
2
|
+
|
3
|
+
import android.support.v7.app.AppCompatActivity
|
4
|
+
import android.os.Bundle
|
5
|
+
import android.widget.DatePicker
|
6
|
+
import android.widget.Toast
|
7
|
+
import java.util.Calendar
|
8
|
+
|
9
|
+
class MainActivity : AppCompatActivity() {
|
10
|
+
override fun onCreate(savedInstanceState: Bundle?) {
|
11
|
+
super.onCreate(savedInstanceState)
|
12
|
+
setContentView(R.layout.activity_main)
|
13
|
+
|
14
|
+
val datePicker = findViewById<DatePicker>(R.id.datePicker1)
|
15
|
+
val today = Calendar.getInstance()
|
16
|
+
datePicker.init(today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH)) {
|
17
|
+
view, year, month, day ->
|
18
|
+
val month = month + 1
|
19
|
+
val msg = "You selected: $day/$month/$year"
|
20
|
+
Toast.makeText(this@MainActivity, msg, Toast.LENGTH_SHORT).show()
|
21
|
+
}
|
22
|
+
}
|
23
|
+
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
4
|
+
xmlns:tools="http://schemas.android.com/tools"
|
5
|
+
android:layout_width="match_parent"
|
6
|
+
android:layout_height="match_parent"
|
7
|
+
tools:context=".MainActivity">
|
8
|
+
|
9
|
+
<DatePicker
|
10
|
+
android:id="@+id/datePicker1"
|
11
|
+
android:layout_width="wrap_content"
|
12
|
+
android:layout_height="wrap_content"
|
13
|
+
android:datePickerMode="spinner"
|
14
|
+
android:calendarViewShown="false"
|
15
|
+
app:layout_constraintTop_toTopOf="parent"
|
16
|
+
app:layout_constraintStart_toStartOf="parent"
|
17
|
+
app:layout_constraintEnd_toEndOf="parent"
|
18
|
+
app:layout_constraintBottom_toBottomOf="parent"/>/>
|
19
|
+
|
20
|
+
</android.support.constraint.ConstraintLayout>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
|
3
|
+
<LinearLayout
|
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
|
+
android:orientation="vertical"
|
10
|
+
tools:context=".MainActivity">
|
11
|
+
|
12
|
+
<EditText
|
13
|
+
android:id="@+id/nameEt"
|
14
|
+
android:hint="Enter Name"
|
15
|
+
android:inputType="text"
|
16
|
+
android:layout_width="match_parent"
|
17
|
+
android:layout_height="wrap_content" />
|
18
|
+
|
19
|
+
<EditText
|
20
|
+
android:id="@+id/emailEt"
|
21
|
+
android:hint="Enter Email"
|
22
|
+
android:inputType="textEmailAddress"
|
23
|
+
android:layout_width="match_parent"
|
24
|
+
android:layout_height="wrap_content" />
|
25
|
+
|
26
|
+
<EditText
|
27
|
+
android:id="@+id/phoneEt"
|
28
|
+
android:hint="Enter Phone"
|
29
|
+
android:inputType="phone"
|
30
|
+
android:layout_width="match_parent"
|
31
|
+
android:layout_height="wrap_content" />
|
32
|
+
|
33
|
+
<Button
|
34
|
+
android:id="@+id/saveBtn"
|
35
|
+
android:text="Save"
|
36
|
+
android:layout_width="wrap_content"
|
37
|
+
android:layout_height="wrap_content" />
|
38
|
+
|
39
|
+
</LinearLayout>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
3
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
4
|
+
xmlns:tools="http://schemas.android.com/tools"
|
5
|
+
android:layout_width="match_parent"
|
6
|
+
android:layout_height="match_parent"
|
7
|
+
tools:context=".SecondActivity">
|
8
|
+
<TextView
|
9
|
+
android:id="@+id/resultTv"
|
10
|
+
android:textSize="30sp"
|
11
|
+
android:textStyle="bold"
|
12
|
+
android:textColor="#000"
|
13
|
+
android:layout_width="match_parent"
|
14
|
+
android:layout_height="wrap_content" />
|
15
|
+
</LinearLayout>
|