-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e53e39b
commit bf4a552
Showing
11 changed files
with
317 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
...src/main/java/com/siliconlabs/bledemo/features/iop_test/utils/DialogDeviceInfoFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package com.siliconlabs.bledemo.features.iop_test.utils | ||
|
||
import android.app.AlertDialog | ||
import android.app.Dialog | ||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.DialogFragment | ||
import com.siliconlabs.bledemo.R | ||
import com.siliconlabs.bledemo.databinding.DialogDeviceInfoLayoutBinding | ||
|
||
class DialogDeviceInfoFragment : DialogFragment() { | ||
var title: String? = null | ||
var message: String? = null | ||
var positiveButtonText: String? = null | ||
var negativeButtonText: String? = null | ||
var positiveClickListener: DialogInterface.OnClickListener? = null | ||
var negativeClickListener: DialogInterface.OnClickListener? = null | ||
lateinit var binding: DialogDeviceInfoLayoutBinding | ||
|
||
private var dialogShowing = false | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? { | ||
binding = DialogDeviceInfoLayoutBinding.inflate(inflater, container, false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
|
||
// Set title and message | ||
binding.dialogTitle.text = title | ||
binding.dialogMessage.text = message | ||
|
||
// Set positive button click listener | ||
binding.btnPositive.setOnClickListener { | ||
positiveClickListener?.onClick(dialog, DialogInterface.BUTTON_POSITIVE) | ||
dismiss() | ||
} | ||
|
||
// Set negative button click listener | ||
binding.btnNegative.setOnClickListener { | ||
negativeClickListener?.onClick(dialog, DialogInterface.BUTTON_NEGATIVE) | ||
dismiss() | ||
} | ||
|
||
// Set button texts | ||
binding.btnPositive.text = positiveButtonText | ||
binding.btnNegative.text = negativeButtonText | ||
|
||
} | ||
/*override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
val builder = AlertDialog.Builder(requireActivity()) | ||
builder.setTitle(title) | ||
builder.setMessage(message) | ||
if (positiveButtonText != null) { | ||
builder.setPositiveButton(positiveButtonText, positiveClickListener) | ||
} | ||
if (negativeButtonText != null) { | ||
builder.setNegativeButton(negativeButtonText, negativeClickListener) | ||
} | ||
val dialog = builder.create() | ||
dialog.setOnShowListener { | ||
dialogShowing = true | ||
} | ||
dialog.setOnDismissListener { | ||
dialogShowing = false | ||
} | ||
return dialog | ||
}*/ | ||
|
||
// Builder pattern for setting dialog properties | ||
class Builder { | ||
private val fragment = DialogDeviceInfoFragment() | ||
|
||
fun setTitle(title: String?): Builder { | ||
fragment.title = title | ||
return this | ||
} | ||
|
||
fun setMessage(message: String?): Builder { | ||
fragment.message = message | ||
return this | ||
} | ||
|
||
fun setPositiveButton(text: String?, listener: DialogInterface.OnClickListener?): Builder { | ||
fragment.positiveButtonText = text | ||
fragment.positiveClickListener = listener | ||
return this | ||
} | ||
|
||
fun setNegativeButton(text: String?, listener: DialogInterface.OnClickListener?): Builder { | ||
fragment.negativeButtonText = text | ||
fragment.negativeClickListener = listener | ||
return this | ||
} | ||
|
||
fun build(): DialogDeviceInfoFragment { | ||
return fragment | ||
} | ||
} | ||
|
||
fun isShowing(): Boolean { | ||
return dialogShowing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!-- rounded_dialog_background.xml --> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<corners android:radius="@dimen/matter_10dp" /> <!-- Adjust radius as needed --> | ||
<solid android:color="@android:color/white" /> <!-- Background color --> | ||
</shape> |
Oops, something went wrong.