This library is a collection of components and utilities that will be used in other Octopus Android projects
Step 1. Add the JitPack repository to your build file Add it in your root build.gradle at the end of repositories:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.Octopus-Indonesia:octopusplatform-sdk-android:{latest-version}'
}
Simply implement TimePickerListener
in your activity, call the method and show it
import id.co.octopus.library.core.DialogUtils
import id.co.octopus.library.core.timepicker.TimePickerListener
class MainActivity : AppCompatActivity(), TimePickerListener {
private fun showDialog() {
DialogUtils.showTimePickerBottomDialog(
this@MainActivity,
"Title Dialog",
textView.text.toString(),
this@MainActivity
)
}
/*
* Get time who picked in time picker dialog
* */
override fun onPicked(timePicked: String) {
Log.d(TAG, timePicked)
textView.text = timePicked
}
}
timepicker-demo.mp4
import id.co.octopus.library.core.DialogUtils
import id.co.octopus.library.core.textpicker.TextPickerListener
import id.co.octopus.library.core.textpicker.TextPickerView
class MainActivity : AppCompatActivity(), TextPickerListener //implement the listener
{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//init the view
val textPickerView = findViewById<TextPickerView>(R.id.textPickerView)
//set list to component
val list = listOf("Item 1", "Item 2", "Item 3 Item 3 Item 3 Item 3 Item 3 Item 3 Item 3 Item 3")
textPickerView.setCustomList(list)
button.setOnClickListener {
Log.d(TAG, "${textPickerView.getTextPicked()}")
}
}
/*
* Get text who selected in bottom dialog
* */
override fun onTextPicked(textSelected: String) {
Toast.makeText(
this,
"textSelected: $textSelected",
Toast.LENGTH_SHORT
).show()
}
}
If you need to add Material Date/Time picker for the layout. All you have to do is :
<id.co.octopus.library.core.textpicker.TextPickerView
android:id="@+id/textPickerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:textGravityOfPicker="center"
app:textSizePickerDefault="18sp"
app:textSizePickerSelected="20sp"
app:backgroundCenterOfView="@drawable/bg_green"
/>
Attribute | Format | Default |
---|---|---|
backgroundCenterOfView |
reference | drawable |
textColorPickerSelected |
color | #151515 |
textColorPickerDefault |
color | #AEAEAE |
textSizePickerSelected |
dimension | 20sp |
textSizePickerDefault |
dimension | 18sp |
textGravityOfPicker |
integer | start/center/end |
import id.co.octopus.library.core.DialogUtils
import id.co.octopus.library.core.textpicker.TextPickerListener
import id.co.octopus.library.core.textpicker.TextPickerView
class MainActivity : AppCompatActivity(), TextPickerListener //implement the listener
{
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
button.setOnClickListener {
DialogUtils.showTextPickerBottomDialog(
context = this@MainActivity,
dialogTitle = "Choose Gender",
list = list,
listener = this@MainActivity,
textSizePickerSelected = resources.getDimension(R.dimen.text_picker_view_selected_size), //default is 20sp
textSizePickerDefault = resources.getDimension(R.dimen.text_picker_view_default_size) //default is 18sp
textColorPickerSelected = Color.GREEN, //default is #151515
textColorPickerDefault = resources.getColor(R.color.purple_200) //default is #AEAEAE
)
}
}
/*
* Get text who selected in bottom dialog
* */
override fun onTextPicked(textSelected: String) {
Toast.makeText(
this,
"textSelected: $textSelected",
Toast.LENGTH_SHORT
).show()
}
}