-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Allow to capture screenshots of modal Dialogs (PR #221 from den…
…nisdeng2002/dialog-screenshot)
- Loading branch information
Showing
9 changed files
with
184 additions
and
33 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
maoni-sample/src/main/java/org/rm3l/maoni/sample/ui/MaoniBottomSheetDialogFragment.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,42 @@ | ||
package org.rm3l.maoni.sample.ui | ||
|
||
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.google.android.material.floatingactionbutton.FloatingActionButton | ||
import org.rm3l.maoni.Maoni | ||
import org.rm3l.maoni.sample.R | ||
import org.rm3l.maoni.sample.utils.MaoniUtils | ||
|
||
class MaoniBottomSheetDialogFragment : BottomSheetDialogFragment() { | ||
|
||
private var maoni: Maoni? = null | ||
|
||
override fun getTheme(): Int = R.style.RoundedBottomSheetDialog | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, | ||
container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View? = inflater.inflate( | ||
R.layout.bottom_sheet_dialog_fragment_maoni, | ||
container, | ||
false | ||
) | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
view.findViewById<FloatingActionButton>(R.id.fab) | ||
?.setOnClickListener { | ||
maoni = MaoniUtils.buildMaoni(requireContext()) | ||
maoni?.start(dialog) | ||
} | ||
} | ||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
maoni?.clear() | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
maoni-sample/src/main/java/org/rm3l/maoni/sample/utils/MaoniUtils.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,40 @@ | ||
package org.rm3l.maoni.sample.utils | ||
|
||
import android.content.Context | ||
import android.preference.PreferenceManager | ||
import org.rm3l.maoni.Maoni | ||
import org.rm3l.maoni.common.contract.Handler | ||
import org.rm3l.maoni.sample.extensions.getMaoniFeedbackBuilder | ||
import org.rm3l.maoni.sample.extensions.getMaoniFeedbackHandler | ||
|
||
object MaoniUtils { | ||
|
||
@JvmStatic | ||
fun buildMaoni(context: Context): Maoni { | ||
val handlerForMaoni: Handler = context.getMaoniFeedbackHandler() //Custom handler for Maoni, which does nothing more than calling any of the maoni-* available callbacks | ||
val maoniBuilder: Maoni.Builder = context.getMaoniFeedbackBuilder() | ||
// MaoniActivity de-registers handlers, listeners and validators upon activity destroy, | ||
// so we need to re-register it again by reconstructing a new Maoni instance. | ||
// Also, Maoni.start(...) cannot be called twice, | ||
// but we are reusing the Builder to construct a new instance along with its handler. | ||
// | ||
//Note that if no handler/listener is specified, | ||
//Maoni will fall back to opening an Email Intent, so your users can send | ||
//their feedback via email | ||
// MaoniActivity de-registers handlers, listeners and validators upon activity destroy, | ||
// so we need to re-register it again by reconstructing a new Maoni instance. | ||
// Also, Maoni.start(...) cannot be called twice, | ||
// but we are reusing the Builder to construct a new instance along with its handler. | ||
// | ||
//Note that if no handler/listener is specified, | ||
//Maoni will fall back to opening an Email Intent, so your users can send | ||
//their feedback via email | ||
val defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context) | ||
return maoniBuilder | ||
.withScreenCapturingFeature(defaultSharedPreferences | ||
.getBoolean("maoni_screen_capturing_enabled", true)) | ||
.withLogsCapturingFeature(defaultSharedPreferences | ||
.getBoolean("maoni_logs_capturing_enabled", true)) | ||
.withHandler(handlerForMaoni).build() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
maoni-sample/src/main/res/layout/bottom_sheet_dialog_fragment_maoni.xml
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,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content"> | ||
|
||
<TextView | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:gravity="center" | ||
android:padding="10dp" | ||
android:text="@string/main_activity_text" | ||
android:textAppearance="?android:textAppearanceLarge" | ||
android:textColor="@color/white" /> | ||
|
||
<com.google.android.material.floatingactionbutton.FloatingActionButton | ||
android:id="@+id/fab" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:layout_margin="@dimen/fab_margin" | ||
android:src="@drawable/ic_feedback_white_24dp" | ||
app:tint="@color/white" /> | ||
|
||
</androidx.coordinatorlayout.widget.CoordinatorLayout> |
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
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