Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Com 00003 dialogs #3

Merged
merged 6 commits into from
May 4, 2020
Merged

Com 00003 dialogs #3

merged 6 commits into from
May 4, 2020

Conversation

AnelCC
Copy link
Owner

@AnelCC AnelCC commented May 4, 2020

03 Dialogs

A dialog is a small window that prompts the user to make a decision or enter additional information. A dialog does not fill the screen and is normally used for modal events that require users to take an action before they can proceed.

  • Interumptive - stop current program flow
  • Require the user to take action
  • Maintain the user's current context

DialogPage

1. Created simple dialog

Create instance in the activity

val simpleDialog = SimpleDialogFragment()
        simpleDialog.setCancelable(false);
        simpleDialog.show(supportFragmentManager, "SimpleDialogFragment")

Create DialogFragment

class SimpleDialogFragment : DialogFragment() {
    ....
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val builder = AlertDialog.Builder(activity!!)
         ...
        return builder.create()
    }

Created interface to listener events

interface SimpleDialogListener {
    fun onPositiveResult(dlg: DialogFragment)
    fun onNegativeResult(dlg: DialogFragment)
    fun onNeutralResult(dlg: DialogFragment)
}

Implement interface SimpleDialogListener

 override fun onAttach(context: Context) {
        ...
            simpleDialogListener = context as SimpleDialogListener
        ...
    }

Dialog_SimpleDialog

2. Created DatePickerDialog

val cal = Calendar.getInstance()
val datePicker = DatePickerDialog(this,
    DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth ->
        Log.i(TAG, String.format("Date Chosen -- day: %d, month: %d, year: %d", dayOfMonth, monthOfYear, year)) },
    cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH))
datePicker.setTitle("Choose a Date")
datePicker.show()

Dialog_DatePicker

3. Created SingleChoiceDialogFragment

class SingleChoiceDialogFragment : DialogFragment() {
    ...
    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val builder = AlertDialog.Builder(activity)
        ...
        return builder.create()
    }
}
val complexDialog = SingleChoiceDialogFragment() complexDialog.show(supportFragmentManager, "SingleChoiceDialogFragment")

Dialog_dialogChoice
###4. Created Custom Dialog Fragment

val customDialog = CustomDialogFragment()
customDialog.show(supportFragmentManager, "CustomDialogFragment")
class CustomDialogFragment : DialogFragment() {
    private val TAG = "CustomDialogFragment"

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val builder = AlertDialog.Builder(activity!!)

        // Create the custom layout using the LayoutInflater class
        val inflater = activity!!.layoutInflater
        val v = inflater.inflate(R.layout.custom_dialog_layout, null)

        // Build the dialog
        builder.setTitle("Please enter your info")
            .setPositiveButton("OK") { dialog, which -> Log.i(TAG, "OK Clicked") }
            .setNegativeButton("Cancel") { dialog, which -> Log.i(TAG, "Cancel clicked") }
            .setView(v)

        return builder.create()
    }
}

Dialog_CustomFragment

@AnelCC AnelCC merged commit 9bdec62 into master May 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant