Skip to content

Commit 7ac8c9f

Browse files
committed
Updated Date and Time Picker Module
1 parent cb4a8cd commit 7ac8c9f

File tree

4 files changed

+73
-4
lines changed

4 files changed

+73
-4
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
package="source.open.akash.kotlinexample">
55

66
<dist:module dist:instant="true" />
7-
//internet permissions
7+
88
<uses-permission android:name="android.permission.INTERNET" />
9-
//call permissions
109
<uses-permission android:name="android.permission.CALL_PHONE" />
11-
//permissions required for camera open and capture image
1210
<uses-permission android:name="android.permission.CAMERA" />
11+
1312
<uses-feature android:name="android.hardware.camera" />
13+
1414
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
1515

1616
<application
@@ -20,7 +20,8 @@
2020
android:roundIcon="@mipmap/ic_launcher_round"
2121
android:supportsRtl="true"
2222
android:theme="@style/AppTheme">
23-
<activity android:name=".Intent.ExplicitIntentActivity.ReturnresultActivity"></activity>
23+
<activity android:name=".DateTime.DateTimeActivity"></activity>
24+
<activity android:name=".Intent.ExplicitIntentActivity.ReturnresultActivity" />
2425
<activity android:name=".Intent.ExplicitIntentActivity.SharedElementTransitionActivity" />
2526
<activity android:name=".Intent.ExplicitIntentActivity.SecondActivity" />
2627
<activity android:name=".Intent.ExplicitIntentActivity.ExplicitActivity" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package source.open.akash.kotlinexample.DateTime
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import kotlinx.android.synthetic.main.activity_date_time.*
6+
import source.open.akash.kotlinexample.Intent.ImlicitIntentActivity.toast
7+
import source.open.akash.kotlinexample.R
8+
import java.util.*
9+
10+
class DateTimeActivity : AppCompatActivity() {
11+
12+
13+
override fun onCreate(savedInstanceState: Bundle?) {
14+
super.onCreate(savedInstanceState)
15+
setContentView(R.layout.activity_date_time)
16+
17+
//date picker using xml attribute
18+
val calendar: Calendar = Calendar.getInstance()
19+
datePicker.init(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
20+
calendar.get(Calendar.DAY_OF_MONTH), { view, year, monthOfYear, dayOfMonth ->
21+
toast("Date: ${datePicker.dayOfMonth} ${datePicker.month} ${datePicker.year}")
22+
23+
})
24+
25+
//time picker using xml attribute
26+
timePicker.setOnTimeChangedListener({ view, hourOfDay, minute ->
27+
toast("Time : $hourOfDay : $minute")
28+
})
29+
30+
31+
}
32+
}

app/src/main/java/source/open/akash/kotlinexample/MainActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import android.os.Bundle
55
import androidx.appcompat.app.AppCompatActivity
66
import kotlinx.android.synthetic.main.activity_main.*
77
import source.open.akash.kotlinexample.AlertDialog.AlertDialogActivity
8+
import source.open.akash.kotlinexample.DateTime.DateTimeActivity
89
import source.open.akash.kotlinexample.Image.ImageActivity
910
import source.open.akash.kotlinexample.Intent.IntentActivityDemo
1011
import source.open.akash.kotlinexample.Toast.ToastActivity
@@ -40,6 +41,10 @@ class MainActivity : AppCompatActivity() {
4041
startActivity(Intent(this@MainActivity, IntentActivityDemo::class.java))
4142

4243
}
44+
DateTimeWidgetsDemo.setOnClickListener {
45+
startActivity(Intent(this@MainActivity, DateTimeActivity::class.java))
46+
47+
}
4348

4449
}
4550
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:orientation="vertical"
7+
tools:context=".DateTime.DateTimeActivity">
8+
9+
<ScrollView
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content">
12+
13+
<LinearLayout
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"
16+
android:orientation="vertical">
17+
18+
<DatePicker
19+
android:id="@+id/datePicker"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content" />
22+
23+
<TimePicker
24+
android:id="@+id/timePicker"
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content" />
27+
</LinearLayout>
28+
</ScrollView>
29+
30+
31+
</LinearLayout>

0 commit comments

Comments
 (0)