From 0c602fc848525280497c3fe0be961b94827986dc Mon Sep 17 00:00:00 2001 From: kavin-csquare Date: Mon, 30 Jun 2025 10:28:35 +0100 Subject: [PATCH 1/4] feat(sr): add demo bottom sheets dialogs and menu items (MOBILE-16529) --- .../androidsampleapp/SimpleActivity.kt | 81 ++++++++++++++++++ .../fragment/BottomSheetFragment.kt | 19 ++++ .../fragment/CustomAlertDialog.kt | 37 ++++++++ .../fragment/DatePickerFragment.kt | 35 ++++++++ .../fragment/TimePickerFragment.kt | 31 +++++++ .../main/res/drawable/dialog_background.xml | 4 + app/src/main/res/drawable/sense_ai_image.png | Bin 0 -> 30764 bytes app/src/main/res/layout/activity_simple.xml | 71 +++++++++++---- .../main/res/layout/dialog_custom_alert.xml | 34 ++++++++ .../layout/fragment_bottom_sheet_dialog.xml | 41 +++++++++ app/src/main/res/menu/simple_menu.xml | 12 +++ app/src/main/res/values/strings.xml | 14 +++ 12 files changed, 364 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/com/example/androidsampleapp/fragment/BottomSheetFragment.kt create mode 100644 app/src/main/java/com/example/androidsampleapp/fragment/CustomAlertDialog.kt create mode 100644 app/src/main/java/com/example/androidsampleapp/fragment/DatePickerFragment.kt create mode 100644 app/src/main/java/com/example/androidsampleapp/fragment/TimePickerFragment.kt create mode 100644 app/src/main/res/drawable/dialog_background.xml create mode 100644 app/src/main/res/drawable/sense_ai_image.png create mode 100644 app/src/main/res/layout/dialog_custom_alert.xml create mode 100644 app/src/main/res/layout/fragment_bottom_sheet_dialog.xml create mode 100644 app/src/main/res/menu/simple_menu.xml diff --git a/app/src/main/java/com/example/androidsampleapp/SimpleActivity.kt b/app/src/main/java/com/example/androidsampleapp/SimpleActivity.kt index 492e66a..0b1bf4d 100644 --- a/app/src/main/java/com/example/androidsampleapp/SimpleActivity.kt +++ b/app/src/main/java/com/example/androidsampleapp/SimpleActivity.kt @@ -1,11 +1,27 @@ package com.example.androidsampleapp +import android.content.DialogInterface import android.os.Bundle +import android.util.Log +import android.view.Menu +import android.view.MenuItem +import android.view.View +import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import com.contentsquare.android.Contentsquare +import com.contentsquare.android.api.sessionreplay.csqMaskPositiveButton +import com.contentsquare.android.api.sessionreplay.csqMaskTitle import com.example.androidsampleapp.analytics.Analytics +import com.example.androidsampleapp.fragment.BottomSheetFragment +import com.example.androidsampleapp.fragment.CustomAlertDialog +import com.example.androidsampleapp.fragment.DatePickerFragment +import com.example.androidsampleapp.fragment.TimePickerFragment +import java.util.Locale class SimpleActivity : AppCompatActivity() { + private val TAG: String? = SimpleActivity::class.simpleName + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_simple) @@ -15,4 +31,69 @@ class SimpleActivity : AppCompatActivity() { super.onResume() Analytics.tagScreen("Simple-Activity") } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.simple_menu, menu) + + // Apply masking for menu items here + Contentsquare.unMaskMenuItem(R.id.menu_unmasked_item) + Contentsquare.maskMenuItem(R.id.menu_masked_item) + Analytics.tagScreen("Simple_Menu") + + return super.onCreateOptionsMenu(menu) + } + + fun openBottomSheets(view: View) { + val bottomSheetFragment = BottomSheetFragment() + bottomSheetFragment.show(supportFragmentManager, bottomSheetFragment.tag) + Analytics.tagScreen("Bottom_Sheets") + } + + fun openDatePicker(view: View) { + val datePickerFragment = DatePickerFragment { year, month, day -> + val formattedDate = "$day/${month + 1}/$year" + Log.i(TAG, "Selected Date: $formattedDate") + } + datePickerFragment.show(supportFragmentManager, "datePicker") + Analytics.tagScreen("Date_Picker") + } + + fun openTimePicker(view: View) { + val timePickerFragment = TimePickerFragment { hour, minute -> + val formattedTime = String.format(Locale.ROOT, "%02d:%02d", hour, minute) + Log.i(TAG, "Selected Time: $formattedTime") + } + timePickerFragment.show(supportFragmentManager, "timePicker") + Analytics.tagScreen("Time_Picker") + } + + fun openAlertDialog(view: View) { + val builder: AlertDialog.Builder = AlertDialog.Builder(this@SimpleActivity) + builder.setMessage(getString(R.string.alert_message)) + builder.setTitle(getString(R.string.alert_title)) + builder.setCancelable(true) + builder.setPositiveButton(getString(R.string.ok)) { dialog: DialogInterface?, _: Int -> + dialog?.cancel() + } + val alertDialog: AlertDialog = builder.create() + alertDialog.show() + + // Apply Masking only after the show() is called + alertDialog.csqMaskTitle() + alertDialog.csqMaskPositiveButton() + Analytics.tagScreen("Simple_Dialog") + } + + fun openCustomAlertDialog(view: View) { + val dialog = CustomAlertDialog( + context = this, + message = getString(R.string.sense_ai_description_short), + imageResId = R.drawable.sense_ai_image, + onOkPressed = { + Log.i(TAG, "CustomAlertDialog: OK button tapped") + } + ) + dialog.show() + Analytics.tagScreen("Simple_Custom_Dialog") + } } diff --git a/app/src/main/java/com/example/androidsampleapp/fragment/BottomSheetFragment.kt b/app/src/main/java/com/example/androidsampleapp/fragment/BottomSheetFragment.kt new file mode 100644 index 0000000..519d17a --- /dev/null +++ b/app/src/main/java/com/example/androidsampleapp/fragment/BottomSheetFragment.kt @@ -0,0 +1,19 @@ +package com.example.androidsampleapp.fragment + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import com.example.androidsampleapp.R + +class BottomSheetFragment : BottomSheetDialogFragment() { + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_bottom_sheet_dialog, container, false) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/androidsampleapp/fragment/CustomAlertDialog.kt b/app/src/main/java/com/example/androidsampleapp/fragment/CustomAlertDialog.kt new file mode 100644 index 0000000..9ee371b --- /dev/null +++ b/app/src/main/java/com/example/androidsampleapp/fragment/CustomAlertDialog.kt @@ -0,0 +1,37 @@ +package com.example.androidsampleapp.fragment + +import android.app.Dialog +import android.content.Context +import android.os.Bundle +import android.widget.Button +import android.widget.ImageView +import android.widget.TextView +import com.contentsquare.android.Contentsquare +import com.example.androidsampleapp.R + +class CustomAlertDialog( + context: Context, + private val message: String, + private val imageResId: Int = R.drawable.sense_ai_image, + private val onOkPressed: (() -> Unit)? = null +) : Dialog(context) { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.dialog_custom_alert) + + val messageView = findViewById(R.id.alert_message) + val imageView = findViewById(R.id.alert_image) + val okButton = findViewById